More builders (#560)

* address some issues pointed out in review

* re-add to prevent breaking other projects
This commit is contained in:
Dmitriy Ryajov 2021-04-06 14:16:23 -06:00 committed by GitHub
parent 290866dd62
commit 6b930ae7e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -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)

View File

@ -0,0 +1,2 @@
import builders
export builders