Skip to content

Commit

Permalink
Reflect review notices, code refinement - no change in functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
NagyZoltanPeter committed Oct 5, 2023
1 parent 0740eee commit 0ad4bc8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
1 change: 0 additions & 1 deletion tests/wakunode_rest/test_rest_admin.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ suite "Waku v2 Rest API - Admin":
it.multiaddr == constructMultiaddrStr(peerInfo3))

asyncTest "Set wrong peer":
# Connect to nodes 2 and 3 using the Admin API
let nonExistentPeer = "/ip4/0.0.0.0/tcp/10000/p2p/16Uiu2HAm6HZZr7aToTvEBPpiys4UxajCTU97zj5v7RNR2gbniy1D"
let postRes = await client.postPeers(@[nonExistentPeer])

Expand Down
16 changes: 5 additions & 11 deletions waku/waku_api/rest/admin/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,14 @@ proc installAdminV1GetPeersHandler(router: var RestRouter, node: WakuNode) =
proc installAdminV1PostPeersHandler(router: var RestRouter, node: WakuNode) =
router.api(MethodPost, ROUTE_ADMIN_V1_PEERS) do (contentBody: Option[ContentBody]) -> RestApiResponse:

let decodedBody = decodeRequestBody[seq[string]](contentBody)

if decodedBody.isErr():
return RestApiResponse.badRequest(fmt("Failed to decode request: {decodedBody.error}"))

let peers: seq[string] = decodedBody.value()
let peers: seq[string] = decodeRequestBody[seq[string]](contentBody).valueOr:
return RestApiResponse.badRequest(fmt("Failed to decode request: {error}"))

for i, peer in peers:
let peerInfo = parsePeerInfo(peer)
if peerInfo.isErr():
return RestApiResponse.badRequest(fmt("Couldn't parse remote peer info: {peerInfo.error}"))
let peerInfo = parsePeerInfo(peer).valueOr:
return RestApiResponse.badRequest(fmt("Couldn't parse remote peer info: {error}"))

let connOk = await node.peerManager.connectRelay(peerInfo.value, source="rest")
if not connOk:
if not (await node.peerManager.connectRelay(peerInfo, source="rest")):
return RestApiResponse.badRequest(fmt("Failed to connect to peer at index: {i} - {peer}"))

return RestApiResponse.ok()
Expand Down

0 comments on commit 0ad4bc8

Please sign in to comment.