mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 06:16:25 +00:00
Fix last-seen-p2p-address values in /eth/v1/node/peers API endpoint. (#6595)
* Attempt to fix issue with AnyLocal addresses in last-seen-p2p-address field. * Address issues with IPv6 and QUIC protocol addresses. * Attempt to avoid QUIC addresses from site-local networks. * Fix IPv6 handling. * Perform normalization of `last_libp2p_address`. * Switch to LastSeenBook. * Fix address deserialization. * Bump nim-libp2p. * Eliminate unneeded function. * Eliminate unneeded import.
This commit is contained in:
parent
bb22476175
commit
eeab048871
@ -34,6 +34,17 @@ RestJson.useDefaultSerializationFor(
|
||||
RestNodePeerCount,
|
||||
)
|
||||
|
||||
proc normalize*(address: MultiAddress, value: PeerId): MaResult[MultiAddress] =
|
||||
## Checks if `address` has `p2p` suffix, and if not add it.
|
||||
let
|
||||
protos = ? address.protocols()
|
||||
index = protos.find(multiCodec("p2p"))
|
||||
if index == -1:
|
||||
let suffix = ? MultiAddress.init(multiCodec("p2p"), value)
|
||||
concat(address, suffix)
|
||||
else:
|
||||
ok(address)
|
||||
|
||||
proc validateState(states: seq[PeerStateKind]): Result[ConnectionStateSet,
|
||||
cstring] =
|
||||
var res: set[ConnectionState]
|
||||
@ -98,14 +109,13 @@ proc toString(direction: PeerType): string =
|
||||
"outbound"
|
||||
|
||||
proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
|
||||
# TODO (cheatfate): We need to provide filter here, which will be able to
|
||||
# filter such multiaddresses like `/ip4/0.0.0.0` or local addresses or
|
||||
# addresses with peer ids.
|
||||
let addrs = node.network.switch.peerStore[AddressBook][id]
|
||||
if len(addrs) > 0:
|
||||
$addrs[len(addrs) - 1]
|
||||
else:
|
||||
""
|
||||
let
|
||||
address = node.network.switch.peerStore[LastSeenBook][id].valueOr:
|
||||
return ""
|
||||
normalized = address.normalize(id).valueOr:
|
||||
return ""
|
||||
$normalized
|
||||
|
||||
proc getDiscoveryAddresses(node: BeaconNode): seq[string] =
|
||||
let
|
||||
typedRec = TypedRecord.fromRecord(node.network.enrRecord())
|
||||
|
2
vendor/nim-libp2p
vendored
2
vendor/nim-libp2p
vendored
@ -1 +1 @@
|
||||
Subproject commit 8855bce0854ecf4adad7a0556bb2b2d2f98e0e20
|
||||
Subproject commit b7e0df127f35183746e6114dc3c374c517081494
|
Loading…
x
Reference in New Issue
Block a user