diff --git a/squinnondation/peers.py b/squinnondation/peers.py index e74b1c3..75ece30 100644 --- a/squinnondation/peers.py +++ b/squinnondation/peers.py @@ -40,6 +40,7 @@ class Peer: self.addresses = set() self.addresses.add((address, port)) + self.main_address = (address, port) @property def potential(self) -> bool: @@ -49,14 +50,6 @@ class Peer: def potential(self, value: bool) -> None: self.active = not value - @property - def main_address(self) -> Tuple[str, int]: - """ - A client can have multiple addresses. - We contact it only on one of them. - """ - return list(self.addresses)[0] - @property def banned(self) -> bool: """ @@ -80,6 +73,10 @@ class Peer: self.last_long_hello_time = max(self.last_hello_time, other.last_long_hello_time) self.addresses.update(self.addresses) self.addresses.update(other.addresses) + if self.main_address[1] == 1212: #always prefer the non-multicast address + self.main_address = other.main_address + elif other.main_address[1] == 1212: + other.main_address = self.main_address self.id = self.id if self.id > 0 else other.id self.marked_as_banned = other.marked_as_banned return self