Skip to content

Commit

Permalink
renaming to connectPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 29, 2024
1 parent a58fb41 commit a5e9ad8
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 50 deletions.
4 changes: 3 additions & 1 deletion tests/node/test_wakunode_peer_exchange.nim
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ suite "Waku Peer Exchange with discv5":
attempts -= 1

# node2 can be connected, so will be returned by peer exchange
require (await node1.peerManager.connect(node2.switch.peerInfo.toRemotePeerInfo()))
require (
await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo())
)

# Mount peer exchange
await node1.mountPeerExchange()
Expand Down
37 changes: 19 additions & 18 deletions tests/test_peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ procSuite "Peer Manager":
await allFutures(nodes.mapIt(it.start()))

let connOk =
await nodes[0].peerManager.connect(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.connect(nonExistentPeer)) == false
(await nodes[0].peerManager.connectPeer(nonExistentPeer)) == false
await sleepAsync(chronos.milliseconds(500))

check:
Expand All @@ -188,7 +188,8 @@ procSuite "Peer Manager":

# Successful connection
require:
(await nodes[0].peerManager.connect(nodes[1].peerInfo.toRemotePeerInfo())) == true
(await nodes[0].peerManager.connectPeer(nodes[1].peerInfo.toRemotePeerInfo())) ==
true
await sleepAsync(chronos.milliseconds(500))

check:
Expand Down Expand Up @@ -228,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.connect(nonExistentPeer)
let conn1Ok = await nodes[0].peerManager.connectPeer(nonExistentPeer)
check:
# Cannot connect to node2
nodes[0].peerManager.wakuPeerStore.connectedness(nonExistentPeer.peerId) ==
Expand All @@ -255,7 +256,7 @@ procSuite "Peer Manager":
nodes[0].peerManager.wakuPeerStore[NumberFailedConnBook][nodes[1].peerInfo.peerId] =
4
let conn2Ok =
await nodes[0].peerManager.connect(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 @@ -285,7 +286,7 @@ procSuite "Peer Manager":
var remotePeerInfo2 = peerInfo2.toRemotePeerInfo()
remotePeerInfo2.enr = some(node2.enr)

let is12Connected = await node1.peerManager.connect(remotePeerInfo2)
let is12Connected = await node1.peerManager.connectPeer(remotePeerInfo2)
assert is12Connected == true, "Node 1 and 2 not connected"

check:
Expand Down Expand Up @@ -355,7 +356,7 @@ procSuite "Peer Manager":
var remotePeerInfo2 = peerInfo2.toRemotePeerInfo()
remotePeerInfo2.enr = some(node2.enr)

let is12Connected = await node1.peerManager.connect(remotePeerInfo2)
let is12Connected = await node1.peerManager.connectPeer(remotePeerInfo2)
assert is12Connected == true, "Node 1 and 2 not connected"

check:
Expand Down Expand Up @@ -484,7 +485,7 @@ procSuite "Peer Manager":
node2.wakuRelay.codec = betaCodec

require:
(await node1.peerManager.connect(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 @@ -681,9 +682,9 @@ procSuite "Peer Manager":

# all nodes connect to peer 0
require:
(await nodes[1].peerManager.connect(peerInfos[0])) == true
(await nodes[2].peerManager.connect(peerInfos[0])) == true
(await nodes[3].peerManager.connect(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 @@ -809,9 +810,9 @@ procSuite "Peer Manager":
# create some connections/streams
check:
# some relay connections
(await nodes[0].peerManager.connect(pInfos[1])) == true
(await nodes[0].peerManager.connect(pInfos[2])) == true
(await nodes[1].peerManager.connect(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 @@ -1128,16 +1129,16 @@ procSuite "Peer Manager":
nodes[0].peerManager.colocationLimit = 1

# 2 in connections
discard await nodes[1].peerManager.connect(pInfos[0])
discard await nodes[2].peerManager.connect(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.connect(pInfos[3])
discard await nodes[0].peerManager.connect(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
6 changes: 4 additions & 2 deletions tests/test_wakunode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ suite "WakuNode":
await node3.start()
await node3.mountRelay()

discard await node1.peerManager.connect(node2.switch.peerInfo.toRemotePeerInfo())
discard
await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo())
await sleepAsync(3.seconds)
discard await node1.peerManager.connect(node3.switch.peerInfo.toRemotePeerInfo())
discard
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.connect(node2.switch.peerInfo.toRemotePeerInfo())
await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo())
)

# Mount peer exchange
Expand Down
30 changes: 15 additions & 15 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.connect(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.connect(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.connect(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.connect(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.connect(otherRemotePeerInfo)
await peerManager.connect(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.connect(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.connect(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.connect(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.connect(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.connect(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.connect(otherRemotePeerInfo)
check await peerManager.connectPeer(otherRemotePeerInfo)

# FIXME: Once stopped and started, nodes are not considered connected, nor do they reconnect after running connect, as below
# check await otherPeerManager.connect(otherRemotePeerInfo)
# 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.connect(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.connect(otherRemotePeerInfo)
check await peerManager.connectPeer(otherRemotePeerInfo)

# Given both are subscribed to the same pubsub topic
var otherHandlerFuture = newPushHandlerFuture()
Expand Down
7 changes: 4 additions & 3 deletions tests/waku_relay/test_wakunode_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ suite "WakuNode - Relay":
await allFutures(nodes.mapIt(it.mountRelay()))

# Connect nodes
let connOk =
await nodes[0].peerManager.connect(nodes[1].switch.peerInfo.toRemotePeerInfo())
let connOk = await nodes[0].peerManager.connectPeer(
nodes[1].switch.peerInfo.toRemotePeerInfo()
)
require:
connOk == true

Expand Down Expand Up @@ -520,7 +521,7 @@ suite "WakuNode - Relay":
for j in 0 ..< 5:
if i == j:
continue
let connOk = await nodes[i].peerManager.connect(
let connOk = await nodes[i].peerManager.connectPeer(
nodes[j].switch.peerInfo.toRemotePeerInfo()
)
require connOk
Expand Down
11 changes: 6 additions & 5 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.connect(
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.connect(
let connOk = await nodes[i].peerManager.connectPeer(
nodes[j].switch.peerInfo.toRemotePeerInfo()
)
require connOk
Expand Down Expand Up @@ -305,16 +305,17 @@ suite "WakuNode2 - Validators":
)

# nodes[0] is connected only to nodes[1]
let connOk1 =
await nodes[0].peerManager.connect(nodes[1].switch.peerInfo.toRemotePeerInfo())
let connOk1 = await nodes[0].peerManager.connectPeer(
nodes[1].switch.peerInfo.toRemotePeerInfo()
)
require connOk1

# rest of nodes[1..4] are connected in a full mesh
for i in 1 ..< 5:
for j in 1 ..< 5:
if i == j:
continue
let connOk2 = await nodes[i].peerManager.connect(
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.connect(peerInfo2)
let conn3 = await node1.peerManager.connect(peerInfo3)
let conn2 = await node1.peerManager.connectPeer(peerInfo2)
let conn3 = await node1.peerManager.connectPeer(peerInfo3)

# Check successful connections
check:
Expand Down
4 changes: 2 additions & 2 deletions waku/node/peer_manager/peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 connect*(
proc connectPeer*(
pm: PeerManager,
peer: RemotePeerInfo,
dialTimeout = DefaultDialTimeout,
Expand Down Expand Up @@ -352,7 +352,7 @@ proc connectToNodes*(
for node in nodes:
let node = parsePeerInfo(node)
if node.isOk():
futConns.add(pm.connect(node.value))
futConns.add(pm.connectPeer(node.value))
connectedPeers.add(node.value)
else:
error "Couldn't parse node info", error = node.error
Expand Down
2 changes: 1 addition & 1 deletion waku/waku_api/rest/admin/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.connect(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}")
)
Expand Down

0 comments on commit a5e9ad8

Please sign in to comment.