2022-07-04 13:19:21 +00:00
|
|
|
import helpers, commoninterop
|
2021-06-11 22:33:47 +00:00
|
|
|
import ../libp2p
|
2022-09-15 07:43:40 +00:00
|
|
|
import ../libp2p/crypto/crypto, ../libp2p/protocols/connectivity/relay/[relay, client]
|
2022-07-04 13:19:21 +00:00
|
|
|
|
|
|
|
proc switchMplexCreator(
|
|
|
|
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
|
2022-08-01 12:31:22 +00:00
|
|
|
prov: TransportProvider = proc(upgr: Upgrade): Transport =
|
|
|
|
TcpTransport.new({}, upgr)
|
|
|
|
,
|
|
|
|
relay: Relay = Relay.new(circuitRelayV1 = true),
|
2023-06-07 11:12:49 +00:00
|
|
|
): Switch {.raises: [LPError].} =
|
2022-07-04 13:19:21 +00:00
|
|
|
SwitchBuilder
|
|
|
|
.new()
|
|
|
|
.withSignedPeerRecord(false)
|
|
|
|
.withMaxConnections(MaxConnections)
|
|
|
|
.withRng(crypto.newRng())
|
|
|
|
.withAddresses(@[ma])
|
|
|
|
.withMaxIn(-1)
|
|
|
|
.withMaxOut(-1)
|
|
|
|
.withTransport(prov)
|
|
|
|
.withMplex()
|
|
|
|
.withMaxConnsPerPeer(MaxConnectionsPerPeer)
|
|
|
|
.withPeerStore(capacity = 1000)
|
|
|
|
.withNoise()
|
2022-08-01 12:31:22 +00:00
|
|
|
.withCircuitRelay(relay)
|
2022-07-04 13:19:21 +00:00
|
|
|
.withNameResolver(nil)
|
|
|
|
.build()
|
|
|
|
|
|
|
|
proc switchYamuxCreator(
|
|
|
|
ma: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
|
2022-08-01 12:31:22 +00:00
|
|
|
prov: TransportProvider = proc(upgr: Upgrade): Transport =
|
|
|
|
TcpTransport.new({}, upgr)
|
|
|
|
,
|
|
|
|
relay: Relay = Relay.new(circuitRelayV1 = true),
|
2023-06-07 11:12:49 +00:00
|
|
|
): Switch {.raises: [LPError].} =
|
2022-07-04 13:19:21 +00:00
|
|
|
SwitchBuilder
|
|
|
|
.new()
|
|
|
|
.withSignedPeerRecord(false)
|
|
|
|
.withMaxConnections(MaxConnections)
|
|
|
|
.withRng(crypto.newRng())
|
|
|
|
.withAddresses(@[ma])
|
|
|
|
.withMaxIn(-1)
|
|
|
|
.withMaxOut(-1)
|
|
|
|
.withTransport(prov)
|
|
|
|
.withYamux()
|
|
|
|
.withMaxConnsPerPeer(MaxConnectionsPerPeer)
|
|
|
|
.withPeerStore(capacity = 1000)
|
|
|
|
.withNoise()
|
2022-08-01 12:31:22 +00:00
|
|
|
.withCircuitRelay(relay)
|
2022-07-04 13:19:21 +00:00
|
|
|
.withNameResolver(nil)
|
|
|
|
.build()
|
|
|
|
|
|
|
|
suite "Tests interop":
|
|
|
|
commonInteropTests("mplex", switchMplexCreator)
|
|
|
|
relayInteropTests("mplex", switchMplexCreator)
|
|
|
|
|
|
|
|
commonInteropTests("yamux", switchYamuxCreator)
|
|
|
|
relayInteropTests("yamux", switchYamuxCreator)
|