mirror of
https://github.com/vacp2p/mix.git
synced 2026-01-09 03:17:54 -05:00
switched to yamux muxer; update gossipsub usage to match upstream changes
This commit is contained in:
@@ -7,6 +7,7 @@ import
|
|||||||
crypto/secp,
|
crypto/secp,
|
||||||
multiaddress,
|
multiaddress,
|
||||||
builders,
|
builders,
|
||||||
|
muxers/yamux/yamux,
|
||||||
protocols/pubsub/gossipsub,
|
protocols/pubsub/gossipsub,
|
||||||
protocols/pubsub/pubsubpeer,
|
protocols/pubsub/pubsubpeer,
|
||||||
protocols/pubsub/rpc/messages,
|
protocols/pubsub/rpc/messages,
|
||||||
@@ -16,15 +17,12 @@ import
|
|||||||
type Node = tuple[switch: Switch, gossip: GossipSub, mix: MixProtocol, id: int]
|
type Node = tuple[switch: Switch, gossip: GossipSub, mix: MixProtocol, id: int]
|
||||||
|
|
||||||
proc createSwitch(libp2pPrivKey: SkPrivateKey, multiAddr: MultiAddress): Switch =
|
proc createSwitch(libp2pPrivKey: SkPrivateKey, multiAddr: MultiAddress): Switch =
|
||||||
let
|
|
||||||
inTimeout: Duration = 5.minutes
|
|
||||||
outTimeout: Duration = 5.minutes
|
|
||||||
result = SwitchBuilder
|
result = SwitchBuilder
|
||||||
.new()
|
.new()
|
||||||
.withPrivateKey(PrivateKey(scheme: Secp256k1, skkey: libp2pPrivKey))
|
.withPrivateKey(PrivateKey(scheme: Secp256k1, skkey: libp2pPrivKey))
|
||||||
.withAddress(multiAddr)
|
.withAddress(multiAddr)
|
||||||
.withRng(crypto.newRng())
|
.withRng(crypto.newRng())
|
||||||
.withMplex(inTimeout, outTimeout)
|
.withYamux()
|
||||||
.withTcpTransport()
|
.withTcpTransport()
|
||||||
.withNoise()
|
.withNoise()
|
||||||
.build()
|
.build()
|
||||||
@@ -107,8 +105,11 @@ proc oneNode(node: Node) {.async.} =
|
|||||||
for msgNum in 0 ..< 5:
|
for msgNum in 0 ..< 5:
|
||||||
await sleepAsync(500.milliseconds)
|
await sleepAsync(500.milliseconds)
|
||||||
let msg = fmt"Hello from Node {node.id}, Message No: {msgNum + 1}"
|
let msg = fmt"Hello from Node {node.id}, Message No: {msgNum + 1}"
|
||||||
discard
|
discard await node.gossip.publish(
|
||||||
await node.gossip.publish("message", cast[seq[byte]](msg), useCustomConn = true)
|
"message",
|
||||||
|
cast[seq[byte]](msg),
|
||||||
|
publishParams = some(PublishParams(skipMCache: true, useCustomConn: true)),
|
||||||
|
)
|
||||||
|
|
||||||
await sleepAsync(1000.milliseconds)
|
await sleepAsync(1000.milliseconds)
|
||||||
await node.switch.stop()
|
await node.switch.stop()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import
|
|||||||
crypto/secp,
|
crypto/secp,
|
||||||
multiaddress,
|
multiaddress,
|
||||||
builders,
|
builders,
|
||||||
|
muxers/yamux/yamux,
|
||||||
protocols/pubsub/gossipsub,
|
protocols/pubsub/gossipsub,
|
||||||
protocols/pubsub/pubsubpeer,
|
protocols/pubsub/pubsubpeer,
|
||||||
protocols/pubsub/rpc/messages,
|
protocols/pubsub/rpc/messages,
|
||||||
@@ -16,15 +17,12 @@ import
|
|||||||
type Node = tuple[switch: Switch, gossip: GossipSub, mix: MixProtocol, id: int]
|
type Node = tuple[switch: Switch, gossip: GossipSub, mix: MixProtocol, id: int]
|
||||||
|
|
||||||
proc createSwitch(libp2pPrivKey: SkPrivateKey, multiAddr: MultiAddress): Switch =
|
proc createSwitch(libp2pPrivKey: SkPrivateKey, multiAddr: MultiAddress): Switch =
|
||||||
let
|
|
||||||
inTimeout: Duration = 5.minutes
|
|
||||||
outTimeout: Duration = 5.minutes
|
|
||||||
result = SwitchBuilder
|
result = SwitchBuilder
|
||||||
.new()
|
.new()
|
||||||
.withPrivateKey(PrivateKey(scheme: Secp256k1, skkey: libp2pPrivKey))
|
.withPrivateKey(PrivateKey(scheme: Secp256k1, skkey: libp2pPrivKey))
|
||||||
.withAddress(multiAddr)
|
.withAddress(multiAddr)
|
||||||
.withRng(crypto.newRng())
|
.withRng(crypto.newRng())
|
||||||
.withMplex(inTimeout, outTimeout)
|
.withYamux()
|
||||||
.withTcpTransport()
|
.withTcpTransport()
|
||||||
.withNoise()
|
.withNoise()
|
||||||
.build()
|
.build()
|
||||||
@@ -107,8 +105,11 @@ proc oneNode(node: Node, rcvdCnt: ptr Atomic[int]) {.async.} =
|
|||||||
for msgNum in 0 ..< 5:
|
for msgNum in 0 ..< 5:
|
||||||
await sleepAsync(500.milliseconds)
|
await sleepAsync(500.milliseconds)
|
||||||
let msg = fmt"Hello from Node {node.id}, Message No: {msgNum + 1}"
|
let msg = fmt"Hello from Node {node.id}, Message No: {msgNum + 1}"
|
||||||
discard
|
discard await node.gossip.publish(
|
||||||
await node.gossip.publish("message", cast[seq[byte]](msg), useCustomConn = true)
|
"message",
|
||||||
|
cast[seq[byte]](msg),
|
||||||
|
publishParams = some(PublishParams(skipMCache: true, useCustomConn: true)),
|
||||||
|
)
|
||||||
|
|
||||||
await sleepAsync(1000.milliseconds)
|
await sleepAsync(1000.milliseconds)
|
||||||
await node.switch.stop()
|
await node.switch.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user