diff --git a/tests/node/test_wakunode_peer_exchange.nim b/tests/node/test_wakunode_peer_exchange.nim index 6da8d3fa30..edb262b0ed 100644 --- a/tests/node/test_wakunode_peer_exchange.nim +++ b/tests/node/test_wakunode_peer_exchange.nim @@ -272,7 +272,7 @@ suite "Waku Peer Exchange with discv5": # node2 can be connected, so will be returned by peer exchange require ( - await node1.peerManager.connectRelay(node2.switch.peerInfo.toRemotePeerInfo()) + await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo()) ) # Mount peer exchange diff --git a/tests/test_peer_manager.nim b/tests/test_peer_manager.nim index bcc3821cab..8e006848df 100644 --- a/tests/test_peer_manager.nim +++ b/tests/test_peer_manager.nim @@ -37,7 +37,7 @@ import ./testlib/wakunode procSuite "Peer Manager": - asyncTest "connectRelay() works": + asyncTest "connectPeer() works": # Create 2 nodes let nodes = toSeq(0 ..< 2).mapIt( newTestWakuNode(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)) @@ -45,7 +45,7 @@ procSuite "Peer Manager": await allFutures(nodes.mapIt(it.start())) let connOk = - await nodes[0].peerManager.connectRelay(nodes[1].peerInfo.toRemotePeerInfo()) + await nodes[0].peerManager.connectPeer(nodes[1].peerInfo.toRemotePeerInfo()) await sleepAsync(chronos.milliseconds(500)) check: @@ -178,7 +178,7 @@ procSuite "Peer Manager": let nonExistentPeer = nonExistentPeerRes.value require: - (await nodes[0].peerManager.connectRelay(nonExistentPeer)) == false + (await nodes[0].peerManager.connectPeer(nonExistentPeer)) == false await sleepAsync(chronos.milliseconds(500)) check: @@ -188,7 +188,7 @@ procSuite "Peer Manager": # Successful connection require: - (await nodes[0].peerManager.connectRelay(nodes[1].peerInfo.toRemotePeerInfo())) == + (await nodes[0].peerManager.connectPeer(nodes[1].peerInfo.toRemotePeerInfo())) == true await sleepAsync(chronos.milliseconds(500)) @@ -229,7 +229,7 @@ procSuite "Peer Manager": nodes[0].peerManager.backoffFactor = 2 # try to connect to peer that doesnt exist - let conn1Ok = await nodes[0].peerManager.connectRelay(nonExistentPeer) + let conn1Ok = await nodes[0].peerManager.connectPeer(nonExistentPeer) check: # Cannot connect to node2 nodes[0].peerManager.wakuPeerStore.connectedness(nonExistentPeer.peerId) == @@ -256,7 +256,7 @@ procSuite "Peer Manager": nodes[0].peerManager.wakuPeerStore[NumberFailedConnBook][nodes[1].peerInfo.peerId] = 4 let conn2Ok = - await nodes[0].peerManager.connectRelay(nodes[1].peerInfo.toRemotePeerInfo()) + await nodes[0].peerManager.connectPeer(nodes[1].peerInfo.toRemotePeerInfo()) check: conn2Ok == true nodes[0].peerManager.wakuPeerStore[NumberFailedConnBook][nodes[1].peerInfo.peerId] == @@ -286,7 +286,7 @@ procSuite "Peer Manager": var remotePeerInfo2 = peerInfo2.toRemotePeerInfo() remotePeerInfo2.enr = some(node2.enr) - let is12Connected = await node1.peerManager.connectRelay(remotePeerInfo2) + let is12Connected = await node1.peerManager.connectPeer(remotePeerInfo2) assert is12Connected == true, "Node 1 and 2 not connected" check: @@ -356,7 +356,7 @@ procSuite "Peer Manager": var remotePeerInfo2 = peerInfo2.toRemotePeerInfo() remotePeerInfo2.enr = some(node2.enr) - let is12Connected = await node1.peerManager.connectRelay(remotePeerInfo2) + let is12Connected = await node1.peerManager.connectPeer(remotePeerInfo2) assert is12Connected == true, "Node 1 and 2 not connected" check: @@ -485,7 +485,7 @@ procSuite "Peer Manager": node2.wakuRelay.codec = betaCodec require: - (await node1.peerManager.connectRelay(peerInfo2.toRemotePeerInfo())) == true + (await node1.peerManager.connectPeer(peerInfo2.toRemotePeerInfo())) == true check: # Currently connected to node2 node1.peerManager.wakuPeerStore.peers().len == 1 @@ -682,9 +682,9 @@ procSuite "Peer Manager": # all nodes connect to peer 0 require: - (await nodes[1].peerManager.connectRelay(peerInfos[0])) == true - (await nodes[2].peerManager.connectRelay(peerInfos[0])) == true - (await nodes[3].peerManager.connectRelay(peerInfos[0])) == true + (await nodes[1].peerManager.connectPeer(peerInfos[0])) == true + (await nodes[2].peerManager.connectPeer(peerInfos[0])) == true + (await nodes[3].peerManager.connectPeer(peerInfos[0])) == true await sleepAsync(chronos.milliseconds(500)) @@ -810,9 +810,9 @@ procSuite "Peer Manager": # create some connections/streams check: # some relay connections - (await nodes[0].peerManager.connectRelay(pInfos[1])) == true - (await nodes[0].peerManager.connectRelay(pInfos[2])) == true - (await nodes[1].peerManager.connectRelay(pInfos[2])) == true + (await nodes[0].peerManager.connectPeer(pInfos[1])) == true + (await nodes[0].peerManager.connectPeer(pInfos[2])) == true + (await nodes[1].peerManager.connectPeer(pInfos[2])) == true (await nodes[0].peerManager.dialPeer(pInfos[1], WakuFilterSubscribeCodec)).isSome() == true @@ -1129,16 +1129,16 @@ procSuite "Peer Manager": nodes[0].peerManager.colocationLimit = 1 # 2 in connections - discard await nodes[1].peerManager.connectRelay(pInfos[0]) - discard await nodes[2].peerManager.connectRelay(pInfos[0]) + discard await nodes[1].peerManager.connectPeer(pInfos[0]) + discard await nodes[2].peerManager.connectPeer(pInfos[0]) await sleepAsync(chronos.milliseconds(500)) # but one is pruned check nodes[0].peerManager.switch.connManager.getConnections().len == 1 # 2 out connections - discard await nodes[0].peerManager.connectRelay(pInfos[3]) - discard await nodes[0].peerManager.connectRelay(pInfos[4]) + discard await nodes[0].peerManager.connectPeer(pInfos[3]) + discard await nodes[0].peerManager.connectPeer(pInfos[4]) await sleepAsync(chronos.milliseconds(500)) # they are also prunned diff --git a/tests/test_wakunode.nim b/tests/test_wakunode.nim index dbb2d5d8db..b148684fe0 100644 --- a/tests/test_wakunode.nim +++ b/tests/test_wakunode.nim @@ -138,10 +138,10 @@ suite "WakuNode": await node3.mountRelay() discard - await node1.peerManager.connectRelay(node2.switch.peerInfo.toRemotePeerInfo()) + await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo()) await sleepAsync(3.seconds) discard - await node1.peerManager.connectRelay(node3.switch.peerInfo.toRemotePeerInfo()) + await node1.peerManager.connectPeer(node3.switch.peerInfo.toRemotePeerInfo()) check: # Verify that only the first connection succeeded diff --git a/tests/waku_peer_exchange/test_protocol.nim b/tests/waku_peer_exchange/test_protocol.nim index 6c044586a4..11a61c4dc3 100644 --- a/tests/waku_peer_exchange/test_protocol.nim +++ b/tests/waku_peer_exchange/test_protocol.nim @@ -120,7 +120,7 @@ suite "Waku Peer Exchange": # node2 can be connected, so will be returned by peer exchange require ( - await node1.peerManager.connectRelay(node2.switch.peerInfo.toRemotePeerInfo()) + await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo()) ) # Mount peer exchange diff --git a/tests/waku_relay/test_protocol.nim b/tests/waku_relay/test_protocol.nim index 871cfb28d5..399b55ea88 100644 --- a/tests/waku_relay/test_protocol.nim +++ b/tests/waku_relay/test_protocol.nim @@ -104,7 +104,7 @@ suite "Waku Relay": await allFutures(otherSwitch.start(), otherNode.start()) let otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) var otherHandlerFuture = newPushHandlerFuture() proc otherSimpleFutureHandler( @@ -165,7 +165,7 @@ suite "Waku Relay": await allFutures(otherSwitch.start(), otherNode.start()) let otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) var otherHandlerFuture = newPushHandlerFuture() proc otherSimpleFutureHandler( @@ -284,7 +284,7 @@ suite "Waku Relay": await allFutures(otherSwitch.start(), otherNode.start()) let otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) var otherHandlerFuture = newPushHandlerFuture() proc otherSimpleFutureHandler( @@ -374,7 +374,7 @@ suite "Waku Relay": await allFutures(otherSwitch.start(), otherNode.start()) let otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) var otherHandlerFuture = newPushHandlerFuture() proc otherSimpleFutureHandler( @@ -456,8 +456,8 @@ suite "Waku Relay": anotherPeerId = anotherRemotePeerInfo.peerId check: - await peerManager.connectRelay(otherRemotePeerInfo) - await peerManager.connectRelay(anotherRemotePeerInfo) + await peerManager.connectPeer(otherRemotePeerInfo) + await peerManager.connectPeer(anotherRemotePeerInfo) # Given the first node is subscribed to two pubsub topics var handlerFuture2 = newPushHandlerFuture() @@ -673,7 +673,7 @@ suite "Waku Relay": otherMsg6 == fromOtherNodeWakuMessage3 # Given anotherNode is reconnected, but to otherNode - check await anotherPeerManager.connectRelay(otherRemotePeerInfo) + check await anotherPeerManager.connectPeer(otherRemotePeerInfo) check: anotherPeerManager.switch.isConnected(otherPeerId) otherPeerManager.switch.isConnected(anotherPeerId) @@ -848,7 +848,7 @@ suite "Waku Relay": await allFutures(otherSwitch.start(), otherNode.start()) let otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) # Given both are subscribed to the same pubsub topic var otherHandlerFuture = newPushHandlerFuture() @@ -1014,7 +1014,7 @@ suite "Waku Relay": await allFutures(otherSwitch.start(), otherNode.start()) let otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) # Given both are subscribed to the same pubsub topic var otherHandlerFuture = newPushHandlerFuture() @@ -1145,7 +1145,7 @@ suite "Waku Relay": await allFutures(otherSwitch.start(), otherNode.start()) let otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) # Given both are subscribed to the same pubsub topic # Create a different handler than the default to include messages in a seq @@ -1230,7 +1230,7 @@ suite "Waku Relay": otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() otherPeerId = otherRemotePeerInfo.peerId - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) # Given both are subscribed to the same pubsub topic var otherHandlerFuture = newPushHandlerFuture() @@ -1250,10 +1250,10 @@ suite "Waku Relay": await otherSwitch.stop() await otherSwitch.start() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) - # FIXME: Once stopped and started, nodes are not considered connected, nor do they reconnect after running connectRelay, as below - # check await otherPeerManager.connectRelay(otherRemotePeerInfo) + # FIXME: Once stopped and started, nodes are not considered connected, nor do they reconnect after running connectPeer, as below + # check await otherPeerManager.connectPeer(otherRemotePeerInfo) # When sending a message from node let msg1 = fakeWakuMessage(testMessage, pubsubTopic) @@ -1282,7 +1282,7 @@ suite "Waku Relay": # Given node is stopped and restarted await switch.stop() await switch.start() - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) # When sending a message from node handlerFuture = newPushHandlerFuture() @@ -1325,7 +1325,7 @@ suite "Waku Relay": otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() otherPeerId = otherRemotePeerInfo.peerId - check await peerManager.connectRelay(otherRemotePeerInfo) + check await peerManager.connectPeer(otherRemotePeerInfo) # Given both are subscribed to the same pubsub topic var otherHandlerFuture = newPushHandlerFuture() diff --git a/tests/waku_relay/test_wakunode_relay.nim b/tests/waku_relay/test_wakunode_relay.nim index b93875e831..398470163e 100644 --- a/tests/waku_relay/test_wakunode_relay.nim +++ b/tests/waku_relay/test_wakunode_relay.nim @@ -213,7 +213,7 @@ suite "WakuNode - Relay": await allFutures(nodes.mapIt(it.mountRelay())) # Connect nodes - let connOk = await nodes[0].peerManager.connectRelay( + let connOk = await nodes[0].peerManager.connectPeer( nodes[1].switch.peerInfo.toRemotePeerInfo() ) require: @@ -521,7 +521,7 @@ suite "WakuNode - Relay": for j in 0 ..< 5: if i == j: continue - let connOk = await nodes[i].peerManager.connectRelay( + let connOk = await nodes[i].peerManager.connectPeer( nodes[j].switch.peerInfo.toRemotePeerInfo() ) require connOk diff --git a/tests/wakunode2/test_validators.nim b/tests/wakunode2/test_validators.nim index 058d2bedf4..03bc9c99dd 100644 --- a/tests/wakunode2/test_validators.nim +++ b/tests/wakunode2/test_validators.nim @@ -60,7 +60,7 @@ suite "WakuNode2 - Validators": for j in 0 ..< 5: if i == j: continue - let connOk = await nodes[i].peerManager.connectRelay( + let connOk = await nodes[i].peerManager.connectPeer( nodes[j].switch.peerInfo.toRemotePeerInfo() ) require connOk @@ -150,7 +150,7 @@ suite "WakuNode2 - Validators": for j in 0 ..< 5: if i == j: continue - let connOk = await nodes[i].peerManager.connectRelay( + let connOk = await nodes[i].peerManager.connectPeer( nodes[j].switch.peerInfo.toRemotePeerInfo() ) require connOk @@ -305,7 +305,7 @@ suite "WakuNode2 - Validators": ) # nodes[0] is connected only to nodes[1] - let connOk1 = await nodes[0].peerManager.connectRelay( + let connOk1 = await nodes[0].peerManager.connectPeer( nodes[1].switch.peerInfo.toRemotePeerInfo() ) require connOk1 @@ -315,7 +315,7 @@ suite "WakuNode2 - Validators": for j in 1 ..< 5: if i == j: continue - let connOk2 = await nodes[i].peerManager.connectRelay( + let connOk2 = await nodes[i].peerManager.connectPeer( nodes[j].switch.peerInfo.toRemotePeerInfo() ) require connOk2 diff --git a/tests/wakunode_rest/test_rest_admin.nim b/tests/wakunode_rest/test_rest_admin.nim index 51d1133957..fdb0cbc41d 100644 --- a/tests/wakunode_rest/test_rest_admin.nim +++ b/tests/wakunode_rest/test_rest_admin.nim @@ -184,8 +184,8 @@ suite "Waku v2 Rest API - Admin": node1.peerManager.addPeer(peerInfo3, PeerExchange) # Connecting to both peers - let conn2 = await node1.peerManager.connectRelay(peerInfo2) - let conn3 = await node1.peerManager.connectRelay(peerInfo3) + let conn2 = await node1.peerManager.connectPeer(peerInfo2) + let conn3 = await node1.peerManager.connectPeer(peerInfo3) # Check successful connections check: diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 0caa50259c..d4ac364f31 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -402,18 +402,12 @@ proc startNode*( # Connect to configured static nodes if conf.staticnodes.len > 0: - if not conf.relay: - return err("waku relay (--relay=true) should be set when configuring staticnodes") try: await connectToNodes(node, conf.staticnodes, "static") except CatchableError: return err("failed to connect to static nodes: " & getCurrentExceptionMsg()) if dynamicBootstrapNodes.len > 0: - if not conf.relay: - return err( - "waku relay (--relay=true) should be set when configuring dynamicBootstrapNodes" - ) info "Connecting to dynamic bootstrap peers" try: await connectToNodes(node, dynamicBootstrapNodes, "dynamic bootstrap") diff --git a/waku/node/peer_manager/peer_manager.nim b/waku/node/peer_manager/peer_manager.nim index cf633bb13d..e17e9fd0d1 100644 --- a/waku/node/peer_manager/peer_manager.nim +++ b/waku/node/peer_manager/peer_manager.nim @@ -279,7 +279,7 @@ proc pruneInRelayConns(pm: PeerManager, amount: int) {.async.} # Connects to a given node. Note that this function uses `connect` and # does not provide a protocol. Streams for relay (gossipsub) are created # automatically without the needing to dial. -proc connectRelay*( +proc connectPeer*( pm: PeerManager, peer: RemotePeerInfo, dialTimeout = DefaultDialTimeout, @@ -291,11 +291,11 @@ proc connectRelay*( if peerId == pm.switch.peerInfo.peerId: return false - if not pm.wakuPeerStore.hasPeer(peerId, WakuRelayCodec): + if not pm.wakuPeerStore.peerExists(peerId): pm.addPeer(peer) let failedAttempts = pm.wakuPeerStore[NumberFailedConnBook][peerId] - trace "Connecting to relay peer", + trace "Connecting to peer", wireAddr = peer.addrs, peerId = peerId, failedAttempts = failedAttempts var deadline = sleepAsync(dialTimeout) @@ -328,7 +328,7 @@ proc connectRelay*( pm.wakuPeerStore[LastFailedConnBook][peerId] = Moment.init(getTime().toUnix, Second) pm.wakuPeerStore[ConnectionBook][peerId] = CannotConnect - trace "Connecting relay peer failed", + trace "Connecting peer failed", peerId = peerId, reason = reasonFailed, failedAttempts = pm.wakuPeerStore[NumberFailedConnBook][peerId] @@ -352,7 +352,7 @@ proc connectToNodes*( for node in nodes: let node = parsePeerInfo(node) if node.isOk(): - futConns.add(pm.connectRelay(node.value)) + futConns.add(pm.connectPeer(node.value)) connectedPeers.add(node.value) else: error "Couldn't parse node info", error = node.error diff --git a/waku/waku_api/rest/admin/handlers.nim b/waku/waku_api/rest/admin/handlers.nim index ebdcc8ef63..b35ac6eae8 100644 --- a/waku/waku_api/rest/admin/handlers.nim +++ b/waku/waku_api/rest/admin/handlers.nim @@ -140,7 +140,7 @@ proc installAdminV1PostPeersHandler(router: var RestRouter, node: WakuNode) = let e = $error return RestApiResponse.badRequest(fmt("Couldn't parse remote peer info: {e}")) - if not (await node.peerManager.connectRelay(peerInfo, source = "rest")): + if not (await node.peerManager.connectPeer(peerInfo, source = "rest")): return RestApiResponse.badRequest( fmt("Failed to connect to peer at index: {i} - {peer}") )