Address issues with IPv6 and QUIC protocol addresses.

This commit is contained in:
cheatfate 2024-10-04 03:55:20 +03:00
parent a9e53a4a84
commit 2f0580faf3
No known key found for this signature in database
GPG Key ID: 46ADD633A7201F95
1 changed files with 36 additions and 29 deletions

View File

@ -132,6 +132,9 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
var temp: seq[tuple[address: MultiAddress, position: int]]
for address in addresses:
let res =
if TCP.matchPartial(address):
# TODO (cheatfate): We match TCP here because `nim-libp2p` do not have
# QUIC support yet. So we give TCP addresses priority.
if IP4.matchPartial(address):
let address4 = address.getProtocolArgument(multiCodec("ip4")).valueOr:
continue
@ -148,7 +151,7 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
else:
(address, 11)
elif IP6.matchPartial(address):
let address6 = address.getProtocolArgument(multiCodec("ip4")).valueOr:
let address6 = address.getProtocolArgument(multiCodec("ip6")).valueOr:
continue
var ta6 = TransportAddress(family: AddressFamily.IPv4)
ta6.address_v6[0 .. 15] = address6[0 .. 15]
@ -164,6 +167,10 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
(address, 10)
else:
(address, 3)
else:
# TODO (chatfate): As soon as QUIC protocol will be implemented in
# `nim-libp2p` - TCP prioritization should be dropped
(address, 3)
temp.add(res)
if len(temp) > 0: