Skip to content

Commit

Permalink
#2424 / #2587 refactoring to allow socket options to be used for sock…
Browse files Browse the repository at this point in the history
…et upgrades

git-svn-id: https://xpra.org/svn/Xpra/trunk@27656 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 12, 2020
1 parent 7681085 commit 9a3fcc7
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/xpra/net/bytestreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def untilConcludes(self, *args):

def peek(self, _n : int):
#not implemented
return None
return b""

def _write(self, *args):
""" wraps do_write with packet accounting """
Expand Down
8 changes: 4 additions & 4 deletions src/xpra/net/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
InvalidCompressionException, Compressed, LevelCompressed, Compressible, LargeStructure,
)
from xpra.net import packet_encoding
from xpra.net.socket_util import guess_header_protocol
from xpra.net.socket_util import guess_packet_type
from xpra.net.packet_encoding import (
decode, sanity_checks as packet_encoding_sanity_checks,
InvalidPacketEncodingException,
Expand Down Expand Up @@ -753,9 +753,9 @@ def invalid_header(self, proto, data, msg="invalid packet header"):
def _invalid_header(self, proto, data, msg=""):
log("invalid_header(%s, %s bytes: '%s', %s)",
proto, len(data or ""), msg, ellipsizer(data))
guess = guess_header_protocol(data)
if guess[0]:
err = "invalid packet format, %s" % guess[1]
guess = guess_packet_type(data)
if guess:
err = "invalid packet format: %s" % guess
else:
err = "%s: '%s'" % (msg, hexstr(data[:HEADER_SIZE]))
if len(data)>1:
Expand Down
39 changes: 17 additions & 22 deletions src/xpra/net/socket_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
EXIT_SERVER_ALREADY_EXISTS, EXIT_SOCKET_CREATION_ERROR,
)
from xpra.os_util import (
hexstr, bytestostr,
getuid, get_username_for_uid, get_groups, get_group_id,
path_permission_info, monotonic_time, umask_context, WIN32, OSX, POSIX,
)
from xpra.util import (
envint, envbool, csv, parse_simple_dict,
ellipsizer, repr_ellipsized,
ellipsizer,
DEFAULT_PORT,
)
from xpra.make_thread import start_thread
Expand Down Expand Up @@ -419,14 +418,23 @@ def peek_connection(conn, timeout=PEEK_TIMEOUT_MS, size=PEEK_SIZE):
sleep(timeout/4000.0)
elapsed = int(1000*(monotonic_time()-start))
log("peek: elapsed=%s, timeout=%s", elapsed, timeout)
line1 = b""
log("socket %s peek: got %i bytes", conn, len(peek_data))
if peek_data:
line1 = peek_data.splitlines()[0]
log("socket peek=%s", ellipsizer(peek_data, limit=512))
log("socket peek hex=%s", hexstr(peek_data[:128]))
log("socket peek line1=%s", ellipsizer(line1))
return peek_data, line1
return peek_data


def guess_packet_type(data):
if not data:
return None
if data[0]==ord("P") and data[1]==0:
return "xpra"
if data[:4]==b"SSH-":
return "ssh"
if data[0]==0x16:
return "ssl"
line1 = data.splitlines()[0]
if line1.find(b"HTTP/")>0 or line1.split(b" ")[0] in (b"GET", b"POST"):
return "http"
return None


def create_sockets(opts, error_cb):
Expand Down Expand Up @@ -880,19 +888,6 @@ def handle_socket_error(sockpath, sperms, e):
"failed to create socket %s" % sockpath)


def guess_header_protocol(v):
c = int(v[0])
s = bytestostr(v)
get_network_logger().debug("guess_header_protocol(%r) first char=%#x", repr_ellipsized(s), c)
if c==0x16:
return "ssl", "SSL packet?"
if s[:4]=="SSH-":
return "ssh", "SSH packet"
if len(s)>=3 and s.split(" ")[0] in ("GET", "POST"):
return "HTTP", "HTTP %s request" % s.split(" ")[0]
return None, "character %#x, not an xpra client?" % c


#warn just once:
MDNS_WARNING = False
def mdns_publish(display_name, listen_on, text_dict=None):
Expand Down
Loading

0 comments on commit 9a3fcc7

Please sign in to comment.