mirror of https://github.com/vacp2p/nim-libp2p.git
fix(services): setup services before peerinfo is updated (#1120)
This commit is contained in:
parent
bccb305cf5
commit
120549e313
|
@ -349,13 +349,11 @@ proc start*(s: Switch) {.async, public.} =
|
||||||
s.acceptFuts.add(s.accept(t))
|
s.acceptFuts.add(s.accept(t))
|
||||||
s.peerInfo.listenAddrs &= t.addrs
|
s.peerInfo.listenAddrs &= t.addrs
|
||||||
|
|
||||||
await s.peerInfo.update()
|
|
||||||
|
|
||||||
await s.ms.start()
|
|
||||||
|
|
||||||
for service in s.services:
|
for service in s.services:
|
||||||
discard await service.setup(s)
|
discard await service.setup(s)
|
||||||
|
|
||||||
|
await s.peerInfo.update()
|
||||||
|
await s.ms.start()
|
||||||
s.started = true
|
s.started = true
|
||||||
|
|
||||||
debug "Started libp2p node", peer = s.peerInfo
|
debug "Started libp2p node", peer = s.peerInfo
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import std/[os, options, strformat]
|
import std/[os, options, strformat, sequtils]
|
||||||
import redis
|
import redis
|
||||||
import chronos, chronicles
|
import chronos, chronicles
|
||||||
import ../../libp2p/[builders,
|
import ../../libp2p/[builders,
|
||||||
switch,
|
switch,
|
||||||
|
multicodec,
|
||||||
observedaddrmanager,
|
observedaddrmanager,
|
||||||
services/hpservice,
|
services/hpservice,
|
||||||
services/autorelayservice,
|
services/autorelayservice,
|
||||||
|
@ -76,7 +77,7 @@ proc main() {.async.} =
|
||||||
debug "Connected to relay", relayId
|
debug "Connected to relay", relayId
|
||||||
|
|
||||||
# Wait for our relay address to be published
|
# Wait for our relay address to be published
|
||||||
while switch.peerInfo.addrs.len == 0:
|
while not switch.peerInfo.addrs.anyIt(it.contains(multiCodec("p2p-circuit")).tryGet()):
|
||||||
await sleepAsync(100.milliseconds)
|
await sleepAsync(100.milliseconds)
|
||||||
|
|
||||||
if isListener:
|
if isListener:
|
||||||
|
|
|
@ -23,7 +23,7 @@ import stubs/autonatclientstub
|
||||||
proc createSwitch(autonatSvc: Service = nil, withAutonat = true, maxConnsPerPeer = 1, maxConns = 100, nameResolver: NameResolver = nil): Switch =
|
proc createSwitch(autonatSvc: Service = nil, withAutonat = true, maxConnsPerPeer = 1, maxConns = 100, nameResolver: NameResolver = nil): Switch =
|
||||||
var builder = SwitchBuilder.new()
|
var builder = SwitchBuilder.new()
|
||||||
.withRng(newRng())
|
.withRng(newRng())
|
||||||
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ])
|
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ], false)
|
||||||
.withTcpTransport()
|
.withTcpTransport()
|
||||||
.withMaxConnsPerPeer(maxConnsPerPeer)
|
.withMaxConnsPerPeer(maxConnsPerPeer)
|
||||||
.withMaxConnections(maxConns)
|
.withMaxConnections(maxConns)
|
||||||
|
|
|
@ -20,7 +20,7 @@ import ./helpers
|
||||||
proc createSwitch(r: Relay, autorelay: Service = nil): Switch =
|
proc createSwitch(r: Relay, autorelay: Service = nil): Switch =
|
||||||
var builder = SwitchBuilder.new()
|
var builder = SwitchBuilder.new()
|
||||||
.withRng(newRng())
|
.withRng(newRng())
|
||||||
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ])
|
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ], false)
|
||||||
.withTcpTransport()
|
.withTcpTransport()
|
||||||
.withMplex()
|
.withMplex()
|
||||||
.withNoise()
|
.withNoise()
|
||||||
|
|
Loading…
Reference in New Issue