mirror of https://github.com/waku-org/nwaku.git
refactor: remove unnecessary peermanager dependency (#1474)
This commit is contained in:
parent
76bb7520f3
commit
53bf00de69
|
@ -382,7 +382,7 @@ proc mountRelay*(node: WakuNode,
|
||||||
info "mounting relay protocol"
|
info "mounting relay protocol"
|
||||||
|
|
||||||
let initRes = WakuRelay.new(
|
let initRes = WakuRelay.new(
|
||||||
node.peerManager,
|
node.switch,
|
||||||
defaultPubsubTopics = concat(@[DefaultPubsubTopic], topics),
|
defaultPubsubTopics = concat(@[DefaultPubsubTopic], topics),
|
||||||
triggerSelf = triggerSelf
|
triggerSelf = triggerSelf
|
||||||
)
|
)
|
||||||
|
@ -779,13 +779,13 @@ proc lightpushPublish*(node: WakuNode, pubsubTopic: PubsubTopic, message: WakuMe
|
||||||
|
|
||||||
## Waku RLN Relay
|
## Waku RLN Relay
|
||||||
when defined(rln):
|
when defined(rln):
|
||||||
proc mountRlnRelay*(node: WakuNode,
|
proc mountRlnRelay*(node: WakuNode,
|
||||||
rlnConf: WakuRlnConfig,
|
rlnConf: WakuRlnConfig,
|
||||||
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
spamHandler: Option[SpamHandler] = none(SpamHandler),
|
||||||
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)) {.async.} =
|
registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)) {.async.} =
|
||||||
info "mounting rln relay"
|
info "mounting rln relay"
|
||||||
|
|
||||||
let rlnRelayRes = await WakuRlnRelay.new(node.wakuRelay,
|
let rlnRelayRes = await WakuRlnRelay.new(node.wakuRelay,
|
||||||
rlnConf,
|
rlnConf,
|
||||||
spamHandler,
|
spamHandler,
|
||||||
registrationHandler)
|
registrationHandler)
|
||||||
|
|
|
@ -10,15 +10,15 @@ else:
|
||||||
import
|
import
|
||||||
stew/results,
|
stew/results,
|
||||||
chronos,
|
chronos,
|
||||||
chronicles,
|
chronicles,
|
||||||
metrics,
|
metrics,
|
||||||
libp2p/multihash,
|
libp2p/multihash,
|
||||||
libp2p/protocols/pubsub/pubsub,
|
libp2p/protocols/pubsub/pubsub,
|
||||||
libp2p/protocols/pubsub/rpc/messages,
|
libp2p/protocols/pubsub/rpc/messages,
|
||||||
libp2p/protocols/pubsub/gossipsub,
|
libp2p/protocols/pubsub/gossipsub,
|
||||||
libp2p/stream/connection
|
libp2p/stream/connection,
|
||||||
|
libp2p/switch
|
||||||
import
|
import
|
||||||
../node/peer_manager/peer_manager,
|
|
||||||
./waku_message
|
./waku_message
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
@ -36,7 +36,6 @@ type
|
||||||
|
|
||||||
type
|
type
|
||||||
WakuRelay* = ref object of GossipSub
|
WakuRelay* = ref object of GossipSub
|
||||||
peerManager: PeerManager
|
|
||||||
defaultPubsubTopics*: seq[PubsubTopic] # Default configured PubSub topics
|
defaultPubsubTopics*: seq[PubsubTopic] # Default configured PubSub topics
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ proc initProtocolHandler(w: WakuRelay) =
|
||||||
w.codec = WakuRelayCodec
|
w.codec = WakuRelayCodec
|
||||||
|
|
||||||
method initPubSub(w: WakuRelay) {.raises: [InitializationError].} =
|
method initPubSub(w: WakuRelay) {.raises: [InitializationError].} =
|
||||||
## NOTE: This method overrides GossipSub initPubSub method; it called by the
|
## NOTE: This method overrides GossipSub initPubSub method; it called by the
|
||||||
## parent protocol, PubSub.
|
## parent protocol, PubSub.
|
||||||
debug "init waku relay"
|
debug "init waku relay"
|
||||||
|
|
||||||
|
@ -76,11 +75,11 @@ method initPubSub(w: WakuRelay) {.raises: [InitializationError].} =
|
||||||
w.initProtocolHandler()
|
w.initProtocolHandler()
|
||||||
|
|
||||||
|
|
||||||
proc new*(T: type WakuRelay,
|
proc new*(T: type WakuRelay,
|
||||||
peerManager: PeerManager,
|
switch: Switch,
|
||||||
defaultPubsubTopics: seq[PubsubTopic] = @[],
|
defaultPubsubTopics: seq[PubsubTopic] = @[],
|
||||||
triggerSelf: bool = true): WakuRelayResult[T] =
|
triggerSelf: bool = true): WakuRelayResult[T] =
|
||||||
|
|
||||||
proc msgIdProvider(msg: messages.Message): Result[MessageID, ValidationResult] =
|
proc msgIdProvider(msg: messages.Message): Result[MessageID, ValidationResult] =
|
||||||
let hash = MultiHash.digest("sha2-256", msg.data)
|
let hash = MultiHash.digest("sha2-256", msg.data)
|
||||||
if hash.isErr():
|
if hash.isErr():
|
||||||
|
@ -91,7 +90,7 @@ proc new*(T: type WakuRelay,
|
||||||
var wr: WakuRelay
|
var wr: WakuRelay
|
||||||
try:
|
try:
|
||||||
wr = WakuRelay.init(
|
wr = WakuRelay.init(
|
||||||
switch = peerManager.switch,
|
switch = switch,
|
||||||
msgIdProvider = msgIdProvider,
|
msgIdProvider = msgIdProvider,
|
||||||
triggerSelf = triggerSelf,
|
triggerSelf = triggerSelf,
|
||||||
sign = false,
|
sign = false,
|
||||||
|
@ -101,7 +100,6 @@ proc new*(T: type WakuRelay,
|
||||||
except InitializationError:
|
except InitializationError:
|
||||||
return err("initialization error: " & getCurrentExceptionMsg())
|
return err("initialization error: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
wr.peerManager = peerManager
|
|
||||||
wr.defaultPubsubTopics = defaultPubsubTopics
|
wr.defaultPubsubTopics = defaultPubsubTopics
|
||||||
|
|
||||||
ok(wr)
|
ok(wr)
|
||||||
|
@ -119,7 +117,7 @@ method stop*(w: WakuRelay) {.async.} =
|
||||||
method subscribe*(w: WakuRelay, pubsubTopic: PubsubTopic, handler: SubsciptionHandler|PubsubRawHandler) =
|
method subscribe*(w: WakuRelay, pubsubTopic: PubsubTopic, handler: SubsciptionHandler|PubsubRawHandler) =
|
||||||
debug "subscribe", pubsubTopic=pubsubTopic
|
debug "subscribe", pubsubTopic=pubsubTopic
|
||||||
|
|
||||||
var subsHandler: PubsubRawHandler
|
var subsHandler: PubsubRawHandler
|
||||||
when handler is SubsciptionHandler:
|
when handler is SubsciptionHandler:
|
||||||
subsHandler = proc(pubsubTopic: PubsubTopic, data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].} =
|
subsHandler = proc(pubsubTopic: PubsubTopic, data: seq[byte]): Future[void] {.gcsafe, raises: [Defect].} =
|
||||||
let decodeRes = WakuMessage.decode(data)
|
let decodeRes = WakuMessage.decode(data)
|
||||||
|
|
Loading…
Reference in New Issue