mirror of https://github.com/waku-org/nwaku.git
fix(rpc): return error if peer cant be connected (#1476)
This commit is contained in:
parent
019f357dc9
commit
333ce0a2e1
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
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
|
||||
else:
|
||||
# Failed to connect to peers
|
||||
raise newException(ValueError, "Failed to connect to peers: " & $peers)
|
||||
|
||||
rpcsrv.rpc("get_waku_v2_admin_v1_peers") do() -> seq[WakuPeer]:
|
||||
## Returns a list of peers registered for this node
|
||||
|
|
Loading…
Reference in New Issue