Skip to content

Commit

Permalink
Builders (#558)
Browse files Browse the repository at this point in the history
* use a builder pattern to build the switch (#551)

* use a builder pattern to build the switch

* with with

* more refs

* Merge master (#555)

* Revisit Floodsub (#543)

Fixes #525

add coverage to unsubscribeAll and testing

* add mounted protos to identify message (#546)

* add stable/unstable auto bumps

* fix auto-bump CI

* merge nbc auto bump with CI in order to bump only on CI success

* put conditional locks on nbc bump (#549)

* Fix minor exception issues (#550)

Makes code compatible with
status-im/nim-chronos#166 without requiring it.

* fix nimbus ref for auto-bump stable's PR

* Split dialer (#542)

* extracting dialing logic to dialer

* exposing upgrade methods on transport

* cleanup

* fixing tests to use new interfaces

* add comments

* add base exception class and fix hierarchy

* fix imports

* `doAssert` is `ValueError` not `AssertionError`?

* revert back to `AssertionError`

Co-authored-by: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com>
Co-authored-by: Jacek Sieka <jacek@status.im>

* `doAssert` is `ValueError` not `AssertionError`?

* revert back to `AssertionError`

* fix builders

* more builder stuff

* more builders

Co-authored-by: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com>
Co-authored-by: Jacek Sieka <jacek@status.im>
  • Loading branch information
3 people committed Apr 12, 2021
1 parent efe534d commit 2d82753
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libp2p/builders.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import
crypto/crypto, transports/[transport, tcptransport],
muxers/[muxer, mplex/mplex],
protocols/[identify, secure/secure, secure/noise],
connmanager
connmanager, upgrademngrs/muxedupgrade

export
switch, peerid, peerinfo, connection, multiaddress, crypto
Expand All @@ -29,6 +29,8 @@ type
mplexOpts: MplexOpts
tcpTransportOpts: TcpTransportOpts
rng: ref BrHmacDrbgContext
inTimeout: Duration
outTimeout: Duration
maxConnections: int
maxIn: int
maxOut: int
Expand Down Expand Up @@ -138,12 +140,14 @@ proc build*(b: SwitchBuilder): Switch =
let
identify = newIdentify(peerInfo)
connManager = ConnManager.init(b.maxConnsPerPeer, b.maxConnections, b.maxIn, b.maxOut)
ms = newMultistream()
muxedUpgrade = MuxedUpgrade.init(identify, muxers, secureManagerInstances, connManager, ms)

let
transports = block:
var transports: seq[Transport]
if b.tcpTransportOpts.enable:
transports.add(Transport(TcpTransport.init(b.tcpTransportOpts.flags)))
transports.add(Transport(TcpTransport.init(b.tcpTransportOpts.flags, muxedUpgrade)))
transports

if b.secureManagers.len == 0:
Expand All @@ -155,10 +159,8 @@ proc build*(b: SwitchBuilder): Switch =
identity = identify,
muxers = muxers,
secureManagers = secureManagerInstances,
maxConnections = b.maxConnections,
maxIn = b.maxIn,
maxOut = b.maxOut,
maxConnsPerPeer = b.maxConnsPerPeer)
connManager = connManager,
ms = ms)

return switch

Expand Down

0 comments on commit 2d82753

Please sign in to comment.