server: Don't use the address in the config for connection establishment.
The address in the config can contain subpaths and it doesn't make sense for a socket to connect to this address. The net location without the subpath is now contained in server.address.
This commit is contained in:
parent
107a7a606e
commit
b884536e7e
5 changed files with 23 additions and 13 deletions
2
main.py
2
main.py
|
@ -180,7 +180,7 @@ def wrap_socket(server, file_descriptor):
|
||||||
|
|
||||||
ssl_socket = server.ssl_context.wrap_socket(
|
ssl_socket = server.ssl_context.wrap_socket(
|
||||||
sock, do_handshake_on_connect=False,
|
sock, do_handshake_on_connect=False,
|
||||||
server_hostname=server.config.address) # type: ssl.SSLSocket
|
server_hostname=server.address) # type: ssl.SSLSocket
|
||||||
|
|
||||||
server.socket = ssl_socket
|
server.socket = ssl_socket
|
||||||
|
|
||||||
|
|
|
@ -1078,7 +1078,7 @@ def matrix_upload_command_cb(data, buffer, args):
|
||||||
|
|
||||||
upload = Upload(
|
upload = Upload(
|
||||||
server.name,
|
server.name,
|
||||||
server.config.address,
|
server.client.host,
|
||||||
server.client.access_token,
|
server.client.access_token,
|
||||||
room_buffer.room.room_id,
|
room_buffer.room.room_id,
|
||||||
parsed_args.file,
|
parsed_args.file,
|
||||||
|
|
|
@ -251,6 +251,7 @@ class MatrixServer(object):
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
self.address = None
|
||||||
self.client = None
|
self.client = None
|
||||||
self.access_token = None # type: Optional[str]
|
self.access_token = None # type: Optional[str]
|
||||||
self.next_batch = None # type: Optional[str]
|
self.next_batch = None # type: Optional[str]
|
||||||
|
@ -336,15 +337,18 @@ class MatrixServer(object):
|
||||||
netloc, path = (address, "")
|
netloc, path = (address, "")
|
||||||
|
|
||||||
path = path.strip("/")
|
path = path.strip("/")
|
||||||
netloc = "{}:{}".format(netloc, port)
|
|
||||||
|
|
||||||
return "/".join([netloc, path]).rstrip("/")
|
return netloc, "/".join([
|
||||||
|
"{}:{}".format(netloc, port),
|
||||||
|
path
|
||||||
|
]).rstrip("/")
|
||||||
|
|
||||||
def _change_client(self):
|
def _change_client(self):
|
||||||
host = MatrixServer._parse_url(
|
netloc, host = MatrixServer._parse_url(
|
||||||
self.config.address,
|
self.config.address,
|
||||||
str(self.config.port)
|
str(self.config.port)
|
||||||
)
|
)
|
||||||
|
self.address = netloc
|
||||||
self.client = HttpClient(
|
self.client = HttpClient(
|
||||||
host,
|
host,
|
||||||
self.config.username,
|
self.config.username,
|
||||||
|
@ -558,7 +562,6 @@ class MatrixServer(object):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
# type: (MatrixServer) -> int
|
# type: (MatrixServer) -> int
|
||||||
if not self.config.address or not self.config.port:
|
if not self.config.address or not self.config.port:
|
||||||
W.prnt("", self.config.address)
|
|
||||||
message = "{prefix}Server address or port not set".format(
|
message = "{prefix}Server address or port not set".format(
|
||||||
prefix=W.prefix("error")
|
prefix=W.prefix("error")
|
||||||
)
|
)
|
||||||
|
@ -589,7 +592,7 @@ class MatrixServer(object):
|
||||||
"{prefix}matrix: Connecting to " "{server}:{port}{ssl}..."
|
"{prefix}matrix: Connecting to " "{server}:{port}{ssl}..."
|
||||||
).format(
|
).format(
|
||||||
prefix=W.prefix("network"),
|
prefix=W.prefix("network"),
|
||||||
server=self.config.address,
|
server=self.address,
|
||||||
port=self.config.port,
|
port=self.config.port,
|
||||||
ssl=ssl_message,
|
ssl=ssl_message,
|
||||||
)
|
)
|
||||||
|
@ -598,7 +601,7 @@ class MatrixServer(object):
|
||||||
|
|
||||||
W.hook_connect(
|
W.hook_connect(
|
||||||
self.config.proxy,
|
self.config.proxy,
|
||||||
self.config.address,
|
self.address,
|
||||||
self.config.port,
|
self.config.port,
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -82,7 +82,7 @@ def server_buffer_set_title(server):
|
||||||
ip_string = ""
|
ip_string = ""
|
||||||
|
|
||||||
title = ("Matrix: {address}:{port}{ip}").format(
|
title = ("Matrix: {address}:{port}{ip}").format(
|
||||||
address=server.config.address, port=server.config.port, ip=ip_string
|
address=server.address, port=server.config.port, ip=ip_string
|
||||||
)
|
)
|
||||||
|
|
||||||
W.buffer_set(server.server_buffer, "title", title)
|
W.buffer_set(server.server_buffer, "title", title)
|
||||||
|
|
|
@ -6,14 +6,21 @@ G.CONFIG = MockConfig()
|
||||||
|
|
||||||
class TestClass(object):
|
class TestClass(object):
|
||||||
def test_address_parsing(self):
|
def test_address_parsing(self):
|
||||||
host = MatrixServer._parse_url("example.org", "443")
|
netloc, host = MatrixServer._parse_url("example.org", "443")
|
||||||
assert host == "example.org:443"
|
assert host == "example.org:443"
|
||||||
|
assert netloc == "example.org"
|
||||||
|
|
||||||
host = MatrixServer._parse_url("example.org/_matrix", "443")
|
netloc, host = MatrixServer._parse_url("example.org/_matrix", "443")
|
||||||
assert host == "example.org:443/_matrix"
|
assert host == "example.org:443/_matrix"
|
||||||
|
assert netloc == "example.org"
|
||||||
|
|
||||||
host = MatrixServer._parse_url("https://example.org/_matrix", "443")
|
netloc, host = MatrixServer._parse_url(
|
||||||
|
"https://example.org/_matrix",
|
||||||
|
"443"
|
||||||
|
)
|
||||||
assert host == "example.org:443/_matrix"
|
assert host == "example.org:443/_matrix"
|
||||||
|
assert netloc == "example.org"
|
||||||
|
|
||||||
host = MatrixServer._parse_url("https://example.org", "443")
|
netloc, host = MatrixServer._parse_url("https://example.org", "443")
|
||||||
assert host == "example.org:443"
|
assert host == "example.org:443"
|
||||||
|
assert netloc == "example.org"
|
||||||
|
|
Loading…
Add table
Reference in a new issue