Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rpc): return error if peer cant be connected #1476

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/v2/test_jsonrpc_waku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,15 @@ procSuite "Waku v2 JSON-RPC API":
getRes.anyIt(it.protocol == WakuRelayCodec and
it.multiaddr == constructMultiaddrStr(peerInfo3))

# Verify that raises an exception if we can't connect to the peer
let nonExistentPeer = "/ip4/0.0.0.0/tcp/10000/p2p/16Uiu2HAm6HZZr7aToTvEBPpiys4UxajCTU97zj5v7RNR2gbniy1D"
expect(ValueError):
discard await client.post_waku_v2_admin_v1_peers(@[nonExistentPeer])

let malformedPeer = "/malformed/peer"
expect(ValueError):
discard await client.post_waku_v2_admin_v1_peers(@[malformedPeer])

await server.stop()
await server.closeWait()

Expand Down
11 changes: 5 additions & 6 deletions waku/v2/node/jsonrpc/admin_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ proc installAdminApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
## Connect to a list of peers
debug "post_waku_v2_admin_v1_peers"

if (await node.connectToNodes(peers).withTimeout(futTimeout)):
# Successfully connected to peers
return true
else:
# Failed to connect to peers
raise newException(ValueError, "Failed to connect to peers: " & $peers)
for i, peer in peers:
let conn = await node.peerManager.dialPeer(parseRemotePeerInfo(peer), WakuRelayCodec, source="rpc")
if conn.isNone():
raise newException(ValueError, "Failed to connect to peer at index: " & $i & " " & $peer)
return true

rpcsrv.rpc("get_waku_v2_admin_v1_peers") do() -> seq[WakuPeer]:
## Returns a list of peers registered for this node
Expand Down