builder: add multiple local address support (#591)

This commit is contained in:
Tanguy Cizain 2021-06-21 17:14:24 +02:00 committed by GitHub
parent b63e064b4a
commit bee91538ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -36,7 +36,7 @@ type
SwitchBuilder* = ref object SwitchBuilder* = ref object
privKey: Option[PrivateKey] privKey: Option[PrivateKey]
address: MultiAddress addresses: seq[MultiAddress]
secureManagers: seq[SecureProtocol] secureManagers: seq[SecureProtocol]
mplexOpts: MplexOpts mplexOpts: MplexOpts
tcpTransportOpts: TcpTransportOpts tcpTransportOpts: TcpTransportOpts
@ -56,7 +56,7 @@ proc new*(T: type[SwitchBuilder]): T =
SwitchBuilder( SwitchBuilder(
privKey: none(PrivateKey), privKey: none(PrivateKey),
address: address, addresses: @[address],
secureManagers: @[], secureManagers: @[],
tcpTransportOpts: TcpTransportOpts(), tcpTransportOpts: TcpTransportOpts(),
maxConnections: MaxConnections, maxConnections: MaxConnections,
@ -71,9 +71,14 @@ proc withPrivateKey*(b: SwitchBuilder, privateKey: PrivateKey): SwitchBuilder =
b b
proc withAddress*(b: SwitchBuilder, address: MultiAddress): SwitchBuilder = proc withAddress*(b: SwitchBuilder, address: MultiAddress): SwitchBuilder =
b.address = address b.addresses = @[address]
b b
proc withAddresses*(b: SwitchBuilder, addresses: seq[MultiAddress]): SwitchBuilder =
b.addresses = addresses
b
proc withMplex*(b: SwitchBuilder, inTimeout = 5.minutes, outTimeout = 5.minutes): SwitchBuilder = proc withMplex*(b: SwitchBuilder, inTimeout = 5.minutes, outTimeout = 5.minutes): SwitchBuilder =
proc newMuxer(conn: Connection): Muxer = proc newMuxer(conn: Connection): Muxer =
Mplex.init( Mplex.init(
@ -143,7 +148,7 @@ proc build*(b: SwitchBuilder): Switch
let let
peerInfo = PeerInfo.init( peerInfo = PeerInfo.init(
seckey, seckey,
[b.address], b.addresses,
protoVersion = b.protoVersion, protoVersion = b.protoVersion,
agentVersion = b.agentVersion) agentVersion = b.agentVersion)