Connection messages.

This commit is contained in:
poljar (Damir Jelić) 2018-01-30 14:16:25 +01:00
parent 594706e0af
commit 41c694032a
2 changed files with 33 additions and 5 deletions

25
main.py
View file

@ -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)

View file

@ -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