Don't modify peers[foo].lastseen unless peers[foo] exists

This commit is contained in:
Juhani Krekelä 2019-07-19 00:17:45 +03:00
parent a7f841b0a0
commit 0adee9fc54
1 changed files with 6 additions and 4 deletions

View File

@ -244,7 +244,8 @@ def handle_user_command(backend, line):
# Request status
mac = mac_from_name(rest)
if mac in peers:
print('%s === ~%s (%s) [%s]' % (timestamp(), peers[mac].nick, peers[mac].status.name, format_mac(mac)))
peer = peers[mac]
print('%s === ~%s (%s) [%s]' % (timestamp(), peer.nick, peer.status.name, format_mac(mac)))
send_status_request(backend, mac)
else:
@ -329,7 +330,6 @@ def handle_status(mac, status, nick):
# Never seen before
peers[mac] = Peer(nick = None, status = None, lastseen = None)
if peers[mac].nick is not None and peers[mac].status != statuses.offline and nick != peers[mac].nick:
print('%s === ~%s -> ~%s [%s]' % (timestamp(), peers[mac].nick, nick, format_mac(mac)))
@ -462,7 +462,8 @@ def eventloop(proc):
source_mac = readall(proc.stdout, 6)
msgid = readall_u16(proc.stdout)
peers[source_mac].lastseen = time.monotonic()
if source_mac in peers:
peers[source_mac].lastseen = time.monotonic()
# Was it for a message currently waiting?
if len(send_queue) > 0 and send_queue[0].msgid == msgid:
@ -504,7 +505,8 @@ def eventloop(proc):
handle_message(source_mac, message.decode('utf-8'))
peers[source_mac].lastseen = time.monotonic()
if source_mac in peers:
peers[source_mac].lastseen = time.monotonic()
else:
raise ValueError('Unknown event type from backend: %s' % repr(event_type))