mirror of https://github.com/vacp2p/nim-libp2p.git
More builders (#560)
* address some issues pointed out in review * re-add to prevent breaking other projects
This commit is contained in:
parent
290866dd62
commit
6b930ae7e6
|
@ -3,8 +3,7 @@ import
|
||||||
switch, peerid, peerinfo, stream/connection, multiaddress,
|
switch, peerid, peerinfo, stream/connection, multiaddress,
|
||||||
crypto/crypto, transports/[transport, tcptransport],
|
crypto/crypto, transports/[transport, tcptransport],
|
||||||
muxers/[muxer, mplex/mplex],
|
muxers/[muxer, mplex/mplex],
|
||||||
protocols/[identify, secure/secure, secure/noise],
|
protocols/[identify, secure/secure, secure/noise]
|
||||||
connmanager
|
|
||||||
|
|
||||||
export
|
export
|
||||||
switch, peerid, peerinfo, connection, multiaddress, crypto
|
switch, peerid, peerinfo, connection, multiaddress, crypto
|
||||||
|
@ -36,13 +35,12 @@ type
|
||||||
protoVersion: string
|
protoVersion: string
|
||||||
agentVersion: string
|
agentVersion: string
|
||||||
|
|
||||||
proc init*(T: type[SwitchBuilder]): T =
|
proc new*(T: type[SwitchBuilder]): T =
|
||||||
SwitchBuilder(
|
SwitchBuilder(
|
||||||
privKey: none(PrivateKey),
|
privKey: none(PrivateKey),
|
||||||
address: MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
|
address: MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
|
||||||
secureManagers: @[],
|
secureManagers: @[],
|
||||||
tcpTransportOpts: TcpTransportOpts(),
|
tcpTransportOpts: TcpTransportOpts(),
|
||||||
rng: newRng(),
|
|
||||||
maxConnections: MaxConnections,
|
maxConnections: MaxConnections,
|
||||||
maxIn: -1,
|
maxIn: -1,
|
||||||
maxOut: -1,
|
maxOut: -1,
|
||||||
|
@ -137,7 +135,6 @@ proc build*(b: SwitchBuilder): Switch =
|
||||||
|
|
||||||
let
|
let
|
||||||
identify = newIdentify(peerInfo)
|
identify = newIdentify(peerInfo)
|
||||||
connManager = ConnManager.init(b.maxConnsPerPeer, b.maxConnections, b.maxIn, b.maxOut)
|
|
||||||
|
|
||||||
let
|
let
|
||||||
transports = block:
|
transports = block:
|
||||||
|
@ -149,6 +146,9 @@ proc build*(b: SwitchBuilder): Switch =
|
||||||
if b.secureManagers.len == 0:
|
if b.secureManagers.len == 0:
|
||||||
b.secureManagers &= SecureProtocol.Noise
|
b.secureManagers &= SecureProtocol.Noise
|
||||||
|
|
||||||
|
if isNil(b.rng):
|
||||||
|
b.rng = newRng()
|
||||||
|
|
||||||
let switch = newSwitch(
|
let switch = newSwitch(
|
||||||
peerInfo = peerInfo,
|
peerInfo = peerInfo,
|
||||||
transports = transports,
|
transports = transports,
|
||||||
|
@ -179,7 +179,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
||||||
quit("Secio is deprecated!") # use of secio is unsafe
|
quit("Secio is deprecated!") # use of secio is unsafe
|
||||||
|
|
||||||
var b = SwitchBuilder
|
var b = SwitchBuilder
|
||||||
.init()
|
.new()
|
||||||
.withAddress(address)
|
.withAddress(address)
|
||||||
.withRng(rng)
|
.withRng(rng)
|
||||||
.withMaxConnections(maxConnections)
|
.withMaxConnections(maxConnections)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
import builders
|
||||||
|
export builders
|
Loading…
Reference in New Issue