prefer not multicast port addresses

This commit is contained in:
Eichhornchen 2021-01-07 18:25:05 +01:00
parent a8d38faa62
commit 55b9eac037
1 changed files with 5 additions and 8 deletions

View File

@ -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