From 55b9eac03703313f7346c24b3bd3764b4630885d Mon Sep 17 00:00:00 2001 From: Eichhornchen Date: Thu, 7 Jan 2021 18:25:05 +0100 Subject: [PATCH] prefer not multicast port addresses --- squinnondation/peers.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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