mirror of https://github.com/vacp2p/nim-libp2p.git
Make ObservedAddrManager injectable (#970)
This commit is contained in:
parent
6791f5e7bb
commit
4b3bc4f819
|
@ -25,7 +25,7 @@ import
|
||||||
muxers/[muxer, mplex/mplex, yamux/yamux],
|
muxers/[muxer, mplex/mplex, yamux/yamux],
|
||||||
protocols/[identify, secure/secure, secure/noise, rendezvous],
|
protocols/[identify, secure/secure, secure/noise, rendezvous],
|
||||||
protocols/connectivity/[autonat/server, relay/relay, relay/client, relay/rtransport],
|
protocols/connectivity/[autonat/server, relay/relay, relay/client, relay/rtransport],
|
||||||
connmanager, upgrademngrs/muxedupgrade,
|
connmanager, upgrademngrs/muxedupgrade, observedaddrmanager,
|
||||||
nameresolving/nameresolver,
|
nameresolving/nameresolver,
|
||||||
errors, utility
|
errors, utility
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ type
|
||||||
circuitRelay: Relay
|
circuitRelay: Relay
|
||||||
rdv: RendezVous
|
rdv: RendezVous
|
||||||
services: seq[Service]
|
services: seq[Service]
|
||||||
|
observedAddrManager: ObservedAddrManager
|
||||||
|
|
||||||
proc new*(T: type[SwitchBuilder]): T {.public.} =
|
proc new*(T: type[SwitchBuilder]): T {.public.} =
|
||||||
## Creates a SwitchBuilder
|
## Creates a SwitchBuilder
|
||||||
|
@ -201,6 +202,10 @@ proc withServices*(b: SwitchBuilder, services: seq[Service]): SwitchBuilder =
|
||||||
b.services = services
|
b.services = services
|
||||||
b
|
b
|
||||||
|
|
||||||
|
proc withObservedAddrManager*(b: SwitchBuilder, observedAddrManager: ObservedAddrManager): SwitchBuilder =
|
||||||
|
b.observedAddrManager = observedAddrManager
|
||||||
|
b
|
||||||
|
|
||||||
proc build*(b: SwitchBuilder): Switch
|
proc build*(b: SwitchBuilder): Switch
|
||||||
{.raises: [LPError], public.} =
|
{.raises: [LPError], public.} =
|
||||||
|
|
||||||
|
@ -223,8 +228,13 @@ proc build*(b: SwitchBuilder): Switch
|
||||||
protoVersion = b.protoVersion,
|
protoVersion = b.protoVersion,
|
||||||
agentVersion = b.agentVersion)
|
agentVersion = b.agentVersion)
|
||||||
|
|
||||||
|
let identify =
|
||||||
|
if b.observedAddrManager != nil:
|
||||||
|
Identify.new(peerInfo, b.sendSignedPeerRecord, b.observedAddrManager)
|
||||||
|
else:
|
||||||
|
Identify.new(peerInfo, b.sendSignedPeerRecord)
|
||||||
|
|
||||||
let
|
let
|
||||||
identify = Identify.new(peerInfo, b.sendSignedPeerRecord)
|
|
||||||
connManager = ConnManager.new(b.maxConnsPerPeer, b.maxConnections, b.maxIn, b.maxOut)
|
connManager = ConnManager.new(b.maxConnsPerPeer, b.maxConnections, b.maxIn, b.maxOut)
|
||||||
ms = MultistreamSelect.new()
|
ms = MultistreamSelect.new()
|
||||||
muxedUpgrade = MuxedUpgrade.new(b.muxers, secureManagerInstances, ms)
|
muxedUpgrade = MuxedUpgrade.new(b.muxers, secureManagerInstances, ms)
|
||||||
|
|
|
@ -139,12 +139,13 @@ proc decodeMsg*(buf: seq[byte]): Opt[IdentifyInfo] =
|
||||||
proc new*(
|
proc new*(
|
||||||
T: typedesc[Identify],
|
T: typedesc[Identify],
|
||||||
peerInfo: PeerInfo,
|
peerInfo: PeerInfo,
|
||||||
sendSignedPeerRecord = false
|
sendSignedPeerRecord = false,
|
||||||
|
observedAddrManager = ObservedAddrManager.new(),
|
||||||
): T =
|
): T =
|
||||||
let identify = T(
|
let identify = T(
|
||||||
peerInfo: peerInfo,
|
peerInfo: peerInfo,
|
||||||
sendSignedPeerRecord: sendSignedPeerRecord,
|
sendSignedPeerRecord: sendSignedPeerRecord,
|
||||||
observedAddrManager: ObservedAddrManager.new(),
|
observedAddrManager: observedAddrManager,
|
||||||
)
|
)
|
||||||
identify.init()
|
identify.init()
|
||||||
identify
|
identify
|
||||||
|
|
Loading…
Reference in New Issue