Added hub timer
This commit is contained in:
parent
d5e893e139
commit
39b29a30c6
18
src/hub.py
18
src/hub.py
|
@ -57,6 +57,22 @@ def _pub_key(cli, msg):
|
||||||
return False
|
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):
|
def _cli_pubs(coll):
|
||||||
res = {}
|
res = {}
|
||||||
if len(coll) == 0:
|
if len(coll) == 0:
|
||||||
|
@ -104,6 +120,7 @@ def ext_msg(client, server, message):
|
||||||
print('\tTo internal client')
|
print('\tTo internal client')
|
||||||
int_srv.send_message(i_client.ws, message)
|
int_srv.send_message(i_client.ws, message)
|
||||||
else:
|
else:
|
||||||
|
timer_start(msg)
|
||||||
iot_srv.send_message(iot_devs[msg['to']].ws, message)
|
iot_srv.send_message(iot_devs[msg['to']].ws, message)
|
||||||
print('\tTo IoT device')
|
print('\tTo IoT device')
|
||||||
|
|
||||||
|
@ -136,6 +153,7 @@ def iot_msg(client, server, message):
|
||||||
iot.new = False
|
iot.new = False
|
||||||
else:
|
else:
|
||||||
if i_client is not None:
|
if i_client is not None:
|
||||||
|
timer_stop(msg)
|
||||||
int_srv.send_message(i_client.ws, message)
|
int_srv.send_message(i_client.ws, message)
|
||||||
print('\tInternal client safe to send to.')
|
print('\tInternal client safe to send to.')
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user