Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This file is part of Xpra. 

2# Copyright (C) 2013-2020 Antoine Martin <antoine@xpra.org> 

3# Xpra is released under the terms of the GNU GPL v2, or, at your option, any 

4# later version. See the file COPYING for details. 

5 

6import os 

7import threading 

8 

9from xpra.util import repr_ellipsized, envint, envbool 

10from xpra.log import Logger 

11log = Logger("network") 

12 

13class ConnectionClosedException(Exception): 

14 pass 

15 

16MAX_PACKET_SIZE = envint("XPRA_MAX_PACKET_SIZE", 16*1024*1024) 

17FLUSH_HEADER = envbool("XPRA_FLUSH_HEADER", True) 

18 

19SOCKET_TYPES = ("tcp", "ws", "wss", "ssl", "ssh", "rfb", "vsock", "udp") 

20 

21IP_SOCKTYPES = ("tcp", "ssl", "ws", "wss", "ssh", "udp") 

22TCP_SOCKTYPES = ("tcp", "ssl", "ws", "wss", "ssh") 

23 

24 

25#this is used for generating aliases: 

26PACKET_TYPES = [ 

27 "hello", "info", 

28 "open-url", "send-file", "send-data-request", "send-data-response", "ack-file-chunk", "send-file-chunk", 

29 "sound-data", "new-stream", "state-changed", "new-buffer", "cleanup", "add_data", "stop", 

30 "ping", "ping_echo", 

31 "info-response", "server-event", 

32 "disconnect", "set_deflate", "connection-lost", "gibberish", "invalid", 

33 "show-desktop", "desktop_size", 

34 "new-window", "new-override-redirect", "new-tray", 

35 "raise-window", "initiate-moveresize", "window-move-resize", "window-resized", "window-metadata", 

36 "configure-override-redirect", "lost-window", "window-icon", 

37 "draw", 

38 "eos", "cursor", "bell", 

39 "pointer-position", "pointer-grab", "pointer-ungrab", 

40 "webcam-stop", "webcam-ack", 

41 "set-clipboard-enabled", "clipboard-token", "clipboard-request", 

42 "clipboard-contents", "clipboard-contents-none", "clipboard-pending-requests", "clipboard-enable-selections", 

43 "notify_show", "notify_close", 

44 "rpc-reply", "startup-complete", "setting-change", "control", 

45 "encodings", 

46 "udp-control", 

47 ] 

48 

49def get_log_packets(exclude=False): 

50 lp = os.environ.get("XPRA_LOG_PACKETS") 

51 if not lp: 

52 return None 

53 pt = [] 

54 for x in lp.split(","): 

55 if x.startswith("-")==exclude: 

56 pt.append(x[int(exclude):]) 

57 return tuple(pt) 

58 

59def _may_log_packet(sending, packet_type, packet): 

60 if LOG_PACKET_TYPE: 

61 log.info("%s %s (thread=%s)", "sending " if sending else "receiving", packet_type, threading.current_thread()) 

62 if LOG_PACKETS or NOLOG_PACKETS: 

63 if packet_type in NOLOG_PACKETS: 

64 return 

65 if packet_type in LOG_PACKETS or "*" in LOG_PACKETS: 

66 s = str(packet) 

67 if len(s)>PACKET_LOG_MAX_SIZE: 

68 s = repr_ellipsized(s, PACKET_LOG_MAX_SIZE) 

69 log.info(s) 

70 

71def noop(*_args): 

72 pass 

73 

74 

75LOG_PACKETS = None 

76NOLOG_PACKETS = None 

77LOG_PACKET_TYPE = False 

78PACKET_LOG_MAX_SIZE = 500 

79 

80may_log_packet = noop 

81 

82def init(): 

83 global LOG_PACKETS, NOLOG_PACKETS, LOG_PACKET_TYPE, PACKET_LOG_MAX_SIZE 

84 LOG_PACKETS = get_log_packets() 

85 NOLOG_PACKETS = get_log_packets(True) 

86 LOG_PACKET_TYPE = envbool("XPRA_LOG_PACKET_TYPE", False) 

87 

88 PACKET_LOG_MAX_SIZE = envint("XPRA_PACKET_LOG_MAX_SIZE", 500) 

89 

90 global may_log_packet 

91 if LOG_PACKETS or NOLOG_PACKETS or LOG_PACKET_TYPE: 

92 may_log_packet = _may_log_packet 

93 else: 

94 may_log_packet = noop 

95 

96init()