diff --git a/beacon_chain/rpc/rest_node_api.nim b/beacon_chain/rpc/rest_node_api.nim index b96e0724b..d74d72d39 100644 --- a/beacon_chain/rpc/rest_node_api.nim +++ b/beacon_chain/rpc/rest_node_api.nim @@ -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()) diff --git a/vendor/nim-libp2p b/vendor/nim-libp2p index 8855bce08..b7e0df127 160000 --- a/vendor/nim-libp2p +++ b/vendor/nim-libp2p @@ -1 +1 @@ -Subproject commit 8855bce0854ecf4adad7a0556bb2b2d2f98e0e20 +Subproject commit b7e0df127f35183746e6114dc3c374c517081494