diff --git a/squinnondation/hazel.py b/squinnondation/hazel.py index 68f2d0e..c276daa 100644 --- a/squinnondation/hazel.py +++ b/squinnondation/hazel.py @@ -109,11 +109,11 @@ class Squirrel(Hazelnut): return hazelnut @property - def activehazelnuts(self) -> dict: + def active_hazelnuts(self) -> dict: return {(address, port): hazelnut for (address, port), hazelnut in self.hazelnuts.items() if hazelnut.active} @property - def potentialhazelnuts(self) -> dict: + def potential_hazelnuts(self) -> dict: return {(address, port): hazelnut for (address, port), hazelnut in self.hazelnuts.items() if hazelnut.potential} def find_hazelnut(self, address: str, port: int) -> Hazelnut: @@ -267,7 +267,7 @@ class Squirrel(Hazelnut): self.add_message(msg) pkt = Packet.construct(DataTLV.construct(msg, self)) - for hazelnut in list(self.activehazelnuts.values()): + for hazelnut in list(self.active_hazelnuts.values()): self.send_packet(hazelnut, pkt) def handle_mouse_click(self, y: int, x: int, attr: int) -> None: @@ -349,10 +349,10 @@ class Squirrel(Hazelnut): def make_inundation_dict(self) -> dict: """ - Takes the activehazels dictionnary and returns a list of [hazel, date+random, 0] + Takes the active hazels dictionnary and returns a list of [hazel, date+random, 0] """ res = dict() - hazels = list(self.activehazelnuts.items()) + hazels = list(self.active_hazelnuts.items()) for key, hazel in hazels: if hazel.symmetric: next_send = uniform(1, 2) @@ -605,8 +605,8 @@ class Squirrel(Hazelnut): not have enough symmetric neighbours. """ res = [] - lp = len(self.potentialhazelnuts) - val = list(self.potentialhazelnuts.values()) + lp = len(self.potential_hazelnuts) + val = list(self.potential_hazelnuts.values()) for i in range(min(lp, max(0, self.minNS - self.nbNS))): a = randint(0, lp - 1) @@ -617,7 +617,7 @@ class Squirrel(Hazelnut): """ Sends a long HelloTLV to all active neighbours. """ - for hazelnut in self.activehazelnuts.values(): + for hazelnut in self.active_hazelnuts.values(): htlv = HelloTLV().construct(16, self, hazelnut) pkt = Packet().construct(htlv) self.send_packet(hazelnut, pkt) @@ -627,7 +627,7 @@ class Squirrel(Hazelnut): All neighbours that have not sent a HelloTLV in the last 2 minutes are considered not active. """ - val = list(self.activehazelnuts.values()) # create a copy because the dict size will change + val = list(self.active_hazelnuts.values()) # create a copy because the dict size will change for hazelnut in val: if time.time() - hazelnut.last_hello_time > 2 * 60: @@ -654,17 +654,17 @@ class Squirrel(Hazelnut): nb_ns = 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 key, hazelnut in self.activehazelnuts.items(): + for key, hazelnut in self.active_hazelnuts.items(): if time.time() - hazelnut.last_long_hello_time <= 2 * 60: nb_ns += 1 self.hazelnuts[key].symmetric = True ntlv = NeighbourTLV().construct(*hazelnut.main_address) pkt = Packet().construct(ntlv) - for destination in self.activehazelnuts.values(): + for destination in self.active_hazelnuts.values(): if destination.id != hazelnut.id: self.send_packet(destination, pkt) else: - self.activehazelnuts[key].symmetric = False + self.active_hazelnuts[key].symmetric = False self.nbNS = nb_ns def leave(self) -> None: @@ -678,7 +678,7 @@ class Squirrel(Hazelnut): # Broadcast a GoAway gatlv = GoAwayTLV().construct(GoAwayType.EXIT, "I am leaving! Good bye!") pkt = Packet.construct(gatlv) - for hazelnut in self.activehazelnuts.values(): + for hazelnut in self.active_hazelnuts.values(): self.send_packet(hazelnut, pkt) exit(0) @@ -735,7 +735,7 @@ class HazelManager(Thread): # Second part: send long HelloTLVs to neighbours every 30 seconds if time.time() - self.last_check > 30: - self.squirrel.add_system_message(f"I have {len(list(self.squirrel.activehazelnuts))} friends") + self.squirrel.add_system_message(f"I have {len(list(self.squirrel.active_hazelnuts))} friends") self.squirrel.send_hello() self.last_check = time.time() diff --git a/squinnondation/messages.py b/squinnondation/messages.py index e718e34..35c85f7 100644 --- a/squinnondation/messages.py +++ b/squinnondation/messages.py @@ -226,8 +226,8 @@ class NeighbourTLV(TLV): # This case should never happen (and in our protocol it is not possible), # but we include this test as a security measure. return - if not (str(self.ip_address), self.port) in squirrel.activehazelnuts \ - and not (str(self.ip_address), self.port) in squirrel.potentialhazelnuts: + if not (str(self.ip_address), self.port) in squirrel.active_hazelnuts \ + and not (str(self.ip_address), self.port) in squirrel.potential_hazelnuts: hazelnut = squirrel.new_hazel(str(self.ip_address), self.port) hazelnut.potential = True squirrel.update_hazelnut_table(hazelnut)