Skip to content

Commit

Permalink
#3599 rename 'unix-domain' to 'socket'
Browse files Browse the repository at this point in the history
so that the client and server can become more symetrical:
the same noun can be used for client URLs (ie: 'socket:///some/path')
and the server object is now called a 'socket' type
  • Loading branch information
totaam committed Oct 20, 2022
1 parent eb5bb12 commit 1d188dc
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tests/unittests/unit/scripts/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def fd(d):
f(type="invalid", display_name="test")
f(type="vsock", display_name="test", vsock=(10, 1000))
fd({"type" : "named-pipe", "display_name" : "test", "named-pipe" : "TEST-INVALID"})
f(type="unix-domain", display_name=":100000", display="100000")
f(type="socket", display_name=":100000", display="100000")
for socktype in ("tcp", "ssl", "ws", "wss", ):
f(type=socktype, display_name="test", host="localhost", port=100000)
for paramiko in (True, False):
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/unit/scripts/parse_display_name_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def e(s):
raise Exception(f"parse_display_name should fail for {s}")
if POSIX:
e("ZZZZZZ")
t("10", {"display_name" : ":10", "local" : True, "type" : "unix-domain"})
t("10", {"display_name" : ":10", "local" : True, "type" : "socket"})
t(socket_dir+"/thesocket", {"display_name" : "socket://"+socket_dir+"/thesocket"})
t("socket:"+socket_dir+"/thesocket", {"display_name" : "socket:"+socket_dir+"/thesocket"})
e("tcp://host:NOTANUMBER/")
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/unit/server/mixins/fileprint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create_test_sockets(self):
return ()
return [
#socktype, socket, sockpath, cleanup_socket
("unix-domain", None, "/fake/path", None)
("socket", None, "/fake/path", None)
]

def test_fileprint(self):
Expand Down
7 changes: 5 additions & 2 deletions xpra/client/gtk_base/client_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def connect_builtin(self):
params["remote_xpra"] = self.config.remote_xpra
params["proxy_command"] = ["_proxy"]
if self.config.port and self.config.port>0:
params["display"] = ":%s" % self.config.port
params["display"] = f":{self.config.port}"
params["display_as_args"] = [params["display"]]
else:
params["display"] = "auto"
Expand Down Expand Up @@ -761,7 +761,10 @@ def connect_builtin(self):
params["full_ssh"] = full_ssh
params["password"] = password
params["display_name"] = f"ssh://{self.config.host}:{self.config.port}"
elif self.config.mode=="unix-domain":
elif self.config.mode=="display":
params["display"] = f":{self.config.port}"
params["display_name"] = f":{self.config.port}"
elif self.config.mode in ("socket", "unix-domain"):
params["display"] = f":{self.config.port}"
params["display_name"] = f"unix-domain:{self.config.port}"
else:
Expand Down
2 changes: 1 addition & 1 deletion xpra/net/bytestreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def log_new_connection(conn, socket_info=""):
log.info(" from '%s'", pretty_socket(frominfo))
if socket_info:
log.info(" on '%s'", pretty_socket(socket_info))
elif socktype=="unix-domain":
elif socktype=="socket":
frominfo = sockname
log.info(" on '%s'", frominfo)
else:
Expand Down
2 changes: 1 addition & 1 deletion xpra/net/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConnectionClosedException(Exception):
MAX_PACKET_SIZE = envint("XPRA_MAX_PACKET_SIZE", 16*1024*1024)
FLUSH_HEADER = envbool("XPRA_FLUSH_HEADER", True)

SOCKET_TYPES = ("tcp", "ws", "wss", "ssl", "ssh", "rfb", "vsock", "socket", "unix-domain", "named-pipe")
SOCKET_TYPES = ("tcp", "ws", "wss", "ssl", "ssh", "rfb", "vsock", "socket", "named-pipe")

IP_SOCKTYPES = ("tcp", "ssl", "ws", "wss", "ssh")
TCP_SOCKTYPES = ("tcp", "ssl", "ws", "wss", "ssh")
Expand Down
5 changes: 3 additions & 2 deletions xpra/net/socket_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
PEEK_TIMEOUT = envint("XPRA_PEEK_TIMEOUT", 1)
PEEK_TIMEOUT_MS = envint("XPRA_PEEK_TIMEOUT_MS", PEEK_TIMEOUT*1000)
UNIXDOMAIN_PEEK_TIMEOUT_MS = envint("XPRA_UNIX_DOMAIN_PEEK_TIMEOUT_MS", 100)
SOCKET_PEEK_TIMEOUT_MS = envint("XPRA_SOCKET_PEEK_TIMEOUT_MS", UNIXDOMAIN_PEEK_TIMEOUT_MS)
PEEK_SIZE = envint("XPRA_PEEK_SIZE", 8192)

SOCKET_DIR_MODE = num = int(os.environ.get("XPRA_SOCKET_DIR_MODE", "775"), 8)
Expand Down Expand Up @@ -643,7 +644,7 @@ def timeout_probe(sockpath):
log.warn("Warning: some of the sockets are in an unknown state:")
for sockpath in unknown:
log.warn(" %s", sockpath)
t = start_thread(timeout_probe, "probe-%s" % sockpath, daemon=True, args=(sockpath,))
t = start_thread(timeout_probe, f"probe-{sockpath}", daemon=True, args=(sockpath,))
threads.append(t)
log.warn(" please wait as we allow the socket probing to timeout")
#wait for all the threads to do their job:
Expand Down Expand Up @@ -683,7 +684,7 @@ def timeout_probe(sockpath):
try:
sock, cleanup_socket = create_unix_domain_socket(sockpath, sperms)
log.info(f"created unix domain socket {sockpath!r}")
defs[("unix-domain", sock, sockpath, cleanup_socket)] = options
defs[("socket", sock, sockpath, cleanup_socket)] = options
except Exception as e:
handle_socket_error(sockpath, sperms, e)
del e
Expand Down
2 changes: 1 addition & 1 deletion xpra/platform/xposix/sd_listen.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_sd_listen_socket(int fd):
if sd_is_socket_unix(fd, socket.SOCK_STREAM, 1, NULL, 0)>0:
sock = fromfd(socket.AF_UNIX, socket.SOCK_STREAM)
sockpath = sock.getsockname()
return "unix-domain", sock, sockpath
return "socket", sock, sockpath
for family in (socket.AF_INET, socket.AF_INET6):
if sd_is_socket_inet(fd, family, socket.SOCK_STREAM, 1, 0)>0:
sock = fromfd(family, socket.SOCK_STREAM)
Expand Down
8 changes: 4 additions & 4 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def do_pick_display(dotxpra, error_cb, opts, extra_args, cmdline=()):
dir_servers = dotxpra.socket_details(matching_state=DotXpra.LIVE)
try:
sockdir, display, sockpath = single_display_match(dir_servers, error_cb)
except:
except Exception:
if getuid()==0 and opts.system_proxy_socket:
display = ":PROXY"
sockdir = os.path.dirname(opts.system_proxy_socket)
Expand All @@ -845,14 +845,14 @@ def do_pick_display(dotxpra, error_cb, opts, extra_args, cmdline=()):
})
else:
desc.update({
"type" : "unix-domain",
"type" : "socket",
"socket_dir" : sockdir,
"socket_path" : sockpath,
})
return desc
if len(extra_args) == 1:
return parse_display_name(error_cb, opts, extra_args[0], cmdline, find_session_by_name=find_session_by_name)
error_cb("too many arguments (%i): %s" % (len(extra_args), extra_args))
error_cb(f"too many arguments ({len(extra_args)}): {extra_args}")
return None

def single_display_match(dir_servers, error_cb, nomatch="cannot find any live servers to connect to"):
Expand Down Expand Up @@ -996,7 +996,7 @@ def connect_to(display_desc, opts=None, debug_cb=None, ssh_fail_cb=None):
conn.socktype_wrapped = "ssh"
return conn

if dtype == "unix-domain":
if dtype == "socket":
if not hasattr(socket, "AF_UNIX"): # pragma: no cover
raise InitExit(EXIT_UNSUPPORTED, "unix domain sockets are not available on this operating system")
def sockpathfail_cb(msg):
Expand Down
4 changes: 2 additions & 2 deletions xpra/scripts/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def add_query():
add_query()
display = parsed.path.lstrip(":")
desc.update({
"type" : "unix-domain",
"type" : "socket",
"local" : True,
"display" : display,
"socket_dirs" : opts.socket_dirs,
Expand Down Expand Up @@ -585,7 +585,7 @@ def add_query():
add_credentials()
add_query()
desc.update({
"type" : "unix-domain",
"type" : "socket",
"local" : True,
"socket_dir" : os.path.basename(parsed.path),
"socket_dirs" : opts.socket_dirs,
Expand Down
2 changes: 1 addition & 1 deletion xpra/scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ def init_local_sockets():
sockets.update(local_sockets)
if POSIX and (starting or upgrading or starting_desktop):
#all unix domain sockets:
ud_paths = [sockpath for stype, _, sockpath, _ in local_sockets if stype=="unix-domain"]
ud_paths = [sockpath for stype, _, sockpath, _ in local_sockets if stype=="socket"]
forward_xdg_open = bool(opts.forward_xdg_open) or (
opts.forward_xdg_open is None and mode.find("desktop")<0 and mode.find("monitor")<0)
if ud_paths:
Expand Down
6 changes: 3 additions & 3 deletions xpra/server/mixins/fileprint_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def threaded_setup(self):

def init_sockets(self, sockets):
#verify we have a local socket for printing:
unixsockets = [info for socktype, _, info, _ in sockets if socktype=="unix-domain"]
unixsockets = [info for socktype, _, info, _ in sockets if socktype=="socket"]
printlog("local unix domain sockets we can use for printing: %s", unixsockets)
if not unixsockets and self.file_transfer.printing:
if not WIN32:
Expand Down Expand Up @@ -116,7 +116,7 @@ def init_printing(self):
printlog.error("Error: failed to set lpadmin and lpinfo commands", exc_info=True)
printing = False
#verify that we can talk to the socket:
auth_class = self.auth_classes.get("unix-domain")
auth_class = self.auth_classes.get("socket")
if printing and auth_class:
try:
#this should be the name of the auth module:
Expand Down Expand Up @@ -236,7 +236,7 @@ def _process_printers(self, proto, packet):
if ss is None:
return
printers = packet[1]
auth_class = self.auth_classes.get("unix-domain")
auth_class = self.auth_classes.get("socket")
ss.set_printers(printers, self.password_file, auth_class, self.encryption, self.encryption_keyfile)


Expand Down
2 changes: 1 addition & 1 deletion xpra/server/proxy/proxy_instance_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def new_control_connection(self, sock, address):
target = peername or sockname
#sock.settimeout(0)
log("new_control_connection() sock=%s, sockname=%s, address=%s, peername=%s", sock, sockname, address, peername)
sc = SocketConnection(sock, sockname, address, target, "unix-domain")
sc = SocketConnection(sock, sockname, address, target, "socket")
log.info("New proxy instance control connection received:")
log.info(" '%s'", sc)
protocol = Protocol(self, sc, self.process_control_packet)
Expand Down
4 changes: 2 additions & 2 deletions xpra/server/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
PROXY_WS_TIMEOUT = envfloat("XPRA_PROXY_WS_TIMEOUT", "1.0")
assert PROXY_SOCKET_TIMEOUT>0, "invalid proxy socket timeout"
CAN_STOP_PROXY = envbool("XPRA_CAN_STOP_PROXY", getuid()!=0 or WIN32)
STOP_PROXY_SOCKET_TYPES = os.environ.get("XPRA_STOP_PROXY_SOCKET_TYPES", "unix-domain,named-pipe").split(",")
STOP_PROXY_AUTH_SOCKET_TYPES = os.environ.get("XPRA_STOP_PROXY_AUTH_SOCKET_TYPES", "unix-domain").split(",")
STOP_PROXY_SOCKET_TYPES = os.environ.get("XPRA_STOP_PROXY_SOCKET_TYPES", "socket,named-pipe").split(",")
STOP_PROXY_AUTH_SOCKET_TYPES = os.environ.get("XPRA_STOP_PROXY_AUTH_SOCKET_TYPES", "socket").split(",")
#something (a thread lock?) doesn't allow us to use multiprocessing on MS Windows:
PROXY_INSTANCE_THREADED = envbool("XPRA_PROXY_INSTANCE_THREADED", WIN32)
PROXY_CLEANUP_GRACE_PERIOD = envfloat("XPRA_PROXY_CLEANUP_GRACE_PERIOD", "0.5")
Expand Down
25 changes: 12 additions & 13 deletions xpra/server/server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from xpra.net.common import may_log_packet, SOCKET_TYPES, MAX_PACKET_SIZE
from xpra.net.socket_util import (
hosts, mdns_publish, peek_connection,
PEEK_TIMEOUT_MS, UNIXDOMAIN_PEEK_TIMEOUT_MS,
PEEK_TIMEOUT_MS, SOCKET_PEEK_TIMEOUT_MS,
add_listen_socket, accept_connection, guess_packet_type,
ssl_wrap_socket,
)
Expand Down Expand Up @@ -678,11 +678,10 @@ def init_html_proxy(self, opts):
######################################################################
# authentication:
def init_auth(self, opts):
auth = self.get_auth_modules("local-auth", opts.auth or [])
for x in SOCKET_TYPES:
if x in ("socket", "unix-domain", "named-pipe"):
if x in ("socket", "named-pipe"):
#use local-auth for these:
opts_value = auth
opts_value = opts.auth
else:
opts_value = getattr(opts, f"{x}_auth")
self.auth_classes[x] = self.get_auth_modules(x, opts_value)
Expand Down Expand Up @@ -815,7 +814,7 @@ def mdns_publish(self):
mdnslog("mdns_publish() info=%s, socktypes(%s)=%s", info, socktype, socktypes)
for st in socktypes:
recs = mdns_recs.setdefault(st, [])
if socktype=="unix-domain":
if socktype=="socket":
assert st=="ssh"
host = "*"
iport = get_ssh_port()
Expand Down Expand Up @@ -863,7 +862,7 @@ def get_mdns_socktypes(self, socktype):
elif socktype=="ws":
if ssl:
socktypes.append("wss")
elif socktype=="unix-domain":
elif socktype=="socket":
if ssh_access:
socktypes = ["ssh"]
return socktypes
Expand Down Expand Up @@ -914,7 +913,7 @@ def start_listen_sockets(self):
self.socket_info[sock] = info
self.socket_options[sock] = options
self.idle_add(self.add_listen_socket, socktype, sock, options)
if socktype=="unix-domain" and info:
if socktype=="socket" and info:
try:
p = os.path.abspath(info)
self.unix_socket_paths.append(p)
Expand Down Expand Up @@ -1017,13 +1016,13 @@ def _new_connection(self, socktype, listener, handle=0):
if conn is None:
return True
#limit number of concurrent network connections:
if socktype not in ("unix-domain", ) and len(self._potential_protocols)>=self._max_connections:
if socktype!="socket" and len(self._potential_protocols)>=self._max_connections:
netlog.error("Error: too many connections (%i)", len(self._potential_protocols))
netlog.error(" ignoring new one: %s", conn.endpoint)
conn.close()
return True
#from here on, we run in a thread, so we can poll (peek does)
start_thread(self.handle_new_connection, "new-%s-connection" % socktype, True,
start_thread(self.handle_new_connection, f"new-{socktype}-connection", True,
args=(conn, socket_info, socket_options))
return True

Expand Down Expand Up @@ -1087,8 +1086,8 @@ def handle_new_connection(self, conn, socket_info, socket_options):
#rfb does not send any data, waits for a server packet
#so don't bother waiting for something that should never come:
timeout = 0
elif socktype=="unix-domain":
timeout = UNIXDOMAIN_PEEK_TIMEOUT_MS
elif socktype=="socket":
timeout = SOCKET_PEEK_TIMEOUT_MS
peek_data = b""
if timeout>0:
peek_data = peek_connection(conn, timeout)
Expand Down Expand Up @@ -1189,7 +1188,7 @@ def ssl_wrap():
return
peek_data, line1, packet_type = b"", b"", None

if socktype in ("tcp", "unix-domain", "named-pipe") and peek_data:
if socktype in ("tcp", "socket", "named-pipe") and peek_data:
#see if the packet data is actually xpra or something else
#that we need to handle via an ssl wrapper or the websocket adapter:
try:
Expand All @@ -1210,7 +1209,7 @@ def ssl_wrap():
#get the new socket object as we may have wrapped it with ssl:
sock = getattr(conn, "_socket", sock)
pre_read = None
if socktype=="unix-domain" and not peek_data:
if socktype=="socket" and not peek_data:
#try to read from this socket,
#so short lived probes don't go through the whole protocol instantation
try:
Expand Down

0 comments on commit 1d188dc

Please sign in to comment.