server: Use a sync timeout only on HTTP2.

This commit is contained in:
Damir Jelić 2018-08-07 11:26:31 +02:00
parent fb5a889cca
commit 99ca1b50ce
2 changed files with 8 additions and 6 deletions

View file

@ -340,14 +340,12 @@ def finalize_connection(server):
if negotiated_protocol is None:
negotiated_protocol = server.socket.selected_npn_protocol()
transport_type = None
if negotiated_protocol == "http/1.1":
transport_type = TransportType.HTTP
server.transport_type = TransportType.HTTP
elif negotiated_protocol == "h2":
transport_type = TransportType.HTTP2
server.transport_type = TransportType.HTTP2
data = server.client.connect(transport_type)
data = server.client.connect(server.transport_type)
server.send(data)
server.login()

View file

@ -30,6 +30,7 @@ from nio import (
SyncRepsponse,
RoomSendResponse,
TransportResponse,
TransportType,
LocalProtocolError
)
@ -173,6 +174,7 @@ class MatrixServer(object):
self.sync_time = None # type: Optional[float]
self.socket = None # type: ssl.SSLSocket
self.ssl_context = ssl.create_default_context() # type: ssl.SSLContext
self.transport_type = None # type: Optional[nio.TransportType]
# Enable http2 negotiation on the ssl context.
self.ssl_context.set_alpn_protocols(["h2", "http/1.1"])
@ -391,6 +393,7 @@ class MatrixServer(object):
self.send_buffer = b""
self.current_message = None
self.transport_type = None
try:
self.client.disconnect()
@ -702,7 +705,8 @@ def matrix_timer_cb(server_name, remaining_calls):
return W.WEECHAT_RC_OK
if server.sync_time and current_time > (server.sync_time + 2):
server.sync(30000)
timeout = 0 if server.transport_type == TransportType.HTTP else 30000
server.sync(timeout)
while server.send_queue:
message = server.send_queue.popleft()