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,
crypto/crypto, transports/[transport, tcptransport],
muxers/[muxer, mplex/mplex],
protocols/[identify, secure/secure, secure/noise],
connmanager
protocols/[identify, secure/secure, secure/noise]
export
switch, peerid, peerinfo, connection, multiaddress, crypto
@ -36,13 +35,12 @@ type
protoVersion: string
agentVersion: string
proc init*(T: type[SwitchBuilder]): T =
proc new*(T: type[SwitchBuilder]): T =
SwitchBuilder(
privKey: none(PrivateKey),
address: MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
secureManagers: @[],
tcpTransportOpts: TcpTransportOpts(),
rng: newRng(),
maxConnections: MaxConnections,
maxIn: -1,
maxOut: -1,
@ -137,7 +135,6 @@ proc build*(b: SwitchBuilder): Switch =
let
identify = newIdentify(peerInfo)
connManager = ConnManager.init(b.maxConnsPerPeer, b.maxConnections, b.maxIn, b.maxOut)
let
transports = block:
@ -149,6 +146,9 @@ proc build*(b: SwitchBuilder): Switch =
if b.secureManagers.len == 0:
b.secureManagers &= SecureProtocol.Noise
if isNil(b.rng):
b.rng = newRng()
let switch = newSwitch(
peerInfo = peerInfo,
transports = transports,
@ -179,7 +179,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
quit("Secio is deprecated!") # use of secio is unsafe
var b = SwitchBuilder
.init()
.new()
.withAddress(address)
.withRng(rng)
.withMaxConnections(maxConnections)

View File

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