Address issues with IPv6 and QUIC protocol addresses.
This commit is contained in:
parent
a9e53a4a84
commit
2f0580faf3
|
@ -132,37 +132,44 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
|
|||
var temp: seq[tuple[address: MultiAddress, position: int]]
|
||||
for address in addresses:
|
||||
let res =
|
||||
if IP4.matchPartial(address):
|
||||
let address4 = address.getProtocolArgument(multiCodec("ip4")).valueOr:
|
||||
continue
|
||||
var ta4 = TransportAddress(family: AddressFamily.IPv4)
|
||||
ta4.address_v4[0 .. 3] = address4[0 .. 3]
|
||||
if ta4.isLoopback():
|
||||
(address, 9)
|
||||
elif ta4.isLinkLocal():
|
||||
(address, 7)
|
||||
elif ta4.isSiteLocal():
|
||||
(address, 5)
|
||||
elif ta4.isGlobal():
|
||||
(address, 2)
|
||||
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
|
||||
var ta4 = TransportAddress(family: AddressFamily.IPv4)
|
||||
ta4.address_v4[0 .. 3] = address4[0 .. 3]
|
||||
if ta4.isLoopback():
|
||||
(address, 9)
|
||||
elif ta4.isLinkLocal():
|
||||
(address, 7)
|
||||
elif ta4.isSiteLocal():
|
||||
(address, 5)
|
||||
elif ta4.isGlobal():
|
||||
(address, 2)
|
||||
else:
|
||||
(address, 11)
|
||||
elif IP6.matchPartial(address):
|
||||
let address6 = address.getProtocolArgument(multiCodec("ip6")).valueOr:
|
||||
continue
|
||||
var ta6 = TransportAddress(family: AddressFamily.IPv4)
|
||||
ta6.address_v6[0 .. 15] = address6[0 .. 15]
|
||||
if ta6.isLoopback():
|
||||
(address, 8)
|
||||
elif ta6.isLinkLocal():
|
||||
(address, 6)
|
||||
elif ta6.isSiteLocal():
|
||||
(address, 4)
|
||||
elif ta6.isGlobal():
|
||||
(address, 1)
|
||||
else:
|
||||
(address, 10)
|
||||
else:
|
||||
(address, 11)
|
||||
elif IP6.matchPartial(address):
|
||||
let address6 = address.getProtocolArgument(multiCodec("ip4")).valueOr:
|
||||
continue
|
||||
var ta6 = TransportAddress(family: AddressFamily.IPv4)
|
||||
ta6.address_v6[0 .. 15] = address6[0 .. 15]
|
||||
if ta6.isLoopback():
|
||||
(address, 8)
|
||||
elif ta6.isLinkLocal():
|
||||
(address, 6)
|
||||
elif ta6.isSiteLocal():
|
||||
(address, 4)
|
||||
elif ta6.isGlobal():
|
||||
(address, 1)
|
||||
else:
|
||||
(address, 10)
|
||||
(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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue