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

chore: naming connect procedure #3157

Merged
merged 12 commits into from
Oct 29, 2024
2 changes: 1 addition & 1 deletion tests/node/test_wakunode_peer_exchange.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions tests/test_peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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))
)
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:
Expand Down Expand Up @@ -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:
Expand All @@ -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))

Expand Down Expand Up @@ -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) ==
Expand All @@ -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] ==
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_wakunode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/waku_peer_exchange/test_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions tests/waku_relay/test_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/waku_relay/test_wakunode_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/wakunode2/test_validators.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/wakunode_rest/test_rest_admin.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Comment on lines -405 to -416
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need these conditions that I added. When I added them I thought that connectToNodes, which called connectRelay, were only related to Relay protocol but the function name was a misnomer

info "Connecting to dynamic bootstrap peers"
try:
await connectToNodes(node, dynamicBootstrapNodes, "dynamic bootstrap")
Expand Down
Loading
Loading