mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-01-14 18:54:33 +00:00
454f658ba8
* Bugfix: Dialing an already connected peer may lead to crash * Introduced a standard_setup module allowing to instantiate the `Switch` object in an easier manner. * Added `Switch.disconnect(peer)` * Trailing space removed (sorry about polluting the diff)
16 lines
484 B
Nim
16 lines
484 B
Nim
import options, tables
|
|
import chronos
|
|
import ../../libp2p/standard_setup
|
|
export standard_setup
|
|
|
|
proc generateNodes*(num: Natural, gossip: bool = false): seq[Switch] =
|
|
for i in 0..<num:
|
|
result.add(newStandardSwitch(gossip = gossip))
|
|
|
|
proc subscribeNodes*(nodes: seq[Switch]) {.async.} =
|
|
for dialer in nodes:
|
|
for node in nodes:
|
|
if dialer.peerInfo.peerId != node.peerInfo.peerId:
|
|
await dialer.subscribeToPeer(node.peerInfo)
|
|
await sleepAsync(100.millis)
|