From 41c694032a4343f2e123f54c9e4a291a9305c266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Tue, 30 Jan 2018 14:16:25 +0100 Subject: [PATCH] Connection messages. --- main.py | 25 ++++++++++++++++++++++++- matrix/socket.py | 13 +++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 99ef2c4..8c72d71 100644 --- a/main.py +++ b/main.py @@ -128,10 +128,34 @@ def wrap_socket(server, file_descriptor): sock = temp_socket try: + start = time.time() + message = "{prefix}matrix: Doing SSL handshake...".format( + prefix=W.prefix("network")) + + W.prnt(server.server_buffer, message) + + # TODO this blocks currently ssl_socket = server.ssl_context.wrap_socket( sock, server_hostname=server.address) # type: ssl.SSLSocket + cipher = ssl_socket.cipher() + cipher_message = ("{prefix}matrix: Connected using {tls}, and " + "{bit} bit {cipher} cipher suite.").format( + prefix=W.prefix("network"), + tls=cipher[1], + bit=cipher[2], + cipher=cipher[0]) + + W.prnt(server.server_buffer, cipher_message) + + # TODO print out the certificates + # cert = ssl_socket.getpeercert() + # W.prnt(server.server_buffer, pprint.pformat(cert)) + + server.lag = (time.time() - start) * 1000 + W.bar_item_update("lag") + return ssl_socket # TODO add finer grained error messages with the subclass exceptions except ssl.SSLError as error: @@ -241,7 +265,6 @@ def connect_cb(data, status, gnutls_rc, sock, error, ip_address): server.numeric_address = ip_address server_buffer_set_title(server) - server_buffer_prnt(server, "Connected") if not server.access_token: matrix_login(server) diff --git a/matrix/socket.py b/matrix/socket.py index a151131..672caca 100644 --- a/matrix/socket.py +++ b/matrix/socket.py @@ -115,10 +115,15 @@ def send(server, message): end = time.time() message.send_time = end - send_time = (end - start) * 1000 - prnt_debug(DebugType.NETWORK, server, - ("Message done sending ({t}ms), putting message in the " - "receive queue.").format(t=send_time)) + + send_lag = (end - start) * 1000 + lag_string = "{0:.3f}" if send_lag < 1000 else "{0:.1f}" + + prnt_debug(DebugType.NETWORK, server.server_buffer, + ("{prefix}matrix: Message done sending (Lag: {t}s), putting" + " message in the receive queue.").format( + prefix=W.prefix("network"), + t=lag_string.format(send_lag))) server.receive_queue.append(message) return True