mirror of https://github.com/waku-org/nwaku.git
V2cleanup (#115)
* Cleanup of warnings + imports, etc. * Remove connected_peers metric as there is already libp2p_pubsub_peers
This commit is contained in:
parent
1924bcc96c
commit
ddcfc3fdd6
|
@ -6,6 +6,7 @@
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||||
# MIT license (LICENSE-MIT)
|
# MIT license (LICENSE-MIT)
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import unittest, options, tables, sets, sequtils
|
import unittest, options, tables, sets, sequtils
|
||||||
import chronos, chronicles
|
import chronos, chronicles
|
||||||
|
@ -91,7 +92,7 @@ procSuite "FloodSub":
|
||||||
let msg = message()
|
let msg = message()
|
||||||
discard await nodes[0].publish("foobar", msg)
|
discard await nodes[0].publish("foobar", msg)
|
||||||
|
|
||||||
let result = await completionFut.wait(5.seconds)
|
check: await completionFut.wait(5.seconds)
|
||||||
|
|
||||||
await allFuturesThrowing(
|
await allFuturesThrowing(
|
||||||
nodes[0].stop(),
|
nodes[0].stop(),
|
||||||
|
@ -101,6 +102,3 @@ procSuite "FloodSub":
|
||||||
for fut in nodesFut:
|
for fut in nodesFut:
|
||||||
let res = fut.read()
|
let res = fut.read()
|
||||||
await allFuturesThrowing(res)
|
await allFuturesThrowing(res)
|
||||||
|
|
||||||
check:
|
|
||||||
result == true
|
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
import unittest, options, tables, sets, sequtils
|
{.used.}
|
||||||
import chronos, chronicles
|
|
||||||
import utils,
|
import
|
||||||
libp2p/errors,
|
std/[unittest, options, tables, sets],
|
||||||
|
chronos, chronicles,
|
||||||
libp2p/switch,
|
libp2p/switch,
|
||||||
libp2p/protobuf/minprotobuf,
|
libp2p/protobuf/minprotobuf,
|
||||||
libp2p/stream/[bufferstream, connection],
|
libp2p/stream/[bufferstream, connection],
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/pubsub/floodsub,
|
|
||||||
libp2p/protocols/pubsub/rpc/message,
|
libp2p/protocols/pubsub/rpc/message,
|
||||||
libp2p/multistream,
|
libp2p/multistream,
|
||||||
libp2p/transports/transport,
|
libp2p/transports/transport,
|
||||||
libp2p/transports/tcptransport
|
libp2p/transports/tcptransport,
|
||||||
import ../../waku/protocol/v2/[waku_relay, waku_store, filter]
|
../../waku/protocol/v2/[waku_store, filter],
|
||||||
|
../test_helpers, ./utils
|
||||||
import ../test_helpers
|
|
||||||
|
|
||||||
procSuite "Waku Store":
|
procSuite "Waku Store":
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
import unittest
|
{.used.}
|
||||||
|
|
||||||
import confutils, chronicles, chronos, os
|
import
|
||||||
|
std/[unittest, os],
|
||||||
import stew/shims/net as stewNet
|
confutils, chronicles, chronos, stew/shims/net as stewNet,
|
||||||
import libp2p/crypto/crypto
|
json_rpc/[rpcclient, rpcserver],
|
||||||
import libp2p/crypto/secp
|
libp2p/crypto/crypto,
|
||||||
import eth/keys
|
libp2p/crypto/secp,
|
||||||
import json_rpc/[rpcclient, rpcserver]
|
eth/keys,
|
||||||
|
../../waku/node/v2/[config, wakunode2, waku_types],
|
||||||
import ../../waku/node/v2/[config, wakunode2, waku_types]
|
../test_helpers
|
||||||
|
|
||||||
import ../test_helpers
|
|
||||||
|
|
||||||
procSuite "WakuNode":
|
procSuite "WakuNode":
|
||||||
asyncTest "Message published with content filter is retrievable":
|
asyncTest "Message published with content filter is retrievable":
|
||||||
|
|
|
@ -12,4 +12,5 @@ proc subscribeNodes*(nodes: seq[Switch]) {.async.} =
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
if dialer.peerInfo.peerId != node.peerInfo.peerId:
|
if dialer.peerInfo.peerId != node.peerInfo.peerId:
|
||||||
dials.add(dialer.connect(node.peerInfo))
|
dials.add(dialer.connect(node.peerInfo))
|
||||||
|
# TODO: Hmm, does this make sense?
|
||||||
await allFutures(dials)
|
await allFutures(dials)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
strutils,
|
std/strutils,
|
||||||
confutils, confutils/defs, confutils/std/net,
|
confutils, confutils/defs, confutils/std/net,
|
||||||
chronicles, chronos,
|
chronicles, chronos,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import
|
import
|
||||||
json_rpc/rpcserver, options,
|
std/options,
|
||||||
|
json_rpc/rpcserver,
|
||||||
|
nimcrypto/[sysrand, hmac, sha2],
|
||||||
eth/[common, rlp, keys, p2p],
|
eth/[common, rlp, keys, p2p],
|
||||||
../../../protocol/v2/waku_relay,
|
../../../protocol/v2/waku_relay,
|
||||||
nimcrypto/[sysrand, hmac, sha2],
|
|
||||||
../wakunode2,
|
|
||||||
../waku_types
|
../waku_types
|
||||||
|
|
||||||
# Instead of using rlpx waku_protocol here, lets do mock waku2_protocol
|
# Instead of using rlpx waku_protocol here, lets do mock waku2_protocol
|
||||||
|
|
|
@ -11,7 +11,7 @@ import
|
||||||
libp2p/transports/[transport, tcptransport],
|
libp2p/transports/[transport, tcptransport],
|
||||||
libp2p/muxers/[muxer, mplex/mplex, mplex/types],
|
libp2p/muxers/[muxer, mplex/mplex, mplex/types],
|
||||||
libp2p/protocols/[identify, secure/secure],
|
libp2p/protocols/[identify, secure/secure],
|
||||||
libp2p/protocols/pubsub/[pubsub, gossipsub],
|
libp2p/protocols/pubsub/pubsub,
|
||||||
../../protocol/v2/waku_relay
|
../../protocol/v2/waku_relay
|
||||||
|
|
||||||
import
|
import
|
||||||
|
|
|
@ -2,8 +2,6 @@ import
|
||||||
chronos,
|
chronos,
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/protocol,
|
|
||||||
libp2p/protocols/pubsub/pubsub,
|
|
||||||
libp2p/peerinfo,
|
libp2p/peerinfo,
|
||||||
standard_setup
|
standard_setup
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
import
|
import
|
||||||
confutils, config, strutils, chronos, json_rpc/rpcserver, metrics, sequtils,
|
std/[strutils, options],
|
||||||
chronicles/topics_registry, # TODO: What? Need this for setLoglevel, weird.
|
chronos, confutils, json_rpc/rpcserver, metrics, stew/shims/net as stewNet,
|
||||||
eth/[keys, p2p], eth/net/nat,
|
# TODO: Why do we need eth keys?
|
||||||
eth/p2p/[discovery, enode],
|
eth/keys, eth/net/nat,
|
||||||
|
# eth/[keys, p2p], eth/net/nat, eth/p2p/[discovery, enode],
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/protocols/protocol,
|
libp2p/protocols/protocol,
|
||||||
# NOTE For TopicHandler, solve with exports?
|
# NOTE For TopicHandler, solve with exports?
|
||||||
libp2p/protocols/pubsub/pubsub,
|
libp2p/protocols/pubsub/pubsub,
|
||||||
libp2p/peerinfo,
|
libp2p/peerinfo,
|
||||||
stew/shims/net as stewNet,
|
|
||||||
rpc/wakurpc,
|
|
||||||
standard_setup,
|
|
||||||
../../protocol/v2/waku_relay,
|
../../protocol/v2/waku_relay,
|
||||||
waku_types
|
./waku_types, ./config, ./standard_setup, ./rpc/wakurpc
|
||||||
|
|
||||||
# key and crypto modules different
|
# key and crypto modules different
|
||||||
type
|
type
|
||||||
|
@ -34,12 +32,6 @@ type
|
||||||
|
|
||||||
const clientId = "Nimbus waku node"
|
const clientId = "Nimbus waku node"
|
||||||
|
|
||||||
proc setBootNodes(nodes: openArray[string]): seq[ENode] =
|
|
||||||
result = newSeqOfCap[ENode](nodes.len)
|
|
||||||
for nodeId in nodes:
|
|
||||||
# TODO: something more user friendly than an expect
|
|
||||||
result.add(ENode.fromString(nodeId).expect("correct node"))
|
|
||||||
|
|
||||||
# NOTE Any difference here in Waku vs Eth2?
|
# NOTE Any difference here in Waku vs Eth2?
|
||||||
# E.g. Devp2p/Libp2p support, etc.
|
# E.g. Devp2p/Libp2p support, etc.
|
||||||
#func asLibp2pKey*(key: keys.PublicKey): PublicKey =
|
#func asLibp2pKey*(key: keys.PublicKey): PublicKey =
|
||||||
|
@ -216,7 +208,7 @@ proc start*(node: WakuNode, conf: WakuNodeConf) {.async.} =
|
||||||
## Public API
|
## Public API
|
||||||
##
|
##
|
||||||
|
|
||||||
method init*(T: type WakuNode, conf: WakuNodeConf): Future[T] {.async.} =
|
proc init*(T: type WakuNode, conf: WakuNodeConf): Future[T] {.async.} =
|
||||||
## Creates and starts a Waku node.
|
## Creates and starts a Waku node.
|
||||||
##
|
##
|
||||||
let node = await createWakuNode(conf)
|
let node = await createWakuNode(conf)
|
||||||
|
@ -228,7 +220,7 @@ method init*(T: type WakuNode, conf: WakuNodeConf): Future[T] {.async.} =
|
||||||
|
|
||||||
type ContentFilterHandler* = proc(contentFilter: ContentFilter, message: Message)
|
type ContentFilterHandler* = proc(contentFilter: ContentFilter, message: Message)
|
||||||
|
|
||||||
method subscribe*(w: WakuNode, topic: Topic, handler: TopicHandler) =
|
proc subscribe*(w: WakuNode, topic: Topic, handler: TopicHandler) =
|
||||||
## Subscribes to a PubSub topic. Triggers handler when receiving messages on
|
## Subscribes to a PubSub topic. Triggers handler when receiving messages on
|
||||||
## this topic. TopicHandler is a method that takes a topic and some data.
|
## this topic. TopicHandler is a method that takes a topic and some data.
|
||||||
##
|
##
|
||||||
|
@ -239,7 +231,7 @@ method subscribe*(w: WakuNode, topic: Topic, handler: TopicHandler) =
|
||||||
# XXX Consider awaiting here
|
# XXX Consider awaiting here
|
||||||
discard wakuRelay.subscribe(topic, handler)
|
discard wakuRelay.subscribe(topic, handler)
|
||||||
|
|
||||||
method subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFilterHandler) =
|
proc subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFilterHandler) =
|
||||||
echo "NYI"
|
echo "NYI"
|
||||||
## Subscribes to a ContentFilter. Triggers handler when receiving messages on
|
## Subscribes to a ContentFilter. Triggers handler when receiving messages on
|
||||||
## this content filter. ContentFilter is a method that takes some content
|
## this content filter. ContentFilter is a method that takes some content
|
||||||
|
@ -249,21 +241,21 @@ method subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFil
|
||||||
## Status: Not yet implemented.
|
## Status: Not yet implemented.
|
||||||
## TODO Implement as wrapper around `waku_filter` and `subscribe` above.
|
## TODO Implement as wrapper around `waku_filter` and `subscribe` above.
|
||||||
|
|
||||||
method unsubscribe*(w: WakuNode, topic: Topic) =
|
proc unsubscribe*(w: WakuNode, topic: Topic) =
|
||||||
echo "NYI"
|
echo "NYI"
|
||||||
## Unsubscribe from a topic.
|
## Unsubscribe from a topic.
|
||||||
##
|
##
|
||||||
## Status: Not yet implemented.
|
## Status: Not yet implemented.
|
||||||
## TODO Implement.
|
## TODO Implement.
|
||||||
|
|
||||||
method unsubscribe*(w: WakuNode, contentFilter: ContentFilter) =
|
proc unsubscribe*(w: WakuNode, contentFilter: ContentFilter) =
|
||||||
echo "NYI"
|
echo "NYI"
|
||||||
## Unsubscribe from a content filter.
|
## Unsubscribe from a content filter.
|
||||||
##
|
##
|
||||||
## Status: Not yet implemented.
|
## Status: Not yet implemented.
|
||||||
## TODO Implement.
|
## TODO Implement.
|
||||||
|
|
||||||
method publish*(w: WakuNode, topic: Topic, message: Message) =
|
proc publish*(w: WakuNode, topic: Topic, message: Message) =
|
||||||
## Publish a `Message` to a PubSub topic.
|
## Publish a `Message` to a PubSub topic.
|
||||||
##
|
##
|
||||||
## Status: Partially implemented.
|
## Status: Partially implemented.
|
||||||
|
@ -273,7 +265,7 @@ method publish*(w: WakuNode, topic: Topic, message: Message) =
|
||||||
# XXX Consider awaiting here
|
# XXX Consider awaiting here
|
||||||
discard wakuSub.publish(topic, message)
|
discard wakuSub.publish(topic, message)
|
||||||
|
|
||||||
method publish*(w: WakuNode, topic: Topic, contentFilter: ContentFilter, message: Message) =
|
proc publish*(w: WakuNode, topic: Topic, contentFilter: ContentFilter, message: Message) =
|
||||||
## Publish a `Message` to a PubSub topic with a specific content filter.
|
## Publish a `Message` to a PubSub topic with a specific content filter.
|
||||||
## Currently this means a `contentTopic`.
|
## Currently this means a `contentTopic`.
|
||||||
##
|
##
|
||||||
|
@ -288,7 +280,7 @@ method publish*(w: WakuNode, topic: Topic, contentFilter: ContentFilter, message
|
||||||
|
|
||||||
discard wakuSub.publish(topic, message)
|
discard wakuSub.publish(topic, message)
|
||||||
|
|
||||||
method query*(w: WakuNode, query: HistoryQuery): HistoryResponse =
|
proc query*(w: WakuNode, query: HistoryQuery): HistoryResponse =
|
||||||
## Queries for historical messages.
|
## Queries for historical messages.
|
||||||
##
|
##
|
||||||
## Status: Not yet implemented.
|
## Status: Not yet implemented.
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import libp2p/protocols/pubsub/rpc/messages
|
|
||||||
|
|
||||||
import
|
import
|
||||||
tables
|
std/tables,
|
||||||
|
libp2p/protocols/pubsub/rpc/messages
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,17 @@
|
||||||
## This file should eventually correspond to waku_protocol as RLPx subprotocol.
|
## This file should eventually correspond to waku_protocol as RLPx subprotocol.
|
||||||
## Instead, it should likely be on top of GossipSub with a similar interface.
|
## Instead, it should likely be on top of GossipSub with a similar interface.
|
||||||
|
|
||||||
import strutils
|
import
|
||||||
import chronos, chronicles
|
std/[strutils, tables],
|
||||||
import ./filter
|
chronos, chronicles, metrics,
|
||||||
import tables
|
libp2p/protocols/pubsub/pubsub,
|
||||||
import libp2p/protocols/pubsub/pubsub,
|
|
||||||
libp2p/protocols/pubsub/pubsubpeer,
|
libp2p/protocols/pubsub/pubsubpeer,
|
||||||
libp2p/protocols/pubsub/floodsub,
|
libp2p/protocols/pubsub/floodsub,
|
||||||
libp2p/protocols/pubsub/gossipsub,
|
libp2p/protocols/pubsub/gossipsub,
|
||||||
libp2p/protocols/pubsub/rpc/[messages],
|
libp2p/protocols/pubsub/rpc/[messages],
|
||||||
libp2p/stream/connection
|
libp2p/stream/connection,
|
||||||
|
./filter
|
||||||
|
|
||||||
import metrics
|
|
||||||
|
|
||||||
declarePublicGauge connected_peers, "number of peers in the pool" # XXX
|
|
||||||
declarePublicGauge total_messages, "number of messages received"
|
declarePublicGauge total_messages, "number of messages received"
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
@ -28,7 +25,7 @@ type
|
||||||
WakuRelay* = ref object of GossipSub
|
WakuRelay* = ref object of GossipSub
|
||||||
# XXX: just playing
|
# XXX: just playing
|
||||||
text*: string
|
text*: string
|
||||||
gossip_enabled*: bool
|
gossipEnabled*: bool
|
||||||
|
|
||||||
filters: Filters
|
filters: Filters
|
||||||
|
|
||||||
|
@ -41,9 +38,6 @@ method init(w: WakuRelay) =
|
||||||
##
|
##
|
||||||
|
|
||||||
debug "Incoming WakuRelay connection"
|
debug "Incoming WakuRelay connection"
|
||||||
# XXX: Increment connectedPeers counter, unclear if this is the right place tho
|
|
||||||
# Where is the disconnect event?
|
|
||||||
connected_peers.inc()
|
|
||||||
await w.handleConn(conn, proto)
|
await w.handleConn(conn, proto)
|
||||||
|
|
||||||
# XXX: Handler hijack GossipSub here?
|
# XXX: Handler hijack GossipSub here?
|
||||||
|
@ -57,9 +51,9 @@ method initPubSub*(w: WakuRelay) =
|
||||||
debug "w.text", text = w.text
|
debug "w.text", text = w.text
|
||||||
|
|
||||||
# Not using GossipSub
|
# Not using GossipSub
|
||||||
w.gossip_enabled = false
|
w.gossipEnabled = false
|
||||||
|
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
procCall GossipSub(w).initPubSub()
|
procCall GossipSub(w).initPubSub()
|
||||||
else:
|
else:
|
||||||
procCall FloodSub(w).initPubSub()
|
procCall FloodSub(w).initPubSub()
|
||||||
|
@ -73,7 +67,7 @@ method subscribe*(w: WakuRelay,
|
||||||
# XXX: Pubsub really
|
# XXX: Pubsub really
|
||||||
|
|
||||||
# XXX: This is what is called, I think
|
# XXX: This is what is called, I think
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
await procCall GossipSub(w).subscribe(topic, handler)
|
await procCall GossipSub(w).subscribe(topic, handler)
|
||||||
else:
|
else:
|
||||||
await procCall FloodSub(w).subscribe(topic, handler)
|
await procCall FloodSub(w).subscribe(topic, handler)
|
||||||
|
@ -92,7 +86,7 @@ method subscribeTopic*(w: WakuRelay,
|
||||||
|
|
||||||
debug "subscribeTopic", topic=topic, subscribe=subscribe, peerId=peerId
|
debug "subscribeTopic", topic=topic, subscribe=subscribe, peerId=peerId
|
||||||
|
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
await procCall GossipSub(w).subscribeTopic(topic, subscribe, peerId)
|
await procCall GossipSub(w).subscribeTopic(topic, subscribe, peerId)
|
||||||
else:
|
else:
|
||||||
await procCall FloodSub(w).subscribeTopic(topic, subscribe, peerId)
|
await procCall FloodSub(w).subscribeTopic(topic, subscribe, peerId)
|
||||||
|
@ -103,14 +97,6 @@ method subscribeTopic*(w: WakuRelay,
|
||||||
info "about to call subscribe"
|
info "about to call subscribe"
|
||||||
await w.subscribe(topic, handler)
|
await w.subscribe(topic, handler)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: Fix decrement connected peers here or somewhere else
|
|
||||||
method handleDisconnect*(w: WakuRelay, peer: PubSubPeer) {.async.} =
|
|
||||||
debug "handleDisconnect (NYI)"
|
|
||||||
#connected_peers.dec()
|
|
||||||
|
|
||||||
method rpcHandler*(w: WakuRelay,
|
method rpcHandler*(w: WakuRelay,
|
||||||
peer: PubSubPeer,
|
peer: PubSubPeer,
|
||||||
rpcMsgs: seq[RPCMsg]) {.async.} =
|
rpcMsgs: seq[RPCMsg]) {.async.} =
|
||||||
|
@ -119,7 +105,7 @@ method rpcHandler*(w: WakuRelay,
|
||||||
# XXX: Right place?
|
# XXX: Right place?
|
||||||
total_messages.inc()
|
total_messages.inc()
|
||||||
|
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
await procCall GossipSub(w).rpcHandler(peer, rpcMsgs)
|
await procCall GossipSub(w).rpcHandler(peer, rpcMsgs)
|
||||||
else:
|
else:
|
||||||
await procCall FloodSub(w).rpcHandler(peer, rpcMsgs)
|
await procCall FloodSub(w).rpcHandler(peer, rpcMsgs)
|
||||||
|
@ -134,7 +120,7 @@ method publish*(w: WakuRelay,
|
||||||
data: seq[byte]): Future[int] {.async.} =
|
data: seq[byte]): Future[int] {.async.} =
|
||||||
debug "publish", topic=topic
|
debug "publish", topic=topic
|
||||||
|
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
return await procCall GossipSub(w).publish(topic, data)
|
return await procCall GossipSub(w).publish(topic, data)
|
||||||
else:
|
else:
|
||||||
return await procCall FloodSub(w).publish(topic, data)
|
return await procCall FloodSub(w).publish(topic, data)
|
||||||
|
@ -142,7 +128,7 @@ method publish*(w: WakuRelay,
|
||||||
method unsubscribe*(w: WakuRelay,
|
method unsubscribe*(w: WakuRelay,
|
||||||
topics: seq[TopicPair]) {.async.} =
|
topics: seq[TopicPair]) {.async.} =
|
||||||
debug "unsubscribe"
|
debug "unsubscribe"
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
await procCall GossipSub(w).unsubscribe(topics)
|
await procCall GossipSub(w).unsubscribe(topics)
|
||||||
else:
|
else:
|
||||||
await procCall FloodSub(w).unsubscribe(topics)
|
await procCall FloodSub(w).unsubscribe(topics)
|
||||||
|
@ -150,14 +136,14 @@ method unsubscribe*(w: WakuRelay,
|
||||||
# GossipSub specific methods
|
# GossipSub specific methods
|
||||||
method start*(w: WakuRelay) {.async.} =
|
method start*(w: WakuRelay) {.async.} =
|
||||||
debug "start"
|
debug "start"
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
await procCall GossipSub(w).start()
|
await procCall GossipSub(w).start()
|
||||||
else:
|
else:
|
||||||
await procCall FloodSub(w).start()
|
await procCall FloodSub(w).start()
|
||||||
|
|
||||||
method stop*(w: WakuRelay) {.async.} =
|
method stop*(w: WakuRelay) {.async.} =
|
||||||
debug "stop"
|
debug "stop"
|
||||||
if w.gossip_enabled:
|
if w.gossipEnabled:
|
||||||
await procCall GossipSub(w).stop()
|
await procCall GossipSub(w).stop()
|
||||||
else:
|
else:
|
||||||
await procCall FloodSub(w).stop()
|
await procCall FloodSub(w).stop()
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
import chronos, chronicles
|
import
|
||||||
import ./filter
|
std/tables,
|
||||||
import tables
|
chronos, chronicles, metrics, stew/results,
|
||||||
import libp2p/protocols/pubsub/pubsub,
|
|
||||||
libp2p/protocols/pubsub/pubsubpeer,
|
|
||||||
libp2p/protocols/pubsub/floodsub,
|
|
||||||
libp2p/protocols/pubsub/gossipsub,
|
|
||||||
libp2p/protocols/pubsub/rpc/[messages, protobuf],
|
libp2p/protocols/pubsub/rpc/[messages, protobuf],
|
||||||
libp2p/protocols/protocol,
|
libp2p/protocols/protocol,
|
||||||
libp2p/protobuf/minprotobuf,
|
libp2p/protobuf/minprotobuf,
|
||||||
libp2p/stream/connection
|
libp2p/stream/connection,
|
||||||
|
./filter
|
||||||
import metrics
|
|
||||||
|
|
||||||
import stew/results
|
|
||||||
|
|
||||||
const
|
const
|
||||||
WakuStoreCodec* = "/vac/waku/store/2.0.0-alpha2"
|
WakuStoreCodec* = "/vac/waku/store/2.0.0-alpha2"
|
||||||
|
@ -33,7 +26,7 @@ type
|
||||||
WakuStore* = ref object of LPProtocol
|
WakuStore* = ref object of LPProtocol
|
||||||
messages*: seq[Message]
|
messages*: seq[Message]
|
||||||
|
|
||||||
method init*(T: type HistoryQuery, buffer: seq[byte]): ProtoResult[T] =
|
proc init*(T: type HistoryQuery, buffer: seq[byte]): ProtoResult[T] =
|
||||||
var msg = HistoryQuery()
|
var msg = HistoryQuery()
|
||||||
let pb = initProtoBuffer(buffer)
|
let pb = initProtoBuffer(buffer)
|
||||||
|
|
||||||
|
@ -77,7 +70,7 @@ proc init*(T: type StoreRPC, buffer: seq[byte]): ProtoResult[T] =
|
||||||
|
|
||||||
ok(rpc)
|
ok(rpc)
|
||||||
|
|
||||||
method encode*(query: HistoryQuery): ProtoBuffer =
|
proc encode*(query: HistoryQuery): ProtoBuffer =
|
||||||
result = initProtoBuffer()
|
result = initProtoBuffer()
|
||||||
|
|
||||||
result.write(1, query.uuid)
|
result.write(1, query.uuid)
|
||||||
|
@ -85,7 +78,7 @@ method encode*(query: HistoryQuery): ProtoBuffer =
|
||||||
for topic in query.topics:
|
for topic in query.topics:
|
||||||
result.write(2, topic)
|
result.write(2, topic)
|
||||||
|
|
||||||
method encode*(response: HistoryResponse): ProtoBuffer =
|
proc encode*(response: HistoryResponse): ProtoBuffer =
|
||||||
result = initProtoBuffer()
|
result = initProtoBuffer()
|
||||||
|
|
||||||
result.write(1, response.uuid)
|
result.write(1, response.uuid)
|
||||||
|
@ -93,7 +86,7 @@ method encode*(response: HistoryResponse): ProtoBuffer =
|
||||||
for msg in response.messages:
|
for msg in response.messages:
|
||||||
result.write(2, msg.encodeMessage())
|
result.write(2, msg.encodeMessage())
|
||||||
|
|
||||||
method encode*(response: StoreRPC): ProtoBuffer =
|
proc encode*(response: StoreRPC): ProtoBuffer =
|
||||||
result = initProtoBuffer()
|
result = initProtoBuffer()
|
||||||
|
|
||||||
for query in response.query:
|
for query in response.query:
|
||||||
|
@ -110,7 +103,7 @@ proc query(w: WakuStore, query: HistoryQuery): HistoryResponse =
|
||||||
result.messages.insert(msg)
|
result.messages.insert(msg)
|
||||||
break
|
break
|
||||||
|
|
||||||
method init*(T: type WakuStore): T =
|
proc init*(T: type WakuStore): T =
|
||||||
var ws = WakuStore()
|
var ws = WakuStore()
|
||||||
|
|
||||||
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
||||||
|
|
Loading…
Reference in New Issue