From 39b29a30c624cbd2d83138b42fc80c8932b8df2c Mon Sep 17 00:00:00 2001 From: hornet Date: Wed, 1 Dec 2021 00:35:30 -0500 Subject: [PATCH] Added hub timer --- src/hub.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/hub.py b/src/hub.py index b69d664..7f7aec1 100644 --- a/src/hub.py +++ b/src/hub.py @@ -57,6 +57,22 @@ def _pub_key(cli, msg): return False +timers = {} + +def timer_start(msg): + # the ID is always between 0 and 1 + now = time.time() + name = msg['to'] + msg['id'] + timers[name] = now + +def timer_stop(msg): + now = time.time() + name = msg['from'] + msg['id'] + if name in timers: + with open('time_differences', 'w') as f: + f.write(f'{msg["from"]},{now - timers[name]}') + + def _cli_pubs(coll): res = {} if len(coll) == 0: @@ -104,6 +120,7 @@ def ext_msg(client, server, message): print('\tTo internal client') int_srv.send_message(i_client.ws, message) else: + timer_start(msg) iot_srv.send_message(iot_devs[msg['to']].ws, message) print('\tTo IoT device') @@ -136,6 +153,7 @@ def iot_msg(client, server, message): iot.new = False else: if i_client is not None: + timer_stop(msg) int_srv.send_message(i_client.ws, message) print('\tInternal client safe to send to.') else: