more refs

This commit is contained in:
Giovanni Petrantoni 2021-03-29 11:16:57 +09:00
parent 1facb7c613
commit cde444d490
1 changed files with 15 additions and 30 deletions

View File

@ -14,7 +14,7 @@ type
Noise, Noise,
Secio {.deprecated.} Secio {.deprecated.}
SwitchBuilder* {.byref.} = object SwitchBuilder* = ref object
privKey: Option[PrivateKey] privKey: Option[PrivateKey]
address: MultiAddress address: MultiAddress
secureManagers: seq[SecureProtocol] secureManagers: seq[SecureProtocol]
@ -52,74 +52,59 @@ proc init*(_: type[SwitchBuilder]): SwitchBuilder =
# so in nim we are stuck with this hardly efficient way and hopey compiler figures it out.. heh # so in nim we are stuck with this hardly efficient way and hopey compiler figures it out.. heh
# maybe {.byref.} works.... I would not bet on it but let's use it. # maybe {.byref.} works.... I would not bet on it but let's use it.
proc withPrivateKey*(builder: SwitchBuilder, privateKey: PrivateKey): SwitchBuilder = proc withPrivateKey*(b: SwitchBuilder, privateKey: PrivateKey): SwitchBuilder =
var b = builder
b.privKey = some(privateKey) b.privKey = some(privateKey)
b b
proc withAddress*(builder: SwitchBuilder, address: MultiAddress): SwitchBuilder = proc withAddress*(b: SwitchBuilder, address: MultiAddress): SwitchBuilder =
var b = builder
b.address = address b.address = address
b b
proc withSecureManager*(builder: SwitchBuilder, secureManager: SecureProtocol): SwitchBuilder = proc withSecureManager*(b: SwitchBuilder, secureManager: SecureProtocol): SwitchBuilder =
var b = builder
b.secureManagers &= secureManager b.secureManagers &= secureManager
b b
proc withTcpTransport*(builder: SwitchBuilder, flags: set[ServerFlags] = {}): SwitchBuilder = proc withTcpTransport*(b: SwitchBuilder, flags: set[ServerFlags] = {}): SwitchBuilder =
var b = builder
b.tcpTransportFlags = some(flags) b.tcpTransportFlags = some(flags)
b b
proc withRng*(builder: SwitchBuilder, rng: ref BrHmacDrbgContext): SwitchBuilder = proc withRng*(b: SwitchBuilder, rng: ref BrHmacDrbgContext): SwitchBuilder =
var b = builder
b.rng = rng b.rng = rng
b b
proc withInTimeout*(builder: SwitchBuilder, inTimeout: Duration): SwitchBuilder = proc withInTimeout*(b: SwitchBuilder, inTimeout: Duration): SwitchBuilder =
var b = builder
b.inTimeout = inTimeout b.inTimeout = inTimeout
b b
proc withOutTimeout*(builder: SwitchBuilder, outTimeout: Duration): SwitchBuilder = proc withOutTimeout*(b: SwitchBuilder, outTimeout: Duration): SwitchBuilder =
var b = builder
b.outTimeout = outTimeout b.outTimeout = outTimeout
b b
proc withMaxConnections*(builder: SwitchBuilder, maxConnections: int): SwitchBuilder = proc withMaxConnections*(b: SwitchBuilder, maxConnections: int): SwitchBuilder =
var b = builder
b.maxConnections = maxConnections b.maxConnections = maxConnections
b b
proc withMaxIn*(builder: SwitchBuilder, maxIn: int): SwitchBuilder = proc withMaxIn*(b: SwitchBuilder, maxIn: int): SwitchBuilder =
var b = builder
b.maxIn = maxIn b.maxIn = maxIn
b b
proc withMaxOut*(builder: SwitchBuilder, maxOut: int): SwitchBuilder = proc withMaxOut*(b: SwitchBuilder, maxOut: int): SwitchBuilder =
var b = builder
b.maxOut = maxOut b.maxOut = maxOut
b b
proc withMaxConnsPerPeer*(builder: SwitchBuilder, maxConnsPerPeer: int): SwitchBuilder = proc withMaxConnsPerPeer*(b: SwitchBuilder, maxConnsPerPeer: int): SwitchBuilder =
var b = builder
b.maxConnsPerPeer = maxConnsPerPeer b.maxConnsPerPeer = maxConnsPerPeer
b b
proc withProtoVersion*(builder: SwitchBuilder, protoVersion: string): SwitchBuilder = proc withProtoVersion*(b: SwitchBuilder, protoVersion: string): SwitchBuilder =
var b = builder
b.protoVersion = some(protoVersion) b.protoVersion = some(protoVersion)
b b
proc withAgentVersion*(builder: SwitchBuilder, agentVersion: string): SwitchBuilder = proc withAgentVersion*(b: SwitchBuilder, agentVersion: string): SwitchBuilder =
var b = builder
b.agentVersion = some(agentVersion) b.agentVersion = some(agentVersion)
b b
proc build*(builder: SwitchBuilder): Switch = proc build*(b: SwitchBuilder): Switch =
var b = builder
let let
inTimeout = b.inTimeout inTimeout = b.inTimeout
outTimeout = b.outTimeout outTimeout = b.outTimeout