diff --git a/tests/wakunode_rest/test_rest_admin.nim b/tests/wakunode_rest/test_rest_admin.nim index d7b83d23bf..b6c9336d08 100644 --- a/tests/wakunode_rest/test_rest_admin.nim +++ b/tests/wakunode_rest/test_rest_admin.nim @@ -21,6 +21,7 @@ import waku_api/rest/admin/handlers as admin_api, waku_api/rest/admin/client as admin_api_client, waku_relay, + waku_peer_exchange, ], ../testlib/wakucore, ../testlib/wakunode, @@ -45,7 +46,12 @@ suite "Waku v2 Rest API - Admin": newTestWakuNode(generateSecp256k1Key(), parseIpAddress("127.0.0.1"), Port(60604)) await allFutures(node1.start(), node2.start(), node3.start()) - await allFutures(node1.mountRelay(), node2.mountRelay(), node3.mountRelay()) + await allFutures( + node1.mountRelay(), + node2.mountRelay(), + node3.mountRelay(), + node3.mountPeerExchange(), + ) peerInfo1 = node1.switch.peerInfo peerInfo2 = node2.switch.peerInfo @@ -94,6 +100,12 @@ suite "Waku v2 Rest API - Admin": it.multiaddr == constructMultiaddrStr(peerInfo3) ) + # Check peer 3 + getRes.data.anyIt( + it.protocols.find(WakuPeerExchangeCodec) >= 0 and + it.multiaddr == constructMultiaddrStr(peerInfo3) + ) + asyncTest "Set wrong peer": let nonExistentPeer = "/ip4/0.0.0.0/tcp/10000/p2p/16Uiu2HAm6HZZr7aToTvEBPpiys4UxajCTU97zj5v7RNR2gbniy1D" @@ -170,7 +182,7 @@ suite "Waku v2 Rest API - Admin": getRes.data == "Error: Filter Protocol is not mounted to the node" asyncTest "Get peer origin": - # Adding peers to the Peer Store + # Adding peers to the Peer Store node1.peerManager.addPeer(peerInfo2, Discv5) node1.peerManager.addPeer(peerInfo3, PeerExchange) diff --git a/waku/waku_api/rest/admin/handlers.nim b/waku/waku_api/rest/admin/handlers.nim index 1ac7a79d59..435d19de25 100644 --- a/waku/waku_api/rest/admin/handlers.nim +++ b/waku/waku_api/rest/admin/handlers.nim @@ -14,6 +14,7 @@ import ../../../waku_filter_v2, ../../../waku_lightpush/common, ../../../waku_relay, + ../../../waku_peer_exchange, ../../../waku_node, ../../../node/peer_manager, ../responses, @@ -40,65 +41,65 @@ proc installAdminV1GetPeersHandler(router: var RestRouter, node: WakuNode) = router.api(MethodGet, ROUTE_ADMIN_V1_PEERS) do() -> RestApiResponse: var peers: WakuPeers = @[] - if not node.wakuRelay.isNil(): - let relayPeers = node.peerManager.peerStore.peers(WakuRelayCodec).mapIt( - ( - multiaddr: constructMultiaddrStr(it), - protocol: WakuRelayCodec, - connected: it.connectedness == Connectedness.Connected, - origin: it.origin, - ) + let relayPeers = node.peerManager.peerStore.peers(WakuRelayCodec).mapIt( + ( + multiaddr: constructMultiaddrStr(it), + protocol: WakuRelayCodec, + connected: it.connectedness == Connectedness.Connected, + origin: it.origin, ) - tuplesToWakuPeers(peers, relayPeers) - - if not node.wakuFilter.isNil(): - let filterV2Peers = node.peerManager.peerStore - .peers(WakuFilterSubscribeCodec) - .mapIt( - ( - multiaddr: constructMultiaddrStr(it), - protocol: WakuFilterSubscribeCodec, - connected: it.connectedness == Connectedness.Connected, - origin: it.origin, - ) + ) + tuplesToWakuPeers(peers, relayPeers) + + let filterV2Peers = node.peerManager.peerStore.peers(WakuFilterSubscribeCodec).mapIt( + ( + multiaddr: constructMultiaddrStr(it), + protocol: WakuFilterSubscribeCodec, + connected: it.connectedness == Connectedness.Connected, + origin: it.origin, ) - tuplesToWakuPeers(peers, filterV2Peers) - - if not node.wakuStore.isNil(): - let storePeers = node.peerManager.peerStore.peers(WakuStoreCodec).mapIt( - ( - multiaddr: constructMultiaddrStr(it), - protocol: WakuStoreCodec, - connected: it.connectedness == Connectedness.Connected, - origin: it.origin, - ) + ) + tuplesToWakuPeers(peers, filterV2Peers) + + let storePeers = node.peerManager.peerStore.peers(WakuStoreCodec).mapIt( + ( + multiaddr: constructMultiaddrStr(it), + protocol: WakuStoreCodec, + connected: it.connectedness == Connectedness.Connected, + origin: it.origin, ) - tuplesToWakuPeers(peers, storePeers) - - if not node.wakuLegacyStore.isNil(): - let legacyStorePeers = node.peerManager.peerStore - .peers(WakuLegacyStoreCodec) - .mapIt( - ( - multiaddr: constructMultiaddrStr(it), - protocol: WakuLegacyStoreCodec, - connected: it.connectedness == Connectedness.Connected, - origin: it.origin, - ) + ) + tuplesToWakuPeers(peers, storePeers) + + let legacyStorePeers = node.peerManager.peerStore.peers(WakuLegacyStoreCodec).mapIt( + ( + multiaddr: constructMultiaddrStr(it), + protocol: WakuLegacyStoreCodec, + connected: it.connectedness == Connectedness.Connected, + origin: it.origin, ) - tuplesToWakuPeers(peers, legacyStorePeers) - - if not node.wakuLightPush.isNil(): - # Map WakuStore peers to WakuPeers and add to return list - let lightpushPeers = node.peerManager.peerStore.peers(WakuLightPushCodec).mapIt( - ( - multiaddr: constructMultiaddrStr(it), - protocol: WakuLightPushCodec, - connected: it.connectedness == Connectedness.Connected, - origin: it.origin, - ) + ) + tuplesToWakuPeers(peers, legacyStorePeers) + + let lightpushPeers = node.peerManager.peerStore.peers(WakuLightPushCodec).mapIt( + ( + multiaddr: constructMultiaddrStr(it), + protocol: WakuLightPushCodec, + connected: it.connectedness == Connectedness.Connected, + origin: it.origin, ) - tuplesToWakuPeers(peers, lightpushPeers) + ) + tuplesToWakuPeers(peers, lightpushPeers) + + let pxPeers = node.peerManager.peerStore.peers(WakuPeerExchangeCodec).mapIt( + ( + multiaddr: constructMultiaddrStr(it), + protocol: WakuPeerExchangeCodec, + connected: it.connectedness == Connectedness.Connected, + origin: it.origin, + ) + ) + tuplesToWakuPeers(peers, pxPeers) let resp = RestApiResponse.jsonResponse(peers, status = Http200) if resp.isErr():