Added a marker to active neighbours to remember if they are symmetric. Fixed a marshal function broken by the last commit

This commit is contained in:
eichhornchen
2020-12-28 18:33:57 +01:00
parent 913f804f5e
commit c01fd697cd
2 changed files with 33 additions and 17 deletions

View File

@ -73,13 +73,13 @@ class Squirrel(Hazelnut):
#dictionnaries of neighbours
self.potentialhazelnuts = dict()
self.activehazelnuts = dict() #of the form [hazelnut, time of last
#hello, time of last long hello]
#hello, time of last long hello, is symmetric]
self.nbNS = 0
self.minNS = 3 #minimal number of symetric neighbours a squirrel needs
#to have.
self.add_system_message(f"Listening on {self.address}:{self.port}")
self.add_system_message(f"I am {self.id}}")
self.add_system_message(f"I am {self.id}")
def new_hazel(self, address: str, port: int) -> Hazelnut:
"""
@ -561,14 +561,17 @@ class Squirrel(Hazelnut):
nbNS = 0
#could send the same to all neighbour, but it means that neighbour A could receive a message with itself in it -> if the others do not pay attention, trouble
for hazelnut in self.activehazelnuts.values() :
if time.time()-hazelnut[2]<=2*60:
for key, hazelnut in self.activehazelnuts.items() :
if time.time()-hazelnut[2]<=10 : #2*60
nbNS+=1
self.activehazelnuts[key][3] = True
ntlv = NeighbourTLV().construct(hazelnut[0].address,hazelnut[0].port)
pkt = Packet().construct(ntlv)
for destination in self.activehazelnuts.values() :
if destination[0].id != hazelnut[0].id :
self.send_packet(destination[0], pkt)
else:
self.activehazelnuts[key][3] = False
self.nbNS = nbNS
self.refresh_lock.release()
@ -634,6 +637,18 @@ class HazelManager(Thread):
if time.time()-self.last_neighbour > 10: #60 :
self.squirrel.send_neighbours()
self.last_neighbour = time.time()
class Inondator(Thread):
"""
A process to manage the inondation
"""
def __init__(self, squirrel: Squirrel, *args, **kwargs):
super().__init__(*args, **kwargs)
self.squirrel = squirrel
self.last_check = 0
def run(self) -> None:
while True:
class Message: