2020-05-06 09:26:08 +00:00
|
|
|
include ../../libp2p/protocols/pubsub/gossipsub
|
|
|
|
|
2020-05-08 20:58:23 +00:00
|
|
|
{.used.}
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
import unittest
|
2020-05-21 20:24:20 +00:00
|
|
|
import stew/byteutils
|
2020-05-06 09:26:08 +00:00
|
|
|
import ../../libp2p/errors
|
|
|
|
import ../../libp2p/stream/bufferstream
|
|
|
|
|
2020-05-08 20:10:06 +00:00
|
|
|
import ../helpers
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
type
|
|
|
|
TestGossipSub = ref object of GossipSub
|
|
|
|
|
2020-05-21 20:24:20 +00:00
|
|
|
proc noop(data: seq[byte]) {.async, gcsafe.} = discard
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
suite "GossipSub internal":
|
|
|
|
teardown:
|
2020-05-08 20:10:06 +00:00
|
|
|
for tracker in testTrackers():
|
2020-05-21 20:24:20 +00:00
|
|
|
# echo tracker.dump()
|
2020-05-08 20:10:06 +00:00
|
|
|
check tracker.isLeaked() == false
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
test "`rebalanceMesh` Degree Lo":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.mesh[topic] = initHashSet[string]()
|
|
|
|
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<15:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].conn = conn
|
|
|
|
gossipSub.mesh[topic].incl(peerInfo.id)
|
|
|
|
|
|
|
|
check gossipSub.peers.len == 15
|
|
|
|
await gossipSub.rebalanceMesh(topic)
|
|
|
|
check gossipSub.mesh[topic].len == GossipSubD
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
|
|
|
test "`rebalanceMesh` Degree Hi":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.gossipsub[topic] = initHashSet[string]()
|
2020-06-28 02:03:33 +00:00
|
|
|
gossipSub.topics[topic] = Topic() # has to be in topics to rebalance
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<15:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].conn = conn
|
|
|
|
gossipSub.gossipsub[topic].incl(peerInfo.id)
|
|
|
|
|
|
|
|
check gossipSub.gossipsub[topic].len == 15
|
|
|
|
await gossipSub.rebalanceMesh(topic)
|
|
|
|
check gossipSub.mesh[topic].len == GossipSubD
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
|
|
|
test "`replenishFanout` Degree Lo":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
proc handler(peer: PubSubPeer, msg: seq[RPCMsg]) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.gossipsub[topic] = initHashSet[string]()
|
|
|
|
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<15:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
var peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
2020-06-28 02:03:33 +00:00
|
|
|
gossipSub.peers[peerInfo.id].topics &= topic
|
2020-05-06 09:26:08 +00:00
|
|
|
gossipSub.gossipsub[topic].incl(peerInfo.id)
|
|
|
|
|
|
|
|
check gossipSub.gossipsub[topic].len == 15
|
2020-06-27 11:49:53 +00:00
|
|
|
gossipSub.replenishFanout(topic)
|
2020-05-06 09:26:08 +00:00
|
|
|
check gossipSub.fanout[topic].len == GossipSubD
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
|
|
|
test "`dropFanoutPeers` drop expired fanout topics":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
proc handler(peer: PubSubPeer, msg: seq[RPCMsg]) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.fanout[topic] = initHashSet[string]()
|
2020-05-21 20:24:20 +00:00
|
|
|
gossipSub.lastFanoutPubSub[topic] = Moment.fromNow(1.millis)
|
|
|
|
await sleepAsync(5.millis) # allow the topic to expire
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<6:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
|
|
|
gossipSub.fanout[topic].incl(peerInfo.id)
|
|
|
|
|
|
|
|
check gossipSub.fanout[topic].len == GossipSubD
|
|
|
|
|
|
|
|
await gossipSub.dropFanoutPeers()
|
|
|
|
check topic notin gossipSub.fanout
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
|
|
|
test "`dropFanoutPeers` leave unexpired fanout topics":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
proc handler(peer: PubSubPeer, msg: seq[RPCMsg]) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
let topic1 = "foobar1"
|
|
|
|
let topic2 = "foobar2"
|
|
|
|
gossipSub.fanout[topic1] = initHashSet[string]()
|
|
|
|
gossipSub.fanout[topic2] = initHashSet[string]()
|
2020-05-21 20:24:20 +00:00
|
|
|
gossipSub.lastFanoutPubSub[topic1] = Moment.fromNow(1.millis)
|
2020-05-15 02:01:33 +00:00
|
|
|
gossipSub.lastFanoutPubSub[topic2] = Moment.fromNow(1.minutes)
|
2020-05-21 20:24:20 +00:00
|
|
|
await sleepAsync(5.millis) # allow the topic to expire
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<6:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
|
|
|
gossipSub.fanout[topic1].incl(peerInfo.id)
|
|
|
|
gossipSub.fanout[topic2].incl(peerInfo.id)
|
|
|
|
|
|
|
|
check gossipSub.fanout[topic1].len == GossipSubD
|
|
|
|
check gossipSub.fanout[topic2].len == GossipSubD
|
|
|
|
|
|
|
|
await gossipSub.dropFanoutPeers()
|
|
|
|
check topic1 notin gossipSub.fanout
|
|
|
|
check topic2 in gossipSub.fanout
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
|
|
|
test "`getGossipPeers` - should gather up to degree D non intersecting peers":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
proc handler(peer: PubSubPeer, msg: seq[RPCMsg]) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.mesh[topic] = initHashSet[string]()
|
|
|
|
gossipSub.fanout[topic] = initHashSet[string]()
|
|
|
|
gossipSub.gossipsub[topic] = initHashSet[string]()
|
|
|
|
var conns = newSeq[Connection]()
|
2020-05-21 20:24:20 +00:00
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
# generate mesh and fanout peers
|
2020-05-06 09:26:08 +00:00
|
|
|
for i in 0..<30:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
|
|
|
if i mod 2 == 0:
|
|
|
|
gossipSub.fanout[topic].incl(peerInfo.id)
|
|
|
|
else:
|
|
|
|
gossipSub.mesh[topic].incl(peerInfo.id)
|
|
|
|
|
2020-05-21 20:24:20 +00:00
|
|
|
# generate gossipsub (free standing) peers
|
2020-05-06 09:26:08 +00:00
|
|
|
for i in 0..<15:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
|
|
|
gossipSub.gossipsub[topic].incl(peerInfo.id)
|
|
|
|
|
2020-05-21 20:24:20 +00:00
|
|
|
# generate messages
|
|
|
|
for i in 0..5:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-21 20:24:20 +00:00
|
|
|
conns &= conn
|
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
let msg = newMessage(peerInfo, ("HELLO" & $i).toBytes(), topic, false)
|
|
|
|
gossipSub.mcache.put(msg)
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
check gossipSub.fanout[topic].len == 15
|
2020-05-21 20:24:20 +00:00
|
|
|
check gossipSub.mesh[topic].len == 15
|
2020-05-06 09:26:08 +00:00
|
|
|
check gossipSub.gossipsub[topic].len == 15
|
|
|
|
|
|
|
|
let peers = gossipSub.getGossipPeers()
|
|
|
|
check peers.len == GossipSubD
|
|
|
|
for p in peers.keys:
|
|
|
|
check p notin gossipSub.fanout[topic]
|
|
|
|
check p notin gossipSub.mesh[topic]
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
|
|
|
test "`getGossipPeers` - should not crash on missing topics in mesh":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
proc handler(peer: PubSubPeer, msg: seq[RPCMsg]) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.fanout[topic] = initHashSet[string]()
|
|
|
|
gossipSub.gossipsub[topic] = initHashSet[string]()
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<30:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
|
|
|
if i mod 2 == 0:
|
|
|
|
gossipSub.fanout[topic].incl(peerInfo.id)
|
|
|
|
else:
|
|
|
|
gossipSub.gossipsub[topic].incl(peerInfo.id)
|
|
|
|
|
2020-05-21 20:24:20 +00:00
|
|
|
# generate messages
|
|
|
|
for i in 0..5:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-21 20:24:20 +00:00
|
|
|
conns &= conn
|
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
let msg = newMessage(peerInfo, ("HELLO" & $i).toBytes(), topic, false)
|
|
|
|
gossipSub.mcache.put(msg)
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
let peers = gossipSub.getGossipPeers()
|
|
|
|
check peers.len == GossipSubD
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
2020-05-21 20:24:20 +00:00
|
|
|
test "`getGossipPeers` - should not crash on missing topics in fanout":
|
2020-05-06 09:26:08 +00:00
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
proc handler(peer: PubSubPeer, msg: seq[RPCMsg]) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.mesh[topic] = initHashSet[string]()
|
|
|
|
gossipSub.gossipsub[topic] = initHashSet[string]()
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<30:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
|
|
|
if i mod 2 == 0:
|
|
|
|
gossipSub.mesh[topic].incl(peerInfo.id)
|
|
|
|
else:
|
|
|
|
gossipSub.gossipsub[topic].incl(peerInfo.id)
|
|
|
|
|
2020-05-21 20:24:20 +00:00
|
|
|
# generate messages
|
|
|
|
for i in 0..5:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-21 20:24:20 +00:00
|
|
|
conns &= conn
|
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
let msg = newMessage(peerInfo, ("HELLO" & $i).toBytes(), topic, false)
|
|
|
|
gossipSub.mcache.put(msg)
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
let peers = gossipSub.getGossipPeers()
|
|
|
|
check peers.len == GossipSubD
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|
|
|
|
|
|
|
|
test "`getGossipPeers` - should not crash on missing topics in gossip":
|
|
|
|
proc testRun(): Future[bool] {.async.} =
|
|
|
|
let gossipSub = newPubSub(TestGossipSub,
|
2020-05-21 20:24:20 +00:00
|
|
|
PeerInfo.init(PrivateKey.random(ECDSA).get()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
proc handler(peer: PubSubPeer, msg: seq[RPCMsg]) {.async.} =
|
|
|
|
discard
|
|
|
|
|
|
|
|
let topic = "foobar"
|
|
|
|
gossipSub.mesh[topic] = initHashSet[string]()
|
|
|
|
gossipSub.fanout[topic] = initHashSet[string]()
|
|
|
|
var conns = newSeq[Connection]()
|
|
|
|
for i in 0..<30:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-06 09:26:08 +00:00
|
|
|
conns &= conn
|
2020-05-21 20:24:20 +00:00
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
2020-05-06 09:26:08 +00:00
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
gossipSub.peers[peerInfo.id] = newPubSubPeer(peerInfo, GossipSubCodec)
|
|
|
|
gossipSub.peers[peerInfo.id].handler = handler
|
|
|
|
if i mod 2 == 0:
|
|
|
|
gossipSub.mesh[topic].incl(peerInfo.id)
|
|
|
|
else:
|
|
|
|
gossipSub.fanout[topic].incl(peerInfo.id)
|
|
|
|
|
2020-05-21 20:24:20 +00:00
|
|
|
# generate messages
|
|
|
|
for i in 0..5:
|
2020-06-19 17:29:43 +00:00
|
|
|
let conn = newBufferStream(noop)
|
2020-05-21 20:24:20 +00:00
|
|
|
conns &= conn
|
|
|
|
let peerInfo = PeerInfo.init(PrivateKey.random(ECDSA).get())
|
|
|
|
conn.peerInfo = peerInfo
|
|
|
|
let msg = newMessage(peerInfo, ("bar" & $i).toBytes(), topic, false)
|
|
|
|
gossipSub.mcache.put(msg)
|
|
|
|
|
2020-05-06 09:26:08 +00:00
|
|
|
let peers = gossipSub.getGossipPeers()
|
|
|
|
check peers.len == 0
|
|
|
|
|
2020-06-02 23:53:38 +00:00
|
|
|
await allFuturesThrowing(conns.mapIt(it.close()))
|
2020-05-06 09:26:08 +00:00
|
|
|
|
|
|
|
result = true
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testRun()) == true
|