mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-06 07:53:12 +00:00
chore: improve connection proc (#3509)
This commit is contained in:
parent
1e920348ec
commit
4b3de54fc5
@ -56,22 +56,6 @@ proc destroyShared(self: ptr PeerManagementRequest) =
|
|||||||
|
|
||||||
deallocShared(self)
|
deallocShared(self)
|
||||||
|
|
||||||
proc connectTo(
|
|
||||||
node: WakuNode, peerMultiAddr: string, dialTimeout: Duration
|
|
||||||
): Result[void, string] =
|
|
||||||
let peers = (peerMultiAddr).split(",").mapIt(strip(it))
|
|
||||||
|
|
||||||
# TODO: the dialTimeout is not being used at all!
|
|
||||||
let connectFut = node.connectToNodes(peers, source = "static")
|
|
||||||
while not connectFut.finished():
|
|
||||||
poll()
|
|
||||||
|
|
||||||
if not connectFut.completed():
|
|
||||||
let msg = "Timeout expired."
|
|
||||||
return err(msg)
|
|
||||||
|
|
||||||
return ok()
|
|
||||||
|
|
||||||
proc process*(
|
proc process*(
|
||||||
self: ptr PeerManagementRequest, waku: Waku
|
self: ptr PeerManagementRequest, waku: Waku
|
||||||
): Future[Result[string, string]] {.async.} =
|
): Future[Result[string, string]] {.async.} =
|
||||||
@ -80,10 +64,9 @@ proc process*(
|
|||||||
|
|
||||||
case self.operation
|
case self.operation
|
||||||
of CONNECT_TO:
|
of CONNECT_TO:
|
||||||
let ret = waku.node.connectTo($self[].peerMultiAddr, self[].dialTimeout)
|
let peers = ($self[].peerMultiAddr).split(",").mapIt(strip(it))
|
||||||
if ret.isErr():
|
await waku.node.connectToNodes(peers, source = "static")
|
||||||
error "CONNECT_TO failed", error = ret.error
|
return ok("")
|
||||||
return err(ret.error)
|
|
||||||
of GET_ALL_PEER_IDS:
|
of GET_ALL_PEER_IDS:
|
||||||
## returns a comma-separated string of peerIDs
|
## returns a comma-separated string of peerIDs
|
||||||
let peerIDs =
|
let peerIDs =
|
||||||
|
|||||||
@ -567,6 +567,9 @@ procSuite "Peer Manager":
|
|||||||
# Connect to relay peers
|
# Connect to relay peers
|
||||||
await nodes[0].peerManager.connectToRelayPeers()
|
await nodes[0].peerManager.connectToRelayPeers()
|
||||||
|
|
||||||
|
# wait for the connections to settle
|
||||||
|
await sleepAsync(chronos.milliseconds(500))
|
||||||
|
|
||||||
check:
|
check:
|
||||||
# Peerstore track all three peers
|
# Peerstore track all three peers
|
||||||
nodes[0].peerManager.switch.peerStore.peers().len == 3
|
nodes[0].peerManager.switch.peerStore.peers().len == 3
|
||||||
@ -637,6 +640,9 @@ procSuite "Peer Manager":
|
|||||||
# Connect to relay peers
|
# Connect to relay peers
|
||||||
await nodes[0].peerManager.manageRelayPeers()
|
await nodes[0].peerManager.manageRelayPeers()
|
||||||
|
|
||||||
|
# wait for the connections to settle
|
||||||
|
await sleepAsync(chronos.milliseconds(500))
|
||||||
|
|
||||||
check:
|
check:
|
||||||
# Peerstore track all three peers
|
# Peerstore track all three peers
|
||||||
nodes[0].peerManager.switch.peerStore.peers().len == 3
|
nodes[0].peerManager.switch.peerStore.peers().len == 3
|
||||||
|
|||||||
@ -372,14 +372,6 @@ proc connectToNodes*(
|
|||||||
info "Finished dialing multiple peers",
|
info "Finished dialing multiple peers",
|
||||||
successfulConns = connectedPeers.len, attempted = nodes.len
|
successfulConns = connectedPeers.len, attempted = nodes.len
|
||||||
|
|
||||||
# The issue seems to be around peers not being fully connected when
|
|
||||||
# trying to subscribe. So what we do is sleep to guarantee nodes are
|
|
||||||
# fully connected.
|
|
||||||
#
|
|
||||||
# This issue was known to Dmitiry on nim-libp2p and may be resolvable
|
|
||||||
# later.
|
|
||||||
await sleepAsync(chronos.seconds(5))
|
|
||||||
|
|
||||||
proc disconnectNode*(pm: PeerManager, peerId: PeerId) {.async.} =
|
proc disconnectNode*(pm: PeerManager, peerId: PeerId) {.async.} =
|
||||||
await pm.switch.disconnect(peerId)
|
await pm.switch.disconnect(peerId)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user