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