1
0

lnworker: choose IP address with recent timestamp (Rogach)

This commit is contained in:
ThomasV
2023-08-30 09:32:34 +02:00
parent f5ab4b0f18
commit 4d0ec8d177

View File

@@ -512,8 +512,8 @@ class LNWorker(Logger, EventListener, NetworkRetryManager[LNPeerAddr]):
@staticmethod
def choose_preferred_address(addr_list: Sequence[Tuple[str, int, int]]) -> Tuple[str, int, int]:
assert len(addr_list) >= 1
# choose first one that is an IP
for host, port, timestamp in addr_list:
# choose the most recent one that is an IP
for host, port, timestamp in sorted(addr_list, key=lambda a: -a[2]):
if is_ip_address(host):
return host, port, timestamp
# otherwise choose one at random