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