mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-28 15:46:33 +00:00
deploy: f457db9e0a09232b9331d5fd0951816dca401ed7
This commit is contained in:
parent
ebe0978c56
commit
33a8f59d34
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# libtool - Provide generalized library-building support services.
|
# libtool - Provide generalized library-building support services.
|
||||||
# Generated automatically by config.status (libbacktrace) version-unused
|
# Generated automatically by config.status (libbacktrace) version-unused
|
||||||
# Libtool was configured on host fv-az196-474:
|
# Libtool was configured on host fv-az182-872:
|
||||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||||
#
|
#
|
||||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||||
|
@ -72,6 +72,11 @@ type
|
|||||||
desc: "Enable spam protection through rln-relay: true|false",
|
desc: "Enable spam protection through rln-relay: true|false",
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
name: "rlnrelay" }: bool
|
name: "rlnrelay" }: bool
|
||||||
|
|
||||||
|
keepAlive* {.
|
||||||
|
desc: "Enable keep-alive for idle connections: true|false",
|
||||||
|
defaultValue: false
|
||||||
|
name: "keep-alive" }: bool
|
||||||
|
|
||||||
swap* {.
|
swap* {.
|
||||||
desc: "Enable swap protocol: true|false",
|
desc: "Enable swap protocol: true|false",
|
||||||
|
@ -454,7 +454,7 @@ proc addRLNRelayValidator*(node: WakuNode, pubsubTopic: string) =
|
|||||||
let pb = PubSub(node.wakuRelay)
|
let pb = PubSub(node.wakuRelay)
|
||||||
pb.addValidator(pubsubTopic, validator)
|
pb.addValidator(pubsubTopic, validator)
|
||||||
|
|
||||||
proc mountRelay*(node: WakuNode, topics: seq[string] = newSeq[string](), rlnRelayEnabled = false) {.gcsafe.} =
|
proc mountRelay*(node: WakuNode, topics: seq[string] = newSeq[string](), rlnRelayEnabled = false, keepAlive = false) {.gcsafe.} =
|
||||||
let wakuRelay = WakuRelay.init(
|
let wakuRelay = WakuRelay.init(
|
||||||
switch = node.switch,
|
switch = node.switch,
|
||||||
# Use default
|
# Use default
|
||||||
@ -464,6 +464,8 @@ proc mountRelay*(node: WakuNode, topics: seq[string] = newSeq[string](), rlnRela
|
|||||||
verifySignature = false
|
verifySignature = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
wakuRelay.keepAlive = keepAlive
|
||||||
|
|
||||||
node.wakuRelay = wakuRelay
|
node.wakuRelay = wakuRelay
|
||||||
node.switch.mount(wakuRelay)
|
node.switch.mount(wakuRelay)
|
||||||
|
|
||||||
@ -691,7 +693,7 @@ when isMainModule:
|
|||||||
|
|
||||||
# Relay setup
|
# Relay setup
|
||||||
if conf.relay: # True by default
|
if conf.relay: # True by default
|
||||||
mountRelay(node, conf.topics.split(" "), rlnRelayEnabled = conf.rlnrelay)
|
mountRelay(node, conf.topics.split(" "), rlnRelayEnabled = conf.rlnrelay, keepAlive = conf.keepAlive)
|
||||||
|
|
||||||
if conf.staticnodes.len > 0:
|
if conf.staticnodes.len > 0:
|
||||||
waitFor connectToNodes(node, conf.staticnodes)
|
waitFor connectToNodes(node, conf.staticnodes)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
## for spec.
|
## for spec.
|
||||||
|
|
||||||
import
|
import
|
||||||
|
std/[tables, sequtils, sets],
|
||||||
chronos, chronicles, metrics,
|
chronos, chronicles, metrics,
|
||||||
libp2p/protocols/pubsub/[pubsub, gossipsub],
|
libp2p/protocols/pubsub/[pubsub, gossipsub],
|
||||||
libp2p/protocols/pubsub/rpc/messages,
|
libp2p/protocols/pubsub/rpc/messages,
|
||||||
@ -12,10 +13,26 @@ import
|
|||||||
logScope:
|
logScope:
|
||||||
topics = "wakurelay"
|
topics = "wakurelay"
|
||||||
|
|
||||||
const WakuRelayCodec* = "/vac/waku/relay/2.0.0-beta2"
|
const
|
||||||
|
WakuRelayCodec* = "/vac/waku/relay/2.0.0-beta2"
|
||||||
|
DefaultKeepAlive = 5.minutes # 50% of the default chronosstream timeout duration
|
||||||
|
|
||||||
type
|
type
|
||||||
WakuRelay* = ref object of GossipSub
|
WakuRelay* = ref object of GossipSub
|
||||||
|
keepAlive*: bool
|
||||||
|
|
||||||
|
proc keepAlive*(w: WakuRelay) {.async.} =
|
||||||
|
while w.keepAlive:
|
||||||
|
# Keep all mesh peers alive when idle
|
||||||
|
trace "Running keepalive"
|
||||||
|
|
||||||
|
for topic in w.topics.keys:
|
||||||
|
trace "Keepalive on topic", topic=topic
|
||||||
|
let mpeers = w.mesh.getOrDefault(topic)
|
||||||
|
|
||||||
|
w.broadcast(toSeq(mpeers), RPCMsg(control: some(ControlMessage(graft: @[ControlGraft(topicID: topic)]))))
|
||||||
|
|
||||||
|
await sleepAsync(DefaultKeepAlive)
|
||||||
|
|
||||||
method init*(w: WakuRelay) =
|
method init*(w: WakuRelay) =
|
||||||
debug "init"
|
debug "init"
|
||||||
@ -81,7 +98,14 @@ method unsubscribeAll*(w: WakuRelay,
|
|||||||
method start*(w: WakuRelay) {.async.} =
|
method start*(w: WakuRelay) {.async.} =
|
||||||
debug "start"
|
debug "start"
|
||||||
await procCall GossipSub(w).start()
|
await procCall GossipSub(w).start()
|
||||||
|
|
||||||
|
if w.keepAlive:
|
||||||
|
# Keep connection to mesh peers alive over periods of idleness
|
||||||
|
asyncSpawn keepAlive(w)
|
||||||
|
|
||||||
method stop*(w: WakuRelay) {.async.} =
|
method stop*(w: WakuRelay) {.async.} =
|
||||||
debug "stop"
|
debug "stop"
|
||||||
|
|
||||||
|
w.keepAlive = false
|
||||||
|
|
||||||
await procCall GossipSub(w).stop()
|
await procCall GossipSub(w).stop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user