Perform normalization of `last_libp2p_address`.

This commit is contained in:
cheatfate 2024-11-26 01:08:27 +02:00
parent 4f7e76137f
commit af9e626fb1
No known key found for this signature in database
GPG Key ID: 46ADD633A7201F95
2 changed files with 15 additions and 2 deletions

View File

@ -35,6 +35,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]
@ -181,7 +192,9 @@ proc getLastSeenAddress(node: BeaconNode, id: PeerId): string =
if len(temp) > 0:
sort(temp, compare, SortOrder.Ascending)
$temp[0].address
let res = normalize(temp[0].address, id).valueOr:
return ""
$res
else:
""

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit 8855bce0854ecf4adad7a0556bb2b2d2f98e0e20
Subproject commit a70d65dd4f33a52471c07f07e3fe1d65f82996ba