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

This commit is contained in:
Alvaro Revuelta 2023-01-09 14:15:03 +01:00 committed by GitHub
parent 019f357dc9
commit 333ce0a2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -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()

View File

@ -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