Store a single hazelnut table

This commit is contained in:
2021-01-05 18:12:57 +01:00
parent 18d1737914
commit 311e1539f9
2 changed files with 29 additions and 26 deletions

View File

@ -159,7 +159,7 @@ class HelloTLV(TLV):
def handle(self, squirrel: Any, sender: Any) -> None:
time_h = time.time()
if not squirrel.is_active(sender):
if not sender.active:
sender.id = self.source_id # The sender we are given misses an id
time_hl = time.time()
else:
@ -167,14 +167,13 @@ class HelloTLV(TLV):
if self.is_long and self.dest_id == squirrel.id:
time_hl = time.time()
# Make sure the sender is not in the potential hazelnuts
squirrel.remove_from_potential(sender.address, sender.port)
# Add entry to/actualize the active hazelnuts dictionnary
sender.last_hello_time = time_h
sender.last_long_hello_time = time_hl
sender.symmetric = True
squirrel.activehazelnuts[(sender.address, sender.port)] = sender
sender.potential = False
sender.active = True
squirrel.update_hazelnut_table(sender)
squirrel.nbNS += 1
squirrel.add_system_message(f"{self.source_id} sent me a Hello " + ("long" if self.is_long else "short"))
@ -374,9 +373,10 @@ class GoAwayTLV(TLV):
self.message.encode("UTF-8")[:self.length - 1]
def handle(self, squirrel: Any, sender: Any) -> None:
if squirrel.is_active(sender):
squirrel.activehazelnuts.pop((sender.address, sender.port))
squirrel.potentialhazelnuts[(sender.address, sender.port)] = sender
if sender.active:
sender.active = False
sender.potential = True
squirrel.update_hazelnut_table(sender)
squirrel.add_system_message("Some told me that he went away : " + self.message)
@staticmethod