mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-17 10:10:09 +00:00
chore: replace Option with Opt (#4035)
* change all usage of std.options.Option[T] to results.Opt[T] * fix broken apps and examples (to validate refactor) * removed all std/options code added for libp2p v2 migration * add broker Opt codec to persistency/backend_comm.nim * add a readValue overload for Opt[T] in tools/confutils/cli_args.nim * keep Option where required (Presto, confutils' config_file.nim) * Change generateRlnProof error handling * Fix imports
This commit is contained in:
parent
1c83c32397
commit
ce918b0819
@ -1,5 +1,4 @@
|
||||
import
|
||||
std/[strutils, times, sequtils, osproc], math, results, options, testutils/unittests
|
||||
import std/[strutils, times, sequtils, osproc], math, results, testutils/unittests
|
||||
|
||||
import
|
||||
logos_delivery/waku/[
|
||||
|
||||
@ -6,7 +6,7 @@ when not (compileOption("threads")):
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[strformat, strutils, times, options, random, sequtils]
|
||||
import std/[strformat, strutils, times, random, sequtils]
|
||||
import
|
||||
confutils,
|
||||
chronicles,
|
||||
@ -48,7 +48,7 @@ import
|
||||
./config_chat2
|
||||
|
||||
import libp2p/protocols/pubsub/rpc/messages, libp2p/protocols/pubsub/pubsub
|
||||
import ../../logos_delivery/waku/rln
|
||||
import logos_delivery/waku/rln
|
||||
|
||||
const Help = """
|
||||
Commands: /[?|help|connect|nick|exit]
|
||||
@ -215,10 +215,10 @@ proc publish(c: Chat, line: string) =
|
||||
try:
|
||||
if not c.node.wakuLegacyLightPush.isNil():
|
||||
# Attempt lightpush
|
||||
(waitFor c.node.legacyLightpushPublish(some(DefaultPubsubTopic), message)).isOkOr:
|
||||
(waitFor c.node.legacyLightpushPublish(Opt.some(DefaultPubsubTopic), message)).isOkOr:
|
||||
error "failed to publish lightpush message", error = error
|
||||
else:
|
||||
(waitFor c.node.publish(some(DefaultPubsubTopic), message)).isOkOr:
|
||||
(waitFor c.node.publish(Opt.some(DefaultPubsubTopic), message)).isOkOr:
|
||||
error "failed to publish message", error = error
|
||||
except CatchableError:
|
||||
error "caught error publishing message: ", error = getCurrentExceptionMsg()
|
||||
@ -383,25 +383,25 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
echo "Connecting to static peers..."
|
||||
await connectToNodes(chat, conf.staticnodes)
|
||||
|
||||
var dnsDiscoveryUrl = none(string)
|
||||
var dnsDiscoveryUrl = Opt.none(string)
|
||||
|
||||
if conf.fleet != Fleet.none:
|
||||
# Use DNS discovery to connect to selected fleet
|
||||
echo "Connecting to " & $conf.fleet & " fleet using DNS discovery..."
|
||||
|
||||
if conf.fleet == Fleet.test:
|
||||
dnsDiscoveryUrl = some(
|
||||
dnsDiscoveryUrl = Opt.some(
|
||||
"enrtree://AOGYWMBYOUIMOENHXCHILPKY3ZRFEULMFI4DOM442QSZ73TT2A7VI@test.waku.nodes.status.im"
|
||||
)
|
||||
else:
|
||||
# Connect to sandbox by default
|
||||
dnsDiscoveryUrl = some(
|
||||
dnsDiscoveryUrl = Opt.some(
|
||||
"enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im"
|
||||
)
|
||||
elif conf.dnsDiscoveryUrl != "":
|
||||
# No pre-selected fleet. Discover nodes via DNS using user config
|
||||
info "Discovering nodes using Waku DNS discovery", url = conf.dnsDiscoveryUrl
|
||||
dnsDiscoveryUrl = some(conf.dnsDiscoveryUrl)
|
||||
dnsDiscoveryUrl = Opt.some(conf.dnsDiscoveryUrl)
|
||||
|
||||
var discoveredNodes: seq[RemotePeerInfo]
|
||||
|
||||
@ -437,17 +437,17 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
if (conf.storenode != "") or (conf.store == true):
|
||||
await node.mountStore()
|
||||
|
||||
var storenode: Option[RemotePeerInfo]
|
||||
var storenode: Opt[RemotePeerInfo]
|
||||
|
||||
if conf.storenode != "":
|
||||
let peerInfo = parsePeerInfo(conf.storenode)
|
||||
if peerInfo.isOk():
|
||||
storenode = some(peerInfo.value)
|
||||
storenode = Opt.some(peerInfo.value)
|
||||
else:
|
||||
error "Incorrect conf.storenode", error = peerInfo.error
|
||||
elif discoveredNodes.len > 0:
|
||||
echo "Store enabled, but no store nodes configured. Choosing one at random from discovered peers"
|
||||
storenode = some(discoveredNodes[rand(0 .. len(discoveredNodes) - 1)])
|
||||
storenode = Opt.some(discoveredNodes[rand(0 .. len(discoveredNodes) - 1)])
|
||||
|
||||
if storenode.isSome():
|
||||
# We have a viable storenode. Let's query it for historical messages.
|
||||
@ -537,14 +537,14 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
credIndex: conf.rlnRelayCredIndex,
|
||||
chainId: UInt256.fromBytesBE(conf.rlnRelayChainId.toBytesBE()),
|
||||
ethClientUrls: conf.ethClientUrls.mapIt(string(it)),
|
||||
creds: some(
|
||||
creds: Opt.some(
|
||||
RlnCreds(path: conf.rlnRelayCredPath, password: conf.rlnRelayCredPassword)
|
||||
),
|
||||
userMessageLimit: conf.rlnRelayUserMessageLimit,
|
||||
epochSizeSec: conf.rlnEpochSizeSec,
|
||||
)
|
||||
|
||||
waitFor node.setRlnValidator(rlnConf, spamHandler = some(spamHandler))
|
||||
waitFor node.setRlnValidator(rlnConf, spamHandler = Opt.some(spamHandler))
|
||||
|
||||
let membershipIndex = node.rln.groupManager.membershipIndex.get()
|
||||
let identityCredential = node.rln.groupManager.idCredentials.get()
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import
|
||||
results,
|
||||
chronicles,
|
||||
chronos,
|
||||
confutils,
|
||||
@ -26,7 +27,7 @@ type
|
||||
.}: LogLevel
|
||||
|
||||
nodekey* {.desc: "P2P node private key as 64 char hex string.", name: "nodekey".}:
|
||||
Option[crypto.PrivateKey]
|
||||
Opt[crypto.PrivateKey]
|
||||
|
||||
listenAddress* {.
|
||||
defaultValue: defaultListenAddress(config),
|
||||
@ -234,7 +235,7 @@ type
|
||||
|
||||
rlnRelayCredIndex* {.
|
||||
desc: "the index of the onchain commitment to use", name: "rln-relay-cred-index"
|
||||
.}: Option[uint]
|
||||
.}: Opt[uint]
|
||||
|
||||
rlnRelayDynamic* {.
|
||||
desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false",
|
||||
@ -317,9 +318,9 @@ proc parseCmdArg*(T: type Port, p: string): T =
|
||||
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
||||
return @[]
|
||||
|
||||
proc parseCmdArg*(T: type Option[uint], p: string): T =
|
||||
proc parseCmdArg*(T: type Opt[uint], p: string): T =
|
||||
try:
|
||||
some(parseUint(p))
|
||||
Opt.some(parseUint(p))
|
||||
except CatchableError:
|
||||
raise newException(ValueError, "Invalid unsigned integer")
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[tables, times, strutils, hashes, sequtils, json, options],
|
||||
results,
|
||||
std/[tables, times, strutils, hashes, sequtils, json],
|
||||
chronos,
|
||||
confutils,
|
||||
chronicles,
|
||||
@ -102,7 +103,7 @@ proc toChat2(cmb: Chat2MatterBridge, jsonNode: JsonNode) {.async.} =
|
||||
|
||||
chat2_mb_transfers.inc(labelValues = ["mb_to_chat2"])
|
||||
|
||||
(await cmb.nodev2.publish(some(DefaultPubsubTopic), msg)).isOkOr:
|
||||
(await cmb.nodev2.publish(Opt.some(DefaultPubsubTopic), msg)).isOkOr:
|
||||
error "failed to publish message", error = error
|
||||
|
||||
proc toMatterbridge(
|
||||
@ -156,8 +157,8 @@ proc new*(
|
||||
nodev2Key: crypto.PrivateKey,
|
||||
nodev2BindIp: IpAddress,
|
||||
nodev2BindPort: Port,
|
||||
nodev2ExtIp = none[IpAddress](),
|
||||
nodev2ExtPort = none[Port](),
|
||||
nodev2ExtIp = Opt.none(IpAddress),
|
||||
nodev2ExtPort = Opt.none(Port),
|
||||
contentTopic: string,
|
||||
): T {.
|
||||
raises: [Defect, ValueError, KeyError, TLSStreamProtocolError, IOError, LPError]
|
||||
@ -264,7 +265,7 @@ when isMainModule:
|
||||
## config, the external port is the same as the bind port.
|
||||
let extPort =
|
||||
if nodev2ExtIp.isSome() and nodev2ExtPort.isNone():
|
||||
some(Port(uint16(conf.libp2pTcpPort) + conf.portsShift))
|
||||
Opt.some(Port(uint16(conf.libp2pTcpPort) + conf.portsShift))
|
||||
else:
|
||||
nodev2ExtPort
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/options,
|
||||
results,
|
||||
confutils,
|
||||
confutils/defs,
|
||||
confutils/std/net,
|
||||
@ -64,7 +64,7 @@ type Chat2MatterbridgeConf* = object
|
||||
|
||||
nodekey* {.
|
||||
desc: "P2P node private key as hex", defaultValueDesc: "random", name: "nodekey"
|
||||
.}: Option[crypto.PrivateKey]
|
||||
.}: Opt[crypto.PrivateKey]
|
||||
|
||||
store* {.
|
||||
desc: "Flag whether to start store protocol", defaultValue: true, name: "store"
|
||||
|
||||
@ -6,7 +6,7 @@ when not (compileOption("threads")):
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[strformat, strutils, times, options, random, sequtils]
|
||||
import std/[strformat, strutils, times, random, sequtils, sets]
|
||||
import
|
||||
confutils,
|
||||
chronicles,
|
||||
@ -31,9 +31,8 @@ import
|
||||
protocols/kademlia/types,
|
||||
protocols/service_discovery/types as sd_types,
|
||||
nameresolving/dnsresolver,
|
||||
protocols/mix/curve25519,
|
||||
protocols/mix/mix_protocol,
|
||||
] # define DNS resolution
|
||||
import libp2p_mix/[curve25519, mix_protocol]
|
||||
import
|
||||
logos_delivery/waku/[
|
||||
waku_core,
|
||||
@ -216,9 +215,9 @@ proc publish(c: Chat, line: string) {.async.} =
|
||||
|
||||
(
|
||||
waitFor c.node.lightpushPublish(
|
||||
some(c.conf.getPubsubTopic(c.node, c.contentTopic)),
|
||||
Opt.some(c.conf.getPubsubTopic(c.node, c.contentTopic)),
|
||||
message,
|
||||
none(RemotePeerInfo),
|
||||
Opt.none(RemotePeerInfo),
|
||||
true,
|
||||
)
|
||||
).isOkOr:
|
||||
@ -312,7 +311,7 @@ proc readInput(wfd: AsyncFD) {.thread, raises: [Defect, CatchableError].} =
|
||||
var alreadyUsedServicePeers {.threadvar.}: seq[RemotePeerInfo]
|
||||
|
||||
proc selectRandomServicePeer*(
|
||||
pm: PeerManager, actualPeer: Option[RemotePeerInfo], codec: string
|
||||
pm: PeerManager, actualPeer: Opt[RemotePeerInfo], codec: string
|
||||
): Result[RemotePeerInfo, void] =
|
||||
if actualPeer.isSome():
|
||||
alreadyUsedServicePeers.add(actualPeer.get())
|
||||
@ -355,7 +354,7 @@ proc maintainSubscription(
|
||||
|
||||
let subscribeErr = (
|
||||
await wakuNode.filterSubscribe(
|
||||
some(filterPubsubTopic), filterContentTopic, actualFilterPeer
|
||||
Opt.some(filterPubsubTopic), filterContentTopic, actualFilterPeer
|
||||
)
|
||||
).errorOr:
|
||||
await sleepAsync(SubscriptionMaintenance)
|
||||
@ -377,7 +376,7 @@ proc maintainSubscription(
|
||||
elif not preventPeerSwitch:
|
||||
# try again with new peer without delay
|
||||
let actualFilterPeer = selectRandomServicePeer(
|
||||
wakuNode.peerManager, some(actualFilterPeer), WakuFilterSubscribeCodec
|
||||
wakuNode.peerManager, Opt.some(actualFilterPeer), WakuFilterSubscribeCodec
|
||||
).valueOr:
|
||||
error "Failed to find new service peer. Exiting."
|
||||
noFailedServiceNodeSwitches += 1
|
||||
@ -463,10 +462,9 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
if conf.kadBootstrapNodes.len > 0:
|
||||
var kadBootstrapPeers: seq[(PeerId, seq[MultiAddress])]
|
||||
for nodeStr in conf.kadBootstrapNodes:
|
||||
let (peerId, ma) = block:
|
||||
parseFullAddress(nodeStr).isOkOr:
|
||||
error "Failed to parse kademlia bootstrap node", node = nodeStr, error
|
||||
continue
|
||||
let (peerId, ma) = parseFullAddress(nodeStr).valueOr:
|
||||
error "Failed to parse kademlia bootstrap node", node = nodeStr, error = error
|
||||
continue
|
||||
|
||||
kadBootstrapPeers.add((peerId, @[ma]))
|
||||
|
||||
@ -474,7 +472,7 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
node.mountKademlia(
|
||||
KademliaDiscoveryConf(
|
||||
bootstrapNodes: kadBootstrapPeers,
|
||||
servicesToDiscover: @[MixProtocolID],
|
||||
servicesToDiscover: toHashSet([MixProtocolID]),
|
||||
randomLookupInterval: chronos.seconds(60),
|
||||
serviceLookupInterval: chronos.seconds(60),
|
||||
kadDhtConfig: KadDHTConfig.new(),
|
||||
@ -511,25 +509,25 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
conf: conf,
|
||||
)
|
||||
|
||||
var dnsDiscoveryUrl = none(string)
|
||||
var dnsDiscoveryUrl = Opt.none(string)
|
||||
|
||||
if conf.fleet != Fleet.none:
|
||||
# Use DNS discovery to connect to selected fleet
|
||||
echo "Connecting to " & $conf.fleet & " fleet using DNS discovery..."
|
||||
|
||||
if conf.fleet == Fleet.test:
|
||||
dnsDiscoveryUrl = some(
|
||||
dnsDiscoveryUrl = Opt.some(
|
||||
"enrtree://AOGYWMBYOUIMOENHXCHILPKY3ZRFEULMFI4DOM442QSZ73TT2A7VI@test.waku.nodes.status.im"
|
||||
)
|
||||
else:
|
||||
# Connect to sandbox by default
|
||||
dnsDiscoveryUrl = some(
|
||||
dnsDiscoveryUrl = Opt.some(
|
||||
"enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im"
|
||||
)
|
||||
elif conf.dnsDiscoveryUrl != "":
|
||||
# No pre-selected fleet. Discover nodes via DNS using user config
|
||||
info "Discovering nodes using Waku DNS discovery", url = conf.dnsDiscoveryUrl
|
||||
dnsDiscoveryUrl = some(conf.dnsDiscoveryUrl)
|
||||
dnsDiscoveryUrl = Opt.some(conf.dnsDiscoveryUrl)
|
||||
|
||||
var discoveredNodes: seq[RemotePeerInfo]
|
||||
|
||||
@ -565,17 +563,17 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
if (conf.storenode != "") or (conf.store == true):
|
||||
await node.mountStore()
|
||||
|
||||
var storenode: Option[RemotePeerInfo]
|
||||
var storenode: Opt[RemotePeerInfo]
|
||||
|
||||
if conf.storenode != "":
|
||||
let peerInfo = parsePeerInfo(conf.storenode)
|
||||
if peerInfo.isOk():
|
||||
storenode = some(peerInfo.value)
|
||||
storenode = Opt.some(peerInfo.value)
|
||||
else:
|
||||
error "Incorrect conf.storenode", error = peerInfo.error
|
||||
elif discoveredNodes.len > 0:
|
||||
echo "Store enabled, but no store nodes configured. Choosing one at random from discovered peers"
|
||||
storenode = some(discoveredNodes[rand(0 .. len(discoveredNodes) - 1)])
|
||||
storenode = Opt.some(discoveredNodes[rand(0 .. len(discoveredNodes) - 1)])
|
||||
|
||||
if storenode.isSome():
|
||||
# We have a viable storenode. Let's query it for historical messages.
|
||||
@ -620,7 +618,7 @@ proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} =
|
||||
if servicePeerInfo == nil or $servicePeerInfo.peerId == "":
|
||||
# Assuming that service node supports all services
|
||||
servicePeerInfo = selectRandomServicePeer(
|
||||
node.peerManager, none(RemotePeerInfo), WakuLightpushCodec
|
||||
node.peerManager, Opt.none(RemotePeerInfo), WakuLightpushCodec
|
||||
).valueOr:
|
||||
error "Couldn't find any service peer"
|
||||
quit(QuitFailure)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, chronos, std/strutils, regex
|
||||
import results, chronicles, chronos, std/strutils, regex
|
||||
|
||||
import
|
||||
eth/keys,
|
||||
@ -32,7 +32,7 @@ type
|
||||
.}: LogLevel
|
||||
|
||||
nodekey* {.desc: "P2P node private key as 64 char hex string.", name: "nodekey".}:
|
||||
Option[crypto.PrivateKey]
|
||||
Opt[crypto.PrivateKey]
|
||||
|
||||
listenAddress* {.
|
||||
defaultValue: defaultListenAddress(config),
|
||||
@ -287,9 +287,9 @@ proc parseCmdArg*(T: type Port, p: string): T =
|
||||
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
||||
return @[]
|
||||
|
||||
proc parseCmdArg*(T: type Option[uint], p: string): T =
|
||||
proc parseCmdArg*(T: type Opt[uint], p: string): T =
|
||||
try:
|
||||
some(parseUint(p))
|
||||
Opt.some(parseUint(p))
|
||||
except CatchableError:
|
||||
raise newException(ValueError, "Invalid unsigned integer")
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ else:
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, net, strformat],
|
||||
std/[net, strformat],
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronos, results, options
|
||||
import chronos, results
|
||||
import logos_delivery/waku/[waku_node, waku_core]
|
||||
import publisher_base
|
||||
|
||||
@ -18,7 +18,7 @@ method send*(
|
||||
): Future[Result[void, string]] {.async.} =
|
||||
# when error it must return original error desc due the text is used for distinction between error types in metrics.
|
||||
discard (
|
||||
await self.wakuNode.legacyLightpushPublish(some(topic), message, servicePeer)
|
||||
await self.wakuNode.legacyLightpushPublish(Opt.some(topic), message, servicePeer)
|
||||
).valueOr:
|
||||
return err(error)
|
||||
return ok()
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, strutils, os, sequtils, net],
|
||||
results,
|
||||
std/[strutils, os, sequtils, net],
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
@ -95,7 +96,7 @@ when isMainModule:
|
||||
|
||||
wakuNodeConf.shards = @[conf.shard]
|
||||
wakuNodeConf.contentTopics = conf.contentTopics
|
||||
wakuNodeConf.clusterId = some(conf.clusterId)
|
||||
wakuNodeConf.clusterId = Opt.some(conf.clusterId)
|
||||
## TODO: Depending on the tester needs we might extend here with shards, clusterId, etc...
|
||||
|
||||
wakuNodeConf.metricsServer = true
|
||||
@ -190,7 +191,7 @@ when isMainModule:
|
||||
quit(QuitFailure)
|
||||
|
||||
serviceNodePeerInfo = selectRandomServicePeer(
|
||||
waku.node.peerManager, none(RemotePeerInfo), codec
|
||||
waku.node.peerManager, Opt.none(RemotePeerInfo), codec
|
||||
).valueOr:
|
||||
error "Service node selection failed"
|
||||
quit(QuitFailure)
|
||||
|
||||
@ -188,7 +188,7 @@ proc publishMessages(
|
||||
if not preventPeerSwitch and noFailedPush > maxFailedPush:
|
||||
info "Max push failure limit reached, Try switching peer."
|
||||
actualServicePeer = selectRandomServicePeer(
|
||||
wakuNode.peerManager, some(actualServicePeer), WakuLightPushCodec
|
||||
wakuNode.peerManager, Opt.some(actualServicePeer), WakuLightPushCodec
|
||||
).valueOr:
|
||||
error "Failed to find new service peer. Exiting."
|
||||
noFailedServiceNodeSwitches += 1
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
## subscribe to messages without relay
|
||||
|
||||
import
|
||||
std/options,
|
||||
system/ansi_c,
|
||||
chronicles,
|
||||
chronos,
|
||||
@ -74,7 +73,7 @@ proc maintainSubscription(
|
||||
|
||||
let subscribeErr = (
|
||||
await wakuNode.filterSubscribe(
|
||||
some(filterPubsubTopic), filterContentTopic, actualFilterPeer
|
||||
Opt.some(filterPubsubTopic), filterContentTopic, actualFilterPeer
|
||||
)
|
||||
).errorOr:
|
||||
await sleepAsync(SubscriptionMaintenanceMs)
|
||||
@ -99,7 +98,7 @@ proc maintainSubscription(
|
||||
elif not preventPeerSwitch:
|
||||
# try again with new peer without delay
|
||||
actualFilterPeer = selectRandomServicePeer(
|
||||
wakuNode.peerManager, some(actualFilterPeer), WakuFilterSubscribeCodec
|
||||
wakuNode.peerManager, Opt.some(actualFilterPeer), WakuFilterSubscribeCodec
|
||||
).valueOr:
|
||||
error "Failed to find new service peer. Exiting."
|
||||
noFailedServiceNodeSwitches += 1
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, net, sysrand, random, strformat, strutils, sequtils],
|
||||
results,
|
||||
std/[net, sysrand, random, strformat, strutils, sequtils],
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
@ -53,7 +54,7 @@ proc translateToRemotePeerInfo*(peerAddress: string): Result[RemotePeerInfo, voi
|
||||
## Note: This is kept for future use.
|
||||
proc selectRandomCapablePeer*(
|
||||
pm: PeerManager, codec: string, pubsubTopic: PubsubTopic
|
||||
): Future[Option[RemotePeerInfo]] {.async.} =
|
||||
): Future[Opt[RemotePeerInfo]] {.async.} =
|
||||
var cap = Capabilities.Filter
|
||||
if codec.contains("lightpush"):
|
||||
cap = Capabilities.Lightpush
|
||||
@ -65,9 +66,9 @@ proc selectRandomCapablePeer*(
|
||||
trace "Found supportive peers count", count = supportivePeers.len()
|
||||
trace "Found supportive peers", supportivePeers = $supportivePeers
|
||||
if supportivePeers.len == 0:
|
||||
return none(RemotePeerInfo)
|
||||
return Opt.none(RemotePeerInfo)
|
||||
|
||||
var found = none(RemotePeerInfo)
|
||||
var found = Opt.none(RemotePeerInfo)
|
||||
while found.isNone() and supportivePeers.len > 0:
|
||||
let rndPeerIndex = rand(0 .. supportivePeers.len - 1)
|
||||
let randomPeer = supportivePeers[rndPeerIndex]
|
||||
@ -80,7 +81,7 @@ proc selectRandomCapablePeer*(
|
||||
let connOpt = pm.dialPeer(randomPeer, codec)
|
||||
if (await connOpt.withTimeout(10.seconds)):
|
||||
if connOpt.value().isSome():
|
||||
found = some(randomPeer)
|
||||
found = Opt.some(randomPeer)
|
||||
info "Dialing successful",
|
||||
peer = constructMultiaddrStr(randomPeer), codec = codec
|
||||
else:
|
||||
@ -94,7 +95,7 @@ proc selectRandomCapablePeer*(
|
||||
# Debugging PX gathered peers connectivity
|
||||
proc tryCallAllPxPeers*(
|
||||
pm: PeerManager, codec: string, pubsubTopic: PubsubTopic
|
||||
): Future[Option[seq[RemotePeerInfo]]] {.async.} =
|
||||
): Future[Opt[seq[RemotePeerInfo]]] {.async.} =
|
||||
var capability = Capabilities.Filter
|
||||
if codec.contains("lightpush"):
|
||||
capability = Capabilities.Lightpush
|
||||
@ -107,7 +108,7 @@ proc tryCallAllPxPeers*(
|
||||
info "Found supportive peers count", count = supportivePeers.len()
|
||||
info "Found supportive peers", supportivePeers = $supportivePeers
|
||||
if supportivePeers.len == 0:
|
||||
return none(seq[RemotePeerInfo])
|
||||
return Opt.none(seq[RemotePeerInfo])
|
||||
|
||||
var okPeers: seq[RemotePeerInfo] = @[]
|
||||
|
||||
@ -152,7 +153,7 @@ proc tryCallAllPxPeers*(
|
||||
echo "PX returned peers found callable for " & codec & " / " & $capability & ":\n"
|
||||
echo okPeersStr
|
||||
|
||||
return some(okPeers)
|
||||
return Opt.some(okPeers)
|
||||
|
||||
proc pxLookupServiceNode*(
|
||||
node: WakuNode, conf: LiteProtocolTesterConf
|
||||
@ -168,7 +169,7 @@ proc pxLookupServiceNode*(
|
||||
node.peerManager.addServicePeer(peerExchangeNode, WakuPeerExchangeCodec)
|
||||
|
||||
try:
|
||||
await node.mountPeerExchange(some(conf.clusterId))
|
||||
await node.mountPeerExchange(Opt.some(conf.clusterId))
|
||||
except CatchableError:
|
||||
error "failed to mount waku peer-exchange protocol",
|
||||
error = getCurrentExceptionMsg()
|
||||
@ -207,7 +208,7 @@ var alreadyUsedServicePeers {.threadvar.}: seq[RemotePeerInfo]
|
||||
|
||||
## Select service peers by codec from peer store randomly.
|
||||
proc selectRandomServicePeer*(
|
||||
pm: PeerManager, actualPeer: Option[RemotePeerInfo], codec: string
|
||||
pm: PeerManager, actualPeer: Opt[RemotePeerInfo], codec: string
|
||||
): Result[RemotePeerInfo, void] =
|
||||
if actualPeer.isSome():
|
||||
alreadyUsedServicePeers.add(actualPeer.get())
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[sets, tables, sequtils, options, strformat],
|
||||
std/[sets, tables, sequtils, strformat],
|
||||
chronos/timer as chtimer,
|
||||
chronicles,
|
||||
chronos,
|
||||
@ -123,10 +123,10 @@ proc addMessage*(
|
||||
|
||||
lpt_receiver_sender_peer_count.set(value = self.len)
|
||||
|
||||
proc lastMessageArrivedAt*(self: Statistics): Option[Moment] =
|
||||
proc lastMessageArrivedAt*(self: Statistics): Opt[Moment] =
|
||||
if self.receivedMessages > 0:
|
||||
return some(self.helper.prevArrivedAt)
|
||||
return none(Moment)
|
||||
return Opt.some(self.helper.prevArrivedAt)
|
||||
return Opt.none(Moment)
|
||||
|
||||
proc lossCount*(self: Statistics): uint32 =
|
||||
self.helper.maxIndex - self.receivedMessages
|
||||
@ -271,7 +271,7 @@ proc jsonStats*(self: PerPeerStatistics): string =
|
||||
"{\"result:\": \"Error while generating json stats: " & getCurrentExceptionMsg() &
|
||||
"\"}"
|
||||
|
||||
proc lastMessageArrivedAt*(self: PerPeerStatistics): Option[Moment] =
|
||||
proc lastMessageArrivedAt*(self: PerPeerStatistics): Opt[Moment] =
|
||||
var lastArrivedAt = Moment.init(0, Millisecond)
|
||||
for stat in self.values:
|
||||
let lastMsgFromPeerAt = stat.lastMessageArrivedAt().valueOr:
|
||||
@ -281,9 +281,9 @@ proc lastMessageArrivedAt*(self: PerPeerStatistics): Option[Moment] =
|
||||
lastArrivedAt = lastMsgFromPeerAt
|
||||
|
||||
if lastArrivedAt == Moment.init(0, Millisecond):
|
||||
return none(Moment)
|
||||
return Opt.none(Moment)
|
||||
|
||||
return some(lastArrivedAt)
|
||||
return Opt.some(lastArrivedAt)
|
||||
|
||||
proc checkIfAllMessagesReceived*(
|
||||
self: PerPeerStatistics, maxWaitForLastMessage: Duration
|
||||
|
||||
@ -37,7 +37,7 @@ type LiteProtocolTesterConf* = object
|
||||
desc:
|
||||
"Loads configuration from a TOML file (cmd-line parameters take precedence) for the light waku node",
|
||||
name: "config-file"
|
||||
.}: Option[InputFile]
|
||||
.}: Opt[InputFile]
|
||||
|
||||
## Log configuration
|
||||
logLevel* {.
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
results,
|
||||
chronicles,
|
||||
json_serialization,
|
||||
json_serialization/std/options,
|
||||
json_serialization/pkg/results,
|
||||
json_serialization/lexer
|
||||
|
||||
import logos_delivery/waku/rest_api/endpoint/serdes
|
||||
@ -34,13 +35,13 @@ proc readValue*(
|
||||
reader: var JsonReader[RestJson], value: var ProtocolTesterMessage
|
||||
) {.gcsafe, raises: [SerializationError, IOError].} =
|
||||
var
|
||||
sender: Option[string]
|
||||
index: Option[uint32]
|
||||
count: Option[uint32]
|
||||
startedAt: Option[int64]
|
||||
sinceStart: Option[int64]
|
||||
sincePrev: Option[int64]
|
||||
size: Option[uint64]
|
||||
sender: Opt[string]
|
||||
index: Opt[uint32]
|
||||
count: Opt[uint32]
|
||||
startedAt: Opt[int64]
|
||||
sinceStart: Opt[int64]
|
||||
sincePrev: Opt[int64]
|
||||
size: Opt[uint64]
|
||||
|
||||
for fieldName in readObjectFields(reader):
|
||||
case fieldName
|
||||
@ -49,43 +50,43 @@ proc readValue*(
|
||||
reader.raiseUnexpectedField(
|
||||
"Multiple `sender` fields found", "ProtocolTesterMessage"
|
||||
)
|
||||
sender = some(reader.readValue(string))
|
||||
sender = Opt.some(reader.readValue(string))
|
||||
of "index":
|
||||
if index.isSome():
|
||||
reader.raiseUnexpectedField(
|
||||
"Multiple `index` fields found", "ProtocolTesterMessage"
|
||||
)
|
||||
index = some(reader.readValue(uint32))
|
||||
index = Opt.some(reader.readValue(uint32))
|
||||
of "count":
|
||||
if count.isSome():
|
||||
reader.raiseUnexpectedField(
|
||||
"Multiple `count` fields found", "ProtocolTesterMessage"
|
||||
)
|
||||
count = some(reader.readValue(uint32))
|
||||
count = Opt.some(reader.readValue(uint32))
|
||||
of "startedAt":
|
||||
if startedAt.isSome():
|
||||
reader.raiseUnexpectedField(
|
||||
"Multiple `startedAt` fields found", "ProtocolTesterMessage"
|
||||
)
|
||||
startedAt = some(reader.readValue(int64))
|
||||
startedAt = Opt.some(reader.readValue(int64))
|
||||
of "sinceStart":
|
||||
if sinceStart.isSome():
|
||||
reader.raiseUnexpectedField(
|
||||
"Multiple `sinceStart` fields found", "ProtocolTesterMessage"
|
||||
)
|
||||
sinceStart = some(reader.readValue(int64))
|
||||
sinceStart = Opt.some(reader.readValue(int64))
|
||||
of "sincePrev":
|
||||
if sincePrev.isSome():
|
||||
reader.raiseUnexpectedField(
|
||||
"Multiple `sincePrev` fields found", "ProtocolTesterMessage"
|
||||
)
|
||||
sincePrev = some(reader.readValue(int64))
|
||||
sincePrev = Opt.some(reader.readValue(int64))
|
||||
of "size":
|
||||
if size.isSome():
|
||||
reader.raiseUnexpectedField(
|
||||
"Multiple `size` fields found", "ProtocolTesterMessage"
|
||||
)
|
||||
size = some(reader.readValue(uint64))
|
||||
size = Opt.some(reader.readValue(uint64))
|
||||
else:
|
||||
unrecognizedFieldWarning(value)
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import results, options, chronos
|
||||
import results, chronos
|
||||
import logos_delivery/waku/[waku_node, waku_core, waku_lightpush, waku_lightpush/common]
|
||||
import publisher_base
|
||||
|
||||
@ -18,10 +18,12 @@ method send*(
|
||||
): Future[Result[void, string]] {.async.} =
|
||||
# when error it must return original error desc due the text is used for distinction between error types in metrics.
|
||||
discard (
|
||||
await self.wakuNode.lightpushPublish(some(topic), message, some(servicePeer))
|
||||
await self.wakuNode.lightpushPublish(
|
||||
Opt.some(topic), message, Opt.some(servicePeer)
|
||||
)
|
||||
).valueOr:
|
||||
if error.code == LightPushErrorCode.NO_PEERS_TO_RELAY and
|
||||
error.desc != some("No peers for topic, skipping publish"):
|
||||
error.desc != Opt.some("No peers for topic, skipping publish"):
|
||||
# TODO: We need better separation of errors happening on the client side or the server side.-
|
||||
return err("dial_failure")
|
||||
else:
|
||||
|
||||
@ -422,7 +422,7 @@ proc initAndStartApp(
|
||||
|
||||
let
|
||||
# some hardcoded parameters
|
||||
rng = keys.newRng()
|
||||
rng = crypto.newRng()
|
||||
key = crypto.PrivateKey.random(Secp256k1, rng)[]
|
||||
nodeTcpPort = Port(60000)
|
||||
nodeUdpPort = Port(9000)
|
||||
@ -433,7 +433,9 @@ proc initAndStartApp(
|
||||
var builder = EnrBuilder.init(key)
|
||||
|
||||
builder.withIpAddressAndPorts(
|
||||
ipAddr = some(extIp), tcpPort = some(nodeTcpPort), udpPort = some(nodeUdpPort)
|
||||
ipAddr = Opt.some(extIp),
|
||||
tcpPort = Opt.some(nodeTcpPort),
|
||||
udpPort = Opt.some(nodeUdpPort),
|
||||
)
|
||||
builder.withWakuCapabilities(flags)
|
||||
|
||||
@ -450,7 +452,7 @@ proc initAndStartApp(
|
||||
|
||||
nodeBuilder.withNodeKey(key)
|
||||
nodeBuilder.withRecord(record)
|
||||
nodeBuilder.withSwitchConfiguration(maxConnections = some(MaxConnectedPeers))
|
||||
nodeBuilder.withSwitchConfiguration(maxConnections = Opt.some(MaxConnectedPeers))
|
||||
|
||||
nodeBuilder.withPeerManagerConfig(
|
||||
maxConnections = MaxConnectedPeers,
|
||||
@ -473,7 +475,7 @@ proc initAndStartApp(
|
||||
|
||||
# discv5
|
||||
let discv5Conf = WakuDiscoveryV5Config(
|
||||
discv5Config: none(DiscoveryConfig),
|
||||
discv5Config: Opt.none(DiscoveryConfig),
|
||||
address: bindIp,
|
||||
port: nodeUdpPort,
|
||||
privateKey: keys.PrivateKey(key.skkey),
|
||||
@ -481,7 +483,7 @@ proc initAndStartApp(
|
||||
autoupdateRecord: false,
|
||||
)
|
||||
|
||||
let wakuDiscv5 = WakuDiscoveryV5.new(node.rng, discv5Conf, some(record))
|
||||
let wakuDiscv5 = WakuDiscoveryV5.new(node.rng, discv5Conf, Opt.some(record))
|
||||
|
||||
try:
|
||||
wakuDiscv5.protocol.open()
|
||||
@ -610,11 +612,11 @@ when isMainModule:
|
||||
if conf.rlnRelay and conf.rlnRelayEthContractAddress != "":
|
||||
let rlnConf = WakuRlnConfig(
|
||||
dynamic: conf.rlnRelayDynamic,
|
||||
credIndex: some(uint(0)),
|
||||
credIndex: Opt.some(uint(0)),
|
||||
ethContractAddress: conf.rlnRelayEthContractAddress,
|
||||
ethClientUrls: conf.ethClientUrls.mapIt(string(it)),
|
||||
epochSizeSec: conf.rlnEpochSizeSec,
|
||||
creds: none(RlnCreds),
|
||||
creds: Opt.none(RlnCreds),
|
||||
onFatalErrorAction: onFatalErrorAction,
|
||||
)
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import
|
||||
results,
|
||||
std/[strutils, sequtils, tables, strformat],
|
||||
confutils,
|
||||
chronos,
|
||||
@ -215,7 +216,7 @@ proc main(rng: Rng): Future[int] {.async.} =
|
||||
let netConfig = NetConfig.init(
|
||||
bindIp = bindIp,
|
||||
bindPort = nodeTcpPort,
|
||||
wsBindPort = some(wsBindPort),
|
||||
wsBindPort = Opt.some(wsBindPort),
|
||||
wsEnabled = isWs,
|
||||
wssEnabled = isWss,
|
||||
)
|
||||
@ -244,7 +245,9 @@ proc main(rng: Rng): Future[int] {.async.} =
|
||||
builder.withRecord(record)
|
||||
builder.withNetworkConfiguration(netConfig.tryGet())
|
||||
builder.withSwitchConfiguration(
|
||||
secureKey = some(keyPath), secureCert = some(certPath), nameResolver = resolver
|
||||
secureKey = Opt.some(keyPath),
|
||||
secureCert = Opt.some(certPath),
|
||||
nameResolver = resolver,
|
||||
)
|
||||
|
||||
let node = builder.build().tryGet()
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, strutils, sequtils, net],
|
||||
std/[strutils, sequtils, net],
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import std/options
|
||||
import chronos, results, confutils, confutils/defs
|
||||
import logos_delivery
|
||||
|
||||
@ -67,11 +66,9 @@ when isMainModule:
|
||||
if args.ethRpcEndpoint == "":
|
||||
# Create a basic configuration for the Waku node
|
||||
# No RLN as we don't have an ETH RPC Endpoint
|
||||
conf.mode = Core
|
||||
conf.preset = "logos.dev"
|
||||
else:
|
||||
# Connect to TWN, use ETH RPC Endpoint for RLN
|
||||
conf.mode = Core
|
||||
conf.preset = "twn"
|
||||
conf.ethClientUrls = @[EthRpcUrl(args.ethRpcEndpoint)]
|
||||
|
||||
|
||||
@ -43,13 +43,13 @@ proc messagePushHandler(
|
||||
contentTopic = message.contentTopic,
|
||||
timestamp = message.timestamp
|
||||
|
||||
proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
||||
proc setupAndSubscribe(rng: crypto.Rng) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
notice "starting subscriber", wakuPort = wakuPort
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[]
|
||||
ip = parseIpAddress("0.0.0.0")
|
||||
flags = CapabilitiesBitfield.init(relay = true)
|
||||
|
||||
|
||||
@ -48,13 +48,13 @@ proc splitPeerIdAndAddr(maddr: string): (string, string) =
|
||||
peerId = parts[1]
|
||||
return (address, peerId)
|
||||
|
||||
proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.} =
|
||||
proc setupAndPublish(rng: crypto.Rng, conf: LightPushMixConf) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLog(logging.LogLevel.DEBUG, logging.LogFormat.TEXT)
|
||||
notice "starting publisher", wakuPort = conf.port
|
||||
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get()
|
||||
ip = parseIpAddress("0.0.0.0")
|
||||
flags = CapabilitiesBitfield.init(relay = true)
|
||||
|
||||
@ -84,7 +84,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.}
|
||||
)
|
||||
node.mountLightPushClient()
|
||||
try:
|
||||
await node.mountPeerExchange(some(uint16(clusterId)))
|
||||
await node.mountPeerExchange(Opt.some(uint16(clusterId)))
|
||||
except CatchableError:
|
||||
error "failed to mount waku peer-exchange protocol",
|
||||
error = getCurrentExceptionMsg()
|
||||
@ -164,8 +164,9 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.}
|
||||
timestamp: getNowInNanosecondTime(),
|
||||
) # current timestamp
|
||||
|
||||
let res =
|
||||
await node.wakuLightpushClient.publish(some(LightpushPubsubTopic), message, conn)
|
||||
let res = await node.wakuLightpushClient.publish(
|
||||
Opt.some(LightpushPubsubTopic), message, conn
|
||||
)
|
||||
|
||||
let startTime = getNowInNanosecondTime()
|
||||
|
||||
|
||||
@ -35,13 +35,13 @@ const
|
||||
LightpushPubsubTopic = PubsubTopic("/waku/2/rs/1/0")
|
||||
LightpushContentTopic = ContentTopic("/examples/1/light-pubsub-example/proto")
|
||||
|
||||
proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
proc setupAndPublish(rng: crypto.Rng) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
notice "starting publisher", wakuPort = wakuPort
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get()
|
||||
ip = parseIpAddress("0.0.0.0")
|
||||
flags = CapabilitiesBitfield.init(relay = true)
|
||||
|
||||
@ -87,7 +87,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
quit(QuitFailure)
|
||||
|
||||
let res = await node.legacyLightpushPublish(
|
||||
some(LightpushPubsubTopic), message, lightpushPeer
|
||||
Opt.some(LightpushPubsubTopic), message, lightpushPeer
|
||||
)
|
||||
|
||||
if res.isOk:
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import
|
||||
results,
|
||||
std/[tables, times, sequtils],
|
||||
stew/byteutils,
|
||||
chronicles,
|
||||
@ -37,13 +38,13 @@ const bootstrapNode =
|
||||
const wakuPort = 60000
|
||||
const discv5Port = 9000
|
||||
|
||||
proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
proc setupAndPublish(rng: crypto.Rng) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
notice "starting publisher", wakuPort = wakuPort, discv5Port = discv5Port
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng).get()
|
||||
ip = parseIpAddress("0.0.0.0")
|
||||
flags = CapabilitiesBitfield.init(relay = true)
|
||||
|
||||
@ -63,7 +64,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
discard bootstrapNodeEnr.fromURI(bootstrapNode)
|
||||
|
||||
let discv5Conf = WakuDiscoveryV5Config(
|
||||
discv5Config: none(DiscoveryConfig),
|
||||
discv5Config: Opt.none(DiscoveryConfig),
|
||||
address: ip,
|
||||
port: Port(discv5Port),
|
||||
privateKey: keys.PrivateKey(nodeKey.skkey),
|
||||
@ -75,8 +76,8 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
let wakuDiscv5 = WakuDiscoveryV5.new(
|
||||
node.rng,
|
||||
discv5Conf,
|
||||
some(node.enr),
|
||||
some(node.peerManager),
|
||||
Opt.some(node.enr),
|
||||
Opt.some(node.peerManager),
|
||||
node.topicSubscriptionQueue,
|
||||
)
|
||||
|
||||
@ -119,7 +120,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
|
||||
timestamp: now(),
|
||||
) # current timestamp
|
||||
|
||||
let res = await node.publish(some(pubSubTopic), message)
|
||||
let res = await node.publish(Opt.some(pubSubTopic), message)
|
||||
|
||||
if res.isOk:
|
||||
notice "published message",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import
|
||||
results,
|
||||
std/[tables, sequtils],
|
||||
stew/byteutils,
|
||||
chronicles,
|
||||
@ -35,13 +36,13 @@ const bootstrapNode =
|
||||
const wakuPort = 50000
|
||||
const discv5Port = 8000
|
||||
|
||||
proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
||||
proc setupAndSubscribe(rng: crypto.Rng) {.async.} =
|
||||
# use notice to filter all waku messaging
|
||||
setupLog(logging.LogLevel.NOTICE, logging.LogFormat.TEXT)
|
||||
|
||||
notice "starting subscriber", wakuPort = wakuPort, discv5Port = discv5Port
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[]
|
||||
ip = parseIpAddress("0.0.0.0")
|
||||
flags = CapabilitiesBitfield.init(relay = true)
|
||||
|
||||
@ -61,7 +62,7 @@ proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
||||
discard bootstrapNodeEnr.fromURI(bootstrapNode)
|
||||
|
||||
let discv5Conf = WakuDiscoveryV5Config(
|
||||
discv5Config: none(DiscoveryConfig),
|
||||
discv5Config: Opt.none(DiscoveryConfig),
|
||||
address: ip,
|
||||
port: Port(discv5Port),
|
||||
privateKey: keys.PrivateKey(nodeKey.skkey),
|
||||
@ -73,8 +74,8 @@ proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
|
||||
let wakuDiscv5 = WakuDiscoveryV5.new(
|
||||
node.rng,
|
||||
discv5Conf,
|
||||
some(node.enr),
|
||||
some(node.peerManager),
|
||||
Opt.some(node.enr),
|
||||
Opt.some(node.peerManager),
|
||||
node.topicSubscriptionQueue,
|
||||
)
|
||||
|
||||
|
||||
@ -3,15 +3,16 @@
|
||||
import tools/confutils/cli_args
|
||||
import logos_delivery/waku/[common/logging, waku, factory/networks_config]
|
||||
import
|
||||
std/[options, strutils, os, sequtils],
|
||||
results,
|
||||
std/[strutils, os, sequtils],
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
libp2p/crypto/crypto
|
||||
|
||||
export
|
||||
networks_config, waku, logging, options, strutils, os, sequtils, stewNet, chronicles,
|
||||
chronos, metrics, crypto
|
||||
networks_config, waku, logging, strutils, os, sequtils, stewNet, chronicles, chronos,
|
||||
metrics, crypto
|
||||
|
||||
proc setup*(): Waku =
|
||||
const versionString = "version / git commit hash: " & waku.git_version
|
||||
@ -29,18 +30,18 @@ proc setup*(): Waku =
|
||||
|
||||
# Override configuration
|
||||
conf.maxMessageSize = twnNetworkConf.maxMessageSize
|
||||
conf.clusterId = some(twnNetworkConf.clusterId)
|
||||
conf.clusterId = Opt.some(twnNetworkConf.clusterId)
|
||||
conf.rlnRelayEthContractAddress = twnNetworkConf.rlnRelayEthContractAddress
|
||||
conf.rlnRelayDynamic = some(twnNetworkConf.rlnRelayDynamic)
|
||||
conf.discv5Discovery = some(twnNetworkConf.discv5Discovery)
|
||||
conf.rlnRelayDynamic = Opt.some(twnNetworkConf.rlnRelayDynamic)
|
||||
conf.discv5Discovery = Opt.some(twnNetworkConf.discv5Discovery)
|
||||
conf.discv5BootstrapNodes =
|
||||
conf.discv5BootstrapNodes & twnNetworkConf.discv5BootstrapNodes
|
||||
conf.rlnEpochSizeSec = some(twnNetworkConf.rlnEpochSizeSec)
|
||||
conf.rlnRelayUserMessageLimit = some(twnNetworkConf.rlnRelayUserMessageLimit)
|
||||
conf.rlnEpochSizeSec = Opt.some(twnNetworkConf.rlnEpochSizeSec)
|
||||
conf.rlnRelayUserMessageLimit = Opt.some(twnNetworkConf.rlnRelayUserMessageLimit)
|
||||
|
||||
# Only set rlnRelay to true if relay is configured
|
||||
if conf.relay:
|
||||
conf.rlnRelay = some(twnNetworkConf.rlnRelay)
|
||||
conf.rlnRelay = Opt.some(twnNetworkConf.rlnRelay)
|
||||
|
||||
info "Starting node"
|
||||
var waku = (waitFor Waku.new(conf)).valueOr:
|
||||
|
||||
@ -51,7 +51,7 @@ proc sendThruWaku*(
|
||||
).valueOr:
|
||||
return err("could not append rate limit proof to the message: " & error)
|
||||
|
||||
(await self.waku.node.publish(some(DefaultPubsubTopic), message)).isOkOr:
|
||||
(await self.waku.node.publish(Opt.some(DefaultPubsubTopic), message)).isOkOr:
|
||||
return err("failed to publish message: " & $error)
|
||||
|
||||
info "rate limit proof is appended to the message"
|
||||
@ -182,7 +182,7 @@ proc new*(
|
||||
except CatchableError:
|
||||
error "could not handle SCP message: ", err = getCurrentExceptionMsg()
|
||||
|
||||
waku.node.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(handler)).isOkOr:
|
||||
waku.node.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), Opt.some(handler)).isOkOr:
|
||||
error "could not subscribe to pubsub topic: ", err = $error
|
||||
return err("could not subscribe to pubsub topic: " & $error)
|
||||
return ok(SCP)
|
||||
|
||||
@ -1,22 +1,20 @@
|
||||
import std/[times, options]
|
||||
import std/times
|
||||
import confutils, chronicles, chronos, results
|
||||
|
||||
import logos_delivery/waku/[waku_core, common/protobuf]
|
||||
import libp2p/protobuf/minprotobuf
|
||||
|
||||
export
|
||||
times, options, confutils, chronicles, chronos, results, waku_core, protobuf,
|
||||
minprotobuf
|
||||
export times, confutils, chronicles, chronos, results, waku_core, protobuf, minprotobuf
|
||||
|
||||
type SerializedKey* = seq[byte]
|
||||
|
||||
type WakuStealthCommitmentMsg* = object
|
||||
request*: bool
|
||||
spendingPubKey*: Option[SerializedKey]
|
||||
viewingPubKey*: Option[SerializedKey]
|
||||
ephemeralPubKey*: Option[SerializedKey]
|
||||
stealthCommitment*: Option[SerializedKey]
|
||||
viewTag*: Option[uint64]
|
||||
spendingPubKey*: Opt[SerializedKey]
|
||||
viewingPubKey*: Opt[SerializedKey]
|
||||
ephemeralPubKey*: Opt[SerializedKey]
|
||||
stealthCommitment*: Opt[SerializedKey]
|
||||
viewTag*: Opt[uint64]
|
||||
|
||||
proc decode*(T: type WakuStealthCommitmentMsg, buffer: seq[byte]): ProtoResult[T] =
|
||||
var msg = WakuStealthCommitmentMsg()
|
||||
@ -29,20 +27,20 @@ proc decode*(T: type WakuStealthCommitmentMsg, buffer: seq[byte]): ProtoResult[T
|
||||
discard ?pb.getField(2, spendingPubKey)
|
||||
msg.spendingPubKey =
|
||||
if spendingPubKey.len > 0:
|
||||
some(spendingPubKey)
|
||||
Opt.some(spendingPubKey)
|
||||
else:
|
||||
none(SerializedKey)
|
||||
Opt.none(SerializedKey)
|
||||
var viewingPubKey = newSeq[byte]()
|
||||
discard ?pb.getField(3, viewingPubKey)
|
||||
msg.viewingPubKey =
|
||||
if viewingPubKey.len > 0:
|
||||
some(viewingPubKey)
|
||||
Opt.some(viewingPubKey)
|
||||
else:
|
||||
none(SerializedKey)
|
||||
Opt.none(SerializedKey)
|
||||
|
||||
if msg.spendingPubKey.isSome() and msg.viewingPubKey.isSome():
|
||||
msg.stealthCommitment = none(SerializedKey)
|
||||
msg.viewTag = none(uint64)
|
||||
msg.stealthCommitment = Opt.none(SerializedKey)
|
||||
msg.viewTag = Opt.none(uint64)
|
||||
return ok(msg)
|
||||
if msg.spendingPubKey.isSome() and msg.viewingPubKey.isNone():
|
||||
return err(ProtoError.RequiredFieldMissing)
|
||||
@ -55,25 +53,25 @@ proc decode*(T: type WakuStealthCommitmentMsg, buffer: seq[byte]): ProtoResult[T
|
||||
discard ?pb.getField(4, stealthCommitment)
|
||||
msg.stealthCommitment =
|
||||
if stealthCommitment.len > 0:
|
||||
some(stealthCommitment)
|
||||
Opt.some(stealthCommitment)
|
||||
else:
|
||||
none(SerializedKey)
|
||||
Opt.none(SerializedKey)
|
||||
|
||||
var ephemeralPubKey = newSeq[byte]()
|
||||
discard ?pb.getField(5, ephemeralPubKey)
|
||||
msg.ephemeralPubKey =
|
||||
if ephemeralPubKey.len > 0:
|
||||
some(ephemeralPubKey)
|
||||
Opt.some(ephemeralPubKey)
|
||||
else:
|
||||
none(SerializedKey)
|
||||
Opt.none(SerializedKey)
|
||||
|
||||
var viewTag: uint64
|
||||
discard ?pb.getField(6, viewTag)
|
||||
msg.viewTag =
|
||||
if viewTag != 0:
|
||||
some(viewTag)
|
||||
Opt.some(viewTag)
|
||||
else:
|
||||
none(uint64)
|
||||
Opt.none(uint64)
|
||||
|
||||
if msg.stealthCommitment.isNone() and msg.viewTag.isNone() and
|
||||
msg.ephemeralPubKey.isNone():
|
||||
@ -86,8 +84,8 @@ proc decode*(T: type WakuStealthCommitmentMsg, buffer: seq[byte]): ProtoResult[T
|
||||
return err(ProtoError.RequiredFieldMissing)
|
||||
|
||||
if msg.stealthCommitment.isSome() and msg.viewTag.isSome():
|
||||
msg.spendingPubKey = none(SerializedKey)
|
||||
msg.viewingPubKey = none(SerializedKey)
|
||||
msg.spendingPubKey = Opt.none(SerializedKey)
|
||||
msg.viewingPubKey = Opt.none(SerializedKey)
|
||||
|
||||
ok(msg)
|
||||
|
||||
@ -118,8 +116,8 @@ proc constructRequest*(
|
||||
): WakuStealthCommitmentMsg =
|
||||
WakuStealthCommitmentMsg(
|
||||
request: true,
|
||||
spendingPubKey: some(spendingPubKey),
|
||||
viewingPubKey: some(viewingPubKey),
|
||||
spendingPubKey: Opt.some(spendingPubKey),
|
||||
viewingPubKey: Opt.some(viewingPubKey),
|
||||
)
|
||||
|
||||
proc constructResponse*(
|
||||
@ -127,7 +125,7 @@ proc constructResponse*(
|
||||
): WakuStealthCommitmentMsg =
|
||||
WakuStealthCommitmentMsg(
|
||||
request: false,
|
||||
stealthCommitment: some(stealthCommitment),
|
||||
ephemeralPubKey: some(ephemeralPubKey),
|
||||
viewTag: some(viewTag),
|
||||
stealthCommitment: Opt.some(stealthCommitment),
|
||||
ephemeralPubKey: Opt.some(ephemeralPubKey),
|
||||
viewTag: Opt.some(viewTag),
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import std/[json, sugar, options]
|
||||
import std/[json, sugar]
|
||||
import chronos, chronicles, results, ffi
|
||||
import
|
||||
logos_delivery,
|
||||
@ -24,17 +24,17 @@ func fromJsonNode(jsonContent: JsonNode): Result[StoreQueryRequest, string] =
|
||||
|
||||
let pubsubTopic =
|
||||
if jsonContent.contains("pubsubTopic"):
|
||||
some(jsonContent["pubsubTopic"].getStr())
|
||||
Opt.some(jsonContent["pubsubTopic"].getStr())
|
||||
else:
|
||||
none(string)
|
||||
Opt.none(string)
|
||||
|
||||
let paginationCursor =
|
||||
if jsonContent.contains("paginationCursor"):
|
||||
let hash = jsonContent["paginationCursor"].getStr().hexToHash().valueOr:
|
||||
return err("Failed converting paginationCursor hex string to bytes: " & error)
|
||||
some(hash)
|
||||
Opt.some(hash)
|
||||
else:
|
||||
none(WakuMessageHash)
|
||||
Opt.none(WakuMessageHash)
|
||||
|
||||
let paginationForwardBool = jsonContent["paginationForward"].getBool()
|
||||
let paginationForward =
|
||||
@ -42,9 +42,9 @@ func fromJsonNode(jsonContent: JsonNode): Result[StoreQueryRequest, string] =
|
||||
|
||||
let paginationLimit =
|
||||
if jsonContent.contains("paginationLimit"):
|
||||
some(uint64(jsonContent["paginationLimit"].getInt()))
|
||||
Opt.some(uint64(jsonContent["paginationLimit"].getInt()))
|
||||
else:
|
||||
none(uint64)
|
||||
Opt.none(uint64)
|
||||
|
||||
let startTime = ?jsonContent.getProtoInt64("timeStart")
|
||||
let endTime = ?jsonContent.getProtoInt64("timeEnd")
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import std/[atomics, options, macros]
|
||||
import std/[atomics, macros]
|
||||
import chronicles, chronos, chronos/threadsync, ffi
|
||||
import
|
||||
logos_delivery/waku/waku_core/message/message,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import std/[json, options, strutils]
|
||||
import std/[json, strutils]
|
||||
import results
|
||||
|
||||
proc getProtoInt64*(node: JsonNode, key: string): Result[Option[int64], string] =
|
||||
proc getProtoInt64*(node: JsonNode, key: string): Result[Opt[int64], string] =
|
||||
try:
|
||||
let (value, ok) =
|
||||
if node.hasKey(key):
|
||||
@ -13,8 +13,8 @@ proc getProtoInt64*(node: JsonNode, key: string): Result[Option[int64], string]
|
||||
(0, false)
|
||||
|
||||
if ok:
|
||||
return ok(some(value))
|
||||
return ok(Opt.some(value))
|
||||
|
||||
return ok(none(int64))
|
||||
return ok(Opt.none(int64))
|
||||
except CatchableError:
|
||||
return err("Invalid int64 value in `" & key & "`")
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import std/options
|
||||
import results
|
||||
|
||||
type ReliableChannelManagerConf* = object
|
||||
## All-`Option` partial; unset fields fall back to `createReliableChannel` defaults.
|
||||
segmentationEnableReedSolomon*: Option[bool]
|
||||
## All-`Opt` partial; unset fields fall back to `createReliableChannel` defaults.
|
||||
segmentationEnableReedSolomon*: Opt[bool]
|
||||
## Add Reed-Solomon parity segments for recovery of lost segments.
|
||||
segmentationSegmentSizeBytes*: Option[int] ## Maximum segment size in bytes.
|
||||
sdsAcknowledgementTimeoutMs*: Option[int]
|
||||
segmentationSegmentSizeBytes*: Opt[int] ## Maximum segment size in bytes.
|
||||
sdsAcknowledgementTimeoutMs*: Opt[int]
|
||||
## Time to wait before retransmitting an unacknowledged message.
|
||||
sdsMaxRetransmissions*: Option[int]
|
||||
sdsMaxRetransmissions*: Opt[int]
|
||||
## Maximum retransmission attempts before delivery fails.
|
||||
sdsCausalHistorySize*: Option[int] ## Number of message ids kept in causal history.
|
||||
rateLimitEnabled*: Option[bool] ## Enable rate limiting.
|
||||
rateLimitEpochPeriodSec*: Option[int] ## Rate-limit epoch length in seconds.
|
||||
rateLimitMessagesPerEpoch*: Option[int] ## Messages allowed per rate-limit epoch.
|
||||
sdsCausalHistorySize*: Opt[int] ## Number of message ids kept in causal history.
|
||||
rateLimitEnabled*: Opt[bool] ## Enable rate limiting.
|
||||
rateLimitEpochPeriodSec*: Opt[int] ## Rate-limit epoch length in seconds.
|
||||
rateLimitMessagesPerEpoch*: Opt[int] ## Messages allowed per rate-limit epoch.
|
||||
|
||||
@ -1,19 +1,18 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options
|
||||
import results
|
||||
|
||||
import logos_delivery/api/conf/messaging_conf
|
||||
import logos_delivery/api/conf/channels_conf
|
||||
|
||||
export options, messaging_conf, channels_conf
|
||||
export messaging_conf, channels_conf
|
||||
|
||||
type LogosDeliveryConf* = object
|
||||
## Aggregates the per-layer config objects. A layer is mounted iff its config
|
||||
## is present.
|
||||
kernelConf*: KernelConf
|
||||
messagingConf*: Option[MessagingClientConf]
|
||||
channelsConf*: Option[ReliableChannelManagerConf]
|
||||
messagingConf*: Opt[MessagingClientConf]
|
||||
channelsConf*: Opt[ReliableChannelManagerConf]
|
||||
|
||||
proc init*(T: type LogosDeliveryConf, kernelConf: KernelConf): LogosDeliveryConf =
|
||||
return LogosDeliveryConf(kernelConf: kernelConf)
|
||||
@ -31,8 +30,8 @@ proc init*(
|
||||
return ok(
|
||||
LogosDeliveryConf(
|
||||
kernelConf: KernelConf(kernelConf),
|
||||
messagingConf: some(merged),
|
||||
channelsConf: some(channelsOverrides),
|
||||
messagingConf: Opt.some(merged),
|
||||
channelsConf: Opt.some(channelsOverrides),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[json, options, strutils, tables]
|
||||
import std/[json, strutils, tables]
|
||||
import results
|
||||
|
||||
import tools/confutils/conf_from_json
|
||||
@ -82,8 +82,8 @@ proc parseFlatConf(
|
||||
return ok(
|
||||
LogosDeliveryConf(
|
||||
kernelConf: KernelConf(kernel),
|
||||
messagingConf: some(messaging),
|
||||
channelsConf: some(ReliableChannelManagerConf()),
|
||||
messagingConf: Opt.some(messaging),
|
||||
channelsConf: Opt.some(ReliableChannelManagerConf()),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import std/options
|
||||
import std/net
|
||||
import results
|
||||
import libp2p/crypto/crypto
|
||||
import results, libp2p/crypto/crypto
|
||||
|
||||
import logos_delivery/api/conf/kernel_conf
|
||||
import logos_delivery/waku/common/logging
|
||||
@ -15,44 +13,44 @@ type LogosDeliveryMode* {.pure.} = enum
|
||||
Fleet # kernel-only node from a raw kernel config
|
||||
|
||||
type MessagingClientConf* = object
|
||||
clusterId* {.name: "cluster-id".}: Option[uint16] ## Network cluster id.
|
||||
numShardsInCluster* {.name: "num-shards-in-network".}: Option[uint16]
|
||||
clusterId* {.name: "cluster-id".}: Opt[uint16] ## Network cluster id.
|
||||
numShardsInCluster* {.name: "num-shards-in-network".}: Opt[uint16]
|
||||
## Number of shards in the cluster.
|
||||
p2pTcpPort* {.name: "tcp-port".}: Option[Port] ## TCP listening port.
|
||||
discv5UdpPort* {.name: "discv5-udp-port".}: Option[Port] ## discv5 UDP port.
|
||||
websocketSupport* {.name: "websocket-support".}: Option[bool]
|
||||
p2pTcpPort* {.name: "tcp-port".}: Opt[Port] ## TCP listening port.
|
||||
discv5UdpPort* {.name: "discv5-udp-port".}: Opt[Port] ## discv5 UDP port.
|
||||
websocketSupport* {.name: "websocket-support".}: Opt[bool]
|
||||
## Enable the websocket transport.
|
||||
websocketPort* {.name: "websocket-port".}: Option[Port] ## Websocket listening port.
|
||||
quicSupport* {.name: "quic-support".}: Option[bool] ## Enable the QUIC transport.
|
||||
quicPort* {.name: "quic-port".}: Option[Port] ## QUIC (UDP) listening port.
|
||||
listenIpv4* {.name: "listen-address".}: Option[IpAddress] ## Inbound bind address.
|
||||
maxMessageSize* {.name: "max-msg-size".}: Option[string]
|
||||
websocketPort* {.name: "websocket-port".}: Opt[Port] ## Websocket listening port.
|
||||
quicSupport* {.name: "quic-support".}: Opt[bool] ## Enable the QUIC transport.
|
||||
quicPort* {.name: "quic-port".}: Opt[Port] ## QUIC (UDP) listening port.
|
||||
listenIpv4* {.name: "listen-address".}: Opt[IpAddress] ## Inbound bind address.
|
||||
maxMessageSize* {.name: "max-msg-size".}: Opt[string]
|
||||
## Maximum accepted message size (e.g. "150 KiB").
|
||||
entryNodes* {.name: "entry-node".}: Option[seq[string]]
|
||||
entryNodes* {.name: "entry-node".}: Opt[seq[string]]
|
||||
## Bootstrap / connectivity nodes (enrtree or multiaddr).
|
||||
ethRpcEndpoints* {.name: "rln-relay-eth-client-address".}: Option[seq[EthRpcUrl]]
|
||||
ethRpcEndpoints* {.name: "rln-relay-eth-client-address".}: Opt[seq[EthRpcUrl]]
|
||||
## Ethereum RPC endpoints (required for RLN validation); multiple for fail-over.
|
||||
rlnContractAddress* {.name: "rln-relay-eth-contract-address".}: Option[string]
|
||||
rlnContractAddress* {.name: "rln-relay-eth-contract-address".}: Opt[string]
|
||||
## RLN contract address; when set, RLN validation is enabled.
|
||||
rlnChainId* {.name: "rln-relay-chain-id".}: Option[uint]
|
||||
rlnChainId* {.name: "rln-relay-chain-id".}: Opt[uint]
|
||||
## Chain id the RLN contract is deployed on.
|
||||
rlnEpochSizeSec* {.name: "rln-relay-epoch-sec".}: Option[uint]
|
||||
rlnEpochSizeSec* {.name: "rln-relay-epoch-sec".}: Opt[uint]
|
||||
## RLN epoch size, in seconds.
|
||||
reliabilityEnabled* {.name: "reliability".}: Option[bool]
|
||||
reliabilityEnabled* {.name: "reliability".}: Opt[bool]
|
||||
## Enable store-based send reliability.
|
||||
store*: Option[bool] ## Enable the store protocol.
|
||||
storenode* {.name: "storenode".}: Option[string]
|
||||
storeMessageDbUrl* {.name: "store-message-db-url".}: Option[string]
|
||||
store*: Opt[bool] ## Enable the store protocol.
|
||||
storenode* {.name: "storenode".}: Opt[string]
|
||||
storeMessageDbUrl* {.name: "store-message-db-url".}: Opt[string]
|
||||
## Database connection URL for the store service's persistent storage.
|
||||
storeMessageRetentionPolicy* {.name: "store-message-retention-policy".}:
|
||||
Option[string] ## Store retention policy (e.g. "time:3600;size:1GB").
|
||||
storeMaxNumDbConnections* {.name: "store-max-num-db-connections".}: Option[int]
|
||||
storeMessageRetentionPolicy* {.name: "store-message-retention-policy".}: Opt[string]
|
||||
## Store retention policy (e.g. "time:3600;size:1GB").
|
||||
storeMaxNumDbConnections* {.name: "store-max-num-db-connections".}: Opt[int]
|
||||
## Maximum number of simultaneous store database connections.
|
||||
logLevel* {.name: "log-level".}: Option[logging.LogLevel]
|
||||
logLevel* {.name: "log-level".}: Opt[logging.LogLevel]
|
||||
## Process log level (TRACE..FATAL); applied by the kernel on node creation.
|
||||
logFormat* {.name: "log-format".}: Option[logging.LogFormat]
|
||||
logFormat* {.name: "log-format".}: Opt[logging.LogFormat]
|
||||
## Process log format (TEXT or JSON); applied by the kernel on node creation.
|
||||
nodeKey* {.name: "nodekey".}: Option[crypto.PrivateKey]
|
||||
nodeKey* {.name: "nodekey".}: Opt[crypto.PrivateKey]
|
||||
## P2P node private key (64-char hex): stable identity / peerId across restarts.
|
||||
|
||||
proc applyMode*(conf: var WakuNodeConf, mode: LogosDeliveryMode): ConfResult[void] =
|
||||
@ -62,7 +60,7 @@ proc applyMode*(conf: var WakuNodeConf, mode: LogosDeliveryMode): ConfResult[voi
|
||||
conf.relay = true
|
||||
conf.filter = true
|
||||
conf.lightpush = true
|
||||
conf.discv5Discovery = some(true)
|
||||
conf.discv5Discovery = Opt.some(true)
|
||||
conf.peerExchange = true
|
||||
conf.rendezvous = true
|
||||
of LogosDeliveryMode.Edge:
|
||||
@ -108,11 +106,11 @@ proc toWakuNodeConf*(
|
||||
conf.ethClientUrls = self.ethRpcEndpoints.get()
|
||||
if self.rlnContractAddress.isSome():
|
||||
conf.rlnRelayEthContractAddress = self.rlnContractAddress.get()
|
||||
conf.rlnRelay = some(true)
|
||||
conf.rlnRelay = Opt.some(true)
|
||||
if self.rlnChainId.isSome():
|
||||
conf.rlnRelayChainId = self.rlnChainId.get()
|
||||
if self.rlnEpochSizeSec.isSome():
|
||||
conf.rlnEpochSizeSec = some(self.rlnEpochSizeSec.get().uint64)
|
||||
conf.rlnEpochSizeSec = Opt.some(self.rlnEpochSizeSec.get().uint64)
|
||||
if self.logLevel.isSome():
|
||||
conf.logLevel = self.logLevel.get()
|
||||
if self.logFormat.isSome():
|
||||
@ -132,7 +130,7 @@ proc toWakuNodeConf*(
|
||||
proc merge*(base, overrides: MessagingClientConf): MessagingClientConf =
|
||||
var m = base
|
||||
for _, mField, oField in fieldPairs(m, overrides):
|
||||
when oField is Option:
|
||||
when oField is Opt:
|
||||
if oField.isSome():
|
||||
mField = oField
|
||||
return m
|
||||
@ -140,8 +138,8 @@ proc merge*(base, overrides: MessagingClientConf): MessagingClientConf =
|
||||
proc resolvePreset*(preset: string): ConfResult[MessagingClientConf] =
|
||||
## Preset to messaging-only fields. Kernel-mirrored fields stay unset; the
|
||||
## kernel resolves those from `conf.preset`.
|
||||
let npcOpt = ?toNetworkPresetConf(preset, none(uint16))
|
||||
let npcOpt = ?toNetworkPresetConf(preset, Opt.none(uint16))
|
||||
if npcOpt.isNone():
|
||||
return ok(MessagingClientConf())
|
||||
let npc = npcOpt.get()
|
||||
return ok(MessagingClientConf(reliabilityEnabled: some(npc.p2pReliability)))
|
||||
return ok(MessagingClientConf(reliabilityEnabled: Opt.some(npc.p2pReliability)))
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import libp2p/crypto/crypto
|
||||
{.push raises: [].}
|
||||
|
||||
import bearssl/rand, std/times, chronos
|
||||
import libp2p/crypto/crypto, bearssl/rand, std/times, chronos
|
||||
import stew/byteutils
|
||||
import logos_delivery/waku/utils/requests as request_utils
|
||||
import logos_delivery/waku/waku_core/[topics/content_topic, message/message, time]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
## Reliable Channel layer API — channel lifecycle
|
||||
## (createReliableChannel / closeChannel).
|
||||
import std/[options, tables]
|
||||
import std/tables
|
||||
import results, chronos, chronicles
|
||||
|
||||
import logos_delivery/api/types
|
||||
@ -15,17 +15,17 @@ const SdsJobId = "sds"
|
||||
## One persistency job shared by every channel's SDS state; rows are
|
||||
## keyed by channelId.
|
||||
|
||||
proc sdsPersistence(): Option[Persistence] =
|
||||
proc sdsPersistence(): Opt[Persistence] =
|
||||
## SDS backend from the Persistency singleton; memory-only fallback when
|
||||
## it is unavailable (e.g. unit tests).
|
||||
let p = Persistency.instance().valueOr:
|
||||
info "SDS persistence disabled, running memory-only", reason = $error
|
||||
return none(Persistence)
|
||||
return Opt.none(Persistence)
|
||||
let job = p.openJob(SdsJobId).valueOr:
|
||||
warn "SDS persistence disabled, could not open persistency job",
|
||||
jobId = SdsJobId, reason = $error
|
||||
return none(Persistence)
|
||||
return some(newSdsPersistence(job))
|
||||
return Opt.none(Persistence)
|
||||
return Opt.some(newSdsPersistence(job))
|
||||
|
||||
proc createReliableChannel*(
|
||||
self: ReliableChannelManager,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
## Reliable Channel type.
|
||||
##
|
||||
## A `ReliableChannel` orchestrates segmentation, SDS (end-to-end
|
||||
@ -14,9 +13,8 @@ import logos_delivery/waku/compat/option_valueor
|
||||
##
|
||||
## See: https://lip.logos.co/messaging/raw/reliable-channel-api.html
|
||||
|
||||
import std/[options, tables]
|
||||
import results
|
||||
import chronos
|
||||
import std/tables
|
||||
import results, chronos
|
||||
import bearssl/rand
|
||||
import stew/byteutils
|
||||
import libp2p/crypto/crypto as libp2p_crypto
|
||||
@ -160,17 +158,17 @@ type ClaimedSegment = object
|
||||
channelReqId: RequestId
|
||||
isEphemeral: bool
|
||||
|
||||
proc claimAwaitingChannelReq(self: ReliableChannel): Option[ClaimedSegment] =
|
||||
proc claimAwaitingChannelReq(self: ReliableChannel): Opt[ClaimedSegment] =
|
||||
for channelReqId, state in self.channelReqs.mpairs:
|
||||
if state.awaitingDispatch > 0:
|
||||
state.awaitingDispatch.dec()
|
||||
return some(
|
||||
return Opt.some(
|
||||
ClaimedSegment(
|
||||
channelReqId: channelReqId,
|
||||
isEphemeral: state.persistenceReqType == MessagePersistence.Ephemeral,
|
||||
)
|
||||
)
|
||||
return none(ClaimedSegment)
|
||||
return Opt.none(ClaimedSegment)
|
||||
|
||||
type MessagingOutcome {.pure.} = enum
|
||||
Sent
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[options, tables]
|
||||
import std/tables
|
||||
from std/times import initDuration, getTime, toUnix, nanosecond
|
||||
import results, chronos, chronicles
|
||||
import nimcrypto/keccak
|
||||
@ -37,7 +37,7 @@ type
|
||||
acknowledgementTimeoutMs*: int
|
||||
maxRetransmissions*: int
|
||||
causalHistorySize*: int
|
||||
persistence*: Option[Persistence]
|
||||
persistence*: Opt[Persistence]
|
||||
## Durability backend. `none` runs memory-only: reliability still
|
||||
## works, state does not survive a restart.
|
||||
|
||||
|
||||
@ -9,8 +9,7 @@
|
||||
##
|
||||
## See: https://lip.logos.co/messaging/raw/reliable-channel-api.html
|
||||
|
||||
import std/options
|
||||
import ./segment_message_proto
|
||||
import results, ./segment_message_proto
|
||||
import ./segmentation_persistence
|
||||
|
||||
export segment_message_proto, segmentation_persistence
|
||||
@ -54,12 +53,12 @@ proc performSegmentation*(
|
||||
|
||||
proc handleIncomingSegment*(
|
||||
self: SegmentationHandler, segmentBytes: seq[byte]
|
||||
): Option[ReassemblyResult] =
|
||||
): Opt[ReassemblyResult] =
|
||||
## Skeleton behaviour: every segment is already a complete message
|
||||
## (since `performSegmentation` always emits one), so just hand the
|
||||
## payload straight back.
|
||||
let segment = SegmentMessageProto.decode(segmentBytes)
|
||||
return some(
|
||||
return Opt.some(
|
||||
ReassemblyResult(
|
||||
payload: segment.payload, entireMessageHash: segment.entireMessageHash
|
||||
)
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options
|
||||
import results, chronos, chronicles
|
||||
|
||||
# Each layer has a core module (type + new/start/stop) and an api/ folder whose
|
||||
@ -111,8 +110,8 @@ proc new*(
|
||||
return await LogosDelivery.new(
|
||||
LogosDeliveryConf(
|
||||
kernelConf: KernelConf(conf),
|
||||
messagingConf: some(MessagingClientConf()),
|
||||
channelsConf: some(ReliableChannelManagerConf()),
|
||||
messagingConf: Opt.some(MessagingClientConf()),
|
||||
channelsConf: Opt.some(ReliableChannelManagerConf()),
|
||||
),
|
||||
appCallbacks,
|
||||
)
|
||||
@ -136,8 +135,8 @@ proc new*(
|
||||
return await LogosDelivery.new(
|
||||
LogosDeliveryConf(
|
||||
kernelConf: kernelConf,
|
||||
messagingConf: some(messagingOverrides),
|
||||
channelsConf: some(channelsOverrides),
|
||||
messagingConf: Opt.some(messagingOverrides),
|
||||
channelsConf: Opt.some(channelsOverrides),
|
||||
),
|
||||
appCallbacks,
|
||||
)
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
## This module is in charge of taking care of the messages that this node is expecting to
|
||||
## receive and is backed by store-v3 requests to get an additional degree of certainty
|
||||
##
|
||||
|
||||
import std/[tables, sequtils, options, sets]
|
||||
import results, std/[tables, sequtils, sets]
|
||||
import chronos, chronicles, libp2p/utility
|
||||
import brokers/broker_context
|
||||
import
|
||||
@ -112,10 +111,10 @@ proc checkStore*(self: RecvService) {.async.} =
|
||||
await self.waku.storeQueryToAny(
|
||||
StoreQueryRequest(
|
||||
includeData: false,
|
||||
pubsubTopic: some(pubsubTopic),
|
||||
pubsubTopic: Opt.some(pubsubTopic),
|
||||
contentTopics: toSeq(contentTopics),
|
||||
startTime: some(self.startTimeToCheck - DelayExtra.nanos),
|
||||
endTime: some(self.endTimeToCheck + DelayExtra.nanos),
|
||||
startTime: Opt.some(self.startTimeToCheck - DelayExtra.nanos),
|
||||
endTime: Opt.some(self.endTimeToCheck + DelayExtra.nanos),
|
||||
)
|
||||
)
|
||||
).valueOr:
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import std/[options, times], chronos
|
||||
import results, std/times, chronos
|
||||
import brokers/broker_context
|
||||
import
|
||||
logos_delivery/waku/waku_core,
|
||||
@ -24,7 +23,7 @@ type DeliveryTask* = ref object
|
||||
tryCount*: int
|
||||
state*: DeliveryState
|
||||
deliveryTime*: Moment
|
||||
firstPropagatedTime*: Option[Moment]
|
||||
firstPropagatedTime*: Opt[Moment]
|
||||
## Set once on the first successful propagation; never reset on re-publish.
|
||||
## Anchors the store-validation time cap (see propagationAge).
|
||||
propagateEventEmitted*: bool
|
||||
@ -39,7 +38,7 @@ proc new*(
|
||||
let msg = envelop.toWakuMessage()
|
||||
# TODO: use sync request for such as soon as available
|
||||
let relayShardRes = (
|
||||
RequestRelayShard.request(brokerCtx, none[PubsubTopic](), envelop.contentTopic)
|
||||
RequestRelayShard.request(brokerCtx, Opt.none(PubsubTopic), envelop.contentTopic)
|
||||
).valueOr:
|
||||
error "RequestRelayShard.request failed", error = error
|
||||
return err("Failed create DeliveryTask: " & $error)
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import chronicles, chronos, results
|
||||
import std/options
|
||||
import brokers/broker_context
|
||||
import chronicles, chronos, results, brokers/broker_context
|
||||
import logos_delivery/waku/waku_core, logos_delivery/waku/waku
|
||||
import logos_delivery/waku/api/publish
|
||||
|
||||
@ -54,7 +51,7 @@ method sendImpl*(
|
||||
task.state = DeliveryState.SuccessfullyPropagated
|
||||
task.deliveryTime = Moment.now()
|
||||
if task.firstPropagatedTime.isNone():
|
||||
task.firstPropagatedTime = some(Moment.now())
|
||||
task.firstPropagatedTime = Opt.some(Moment.now())
|
||||
# TODO: with a simple retry processor it might be more accurate to say `Sent`
|
||||
else:
|
||||
# Controversial state, publish says ok but no peer. It should not happen.
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import std/options
|
||||
import chronos, chronicles
|
||||
import results, chronos, chronicles
|
||||
import brokers/broker_context
|
||||
import logos_delivery/waku/[waku_core], logos_delivery/waku/waku_lightpush/[common, rpc]
|
||||
import logos_delivery/waku/requests/health_requests
|
||||
@ -77,7 +75,7 @@ method sendImpl*(self: RelaySendProcessor, task: DeliveryTask) {.async.} =
|
||||
task.state = DeliveryState.SuccessfullyPropagated
|
||||
task.deliveryTime = Moment.now()
|
||||
if task.firstPropagatedTime.isNone():
|
||||
task.firstPropagatedTime = some(Moment.now())
|
||||
task.firstPropagatedTime = Opt.some(Moment.now())
|
||||
else:
|
||||
# It shall not happen, but still covering it
|
||||
task.state = self.fallbackStateToSet
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
## This module reinforces the publish operation with regular store-v3 requests.
|
||||
##
|
||||
|
||||
import std/[sequtils, tables, options, typetraits]
|
||||
import std/[sequtils, tables, typetraits]
|
||||
import chronos, chronicles, libp2p/utility
|
||||
import brokers/broker_context
|
||||
import
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
## Messaging layer core: the `MessagingClient` type plus its construction and
|
||||
## lifecycle. The public operations (subscribe / unsubscribe / send) live in
|
||||
## `messaging/api.nim`.
|
||||
import std/options
|
||||
import results, chronos, chronicles
|
||||
import
|
||||
logos_delivery/api/conf/messaging_conf,
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
## Waku layer API — filter (light client) operations.
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options
|
||||
import results, chronos, chronicles
|
||||
|
||||
import logos_delivery/waku/waku
|
||||
@ -36,7 +34,7 @@ proc filterSubscribe*(
|
||||
let peer = self.node.peerManager.selectPeer(WakuFilterSubscribeCodec).valueOr:
|
||||
return err("could not find peer with WakuFilterSubscribeCodec when subscribing")
|
||||
|
||||
let subFut = self.node.filterSubscribe(some(pubsubTopic), contentTopics, peer)
|
||||
let subFut = self.node.filterSubscribe(Opt.some(pubsubTopic), contentTopics, peer)
|
||||
if not await subFut.withTimeout(FilterOpTimeout):
|
||||
return err("filter subscription timed out")
|
||||
subFut.read().isOkOr:
|
||||
@ -57,7 +55,8 @@ proc filterUnsubscribe*(
|
||||
let peer = self.node.peerManager.selectPeer(WakuFilterSubscribeCodec).valueOr:
|
||||
return err("could not find peer with WakuFilterSubscribeCodec when unsubscribing")
|
||||
|
||||
let unsubFut = self.node.filterUnsubscribe(some(pubsubTopic), contentTopics, peer)
|
||||
let unsubFut =
|
||||
self.node.filterUnsubscribe(Opt.some(pubsubTopic), contentTopics, peer)
|
||||
if not await unsubFut.withTimeout(FilterOpTimeout):
|
||||
return err("filter un-subscription timed out")
|
||||
unsubFut.read().isOkOr:
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
## Waku layer API — lightpush (light client publish) operations.
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import results, chronos, chronicles
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
## Waku layer API — peer management operations.
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[options, sequtils, strutils]
|
||||
import std/[sequtils, strutils]
|
||||
import results, chronos, chronicles
|
||||
import libp2p/[peerid, peerstore]
|
||||
|
||||
|
||||
@ -5,10 +5,8 @@
|
||||
## `WakuLightPushResult` (status code + description) that the send processors
|
||||
## branch on for their retry decisions, and expose relay/lightpush availability
|
||||
## so the messaging layer never inspects `waku.node` directly.
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options
|
||||
import results, chronos
|
||||
|
||||
import logos_delivery/waku/waku
|
||||
@ -46,7 +44,7 @@ proc relayPushHandler*(self: Waku): PushMessageHandler =
|
||||
|
||||
proc lightpushPeerAvailable*(self: Waku, shard: PubsubTopic): bool =
|
||||
## True if a lightpush service peer is available for `shard`.
|
||||
return self.node.peerManager.selectPeer(WakuLightPushCodec, some(shard)).isSome()
|
||||
return self.node.peerManager.selectPeer(WakuLightPushCodec, Opt.some(shard)).isSome()
|
||||
|
||||
proc lightpushPublishToAny*(
|
||||
self: Waku, shard: PubsubTopic, message: WakuMessage
|
||||
@ -55,9 +53,9 @@ proc lightpushPublishToAny*(
|
||||
## through the node's lightpush flow, which attaches an RLN proof per
|
||||
## attempt when RLN is mounted. Returns SERVICE_NOT_AVAILABLE when no peer
|
||||
## is available.
|
||||
let peer = self.node.peerManager.selectPeer(WakuLightPushCodec, some(shard)).valueOr:
|
||||
let peer = self.node.peerManager.selectPeer(WakuLightPushCodec, Opt.some(shard)).valueOr:
|
||||
return lightpushResultServiceUnavailable("no lightpush peer available for shard")
|
||||
try:
|
||||
return await self.node.lightpushPublish(some(shard), message, some(peer))
|
||||
return await self.node.lightpushPublish(Opt.some(shard), message, Opt.some(peer))
|
||||
except CatchableError as e:
|
||||
return lightpushResultInternalError(e.msg)
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
## Waku layer API — store (historical query) operations.
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options
|
||||
import results, chronos, chronicles
|
||||
|
||||
import logos_delivery/waku/waku
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import
|
||||
std/[times, strutils, os, sets, strformat, tables],
|
||||
results,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
# Simple async pool driver for postgress.
|
||||
# Inspired by: https://github.com/treeform/pg/
|
||||
{.push raises: [].}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
# The code in this file is an adaptation of the Sqlite KV Store found in nim-eth.
|
||||
# https://github.com/status-im/nim-eth/blob/master/eth/db/kvstore_sqlite3.nim
|
||||
@ -172,11 +171,11 @@ proc exec*[P](s: SqliteStmt[P, void], params: P): DatabaseResult[void] =
|
||||
res
|
||||
|
||||
template readResult(s: RawStmtPtr, column: cint, T: type): auto =
|
||||
when T is Option:
|
||||
when T is Opt:
|
||||
if sqlite3_column_type(s, column) == SQLITE_NULL:
|
||||
none(typeof(default(T).get()))
|
||||
Opt.none(typeof(default(T).get()))
|
||||
else:
|
||||
some(readSimpleResult(s, column, typeof(default(T).get())))
|
||||
Opt.some(readSimpleResult(s, column, typeof(default(T).get())))
|
||||
else:
|
||||
readSimpleResult(s, column, T)
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, net],
|
||||
std/net,
|
||||
results,
|
||||
eth/keys as eth_keys,
|
||||
eth/p2p/discoveryv5/enr,
|
||||
@ -62,22 +62,22 @@ proc build*(builder: EnrBuilder): EnrResult[enr.Record] =
|
||||
## Builder extension: IP address and TCP/UDP ports
|
||||
|
||||
proc addAddressAndPorts(
|
||||
builder: var EnrBuilder, ip: IpAddress, tcpPort, udpPort: Option[Port]
|
||||
builder: var EnrBuilder, ip: IpAddress, tcpPort, udpPort: Opt[Port]
|
||||
) =
|
||||
builder.ipAddress = Opt.some(ip)
|
||||
builder.tcpPort = tcpPort.toOpt()
|
||||
builder.udpPort = udpPort.toOpt()
|
||||
builder.tcpPort = tcpPort
|
||||
builder.udpPort = udpPort
|
||||
|
||||
proc addPorts(builder: var EnrBuilder, tcp, udp: Option[Port]) =
|
||||
proc addPorts(builder: var EnrBuilder, tcp, udp: Opt[Port]) =
|
||||
# Based on: https://github.com/status-im/nim-eth/blob/4b22fcd/eth/p2p/discoveryv5/enr.nim#L166
|
||||
builder.tcpPort = tcp.toOpt()
|
||||
builder.udpPort = udp.toOpt()
|
||||
builder.tcpPort = tcp
|
||||
builder.udpPort = udp
|
||||
|
||||
proc withIpAddressAndPorts*(
|
||||
builder: var EnrBuilder,
|
||||
ipAddr = none(IpAddress),
|
||||
tcpPort = none(Port),
|
||||
udpPort = none(Port),
|
||||
ipAddr = Opt.none(IpAddress),
|
||||
tcpPort = Opt.none(Port),
|
||||
udpPort = Opt.none(Port),
|
||||
) =
|
||||
if ipAddr.isSome():
|
||||
addAddressAndPorts(builder, ipAddr.get(), tcpPort, udpPort)
|
||||
|
||||
@ -1,23 +1,9 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options, results, eth/keys as eth_keys, libp2p/crypto/crypto as libp2p_crypto
|
||||
import results, eth/keys as eth_keys, libp2p/crypto/crypto as libp2p_crypto
|
||||
|
||||
import eth/p2p/discoveryv5/enr except TypedRecord, toTypedRecord
|
||||
|
||||
## Since enr changed to result.Opt[T] from Option[T] for intercompatibility introduce a conversion between
|
||||
func toOpt*[T](o: Option[T]): Opt[T] =
|
||||
if o.isSome():
|
||||
return Opt.some(o.get())
|
||||
else:
|
||||
return Opt.none(T)
|
||||
|
||||
func toOption*[T](o: Opt[T]): Option[T] =
|
||||
if o.isSome():
|
||||
return some(o.get())
|
||||
else:
|
||||
return none(T)
|
||||
|
||||
## ENR typed record
|
||||
|
||||
# Record identity scheme
|
||||
@ -44,8 +30,8 @@ type TypedRecord* = object
|
||||
proc init(T: type TypedRecord, record: Record): T =
|
||||
TypedRecord(raw: record)
|
||||
|
||||
proc tryGet*(record: TypedRecord, field: string, T: type): Option[T] =
|
||||
return record.raw.tryGet(field, T).toOption()
|
||||
proc tryGet*(record: TypedRecord, field: string, T: type): Opt[T] =
|
||||
return record.raw.tryGet(field, T)
|
||||
|
||||
func toTyped*(record: Record): EnrResult[TypedRecord] =
|
||||
let tr = TypedRecord.init(record)
|
||||
@ -61,38 +47,38 @@ func toTyped*(record: Record): EnrResult[TypedRecord] =
|
||||
|
||||
# Typed record field accessors
|
||||
|
||||
func id*(record: TypedRecord): Option[RecordId] =
|
||||
func id*(record: TypedRecord): Opt[RecordId] =
|
||||
let fieldOpt = record.tryGet("id", string)
|
||||
if fieldOpt.isNone():
|
||||
return none(RecordId)
|
||||
return Opt.none(RecordId)
|
||||
|
||||
let field = toRecordId(fieldOpt.get()).valueOr:
|
||||
return none(RecordId)
|
||||
return Opt.none(RecordId)
|
||||
|
||||
return some(field)
|
||||
return Opt.some(field)
|
||||
|
||||
func secp256k1*(record: TypedRecord): Option[array[33, byte]] =
|
||||
func secp256k1*(record: TypedRecord): Opt[array[33, byte]] =
|
||||
record.tryGet("secp256k1", array[33, byte])
|
||||
|
||||
func ip*(record: TypedRecord): Option[array[4, byte]] =
|
||||
func ip*(record: TypedRecord): Opt[array[4, byte]] =
|
||||
record.tryGet("ip", array[4, byte])
|
||||
|
||||
func ip6*(record: TypedRecord): Option[array[16, byte]] =
|
||||
func ip6*(record: TypedRecord): Opt[array[16, byte]] =
|
||||
record.tryGet("ip6", array[16, byte])
|
||||
|
||||
func tcp*(record: TypedRecord): Option[uint16] =
|
||||
func tcp*(record: TypedRecord): Opt[uint16] =
|
||||
record.tryGet("tcp", uint16)
|
||||
|
||||
func tcp6*(record: TypedRecord): Option[uint16] =
|
||||
func tcp6*(record: TypedRecord): Opt[uint16] =
|
||||
let port = record.tryGet("tcp6", uint16)
|
||||
if port.isNone():
|
||||
return record.tcp()
|
||||
return port
|
||||
|
||||
func udp*(record: TypedRecord): Option[uint16] =
|
||||
func udp*(record: TypedRecord): Opt[uint16] =
|
||||
record.tryGet("udp", uint16)
|
||||
|
||||
func udp6*(record: TypedRecord): Option[uint16] =
|
||||
func udp6*(record: TypedRecord): Opt[uint16] =
|
||||
let port = record.tryGet("udp6", uint16)
|
||||
if port.isNone():
|
||||
return record.udp()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import std/options
|
||||
import results
|
||||
|
||||
type PagingDirection* {.pure.} = enum
|
||||
## PagingDirection determines the direction of pagination
|
||||
@ -11,7 +11,7 @@ proc default*(): PagingDirection {.inline.} =
|
||||
proc into*(b: bool): PagingDirection =
|
||||
PagingDirection(b)
|
||||
|
||||
proc into*(b: Option[bool]): PagingDirection =
|
||||
proc into*(b: Opt[bool]): PagingDirection =
|
||||
if b.isNone():
|
||||
return default()
|
||||
b.get().into()
|
||||
@ -19,7 +19,7 @@ proc into*(b: Option[bool]): PagingDirection =
|
||||
proc into*(d: PagingDirection): bool =
|
||||
d == PagingDirection.FORWARD
|
||||
|
||||
proc into*(d: Option[PagingDirection]): bool =
|
||||
proc into*(d: Opt[PagingDirection]): bool =
|
||||
if d.isNone():
|
||||
return false
|
||||
d.get().into()
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options, libp2p/protobuf/minprotobuf, libp2p/varint
|
||||
import results, libp2p/protobuf/minprotobuf, libp2p/varint
|
||||
|
||||
export minprotobuf, varint
|
||||
|
||||
@ -39,7 +39,7 @@ proc invalidLengthField*(T: type ProtobufError, field: string): T =
|
||||
## Extension methods
|
||||
|
||||
proc write3*(proto: var ProtoBuffer, field: int, value: auto) =
|
||||
when value is Option:
|
||||
when value is Opt:
|
||||
if value.isSome():
|
||||
proto.write(field, value.get())
|
||||
else:
|
||||
|
||||
@ -6,19 +6,19 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[options, tables], libp2p/stream/connection
|
||||
import results, std/tables, libp2p/stream/connection
|
||||
|
||||
import ./[single_token_limiter, service_metrics], ../../utils/tableutils
|
||||
|
||||
export token_bucket, setting, service_metrics
|
||||
|
||||
type PerPeerRateLimiter* = ref object of RootObj
|
||||
setting*: Option[RateLimitSetting]
|
||||
peerBucket: Table[PeerId, Option[TokenBucket]]
|
||||
setting*: Opt[RateLimitSetting]
|
||||
peerBucket: Table[PeerId, Opt[TokenBucket]]
|
||||
|
||||
proc mgetOrPut(
|
||||
perPeerRateLimiter: var PerPeerRateLimiter, peerId: PeerId
|
||||
): var Option[TokenBucket] =
|
||||
): var Opt[TokenBucket] =
|
||||
return perPeerRateLimiter.peerBucket.mgetOrPut(
|
||||
peerId, newTokenBucket(perPeerRateLimiter.setting, ReplenishMode.Continuous)
|
||||
)
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
## RequestRateLimiter
|
||||
##
|
||||
## RequestRateLimiter is a general service protection mechanism.
|
||||
@ -17,11 +16,7 @@ import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, math],
|
||||
chronicles,
|
||||
chronos/timer,
|
||||
libp2p/stream/connection,
|
||||
libp2p/utility
|
||||
results, std/math, chronicles, chronos/timer, libp2p/stream/connection, libp2p/utility
|
||||
|
||||
import std/times except TimeInterval, Duration, seconds, minutes
|
||||
|
||||
@ -41,7 +36,7 @@ const MINUTES_RATIO = 2
|
||||
|
||||
type RequestRateLimiter* = ref object of RootObj
|
||||
tokenBucket: TokenBucket
|
||||
setting*: Option[RateLimitSetting]
|
||||
setting*: Opt[RateLimitSetting]
|
||||
mainBucketSetting: RateLimitSetting
|
||||
ratio: int
|
||||
peerBucketSetting*: RateLimitSetting
|
||||
@ -80,7 +75,7 @@ proc mgetOrPut(
|
||||
requestRateLimiter: var RequestRateLimiter, peerId: PeerId, now: Moment
|
||||
): var TokenBucket =
|
||||
let bucketForNew = newTokenBucket(
|
||||
some(requestRateLimiter.peerBucketSetting), Discrete, now
|
||||
Opt.some(requestRateLimiter.peerBucketSetting), Discrete, now
|
||||
).valueOr:
|
||||
raiseAssert "This branch is not allowed to be reached as it will not be called if the setting is None."
|
||||
|
||||
@ -137,7 +132,7 @@ template checkUsageLimit*(
|
||||
bodyRejected
|
||||
|
||||
# TODO: review these ratio assumptions! Debatable!
|
||||
func calcPeriodRatio(settingOpt: Option[RateLimitSetting]): int =
|
||||
func calcPeriodRatio(settingOpt: Opt[RateLimitSetting]): int =
|
||||
settingOpt.withValue(setting):
|
||||
if setting.isUnlimited():
|
||||
return UNLIMITED_RATIO
|
||||
@ -155,7 +150,7 @@ func calcPeriodRatio(settingOpt: Option[RateLimitSetting]): int =
|
||||
|
||||
# calculates peer cache items timeout
|
||||
# effectively if a peer does not issue any requests for this amount of time will be forgotten.
|
||||
func calcCacheTimeout(settingOpt: Option[RateLimitSetting], ratio: int): Duration =
|
||||
func calcCacheTimeout(settingOpt: Opt[RateLimitSetting], ratio: int): Duration =
|
||||
settingOpt.withValue(setting):
|
||||
if setting.isUnlimited():
|
||||
return UNLIMITED_TIMEOUT
|
||||
@ -167,7 +162,7 @@ func calcCacheTimeout(settingOpt: Option[RateLimitSetting], ratio: int): Duratio
|
||||
return UNLIMITED_TIMEOUT
|
||||
|
||||
func calcPeerTokenSetting(
|
||||
setting: Option[RateLimitSetting], ratio: int
|
||||
setting: Opt[RateLimitSetting], ratio: int
|
||||
): RateLimitSetting =
|
||||
let s = setting.valueOr:
|
||||
return (0, 0.minutes)
|
||||
@ -178,7 +173,7 @@ func calcPeerTokenSetting(
|
||||
|
||||
return (peerVolume, peerPeriod)
|
||||
|
||||
proc newRequestRateLimiter*(setting: Option[RateLimitSetting]): RequestRateLimiter =
|
||||
proc newRequestRateLimiter*(setting: Opt[RateLimitSetting]): RequestRateLimiter =
|
||||
let ratio = calcPeriodRatio(setting)
|
||||
let isLimited = setting.isSome() and not setting.get().isUnlimited()
|
||||
let mainBucketSetting =
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import std/options
|
||||
import metrics, setting
|
||||
import results, metrics, setting
|
||||
|
||||
export metrics
|
||||
|
||||
@ -14,7 +13,7 @@ declarePublicCounter waku_service_requests,
|
||||
declarePublicCounter waku_service_network_bytes,
|
||||
"total incoming traffic of specific waku services", labels = ["service", "direction"]
|
||||
|
||||
proc setServiceLimitMetric*(service: string, limit: Option[RateLimitSetting]) =
|
||||
proc setServiceLimitMetric*(service: string, limit: Opt[RateLimitSetting]) =
|
||||
if limit.isSome() and not limit.get().isUnlimited():
|
||||
waku_service_requests_limit.set(
|
||||
limit.get().calculateLimitPerSecond(), labelValues = [service]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import chronos/timer, std/[tables, strutils, options], regex, results
|
||||
import chronos/timer, std/[tables, strutils], regex, results
|
||||
|
||||
# Setting for TokenBucket defined as volume over period of time
|
||||
type RateLimitSetting* = tuple[volume: int, period: Duration]
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[options], chronos/timer, libp2p/stream/connection, libp2p/utility
|
||||
import results, chronos/timer, libp2p/stream/connection, libp2p/utility
|
||||
|
||||
import std/times except TimeInterval, Duration
|
||||
|
||||
@ -12,17 +12,17 @@ import ./[setting, service_metrics]
|
||||
export token_bucket, setting, service_metrics
|
||||
|
||||
proc newTokenBucket*(
|
||||
setting: Option[RateLimitSetting],
|
||||
setting: Opt[RateLimitSetting],
|
||||
replenishMode: static[ReplenishMode] = ReplenishMode.Continuous,
|
||||
startTime: Moment = Moment.now(),
|
||||
): Option[TokenBucket] =
|
||||
): Opt[TokenBucket] =
|
||||
if setting.isNone():
|
||||
return none[TokenBucket]()
|
||||
return Opt.none(TokenBucket)
|
||||
|
||||
if setting.get().isUnlimited():
|
||||
return none[TokenBucket]()
|
||||
return Opt.none(TokenBucket)
|
||||
|
||||
return some(
|
||||
return Opt.some(
|
||||
TokenBucket.new(
|
||||
capacity = setting.get().volume,
|
||||
fillDuration = setting.get().period,
|
||||
@ -40,7 +40,7 @@ proc checkUsage(
|
||||
return true
|
||||
|
||||
proc checkUsage(
|
||||
t: var Option[TokenBucket], proto: string, now = Moment.now()
|
||||
t: var Opt[TokenBucket], proto: string, now = Moment.now()
|
||||
): bool {.raises: [].} =
|
||||
if t.isNone():
|
||||
return true
|
||||
@ -49,7 +49,7 @@ proc checkUsage(
|
||||
return checkUsage(tokenBucket, proto, now)
|
||||
|
||||
template checkUsageLimit*(
|
||||
t: var Option[TokenBucket] | var TokenBucket,
|
||||
t: var Opt[TokenBucket] | var TokenBucket,
|
||||
proto: string,
|
||||
conn: Connection,
|
||||
bodyWithinLimit, bodyRejected: untyped,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[httpclient, json, uri, options], results
|
||||
import std/[httpclient, json, uri], results
|
||||
|
||||
const
|
||||
# Resource locators
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[options, strutils, net]
|
||||
import std/[strutils, net]
|
||||
import chronicles, eth/net/nat, results, nativesockets
|
||||
|
||||
logScope:
|
||||
@ -18,9 +18,9 @@ var singletonNat: bool = false
|
||||
# TODO: pass `NatStrategy`, not a string
|
||||
proc setupNat*(
|
||||
natConf, clientId: string, tcpPort, udpPort: Port
|
||||
): Result[
|
||||
tuple[ip: Option[IpAddress], tcpPort: Option[Port], udpPort: Option[Port]], string
|
||||
] {.gcsafe.} =
|
||||
): Result[tuple[ip: Opt[IpAddress], tcpPort: Opt[Port], udpPort: Opt[Port]], string] {.
|
||||
gcsafe
|
||||
.} =
|
||||
let strategy =
|
||||
case natConf.toLowerAscii()
|
||||
of "any": NatAny
|
||||
@ -29,8 +29,7 @@ proc setupNat*(
|
||||
of "pmp": NatPmp
|
||||
else: NatNone
|
||||
|
||||
var endpoint:
|
||||
tuple[ip: Option[IpAddress], tcpPort: Option[Port], udpPort: Option[Port]]
|
||||
var endpoint: tuple[ip: Opt[IpAddress], tcpPort: Opt[Port], udpPort: Opt[Port]]
|
||||
|
||||
if strategy != NatNone:
|
||||
## Only initialize the NAT module once
|
||||
@ -47,7 +46,7 @@ proc setupNat*(
|
||||
warn "exception in setupNat", error = getCurrentExceptionMsg()
|
||||
|
||||
if extIP.isSome():
|
||||
endpoint.ip = some(extIp.get())
|
||||
endpoint.ip = Opt.some(extIp.get())
|
||||
# RedirectPorts in considered a gcsafety violation
|
||||
# because it obtains the address of a non-gcsafe proc?
|
||||
var extPorts: Opt[(Port, Port)]
|
||||
@ -65,15 +64,15 @@ proc setupNat*(
|
||||
|
||||
if extPorts.isSome():
|
||||
let (extTcpPort, extUdpPort) = extPorts.get()
|
||||
endpoint.tcpPort = some(extTcpPort)
|
||||
endpoint.udpPort = some(extUdpPort)
|
||||
endpoint.tcpPort = Opt.some(extTcpPort)
|
||||
endpoint.udpPort = Opt.some(extUdpPort)
|
||||
else: # NatNone
|
||||
if not natConf.startsWith("extip:"):
|
||||
return err("not a valid NAT mechanism: " & $natConf)
|
||||
|
||||
try:
|
||||
# any required port redirection is assumed to be done by hand
|
||||
endpoint.ip = some(parseIpAddress(natConf[6 ..^ 1]))
|
||||
endpoint.ip = Opt.some(parseIpAddress(natConf[6 ..^ 1]))
|
||||
except ValueError:
|
||||
return err("not a valid IP address: " & $natConf[6 ..^ 1])
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import std/[strutils, math], results, regex
|
||||
|
||||
proc parseMsgSize*(input: string): Result[uint64, string] =
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
## Polyfill: `valueOr` / `withValue` templates for `std/options.Option[T]`.
|
||||
##
|
||||
## Previously provided transitively by `libp2p/utility`, removed in
|
||||
## nim-libp2p PR #2162 (commit 8a9943145). logos-delivery uses these
|
||||
## templates pervasively on `Option[T]`.
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[macros, options]
|
||||
|
||||
template valueOr*[T](self: Option[T], body: untyped): untyped =
|
||||
let temp = (self)
|
||||
if temp.isSome:
|
||||
temp.get()
|
||||
else:
|
||||
body
|
||||
|
||||
template withValue*[T](self: Option[T], value, body: untyped): untyped =
|
||||
let temp = (self)
|
||||
if temp.isSome:
|
||||
let `value` {.inject.} = temp.get()
|
||||
body
|
||||
|
||||
macro withValue*[T](self: Option[T], value, body, elseStmt: untyped): untyped =
|
||||
let elseBody = elseStmt[0]
|
||||
quote:
|
||||
let temp = (`self`)
|
||||
if temp.isSome:
|
||||
let `value` {.inject.} = temp.get()
|
||||
`body`
|
||||
else:
|
||||
`elseBody`
|
||||
@ -1,4 +1,4 @@
|
||||
import libp2p/crypto/crypto
|
||||
import results, libp2p/crypto/crypto
|
||||
import
|
||||
chronos,
|
||||
chronicles,
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import libp2p/crypto/crypto
|
||||
import libp2p/crypto/rng
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[sequtils, strutils, options, sets, net, json],
|
||||
std/[sequtils, strutils, sets, net, json],
|
||||
results,
|
||||
chronos,
|
||||
chronicles,
|
||||
@ -40,7 +39,7 @@ type Discv5Conf* {.requiresInit.} = object
|
||||
enrAutoUpdate*: bool
|
||||
|
||||
type WakuDiscoveryV5Config* = object
|
||||
discv5Config*: Option[DiscoveryConfig]
|
||||
discv5Config*: Opt[DiscoveryConfig]
|
||||
address*: IpAddress
|
||||
port*: Port
|
||||
privateKey*: eth_keys.PrivateKey
|
||||
@ -56,21 +55,21 @@ type WakuDiscoveryV5* = ref object
|
||||
conf: WakuDiscoveryV5Config
|
||||
protocol*: protocol.Protocol
|
||||
listening*: bool
|
||||
predicate: Option[WakuDiscv5Predicate]
|
||||
peerManager: Option[PeerManager]
|
||||
predicate: Opt[WakuDiscv5Predicate]
|
||||
peerManager: Opt[PeerManager]
|
||||
topicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent]
|
||||
|
||||
proc shardingPredicate*(
|
||||
record: Record, bootnodes: seq[Record] = @[]
|
||||
): Option[WakuDiscv5Predicate] =
|
||||
): Opt[WakuDiscv5Predicate] =
|
||||
## Filter peers based on relay sharding information
|
||||
let typedRecord = record.toTyped().valueOr:
|
||||
info "peer filtering failed", reason = error
|
||||
return none(WakuDiscv5Predicate)
|
||||
return Opt.none(WakuDiscv5Predicate)
|
||||
|
||||
let nodeShard = typedRecord.relaySharding().valueOr:
|
||||
info "no relay sharding information, peer filtering disabled"
|
||||
return none(WakuDiscv5Predicate)
|
||||
return Opt.none(WakuDiscv5Predicate)
|
||||
|
||||
info "peer filtering updated"
|
||||
|
||||
@ -81,14 +80,14 @@ proc shardingPredicate*(
|
||||
nodeShard.shardIds.anyIt(record.containsShard(nodeShard.clusterId, it))
|
||||
) #RFC 64 guideline
|
||||
|
||||
return some(predicate)
|
||||
return Opt.some(predicate)
|
||||
|
||||
proc new*(
|
||||
T: type WakuDiscoveryV5,
|
||||
rng: crypto.Rng,
|
||||
conf: WakuDiscoveryV5Config,
|
||||
record: Option[waku_enr.Record],
|
||||
peerManager: Option[PeerManager] = none(PeerManager),
|
||||
record: Opt[waku_enr.Record],
|
||||
peerManager: Opt[PeerManager] = Opt.none(PeerManager),
|
||||
queue: AsyncEventQueue[SubscriptionEvent] =
|
||||
newAsyncEventQueue[SubscriptionEvent](30),
|
||||
): T =
|
||||
@ -100,7 +99,7 @@ proc new*(
|
||||
privKey = conf.privateKey,
|
||||
bootstrapRecords = conf.bootstrapRecords,
|
||||
enrAutoUpdate = conf.autoupdateRecord,
|
||||
previousRecord = record.toOpt(),
|
||||
previousRecord = record,
|
||||
enrIp = Opt.none(IpAddress),
|
||||
enrTcpPort = Opt.none(Port),
|
||||
enrUdpPort = Opt.none(Port),
|
||||
@ -110,7 +109,7 @@ proc new*(
|
||||
if record.isSome():
|
||||
shardingPredicate(record.get(), conf.bootstrapRecords)
|
||||
else:
|
||||
none(WakuDiscv5Predicate)
|
||||
Opt.none(WakuDiscv5Predicate)
|
||||
|
||||
WakuDiscoveryV5(
|
||||
conf: conf,
|
||||
@ -221,7 +220,7 @@ proc logDiscv5FoundPeers(discoveredRecords: seq[waku_enr.Record]) =
|
||||
addrs = addrs, enr = recordUri, capabilities = capabilities, shards = shardsStr
|
||||
|
||||
proc findRandomPeers*(
|
||||
wd: WakuDiscoveryV5, overridePred = none(WakuDiscv5Predicate)
|
||||
wd: WakuDiscoveryV5, overridePred = Opt.none(WakuDiscv5Predicate)
|
||||
): Future[seq[waku_enr.Record]] {.async.} =
|
||||
## Find random peers to connect to using Discovery v5
|
||||
let discoveredNodes = await wd.protocol.queryRandom()
|
||||
@ -445,7 +444,7 @@ proc setupDiscoveryV5*(
|
||||
let discv5UdpPort = conf.udpPort
|
||||
|
||||
let discv5Conf = WakuDiscoveryV5Config(
|
||||
discv5Config: some(discv5Config),
|
||||
discv5Config: Opt.some(discv5Config),
|
||||
address: p2pListenAddress,
|
||||
port: discv5UdpPort,
|
||||
privateKey: eth_keys.PrivateKey(key.skkey),
|
||||
@ -455,7 +454,11 @@ proc setupDiscoveryV5*(
|
||||
|
||||
return ok(
|
||||
WakuDiscoveryV5.new(
|
||||
rng, discv5Conf, some(myENR), some(nodePeerManager), nodeTopicSubscriptionQueue
|
||||
rng,
|
||||
discv5Conf,
|
||||
Opt.some(myENR),
|
||||
Opt.some(nodePeerManager),
|
||||
nodeTopicSubscriptionQueue,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
## A set of utilities to integrate EIP-1459 DNS-based discovery
|
||||
@ -7,7 +6,7 @@ import logos_delivery/waku/compat/option_valueor
|
||||
## EIP-1459 is defined in https://eips.ethereum.org/EIPS/eip-1459
|
||||
|
||||
import
|
||||
std/[options, net, sequtils, sugar],
|
||||
std/[net, sequtils, sugar],
|
||||
chronicles,
|
||||
chronos,
|
||||
metrics,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[options, sequtils, sets]
|
||||
import std/[sequtils, sets]
|
||||
import
|
||||
chronos,
|
||||
chronicles,
|
||||
@ -51,45 +50,45 @@ type KademliaDiscoveryConf* = object
|
||||
clientMode*: bool
|
||||
xprPublishing*: bool
|
||||
|
||||
proc extractMixPubKey*(service: ServiceInfo): Option[Curve25519Key] =
|
||||
proc extractMixPubKey*(service: ServiceInfo): Opt[Curve25519Key] =
|
||||
if service.id != MixProtocolID:
|
||||
return none(Curve25519Key)
|
||||
return Opt.none(Curve25519Key)
|
||||
|
||||
if service.data.len != Curve25519KeySize:
|
||||
trace "invalid mix pub key length",
|
||||
expected = Curve25519KeySize,
|
||||
actual = service.data.len,
|
||||
dataHex = byteutils.toHex(service.data)
|
||||
return none(Curve25519Key)
|
||||
return Opt.none(Curve25519Key)
|
||||
|
||||
let key = intoCurve25519Key(service.data)
|
||||
|
||||
return some(key)
|
||||
return Opt.some(key)
|
||||
|
||||
proc remotePeerInfoFrom*(record: ExtendedPeerRecord): Option[RemotePeerInfo] =
|
||||
proc remotePeerInfoFrom*(record: ExtendedPeerRecord): Opt[RemotePeerInfo] =
|
||||
if record.addresses.len == 0:
|
||||
trace "missing addresses", peerId = record.peerId
|
||||
return none(RemotePeerInfo)
|
||||
return Opt.none(RemotePeerInfo)
|
||||
|
||||
let addrs = record.addresses.mapIt(it.address)
|
||||
if addrs.len == 0:
|
||||
trace "no dialable addresses", peerId = record.peerId
|
||||
return none(RemotePeerInfo)
|
||||
return Opt.none(RemotePeerInfo)
|
||||
|
||||
let protocols = record.services.mapIt(it.id)
|
||||
|
||||
var mixPubKey: Option[Curve25519Key] = none(Curve25519Key)
|
||||
var mixPubKey: Opt[Curve25519Key] = Opt.none(Curve25519Key)
|
||||
for service in record.services:
|
||||
let key = extractMixPubKey(service).valueOr:
|
||||
continue
|
||||
mixPubKey = some(key)
|
||||
mixPubKey = Opt.some(key)
|
||||
|
||||
trace "successfully extracted mix pub key",
|
||||
peerId = record.peerId, keyHex = byteutils.toHex(mixPubKey.get())
|
||||
|
||||
break
|
||||
|
||||
return some(
|
||||
return Opt.some(
|
||||
RemotePeerInfo.init(
|
||||
record.peerId,
|
||||
addrs = addrs,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, net, math],
|
||||
std/[net, math],
|
||||
results,
|
||||
chronicles,
|
||||
libp2p/crypto/crypto,
|
||||
@ -23,14 +23,14 @@ import
|
||||
|
||||
type
|
||||
WakuNodeBuilder* = object # General
|
||||
nodeRng: Option[crypto.Rng]
|
||||
nodeKey: Option[crypto.PrivateKey]
|
||||
netConfig: Option[NetConfig]
|
||||
record: Option[enr.Record]
|
||||
nodeRng: Opt[crypto.Rng]
|
||||
nodeKey: Opt[crypto.PrivateKey]
|
||||
netConfig: Opt[NetConfig]
|
||||
record: Opt[enr.Record]
|
||||
|
||||
# Peer storage and peer manager
|
||||
peerStorage: Option[PeerStorage]
|
||||
peerStorageCapacity: Option[int]
|
||||
peerStorage: Opt[PeerStorage]
|
||||
peerStorageCapacity: Opt[int]
|
||||
|
||||
# Peer manager config
|
||||
maxRelayPeers: int
|
||||
@ -39,16 +39,16 @@ type
|
||||
shardAware: bool
|
||||
|
||||
# Libp2p switch
|
||||
switchMaxConnections: Option[int]
|
||||
switchNameResolver: Option[NameResolver]
|
||||
switchAgentString: Option[string]
|
||||
switchSslSecureKey: Option[string]
|
||||
switchSslSecureCert: Option[string]
|
||||
switchSendSignedPeerRecord: Option[bool]
|
||||
switchMaxConnections: Opt[int]
|
||||
switchNameResolver: Opt[NameResolver]
|
||||
switchAgentString: Opt[string]
|
||||
switchSslSecureKey: Opt[string]
|
||||
switchSslSecureCert: Opt[string]
|
||||
switchSendSignedPeerRecord: Opt[bool]
|
||||
circuitRelay: Relay
|
||||
|
||||
# Rate limit configs for non-relay req-resp protocols
|
||||
rateLimitSettings: Option[ProtocolRateLimitSettings]
|
||||
rateLimitSettings: Opt[ProtocolRateLimitSettings]
|
||||
|
||||
WakuNodeBuilderResult* = Result[void, string]
|
||||
|
||||
@ -60,29 +60,29 @@ proc init*(T: type WakuNodeBuilder): WakuNodeBuilder =
|
||||
## General
|
||||
|
||||
proc withRng*(builder: var WakuNodeBuilder, rng: crypto.Rng) =
|
||||
builder.nodeRng = some(rng)
|
||||
builder.nodeRng = Opt.some(rng)
|
||||
|
||||
proc withNodeKey*(builder: var WakuNodeBuilder, nodeKey: crypto.PrivateKey) =
|
||||
builder.nodeKey = some(nodeKey)
|
||||
builder.nodeKey = Opt.some(nodeKey)
|
||||
|
||||
proc withRecord*(builder: var WakuNodeBuilder, record: enr.Record) =
|
||||
builder.record = some(record)
|
||||
builder.record = Opt.some(record)
|
||||
|
||||
proc withNetworkConfiguration*(builder: var WakuNodeBuilder, config: NetConfig) =
|
||||
builder.netConfig = some(config)
|
||||
builder.netConfig = Opt.some(config)
|
||||
|
||||
proc withNetworkConfigurationDetails*(
|
||||
builder: var WakuNodeBuilder,
|
||||
bindIp: IpAddress,
|
||||
bindPort: Port,
|
||||
extIp = none(IpAddress),
|
||||
extPort = none(Port),
|
||||
extIp = Opt.none(IpAddress),
|
||||
extPort = Opt.none(Port),
|
||||
extMultiAddrs = newSeq[MultiAddress](),
|
||||
wsBindPort: Port = Port(8000),
|
||||
wsEnabled: bool = false,
|
||||
wssEnabled: bool = false,
|
||||
wakuFlags = none(CapabilitiesBitfield),
|
||||
dns4DomainName = none(string),
|
||||
wakuFlags = Opt.none(CapabilitiesBitfield),
|
||||
dns4DomainName = Opt.none(string),
|
||||
dnsNameServers = @[parseIpAddress("1.1.1.1"), parseIpAddress("1.0.0.1")],
|
||||
): WakuNodeBuilderResult {.
|
||||
deprecated: "use 'builder.withNetworkConfiguration()' instead"
|
||||
@ -93,7 +93,7 @@ proc withNetworkConfigurationDetails*(
|
||||
extIp = extIp,
|
||||
extPort = extPort,
|
||||
extMultiAddrs = extMultiAddrs,
|
||||
wsBindPort = some(wsBindPort),
|
||||
wsBindPort = Opt.some(wsBindPort),
|
||||
wsEnabled = wsEnabled,
|
||||
wssEnabled = wssEnabled,
|
||||
wakuFlags = wakuFlags,
|
||||
@ -106,10 +106,10 @@ proc withNetworkConfigurationDetails*(
|
||||
## Peer storage and peer manager
|
||||
|
||||
proc withPeerStorage*(
|
||||
builder: var WakuNodeBuilder, peerStorage: PeerStorage, capacity = none(int)
|
||||
builder: var WakuNodeBuilder, peerStorage: PeerStorage, capacity = Opt.none(int)
|
||||
) =
|
||||
if not peerStorage.isNil():
|
||||
builder.peerStorage = some(peerStorage)
|
||||
builder.peerStorage = Opt.some(peerStorage)
|
||||
|
||||
builder.peerStorageCapacity = capacity
|
||||
|
||||
@ -131,7 +131,7 @@ proc withColocationLimit*(builder: var WakuNodeBuilder, colocationLimit: int) =
|
||||
builder.colocationLimit = colocationLimit
|
||||
|
||||
proc withRateLimit*(builder: var WakuNodeBuilder, limits: ProtocolRateLimitSettings) =
|
||||
builder.rateLimitSettings = some(limits)
|
||||
builder.rateLimitSettings = Opt.some(limits)
|
||||
|
||||
proc withCircuitRelay*(builder: var WakuNodeBuilder, circuitRelay: Relay) =
|
||||
builder.circuitRelay = circuitRelay
|
||||
@ -140,21 +140,21 @@ proc withCircuitRelay*(builder: var WakuNodeBuilder, circuitRelay: Relay) =
|
||||
|
||||
proc withSwitchConfiguration*(
|
||||
builder: var WakuNodeBuilder,
|
||||
maxConnections = none(int),
|
||||
maxConnections = Opt.none(int),
|
||||
nameResolver: NameResolver = nil,
|
||||
sendSignedPeerRecord = false,
|
||||
secureKey = none(string),
|
||||
secureCert = none(string),
|
||||
agentString = none(string),
|
||||
secureKey = Opt.none(string),
|
||||
secureCert = Opt.none(string),
|
||||
agentString = Opt.none(string),
|
||||
) =
|
||||
builder.switchMaxConnections = maxConnections
|
||||
builder.switchSendSignedPeerRecord = some(sendSignedPeerRecord)
|
||||
builder.switchSendSignedPeerRecord = Opt.some(sendSignedPeerRecord)
|
||||
builder.switchSslSecureKey = secureKey
|
||||
builder.switchSslSecureCert = secureCert
|
||||
builder.switchAgentString = agentString
|
||||
|
||||
if not nameResolver.isNil():
|
||||
builder.switchNameResolver = some(nameResolver)
|
||||
builder.switchNameResolver = Opt.some(nameResolver)
|
||||
|
||||
## Build
|
||||
|
||||
@ -209,8 +209,8 @@ proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] =
|
||||
let peerManager = PeerManager.new(
|
||||
switch = switch,
|
||||
storage = builder.peerStorage.get(nil),
|
||||
maxRelayPeers = some(builder.maxRelayPeers),
|
||||
maxServicePeers = some(builder.maxServicePeers),
|
||||
maxRelayPeers = Opt.some(builder.maxRelayPeers),
|
||||
maxServicePeers = Opt.some(builder.maxServicePeers),
|
||||
colocationLimit = builder.colocationLimit,
|
||||
shardedPeerManagement = builder.shardAware,
|
||||
maxConnections = builder.switchMaxConnections.get(MaxConnections),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/[net, options, sequtils], results
|
||||
import chronicles, std/[net, sequtils], results
|
||||
import ../waku_conf
|
||||
|
||||
logScope:
|
||||
@ -16,49 +16,49 @@ const
|
||||
## Discv5 Config Builder ##
|
||||
###########################
|
||||
type Discv5ConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
enabled*: Opt[bool]
|
||||
|
||||
bootstrapNodes*: seq[string]
|
||||
bitsPerHop*: Option[int]
|
||||
bucketIpLimit*: Option[uint]
|
||||
enrAutoUpdate*: Option[bool]
|
||||
tableIpLimit*: Option[uint]
|
||||
udpPort*: Option[Port]
|
||||
bitsPerHop*: Opt[int]
|
||||
bucketIpLimit*: Opt[uint]
|
||||
enrAutoUpdate*: Opt[bool]
|
||||
tableIpLimit*: Opt[uint]
|
||||
udpPort*: Opt[Port]
|
||||
|
||||
proc init*(T: type Discv5ConfBuilder): Discv5ConfBuilder =
|
||||
Discv5ConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var Discv5ConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withBitsPerHop*(b: var Discv5ConfBuilder, bitsPerHop: int) =
|
||||
b.bitsPerHop = some(bitsPerHop)
|
||||
b.bitsPerHop = Opt.some(bitsPerHop)
|
||||
|
||||
proc withBucketIpLimit*(b: var Discv5ConfBuilder, bucketIpLimit: uint) =
|
||||
b.bucketIpLimit = some(bucketIpLimit)
|
||||
b.bucketIpLimit = Opt.some(bucketIpLimit)
|
||||
|
||||
proc withEnrAutoUpdate*(b: var Discv5ConfBuilder, enrAutoUpdate: bool) =
|
||||
b.enrAutoUpdate = some(enrAutoUpdate)
|
||||
b.enrAutoUpdate = Opt.some(enrAutoUpdate)
|
||||
|
||||
proc withTableIpLimit*(b: var Discv5ConfBuilder, tableIpLimit: uint) =
|
||||
b.tableIpLimit = some(tableIpLimit)
|
||||
b.tableIpLimit = Opt.some(tableIpLimit)
|
||||
|
||||
proc withUdpPort*(b: var Discv5ConfBuilder, udpPort: Port) =
|
||||
b.udpPort = some(udpPort)
|
||||
b.udpPort = Opt.some(udpPort)
|
||||
|
||||
proc withUdpPort*(b: var Discv5ConfBuilder, udpPort: uint16) =
|
||||
b.udpPort = some(Port(udpPort))
|
||||
b.udpPort = Opt.some(Port(udpPort))
|
||||
|
||||
proc withBootstrapNodes*(b: var Discv5ConfBuilder, bootstrapNodes: seq[string]) =
|
||||
# TODO: validate ENRs?
|
||||
b.bootstrapNodes = concat(b.bootstrapNodes, bootstrapNodes)
|
||||
|
||||
proc build*(b: Discv5ConfBuilder): Result[Option[Discv5Conf], string] =
|
||||
proc build*(b: Discv5ConfBuilder): Result[Opt[Discv5Conf], string] =
|
||||
if not b.enabled.get(DefaultDiscv5Enabled):
|
||||
return ok(none(Discv5Conf))
|
||||
return ok(Opt.none(Discv5Conf))
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
Discv5Conf(
|
||||
bootstrapNodes: b.bootstrapNodes,
|
||||
bitsPerHop: b.bitsPerHop.get(DefaultDiscv5BitsPerHop),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/[net, options, strutils], results
|
||||
import chronicles, std/[net, strutils], results
|
||||
import ../waku_conf
|
||||
|
||||
logScope:
|
||||
@ -8,21 +8,21 @@ logScope:
|
||||
## DNS Discovery Config Builder ##
|
||||
##################################
|
||||
type DnsDiscoveryConfBuilder* = object
|
||||
enrTreeUrl*: Option[string]
|
||||
enrTreeUrl*: Opt[string]
|
||||
nameServers*: seq[IpAddress]
|
||||
|
||||
proc init*(T: type DnsDiscoveryConfBuilder): DnsDiscoveryConfBuilder =
|
||||
DnsDiscoveryConfBuilder()
|
||||
|
||||
proc withEnrTreeUrl*(b: var DnsDiscoveryConfBuilder, enrTreeUrl: string) =
|
||||
b.enrTreeUrl = some(enrTreeUrl)
|
||||
b.enrTreeUrl = Opt.some(enrTreeUrl)
|
||||
|
||||
proc withNameServers*(b: var DnsDiscoveryConfBuilder, nameServers: seq[IpAddress]) =
|
||||
b.nameServers = nameServers
|
||||
|
||||
proc build*(b: DnsDiscoveryConfBuilder): Result[Option[DnsDiscoveryConf], string] =
|
||||
proc build*(b: DnsDiscoveryConfBuilder): Result[Opt[DnsDiscoveryConf], string] =
|
||||
if b.enrTreeUrl.isNone():
|
||||
return ok(none(DnsDiscoveryConf))
|
||||
return ok(Opt.none(DnsDiscoveryConf))
|
||||
|
||||
if isEmptyOrWhiteSpace(b.enrTreeUrl.get()):
|
||||
return err("dnsDiscovery.enrTreeUrl cannot be an empty string")
|
||||
@ -30,5 +30,7 @@ proc build*(b: DnsDiscoveryConfBuilder): Result[Option[DnsDiscoveryConf], string
|
||||
return err("dnsDiscovery.nameServers is not specified")
|
||||
|
||||
return ok(
|
||||
some(DnsDiscoveryConf(nameServers: b.nameServers, enrTreeUrl: b.enrTreeUrl.get()))
|
||||
Opt.some(
|
||||
DnsDiscoveryConf(nameServers: b.nameServers, enrTreeUrl: b.enrTreeUrl.get())
|
||||
)
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/options, results
|
||||
import chronicles, results
|
||||
import ../waku_conf
|
||||
|
||||
logScope:
|
||||
@ -14,40 +14,40 @@ const
|
||||
## Filter Service Config Builder ##
|
||||
###################################
|
||||
type FilterServiceConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
maxPeersToServe*: Option[uint32]
|
||||
subscriptionTimeout*: Option[uint16]
|
||||
maxCriteria*: Option[uint32]
|
||||
enabled*: Opt[bool]
|
||||
maxPeersToServe*: Opt[uint32]
|
||||
subscriptionTimeout*: Opt[uint16]
|
||||
maxCriteria*: Opt[uint32]
|
||||
|
||||
proc init*(T: type FilterServiceConfBuilder): FilterServiceConfBuilder =
|
||||
FilterServiceConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var FilterServiceConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withMaxPeersToServe*(b: var FilterServiceConfBuilder, maxPeersToServe: uint32) =
|
||||
b.maxPeersToServe = some(maxPeersToServe)
|
||||
b.maxPeersToServe = Opt.some(maxPeersToServe)
|
||||
|
||||
proc withMaxPeersToServeIfNotAssigned*(
|
||||
b: var FilterServiceConfBuilder, maxPeersToServe: uint32
|
||||
) =
|
||||
if b.maxPeersToServe.isNone():
|
||||
b.maxPeersToServe = some(maxPeersToServe)
|
||||
b.maxPeersToServe = Opt.some(maxPeersToServe)
|
||||
|
||||
proc withSubscriptionTimeout*(
|
||||
b: var FilterServiceConfBuilder, subscriptionTimeout: uint16
|
||||
) =
|
||||
b.subscriptionTimeout = some(subscriptionTimeout)
|
||||
b.subscriptionTimeout = Opt.some(subscriptionTimeout)
|
||||
|
||||
proc withMaxCriteria*(b: var FilterServiceConfBuilder, maxCriteria: uint32) =
|
||||
b.maxCriteria = some(maxCriteria)
|
||||
b.maxCriteria = Opt.some(maxCriteria)
|
||||
|
||||
proc build*(b: FilterServiceConfBuilder): Result[Option[FilterServiceConf], string] =
|
||||
proc build*(b: FilterServiceConfBuilder): Result[Opt[FilterServiceConf], string] =
|
||||
if not b.enabled.get(DefaultFilterEnabled):
|
||||
return ok(none(FilterServiceConf))
|
||||
return ok(Opt.none(FilterServiceConf))
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
FilterServiceConf(
|
||||
maxPeersToServe: b.maxPeersToServe.get(DefaultFilterMaxPeersToServe),
|
||||
subscriptionTimeout: b.subscriptionTimeout.get(DefaultFilterSubscriptionTimeout),
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import chronicles, std/options, results
|
||||
import logos_delivery/waku/discovery/waku_kademlia
|
||||
import chronicles, results, logos_delivery/waku/discovery/waku_kademlia
|
||||
import chronos
|
||||
import libp2p/[peerid, multiaddress, peerinfo]
|
||||
import libp2p/protocols/kademlia/types
|
||||
@ -15,16 +13,16 @@ const
|
||||
DefaultServiceLookupInterval* = chronos.seconds(60)
|
||||
|
||||
type KademliaDiscoveryConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
enabled*: Opt[bool]
|
||||
bootstrapNodes*: seq[string]
|
||||
randomLookupInterval*: Option[Duration]
|
||||
serviceLookupInterval*: Option[Duration]
|
||||
randomLookupInterval*: Opt[Duration]
|
||||
serviceLookupInterval*: Opt[Duration]
|
||||
|
||||
proc init*(T: type KademliaDiscoveryConfBuilder): KademliaDiscoveryConfBuilder =
|
||||
KademliaDiscoveryConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var KademliaDiscoveryConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withBootstrapNodes*(
|
||||
b: var KademliaDiscoveryConfBuilder, bootstrapNodes: seq[string]
|
||||
@ -34,22 +32,22 @@ proc withBootstrapNodes*(
|
||||
proc withRandomLookupInterval*(
|
||||
b: var KademliaDiscoveryConfBuilder, interval: Duration
|
||||
) =
|
||||
b.randomLookupInterval = some(interval)
|
||||
b.randomLookupInterval = Opt.some(interval)
|
||||
|
||||
proc withServiceLookupInterval*(
|
||||
b: var KademliaDiscoveryConfBuilder, interval: Duration
|
||||
) =
|
||||
b.serviceLookupInterval = some(interval)
|
||||
b.serviceLookupInterval = Opt.some(interval)
|
||||
|
||||
proc build*(
|
||||
b: KademliaDiscoveryConfBuilder
|
||||
): Result[Option[KademliaDiscoveryConf], string] =
|
||||
): Result[Opt[KademliaDiscoveryConf], string] =
|
||||
# Explicit disable wins: enabled=false disables regardless of bootstrap nodes.
|
||||
if b.enabled == some(false):
|
||||
return ok(none(KademliaDiscoveryConf))
|
||||
if b.enabled == Opt.some(false):
|
||||
return ok(Opt.none(KademliaDiscoveryConf))
|
||||
# Otherwise enabled if config-enabled or any bootstrap nodes are provided.
|
||||
if not b.enabled.get(DefaultKadEnabled) and b.bootstrapNodes.len == 0:
|
||||
return ok(none(KademliaDiscoveryConf))
|
||||
return ok(Opt.none(KademliaDiscoveryConf))
|
||||
|
||||
var parsedNodes: seq[(PeerId, seq[MultiAddress])]
|
||||
for nodeStr in b.bootstrapNodes:
|
||||
@ -58,7 +56,7 @@ proc build*(
|
||||
parsedNodes.add((peerId, @[ma]))
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
KademliaDiscoveryConf(
|
||||
bootstrapNodes: parsedNodes,
|
||||
randomLookupInterval: b.randomLookupInterval.get(DefaultRandomLookupInterval),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/[net, options], results
|
||||
import chronicles, std/net, results
|
||||
import ../waku_conf
|
||||
|
||||
logScope:
|
||||
@ -14,36 +14,36 @@ const
|
||||
## Metrics Server Config Builder ##
|
||||
###################################
|
||||
type MetricsServerConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
enabled*: Opt[bool]
|
||||
|
||||
httpAddress*: Option[IpAddress]
|
||||
httpPort*: Option[Port]
|
||||
logging*: Option[bool]
|
||||
httpAddress*: Opt[IpAddress]
|
||||
httpPort*: Opt[Port]
|
||||
logging*: Opt[bool]
|
||||
|
||||
proc init*(T: type MetricsServerConfBuilder): MetricsServerConfBuilder =
|
||||
MetricsServerConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var MetricsServerConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withHttpAddress*(b: var MetricsServerConfBuilder, httpAddress: IpAddress) =
|
||||
b.httpAddress = some(httpAddress)
|
||||
b.httpAddress = Opt.some(httpAddress)
|
||||
|
||||
proc withHttpPort*(b: var MetricsServerConfBuilder, httpPort: Port) =
|
||||
b.httpPort = some(httpPort)
|
||||
b.httpPort = Opt.some(httpPort)
|
||||
|
||||
proc withHttpPort*(b: var MetricsServerConfBuilder, httpPort: uint16) =
|
||||
b.httpPort = some(Port(httpPort))
|
||||
b.httpPort = Opt.some(Port(httpPort))
|
||||
|
||||
proc withLogging*(b: var MetricsServerConfBuilder, logging: bool) =
|
||||
b.logging = some(logging)
|
||||
b.logging = Opt.some(logging)
|
||||
|
||||
proc build*(b: MetricsServerConfBuilder): Result[Option[MetricsServerConf], string] =
|
||||
proc build*(b: MetricsServerConfBuilder): Result[Opt[MetricsServerConf], string] =
|
||||
if not b.enabled.get(DefaultMetricsEnabled):
|
||||
return ok(none(MetricsServerConf))
|
||||
return ok(Opt.none(MetricsServerConf))
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
MetricsServerConf(
|
||||
httpAddress: b.httpAddress.get(DefaultMetricsHttpAddress),
|
||||
httpPort: b.httpPort.get(DefaultMetricsHttpPort),
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import chronicles, std/options, results
|
||||
import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p_mix/curve25519
|
||||
import
|
||||
chronicles,
|
||||
results,
|
||||
libp2p/crypto/crypto,
|
||||
libp2p/crypto/curve25519,
|
||||
libp2p_mix/curve25519
|
||||
import ../waku_conf, logos_delivery/waku/waku_mix
|
||||
|
||||
logScope:
|
||||
@ -12,35 +15,39 @@ const DefaultMixEnabled: bool = false
|
||||
## Mix Config Builder ##
|
||||
##################################
|
||||
type MixConfBuilder* = object
|
||||
enabled: Option[bool]
|
||||
mixKey: Option[string]
|
||||
enabled: Opt[bool]
|
||||
mixKey: Opt[string]
|
||||
mixNodes: seq[MixNodePubInfo]
|
||||
|
||||
proc init*(T: type MixConfBuilder): MixConfBuilder =
|
||||
MixConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var MixConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withMixKey*(b: var MixConfBuilder, mixKey: string) =
|
||||
b.mixKey = some(mixKey)
|
||||
b.mixKey = Opt.some(mixKey)
|
||||
|
||||
proc withMixNodes*(b: var MixConfBuilder, mixNodes: seq[MixNodePubInfo]) =
|
||||
b.mixNodes = mixNodes
|
||||
|
||||
proc build*(b: MixConfBuilder): Result[Option[MixConf], string] =
|
||||
proc build*(b: MixConfBuilder): Result[Opt[MixConf], string] =
|
||||
if not b.enabled.get(DefaultMixEnabled):
|
||||
return ok(none[MixConf]())
|
||||
return ok(Opt.none(MixConf))
|
||||
else:
|
||||
if b.mixKey.isSome():
|
||||
let mixPrivKey = intoCurve25519Key(ncrutils.fromHex(b.mixKey.get()))
|
||||
let mixPubKey = public(mixPrivKey)
|
||||
return ok(
|
||||
some(MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey, mixNodes: b.mixNodes))
|
||||
Opt.some(
|
||||
MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey, mixNodes: b.mixNodes)
|
||||
)
|
||||
)
|
||||
else:
|
||||
let (mixPrivKey, mixPubKey) = generateKeyPair().valueOr:
|
||||
return err("Generate key pair error: " & $error)
|
||||
return ok(
|
||||
some(MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey, mixNodes: b.mixNodes))
|
||||
Opt.some(
|
||||
MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey, mixNodes: b.mixNodes)
|
||||
)
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/[net, options], results
|
||||
import chronicles, std/net, results
|
||||
import logos_delivery/waku/factory/waku_conf
|
||||
|
||||
logScope:
|
||||
@ -11,23 +11,23 @@ const DefaultQuicPort*: Port = Port(60000)
|
||||
## QUIC Config Builder ##
|
||||
#########################
|
||||
type QuicConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
quicPort*: Option[Port]
|
||||
enabled*: Opt[bool]
|
||||
quicPort*: Opt[Port]
|
||||
|
||||
proc init*(T: type QuicConfBuilder): QuicConfBuilder =
|
||||
QuicConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var QuicConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withQuicPort*(b: var QuicConfBuilder, quicPort: Port) =
|
||||
b.quicPort = some(quicPort)
|
||||
b.quicPort = Opt.some(quicPort)
|
||||
|
||||
proc withQuicPort*(b: var QuicConfBuilder, quicPort: uint16) =
|
||||
b.quicPort = some(Port(quicPort))
|
||||
b.quicPort = Opt.some(Port(quicPort))
|
||||
|
||||
proc build*(b: QuicConfBuilder): Result[Option[QuicConf], string] =
|
||||
proc build*(b: QuicConfBuilder): Result[Opt[QuicConf], string] =
|
||||
if not b.enabled.get(false):
|
||||
return ok(none(QuicConf))
|
||||
return ok(Opt.none(QuicConf))
|
||||
|
||||
return ok(some(QuicConf(port: b.quicPort.get(DefaultQuicPort))))
|
||||
return ok(Opt.some(QuicConf(port: b.quicPort.get(DefaultQuicPort))))
|
||||
|
||||
@ -1,25 +1,23 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import chronicles, std/[net, options], results
|
||||
import logos_delivery/waku/common/rate_limit/setting
|
||||
import chronicles, std/net, results, logos_delivery/waku/common/rate_limit/setting
|
||||
|
||||
logScope:
|
||||
topics = "waku conf builder rate limit"
|
||||
|
||||
type RateLimitConfBuilder* = object
|
||||
strValue: Option[seq[string]]
|
||||
objValue: Option[ProtocolRateLimitSettings]
|
||||
strValue: Opt[seq[string]]
|
||||
objValue: Opt[ProtocolRateLimitSettings]
|
||||
|
||||
proc init*(T: type RateLimitConfBuilder): RateLimitConfBuilder =
|
||||
RateLimitConfBuilder()
|
||||
|
||||
proc withRateLimits*(b: var RateLimitConfBuilder, rateLimits: seq[string]) =
|
||||
b.strValue = some(rateLimits)
|
||||
b.strValue = Opt.some(rateLimits)
|
||||
|
||||
proc withRateLimitsIfNotAssigned*(
|
||||
b: var RateLimitConfBuilder, rateLimits: seq[string]
|
||||
) =
|
||||
if b.strValue.isNone() or b.strValue.get().len == 0:
|
||||
b.strValue = some(rateLimits)
|
||||
b.strValue = Opt.some(rateLimits)
|
||||
|
||||
proc build*(b: RateLimitConfBuilder): Result[ProtocolRateLimitSettings, string] =
|
||||
if b.strValue.isSome() and b.objValue.isSome():
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/[net, options, sequtils], results
|
||||
import chronicles, std/[net, sequtils], results
|
||||
import ../waku_conf
|
||||
|
||||
logScope:
|
||||
@ -13,41 +13,41 @@ const
|
||||
## REST Server Config Builder ##
|
||||
################################
|
||||
type RestServerConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
enabled*: Opt[bool]
|
||||
|
||||
allowOrigin*: seq[string]
|
||||
listenAddress*: Option[IpAddress]
|
||||
port*: Option[Port]
|
||||
admin*: Option[bool]
|
||||
relayCacheCapacity*: Option[uint32]
|
||||
listenAddress*: Opt[IpAddress]
|
||||
port*: Opt[Port]
|
||||
admin*: Opt[bool]
|
||||
relayCacheCapacity*: Opt[uint32]
|
||||
|
||||
proc init*(T: type RestServerConfBuilder): RestServerConfBuilder =
|
||||
RestServerConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var RestServerConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withAllowOrigin*(b: var RestServerConfBuilder, allowOrigin: seq[string]) =
|
||||
b.allowOrigin = concat(b.allowOrigin, allowOrigin)
|
||||
|
||||
proc withListenAddress*(b: var RestServerConfBuilder, listenAddress: IpAddress) =
|
||||
b.listenAddress = some(listenAddress)
|
||||
b.listenAddress = Opt.some(listenAddress)
|
||||
|
||||
proc withPort*(b: var RestServerConfBuilder, port: Port) =
|
||||
b.port = some(port)
|
||||
b.port = Opt.some(port)
|
||||
|
||||
proc withPort*(b: var RestServerConfBuilder, port: uint16) =
|
||||
b.port = some(Port(port))
|
||||
b.port = Opt.some(Port(port))
|
||||
|
||||
proc withAdmin*(b: var RestServerConfBuilder, admin: bool) =
|
||||
b.admin = some(admin)
|
||||
b.admin = Opt.some(admin)
|
||||
|
||||
proc withRelayCacheCapacity*(b: var RestServerConfBuilder, relayCacheCapacity: uint32) =
|
||||
b.relayCacheCapacity = some(relayCacheCapacity)
|
||||
b.relayCacheCapacity = Opt.some(relayCacheCapacity)
|
||||
|
||||
proc build*(b: RestServerConfBuilder): Result[Option[RestServerConf], string] =
|
||||
proc build*(b: RestServerConfBuilder): Result[Opt[RestServerConf], string] =
|
||||
if not b.enabled.get(DefaultRestEnabled):
|
||||
return ok(none(RestServerConf))
|
||||
return ok(Opt.none(RestServerConf))
|
||||
|
||||
if b.listenAddress.isNone():
|
||||
return err("restServer.listenAddress is not specified")
|
||||
@ -55,7 +55,7 @@ proc build*(b: RestServerConfBuilder): Result[Option[RestServerConf], string] =
|
||||
return err("restServer.relayCacheCapacity is not specified")
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
RestServerConf(
|
||||
allowOrigin: b.allowOrigin,
|
||||
listenAddress: b.listenAddress.get(),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/options, results, stint, stew/endians2
|
||||
import chronicles, results, stint, stew/endians2
|
||||
import ../waku_conf
|
||||
|
||||
logScope:
|
||||
@ -13,69 +13,69 @@ const
|
||||
## RLN Relay Config Builder ##
|
||||
##############################
|
||||
type RlnConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
chainId*: Option[UInt256]
|
||||
ethClientUrls*: Option[seq[string]]
|
||||
ethContractAddress*: Option[string]
|
||||
credIndex*: Option[uint]
|
||||
credPassword*: Option[string]
|
||||
credPath*: Option[string]
|
||||
dynamic*: Option[bool]
|
||||
epochSizeSec*: Option[uint64]
|
||||
userMessageLimit*: Option[uint64]
|
||||
enabled*: Opt[bool]
|
||||
chainId*: Opt[UInt256]
|
||||
ethClientUrls*: Opt[seq[string]]
|
||||
ethContractAddress*: Opt[string]
|
||||
credIndex*: Opt[uint]
|
||||
credPassword*: Opt[string]
|
||||
credPath*: Opt[string]
|
||||
dynamic*: Opt[bool]
|
||||
epochSizeSec*: Opt[uint64]
|
||||
userMessageLimit*: Opt[uint64]
|
||||
|
||||
proc init*(T: type RlnConfBuilder): RlnConfBuilder =
|
||||
RlnConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var RlnConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withChainId*(b: var RlnConfBuilder, chainId: uint | UInt256) =
|
||||
when chainId is uint:
|
||||
b.chainId = some(UInt256.fromBytesBE(chainId.toBytesBE()))
|
||||
b.chainId = Opt.some(UInt256.fromBytesBE(chainId.toBytesBE()))
|
||||
else:
|
||||
b.chainId = some(chainId)
|
||||
b.chainId = Opt.some(chainId)
|
||||
|
||||
proc withCredIndex*(b: var RlnConfBuilder, credIndex: uint) =
|
||||
b.credIndex = some(credIndex)
|
||||
b.credIndex = Opt.some(credIndex)
|
||||
|
||||
proc withCredPassword*(b: var RlnConfBuilder, credPassword: string) =
|
||||
b.credPassword = some(credPassword)
|
||||
b.credPassword = Opt.some(credPassword)
|
||||
|
||||
proc withCredPath*(b: var RlnConfBuilder, credPath: string) =
|
||||
b.credPath = some(credPath)
|
||||
b.credPath = Opt.some(credPath)
|
||||
|
||||
proc withDynamic*(b: var RlnConfBuilder, dynamic: bool) =
|
||||
b.dynamic = some(dynamic)
|
||||
b.dynamic = Opt.some(dynamic)
|
||||
|
||||
proc withEthClientUrls*(b: var RlnConfBuilder, ethClientUrls: seq[string]) =
|
||||
b.ethClientUrls = some(ethClientUrls)
|
||||
b.ethClientUrls = Opt.some(ethClientUrls)
|
||||
|
||||
proc withEthContractAddress*(b: var RlnConfBuilder, ethContractAddress: string) =
|
||||
b.ethContractAddress = some(ethContractAddress)
|
||||
b.ethContractAddress = Opt.some(ethContractAddress)
|
||||
|
||||
proc withEpochSizeSec*(b: var RlnConfBuilder, epochSizeSec: uint64) =
|
||||
b.epochSizeSec = some(epochSizeSec)
|
||||
b.epochSizeSec = Opt.some(epochSizeSec)
|
||||
|
||||
proc withUserMessageLimit*(b: var RlnConfBuilder, userMessageLimit: uint64) =
|
||||
b.userMessageLimit = some(userMessageLimit)
|
||||
b.userMessageLimit = Opt.some(userMessageLimit)
|
||||
|
||||
proc build*(b: RlnConfBuilder): Result[Option[RlnConf], string] =
|
||||
proc build*(b: RlnConfBuilder): Result[Opt[RlnConf], string] =
|
||||
if not b.enabled.get(DefaultRlnRelayEnabled):
|
||||
return ok(none(RlnConf))
|
||||
return ok(Opt.none(RlnConf))
|
||||
|
||||
if b.chainId.isNone():
|
||||
return err("RLN Relay Chain Id is not specified")
|
||||
|
||||
let creds =
|
||||
if b.credPath.isSome() and b.credPassword.isSome():
|
||||
some(RlnCreds(path: b.credPath.get(), password: b.credPassword.get()))
|
||||
Opt.some(RlnCreds(path: b.credPath.get(), password: b.credPassword.get()))
|
||||
elif b.credPath.isSome() and b.credPassword.isNone():
|
||||
return err("RLN Relay Credential Password is not specified but path is")
|
||||
elif b.credPath.isNone() and b.credPassword.isSome():
|
||||
return err("RLN Relay Credential Path is not specified but password is")
|
||||
else:
|
||||
none(RlnCreds)
|
||||
Opt.none(RlnCreds)
|
||||
|
||||
if b.dynamic.isNone():
|
||||
return err("rlnRelay.dynamic is not specified")
|
||||
@ -84,7 +84,7 @@ proc build*(b: RlnConfBuilder): Result[Option[RlnConf], string] =
|
||||
if b.ethContractAddress.get("") == "":
|
||||
return err("rlnRelay.ethContractAddress is not specified")
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
RlnConf(
|
||||
chainId: b.chainId.get(),
|
||||
credIndex: b.credIndex,
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import std/[options, strutils, sequtils]
|
||||
import chronicles, results, chronos
|
||||
import std/[strutils, sequtils], chronicles, results, chronos
|
||||
import ../waku_conf, ./store_sync_conf_builder
|
||||
|
||||
logScope:
|
||||
@ -18,35 +16,35 @@ const
|
||||
## Store Service Config Builder ##
|
||||
##################################
|
||||
type StoreServiceConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
enabled*: Opt[bool]
|
||||
|
||||
dbMigration*: Option[bool]
|
||||
dbURl*: Option[string]
|
||||
dbVacuum*: Option[bool]
|
||||
maxNumDbConnections*: Option[int]
|
||||
dbMigration*: Opt[bool]
|
||||
dbURl*: Opt[string]
|
||||
dbVacuum*: Opt[bool]
|
||||
maxNumDbConnections*: Opt[int]
|
||||
retentionPolicies*: seq[string]
|
||||
resume*: Option[bool]
|
||||
resume*: Opt[bool]
|
||||
storeSyncConf*: StoreSyncConfBuilder
|
||||
|
||||
proc init*(T: type StoreServiceConfBuilder): StoreServiceConfBuilder =
|
||||
StoreServiceConfBuilder(storeSyncConf: StoreSyncConfBuilder.init())
|
||||
|
||||
proc withEnabled*(b: var StoreServiceConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withDbMigration*(b: var StoreServiceConfBuilder, dbMigration: bool) =
|
||||
b.dbMigration = some(dbMigration)
|
||||
b.dbMigration = Opt.some(dbMigration)
|
||||
|
||||
proc withDbUrl*(b: var StoreServiceConfBuilder, dbUrl: string) =
|
||||
b.dbURl = some(dbUrl)
|
||||
b.dbURl = Opt.some(dbUrl)
|
||||
|
||||
proc withDbVacuum*(b: var StoreServiceConfBuilder, dbVacuum: bool) =
|
||||
b.dbVacuum = some(dbVacuum)
|
||||
b.dbVacuum = Opt.some(dbVacuum)
|
||||
|
||||
proc withMaxNumDbConnections*(
|
||||
b: var StoreServiceConfBuilder, maxNumDbConnections: int
|
||||
) =
|
||||
b.maxNumDbConnections = some(maxNumDbConnections)
|
||||
b.maxNumDbConnections = Opt.some(maxNumDbConnections)
|
||||
|
||||
proc withRetentionPolicies*(b: var StoreServiceConfBuilder, retentionPolicies: string) =
|
||||
b.retentionPolicies = retentionPolicies
|
||||
@ -56,7 +54,7 @@ proc withRetentionPolicies*(b: var StoreServiceConfBuilder, retentionPolicies: s
|
||||
.filterIt(it.len > 0)
|
||||
|
||||
proc withResume*(b: var StoreServiceConfBuilder, resume: bool) =
|
||||
b.resume = some(resume)
|
||||
b.resume = Opt.some(resume)
|
||||
|
||||
const ValidRetentionPolicyTypes = ["time", "capacity", "size"]
|
||||
|
||||
@ -85,9 +83,9 @@ proc validateRetentionPolicies(policies: seq[string]): Result[void, string] =
|
||||
|
||||
return ok()
|
||||
|
||||
proc build*(b: StoreServiceConfBuilder): Result[Option[StoreServiceConf], string] =
|
||||
proc build*(b: StoreServiceConfBuilder): Result[Opt[StoreServiceConf], string] =
|
||||
if not b.enabled.get(DefaultStoreEnabled):
|
||||
return ok(none(StoreServiceConf))
|
||||
return ok(Opt.none(StoreServiceConf))
|
||||
|
||||
if b.dbUrl.get("") == "":
|
||||
return err "store.dbUrl is not specified"
|
||||
@ -104,7 +102,7 @@ proc build*(b: StoreServiceConfBuilder): Result[Option[StoreServiceConf], string
|
||||
b.retentionPolicies
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
StoreServiceConf(
|
||||
dbMigration: b.dbMigration.get(DefaultStoreDbMigration),
|
||||
dbURl: b.dbUrl.get(),
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/options, results
|
||||
import chronicles, results
|
||||
import ../waku_conf
|
||||
|
||||
logScope:
|
||||
@ -10,30 +10,30 @@ const DefaultStoreSyncEnabled: bool = false
|
||||
## Store Sync Config Builder ##
|
||||
##################################
|
||||
type StoreSyncConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
enabled*: Opt[bool]
|
||||
|
||||
rangeSec*: Option[uint32]
|
||||
intervalSec*: Option[uint32]
|
||||
relayJitterSec*: Option[uint32]
|
||||
rangeSec*: Opt[uint32]
|
||||
intervalSec*: Opt[uint32]
|
||||
relayJitterSec*: Opt[uint32]
|
||||
|
||||
proc init*(T: type StoreSyncConfBuilder): StoreSyncConfBuilder =
|
||||
StoreSyncConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var StoreSyncConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withRangeSec*(b: var StoreSyncConfBuilder, rangeSec: uint32) =
|
||||
b.rangeSec = some(rangeSec)
|
||||
b.rangeSec = Opt.some(rangeSec)
|
||||
|
||||
proc withIntervalSec*(b: var StoreSyncConfBuilder, intervalSec: uint32) =
|
||||
b.intervalSec = some(intervalSec)
|
||||
b.intervalSec = Opt.some(intervalSec)
|
||||
|
||||
proc withRelayJitterSec*(b: var StoreSyncConfBuilder, relayJitterSec: uint32) =
|
||||
b.relayJitterSec = some(relayJitterSec)
|
||||
b.relayJitterSec = Opt.some(relayJitterSec)
|
||||
|
||||
proc build*(b: StoreSyncConfBuilder): Result[Option[StoreSyncConf], string] =
|
||||
proc build*(b: StoreSyncConfBuilder): Result[Opt[StoreSyncConf], string] =
|
||||
if not b.enabled.get(DefaultStoreSyncEnabled):
|
||||
return ok(none(StoreSyncConf))
|
||||
return ok(Opt.none(StoreSyncConf))
|
||||
|
||||
if b.rangeSec.isNone():
|
||||
return err "store.rangeSec is not specified"
|
||||
@ -43,7 +43,7 @@ proc build*(b: StoreSyncConfBuilder): Result[Option[StoreSyncConf], string] =
|
||||
return err "store.relayJitterSec is not specified"
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
StoreSyncConf(
|
||||
rangeSec: b.rangeSec.get(),
|
||||
intervalSec: b.intervalSec.get(),
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import
|
||||
libp2p/crypto/crypto,
|
||||
libp2p/multiaddress,
|
||||
std/[net, options, sequtils],
|
||||
std/[net, sequtils],
|
||||
stint,
|
||||
chronicles,
|
||||
chronos,
|
||||
@ -101,14 +100,14 @@ type MaxMessageSize* = object
|
||||
# TODO: Add default to most values so that when a developer uses
|
||||
# the builder, it works out-of-the-box
|
||||
type WakuConfBuilder* = object
|
||||
nodeKey: Option[crypto.PrivateKey]
|
||||
nodeKey: Opt[crypto.PrivateKey]
|
||||
|
||||
clusterId: Option[uint16]
|
||||
shardingConf: Option[ShardingConfKind]
|
||||
numShardsInCluster: Option[uint16]
|
||||
subscribeShards: Option[seq[uint16]]
|
||||
protectedShards: Option[seq[ProtectedShard]]
|
||||
contentTopics: Option[seq[string]]
|
||||
clusterId: Opt[uint16]
|
||||
shardingConf: Opt[ShardingConfKind]
|
||||
numShardsInCluster: Opt[uint16]
|
||||
subscribeShards: Opt[seq[uint16]]
|
||||
protectedShards: Opt[seq[ProtectedShard]]
|
||||
contentTopics: Opt[seq[string]]
|
||||
|
||||
# Conf builders
|
||||
dnsDiscoveryConf*: DnsDiscoveryConfBuilder
|
||||
@ -124,54 +123,54 @@ type WakuConfBuilder* = object
|
||||
rateLimitConf*: RateLimitConfBuilder
|
||||
kademliaDiscoveryConf*: KademliaDiscoveryConfBuilder
|
||||
# End conf builders
|
||||
relay: Option[bool]
|
||||
lightPush: Option[bool]
|
||||
peerExchange: Option[bool]
|
||||
storeSync: Option[bool]
|
||||
relayPeerExchange: Option[bool]
|
||||
mix: Option[bool]
|
||||
relay: Opt[bool]
|
||||
lightPush: Opt[bool]
|
||||
peerExchange: Opt[bool]
|
||||
storeSync: Opt[bool]
|
||||
relayPeerExchange: Opt[bool]
|
||||
mix: Opt[bool]
|
||||
|
||||
# TODO: move within a relayConf
|
||||
rendezvous: Option[bool]
|
||||
rendezvous: Opt[bool]
|
||||
|
||||
networkPresetConf: Option[NetworkPresetConf]
|
||||
networkPresetConf: Opt[NetworkPresetConf]
|
||||
|
||||
staticNodes: seq[string]
|
||||
|
||||
remoteStoreNode: Option[string]
|
||||
remoteLightPushNode: Option[string]
|
||||
remoteFilterNode: Option[string]
|
||||
remotePeerExchangeNode: Option[string]
|
||||
remoteStoreNode: Opt[string]
|
||||
remoteLightPushNode: Opt[string]
|
||||
remoteFilterNode: Opt[string]
|
||||
remotePeerExchangeNode: Opt[string]
|
||||
|
||||
maxMessageSize: MaxMessageSize
|
||||
|
||||
logLevel: Option[logging.LogLevel]
|
||||
logFormat: Option[logging.LogFormat]
|
||||
logLevel: Opt[logging.LogLevel]
|
||||
logFormat: Opt[logging.LogFormat]
|
||||
|
||||
natStrategy: Option[string]
|
||||
natStrategy: Opt[string]
|
||||
|
||||
p2pTcpPort: Option[Port]
|
||||
p2pListenAddress: Option[IpAddress]
|
||||
portsShift: Option[uint16]
|
||||
dns4DomainName: Option[string]
|
||||
p2pTcpPort: Opt[Port]
|
||||
p2pListenAddress: Opt[IpAddress]
|
||||
portsShift: Opt[uint16]
|
||||
dns4DomainName: Opt[string]
|
||||
extMultiAddrs: seq[string]
|
||||
extMultiAddrsOnly: Option[bool]
|
||||
extMultiAddrsOnly: Opt[bool]
|
||||
|
||||
dnsAddrsNameServers: seq[IpAddress]
|
||||
|
||||
peerPersistence: Option[bool]
|
||||
peerStoreCapacity: Option[int]
|
||||
maxConnections: Option[int]
|
||||
colocationLimit: Option[int]
|
||||
peerPersistence: Opt[bool]
|
||||
peerStoreCapacity: Opt[int]
|
||||
maxConnections: Opt[int]
|
||||
colocationLimit: Opt[int]
|
||||
|
||||
agentString: Option[string]
|
||||
agentString: Opt[string]
|
||||
|
||||
maxRelayPeers: Option[int]
|
||||
relayShardedPeerManagement: Option[bool]
|
||||
relayServiceRatio: Option[string]
|
||||
circuitRelayClient: Option[bool]
|
||||
maxRelayPeers: Opt[int]
|
||||
relayShardedPeerManagement: Opt[bool]
|
||||
relayServiceRatio: Opt[string]
|
||||
circuitRelayClient: Opt[bool]
|
||||
|
||||
localStoragePath: Option[string]
|
||||
localStoragePath: Opt[string]
|
||||
|
||||
proc init*(T: type WakuConfBuilder): WakuConfBuilder =
|
||||
WakuConfBuilder(
|
||||
@ -191,74 +190,74 @@ proc init*(T: type WakuConfBuilder): WakuConfBuilder =
|
||||
proc withNetworkPresetConf*(
|
||||
b: var WakuConfBuilder, networkPresetConf: NetworkPresetConf
|
||||
) =
|
||||
b.networkPresetConf = some(networkPresetConf)
|
||||
b.networkPresetConf = Opt.some(networkPresetConf)
|
||||
|
||||
proc withNodeKey*(b: var WakuConfBuilder, nodeKey: crypto.PrivateKey) =
|
||||
b.nodeKey = some(nodeKey)
|
||||
b.nodeKey = Opt.some(nodeKey)
|
||||
|
||||
proc withClusterId*(b: var WakuConfBuilder, clusterId: uint16) =
|
||||
b.clusterId = some(clusterId)
|
||||
b.clusterId = Opt.some(clusterId)
|
||||
|
||||
proc withShardingConf*(b: var WakuConfBuilder, shardingConf: ShardingConfKind) =
|
||||
b.shardingConf = some(shardingConf)
|
||||
b.shardingConf = Opt.some(shardingConf)
|
||||
|
||||
proc withNumShardsInCluster*(b: var WakuConfBuilder, numShardsInCluster: uint16) =
|
||||
b.numShardsInCluster = some(numShardsInCluster)
|
||||
b.numShardsInCluster = Opt.some(numShardsInCluster)
|
||||
|
||||
proc withSubscribeShards*(b: var WakuConfBuilder, shards: seq[uint16]) =
|
||||
b.subscribeShards = some(shards)
|
||||
b.subscribeShards = Opt.some(shards)
|
||||
|
||||
proc withProtectedShards*(
|
||||
b: var WakuConfBuilder, protectedShards: seq[ProtectedShard]
|
||||
) =
|
||||
b.protectedShards = some(protectedShards)
|
||||
b.protectedShards = Opt.some(protectedShards)
|
||||
|
||||
proc withContentTopics*(b: var WakuConfBuilder, contentTopics: seq[string]) =
|
||||
b.contentTopics = some(contentTopics)
|
||||
b.contentTopics = Opt.some(contentTopics)
|
||||
|
||||
proc withRelay*(b: var WakuConfBuilder, relay: bool) =
|
||||
b.relay = some(relay)
|
||||
b.relay = Opt.some(relay)
|
||||
|
||||
proc withLightPush*(b: var WakuConfBuilder, lightPush: bool) =
|
||||
b.lightPush = some(lightPush)
|
||||
b.lightPush = Opt.some(lightPush)
|
||||
|
||||
proc withStoreSync*(b: var WakuConfBuilder, storeSync: bool) =
|
||||
b.storeSync = some(storeSync)
|
||||
b.storeSync = Opt.some(storeSync)
|
||||
|
||||
proc withPeerExchange*(b: var WakuConfBuilder, peerExchange: bool) =
|
||||
b.peerExchange = some(peerExchange)
|
||||
b.peerExchange = Opt.some(peerExchange)
|
||||
|
||||
proc withRelayPeerExchange*(b: var WakuConfBuilder, relayPeerExchange: bool) =
|
||||
b.relayPeerExchange = some(relayPeerExchange)
|
||||
b.relayPeerExchange = Opt.some(relayPeerExchange)
|
||||
|
||||
proc withRendezvous*(b: var WakuConfBuilder, rendezvous: bool) =
|
||||
b.rendezvous = some(rendezvous)
|
||||
b.rendezvous = Opt.some(rendezvous)
|
||||
|
||||
proc withMix*(builder: var WakuConfBuilder, mix: bool) =
|
||||
builder.mix = some(mix)
|
||||
builder.mix = Opt.some(mix)
|
||||
|
||||
proc withRemoteStoreNode*(b: var WakuConfBuilder, remoteStoreNode: string) =
|
||||
b.remoteStoreNode = some(remoteStoreNode)
|
||||
b.remoteStoreNode = Opt.some(remoteStoreNode)
|
||||
|
||||
proc withRemoteLightPushNode*(b: var WakuConfBuilder, remoteLightPushNode: string) =
|
||||
b.remoteLightPushNode = some(remoteLightPushNode)
|
||||
b.remoteLightPushNode = Opt.some(remoteLightPushNode)
|
||||
|
||||
proc withRemoteFilterNode*(b: var WakuConfBuilder, remoteFilterNode: string) =
|
||||
b.remoteFilterNode = some(remoteFilterNode)
|
||||
b.remoteFilterNode = Opt.some(remoteFilterNode)
|
||||
|
||||
proc withRemotePeerExchangeNode*(
|
||||
b: var WakuConfBuilder, remotePeerExchangeNode: string
|
||||
) =
|
||||
b.remotePeerExchangeNode = some(remotePeerExchangeNode)
|
||||
b.remotePeerExchangeNode = Opt.some(remotePeerExchangeNode)
|
||||
|
||||
proc withPeerPersistence*(b: var WakuConfBuilder, peerPersistence: bool) =
|
||||
b.peerPersistence = some(peerPersistence)
|
||||
b.peerPersistence = Opt.some(peerPersistence)
|
||||
|
||||
proc withPeerStoreCapacity*(b: var WakuConfBuilder, peerStoreCapacity: int) =
|
||||
b.peerStoreCapacity = some(peerStoreCapacity)
|
||||
b.peerStoreCapacity = Opt.some(peerStoreCapacity)
|
||||
|
||||
proc withMaxConnections*(b: var WakuConfBuilder, maxConnections: int) =
|
||||
b.maxConnections = some(maxConnections)
|
||||
b.maxConnections = Opt.some(maxConnections)
|
||||
|
||||
proc withDnsAddrsNameServers*(
|
||||
b: var WakuConfBuilder, dnsAddrsNameServers: seq[IpAddress]
|
||||
@ -266,51 +265,51 @@ proc withDnsAddrsNameServers*(
|
||||
b.dnsAddrsNameServers.insert(dnsAddrsNameServers)
|
||||
|
||||
proc withLogLevel*(b: var WakuConfBuilder, logLevel: logging.LogLevel) =
|
||||
b.logLevel = some(logLevel)
|
||||
b.logLevel = Opt.some(logLevel)
|
||||
|
||||
proc withLogFormat*(b: var WakuConfBuilder, logFormat: logging.LogFormat) =
|
||||
b.logFormat = some(logFormat)
|
||||
b.logFormat = Opt.some(logFormat)
|
||||
|
||||
proc withP2pTcpPort*(b: var WakuConfBuilder, p2pTcpPort: Port) =
|
||||
b.p2pTcpPort = some(p2pTcpPort)
|
||||
b.p2pTcpPort = Opt.some(p2pTcpPort)
|
||||
|
||||
proc withP2pTcpPort*(b: var WakuConfBuilder, p2pTcpPort: uint16) =
|
||||
b.p2pTcpPort = some(Port(p2pTcpPort))
|
||||
b.p2pTcpPort = Opt.some(Port(p2pTcpPort))
|
||||
|
||||
proc withPortsShift*(b: var WakuConfBuilder, portsShift: uint16) =
|
||||
b.portsShift = some(portsShift)
|
||||
b.portsShift = Opt.some(portsShift)
|
||||
|
||||
proc withP2pListenAddress*(b: var WakuConfBuilder, p2pListenAddress: IpAddress) =
|
||||
b.p2pListenAddress = some(p2pListenAddress)
|
||||
b.p2pListenAddress = Opt.some(p2pListenAddress)
|
||||
|
||||
proc withExtMultiAddrsOnly*(b: var WakuConfBuilder, extMultiAddrsOnly: bool) =
|
||||
b.extMultiAddrsOnly = some(extMultiAddrsOnly)
|
||||
b.extMultiAddrsOnly = Opt.some(extMultiAddrsOnly)
|
||||
|
||||
proc withDns4DomainName*(b: var WakuConfBuilder, dns4DomainName: string) =
|
||||
b.dns4DomainName = some(dns4DomainName)
|
||||
b.dns4DomainName = Opt.some(dns4DomainName)
|
||||
|
||||
proc withNatStrategy*(b: var WakuConfBuilder, natStrategy: string) =
|
||||
b.natStrategy = some(natStrategy)
|
||||
b.natStrategy = Opt.some(natStrategy)
|
||||
|
||||
proc withAgentString*(b: var WakuConfBuilder, agentString: string) =
|
||||
b.agentString = some(agentString)
|
||||
b.agentString = Opt.some(agentString)
|
||||
|
||||
proc withColocationLimit*(b: var WakuConfBuilder, colocationLimit: int) =
|
||||
b.colocationLimit = some(colocationLimit)
|
||||
b.colocationLimit = Opt.some(colocationLimit)
|
||||
|
||||
proc withRelayServiceRatio*(b: var WakuConfBuilder, relayServiceRatio: string) =
|
||||
b.relayServiceRatio = some(relayServiceRatio)
|
||||
b.relayServiceRatio = Opt.some(relayServiceRatio)
|
||||
|
||||
proc withCircuitRelayClient*(b: var WakuConfBuilder, circuitRelayClient: bool) =
|
||||
b.circuitRelayClient = some(circuitRelayClient)
|
||||
b.circuitRelayClient = Opt.some(circuitRelayClient)
|
||||
|
||||
proc withRelayShardedPeerManagement*(
|
||||
b: var WakuConfBuilder, relayShardedPeerManagement: bool
|
||||
) =
|
||||
b.relayShardedPeerManagement = some(relayShardedPeerManagement)
|
||||
b.relayShardedPeerManagement = Opt.some(relayShardedPeerManagement)
|
||||
|
||||
proc withLocalStoragePath*(b: var WakuConfBuilder, localStoragePath: string) =
|
||||
b.localStoragePath = some(localStoragePath)
|
||||
b.localStoragePath = Opt.some(localStoragePath)
|
||||
|
||||
proc withExtMultiAddrs*(builder: var WakuConfBuilder, extMultiAddrs: seq[string]) =
|
||||
builder.extMultiAddrs = concat(builder.extMultiAddrs, extMultiAddrs)
|
||||
@ -339,9 +338,9 @@ proc nodeKey(
|
||||
return ok(nodeKey)
|
||||
|
||||
proc buildShardingConf(
|
||||
bShardingConfKind: Option[ShardingConfKind],
|
||||
bNumShardsInCluster: Option[uint16],
|
||||
bSubscribeShards: Option[seq[uint16]],
|
||||
bShardingConfKind: Opt[ShardingConfKind],
|
||||
bNumShardsInCluster: Opt[uint16],
|
||||
bSubscribeShards: Opt[seq[uint16]],
|
||||
): (ShardingConf, seq[uint16]) =
|
||||
case bShardingConfKind.get(DefaultShardingConfKind)
|
||||
of StaticSharding:
|
||||
@ -354,7 +353,7 @@ proc buildShardingConf(
|
||||
(shardingConf, bSubscribeShards.get(toSeq(0.uint16 .. upperShard)))
|
||||
|
||||
template checkSetPresetValueToField[T](
|
||||
field: var Option[T], presetVal: T, msg: static string
|
||||
field: var Opt[T], presetVal: T, msg: static string
|
||||
) =
|
||||
## Set the field to the preset's value, unless the field is already set
|
||||
## (explicit wins). Warn iff the field's existing value differs from the
|
||||
@ -364,7 +363,7 @@ template checkSetPresetValueToField[T](
|
||||
if field.get() != presetVal:
|
||||
warn msg, used = field.get(), discarded = presetVal
|
||||
else:
|
||||
field = some(presetVal)
|
||||
field = Opt.some(presetVal)
|
||||
|
||||
proc checkAddPresetValueToField[T](field: var seq[T], presetVals: seq[T]) =
|
||||
## Append the preset's list values to the field's existing list. Lists
|
||||
@ -481,7 +480,7 @@ proc applyNetworkPresetConf(builder: var WakuConfBuilder) =
|
||||
warn "Failed to process entry nodes from network conf", error = processed.error()
|
||||
|
||||
proc rejectOverride[T](
|
||||
field: Option[T], presetValue: T, msg: string
|
||||
field: Opt[T], presetValue: T, msg: string
|
||||
): Result[void, string] =
|
||||
## Errors with `msg` if `field` is set to anything other than the preset's value.
|
||||
if field.isSome() and field.get() != presetValue:
|
||||
@ -702,11 +701,11 @@ proc build*(
|
||||
if builder.dns4DomainName.isSome():
|
||||
let d = builder.dns4DomainName.get()
|
||||
if d.string != "":
|
||||
some(d)
|
||||
Opt.some(d)
|
||||
else:
|
||||
none(string)
|
||||
Opt.none(string)
|
||||
else:
|
||||
none(string)
|
||||
Opt.none(string)
|
||||
|
||||
var extMultiAddrs: seq[MultiAddress] = @[]
|
||||
for s in builder.extMultiAddrs:
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import chronicles, std/[net, options], results
|
||||
import chronicles, std/net, results
|
||||
import logos_delivery/waku/factory/waku_conf
|
||||
|
||||
logScope:
|
||||
@ -13,45 +13,45 @@ const
|
||||
## WebSocket Config Builder ##
|
||||
##############################
|
||||
type WebSocketConfBuilder* = object
|
||||
enabled*: Option[bool]
|
||||
webSocketPort*: Option[Port]
|
||||
secureEnabled*: Option[bool]
|
||||
keyPath*: Option[string]
|
||||
certPath*: Option[string]
|
||||
enabled*: Opt[bool]
|
||||
webSocketPort*: Opt[Port]
|
||||
secureEnabled*: Opt[bool]
|
||||
keyPath*: Opt[string]
|
||||
certPath*: Opt[string]
|
||||
|
||||
proc init*(T: type WebSocketConfBuilder): WebSocketConfBuilder =
|
||||
WebSocketConfBuilder()
|
||||
|
||||
proc withEnabled*(b: var WebSocketConfBuilder, enabled: bool) =
|
||||
b.enabled = some(enabled)
|
||||
b.enabled = Opt.some(enabled)
|
||||
|
||||
proc withSecureEnabled*(b: var WebSocketConfBuilder, secureEnabled: bool) =
|
||||
b.secureEnabled = some(secureEnabled)
|
||||
b.secureEnabled = Opt.some(secureEnabled)
|
||||
if b.secureEnabled.get():
|
||||
b.enabled = some(true) # ws must be enabled to use wss
|
||||
b.enabled = Opt.some(true) # ws must be enabled to use wss
|
||||
|
||||
proc withWebSocketPort*(b: var WebSocketConfBuilder, webSocketPort: Port) =
|
||||
b.webSocketPort = some(webSocketPort)
|
||||
b.webSocketPort = Opt.some(webSocketPort)
|
||||
|
||||
proc withWebSocketPort*(b: var WebSocketConfBuilder, webSocketPort: uint16) =
|
||||
b.webSocketPort = some(Port(webSocketPort))
|
||||
b.webSocketPort = Opt.some(Port(webSocketPort))
|
||||
|
||||
proc withKeyPath*(b: var WebSocketConfBuilder, keyPath: string) =
|
||||
b.keyPath = some(keyPath)
|
||||
b.keyPath = Opt.some(keyPath)
|
||||
|
||||
proc withCertPath*(b: var WebSocketConfBuilder, certPath: string) =
|
||||
b.certPath = some(certPath)
|
||||
b.certPath = Opt.some(certPath)
|
||||
|
||||
proc build*(b: WebSocketConfBuilder): Result[Option[WebSocketConf], string] =
|
||||
proc build*(b: WebSocketConfBuilder): Result[Opt[WebSocketConf], string] =
|
||||
if not b.enabled.get(DefaultWebSocketEnabled):
|
||||
return ok(none(WebSocketConf))
|
||||
return ok(Opt.none(WebSocketConf))
|
||||
|
||||
if not b.secureEnabled.get(DefaultWebSocketSecureEnabled):
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
WebSocketConf(
|
||||
port: b.webSocketPort.get(DefaultWebSocketPort),
|
||||
secureConf: none(WebSocketSecureConf),
|
||||
secureConf: Opt.none(WebSocketSecureConf),
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -62,10 +62,10 @@ proc build*(b: WebSocketConfBuilder): Result[Option[WebSocketConf], string] =
|
||||
return err("WebSocketSecure enabled but cert path is not specified")
|
||||
|
||||
return ok(
|
||||
some(
|
||||
Opt.some(
|
||||
WebSocketConf(
|
||||
port: b.webSocketPort.get(DefaultWebSocketPort),
|
||||
secureConf: some(
|
||||
secureConf: Opt.some(
|
||||
WebSocketSecureConf(keyPath: b.keyPath.get(), certPath: b.certPath.get())
|
||||
),
|
||||
)
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import
|
||||
chronicles,
|
||||
chronos,
|
||||
@ -6,7 +5,7 @@ import
|
||||
libp2p/crypto/curve25519,
|
||||
libp2p/multiaddress,
|
||||
libp2p/nameresolving/dnsresolver,
|
||||
std/[options, sequtils, net],
|
||||
std/[sequtils, net],
|
||||
results
|
||||
|
||||
import
|
||||
@ -85,9 +84,9 @@ proc dnsResolve*(
|
||||
proc networkConfiguration*(
|
||||
clusterId: uint16,
|
||||
conf: EndpointConf,
|
||||
discv5Conf: Option[Discv5Conf],
|
||||
webSocketConf: Option[WebSocketConf],
|
||||
quicConf: Option[QuicConf],
|
||||
discv5Conf: Opt[Discv5Conf],
|
||||
webSocketConf: Opt[WebSocketConf],
|
||||
quicConf: Opt[QuicConf],
|
||||
wakuFlags: CapabilitiesBitfield,
|
||||
dnsAddrsNameServers: seq[IpAddress],
|
||||
clientId: string,
|
||||
@ -97,9 +96,9 @@ proc networkConfiguration*(
|
||||
let (quicEnabled, quicBindPort) =
|
||||
if quicConf.isSome():
|
||||
let qConf = quicConf.get()
|
||||
(true, some(qConf.port))
|
||||
(true, Opt.some(qConf.port))
|
||||
else:
|
||||
(false, none(Port))
|
||||
(false, Opt.none(Port))
|
||||
|
||||
# NAT-map the QUIC UDP port (placeholder when QUIC off)
|
||||
var (extIp, extTcpPort, extUdpPort) = setupNat(
|
||||
@ -110,9 +109,9 @@ proc networkConfiguration*(
|
||||
let
|
||||
discv5UdpPort =
|
||||
if discv5Conf.isSome():
|
||||
some(discv5Conf.get().udpPort)
|
||||
Opt.some(discv5Conf.get().udpPort)
|
||||
else:
|
||||
none(Port)
|
||||
Opt.none(Port)
|
||||
|
||||
## TODO: the NAT setup assumes a manual port mapping configuration if extIp
|
||||
## config is set. This probably implies adding manual config item for
|
||||
@ -120,7 +119,7 @@ proc networkConfiguration*(
|
||||
## manual config, the external port is the same as the bind port.
|
||||
extPort =
|
||||
if (extIp.isSome() or conf.dns4DomainName.isSome()) and extTcpPort.isNone():
|
||||
some(tcpBindPort)
|
||||
Opt.some(tcpBindPort)
|
||||
else:
|
||||
extTcpPort
|
||||
|
||||
@ -136,7 +135,7 @@ proc networkConfiguration*(
|
||||
let dns = (await dnsResolve(conf.dns4DomainName.get(), dnsAddrsNameServers)).valueOr:
|
||||
return err($error) # Pass error down the stack
|
||||
|
||||
extIp = some(parseIpAddress(dns))
|
||||
extIp = Opt.some(parseIpAddress(dns))
|
||||
except CatchableError:
|
||||
return
|
||||
err("Could not update extIp to resolved DNS IP: " & getCurrentExceptionMsg())
|
||||
@ -144,9 +143,9 @@ proc networkConfiguration*(
|
||||
let (wsEnabled, wsBindPort, wssEnabled) =
|
||||
if webSocketConf.isSome:
|
||||
let wsConf = webSocketConf.get()
|
||||
(true, some(wsConf.port), wsConf.secureConf.isSome)
|
||||
(true, Opt.some(wsConf.port), wsConf.secureConf.isSome)
|
||||
else:
|
||||
(false, none(Port), false)
|
||||
(false, Opt.none(Port), false)
|
||||
|
||||
# Wrap in none because NetConfig does not have a default constructor
|
||||
# TODO: We could change bindIp in NetConfig to be something less restrictive
|
||||
@ -167,7 +166,7 @@ proc networkConfiguration*(
|
||||
extQuicPort = extQuicPort,
|
||||
dns4DomainName = conf.dns4DomainName,
|
||||
discv5UdpPort = discv5UdpPort,
|
||||
wakuFlags = some(wakuFlags),
|
||||
wakuFlags = Opt.some(wakuFlags),
|
||||
dnsNameServers = dnsAddrsNameServers,
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import
|
||||
std/[options, sequtils],
|
||||
results,
|
||||
std/sequtils,
|
||||
chronicles,
|
||||
chronos,
|
||||
libp2p/peerid,
|
||||
@ -44,7 +44,7 @@ import
|
||||
## Peer persistence
|
||||
|
||||
const PeerPersistenceDbUrl = "peers.db"
|
||||
proc setupPeerStorage(): Result[Option[WakuPeerStorage], string] =
|
||||
proc setupPeerStorage(): Result[Opt[WakuPeerStorage], string] =
|
||||
let db = ?SqliteDatabase.new(PeerPersistenceDbUrl)
|
||||
|
||||
?peer_store_sqlite_migrations.migrate(db)
|
||||
@ -52,7 +52,7 @@ proc setupPeerStorage(): Result[Option[WakuPeerStorage], string] =
|
||||
let res = WakuPeerStorage.new(db).valueOr:
|
||||
return err("failed to init peer store" & error)
|
||||
|
||||
return ok(some(res))
|
||||
return ok(Opt.some(res))
|
||||
|
||||
## Init waku node instance
|
||||
|
||||
@ -61,7 +61,7 @@ proc initNode(
|
||||
netConfig: NetConfig,
|
||||
rng: crypto.Rng,
|
||||
record: enr.Record,
|
||||
peerStore: Option[WakuPeerStorage],
|
||||
peerStore: Opt[WakuPeerStorage],
|
||||
relay: Relay,
|
||||
dynamicBootstrapNodes: openArray[RemotePeerInfo] = @[],
|
||||
): Result[WakuNode, string] =
|
||||
@ -78,9 +78,9 @@ proc initNode(
|
||||
let (secureKey, secureCert) =
|
||||
if conf.webSocketConf.isSome() and conf.webSocketConf.get().secureConf.isSome():
|
||||
let wssConf = conf.webSocketConf.get().secureConf.get()
|
||||
(some(wssConf.keyPath), some(wssConf.certPath))
|
||||
(Opt.some(wssConf.keyPath), Opt.some(wssConf.certPath))
|
||||
else:
|
||||
(none(string), none(string))
|
||||
(Opt.none(string), Opt.none(string))
|
||||
|
||||
let nameResolver =
|
||||
DnsResolver.new(conf.dnsAddrsNameServers.mapIt(initTAddress(it, Port(53))))
|
||||
@ -93,13 +93,13 @@ proc initNode(
|
||||
builder.withNetworkConfiguration(netConfig)
|
||||
builder.withPeerStorage(pStorage, capacity = conf.peerStoreCapacity)
|
||||
builder.withSwitchConfiguration(
|
||||
maxConnections = some(conf.maxConnections.int),
|
||||
maxConnections = Opt.some(conf.maxConnections.int),
|
||||
secureKey = secureKey,
|
||||
secureCert = secureCert,
|
||||
nameResolver = nameResolver,
|
||||
sendSignedPeerRecord = conf.relayPeerExchange,
|
||||
# We send our own signed peer record when peer exchange enabled
|
||||
agentString = some(conf.agentString),
|
||||
agentString = Opt.some(conf.agentString),
|
||||
)
|
||||
builder.withColocationLimit(conf.colocationLimit)
|
||||
|
||||
@ -252,7 +252,7 @@ proc setupProtocols(
|
||||
warn("Auto sharding is disabled")
|
||||
|
||||
# Mount relay on all nodes
|
||||
var peerExchangeHandler = none(RoutingRecordsHandler)
|
||||
var peerExchangeHandler = Opt.none(RoutingRecordsHandler)
|
||||
if conf.relayPeerExchange:
|
||||
proc handlePeerExchange(
|
||||
peer: PeerId, topic: string, peers: seq[RoutingRecordsPair]
|
||||
@ -270,7 +270,7 @@ proc setupProtocols(
|
||||
# Peers added are filtered by the peer manager
|
||||
node.peerManager.addPeer(peer, PeerOrigin.PeerExchange)
|
||||
|
||||
peerExchangeHandler = some(handlePeerExchange)
|
||||
peerExchangeHandler = Opt.some(handlePeerExchange)
|
||||
|
||||
# TODO: when using autosharding, the user should not be expected to pass any shards, but only content topics
|
||||
# Hence, this joint logic should be removed in favour of an either logic:
|
||||
@ -388,7 +388,7 @@ proc setupProtocols(
|
||||
if conf.peerExchangeService:
|
||||
try:
|
||||
await mountPeerExchange(
|
||||
node, some(conf.clusterId), node.rateLimitSettings.getSetting(PEEREXCHG)
|
||||
node, Opt.some(conf.clusterId), node.rateLimitSettings.getSetting(PEEREXCHG)
|
||||
)
|
||||
except CatchableError:
|
||||
return
|
||||
@ -479,7 +479,7 @@ proc setupNode*(
|
||||
info "Setting up storage"
|
||||
|
||||
## Peer persistence
|
||||
var peerStore: Option[WakuPeerStorage]
|
||||
var peerStore: Opt[WakuPeerStorage]
|
||||
if wakuConf.peerPersistence:
|
||||
peerStore = setupPeerStorage().valueOr:
|
||||
error "Setting up storage failed", error = "failed to setup peer store " & error
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/[net, options, strutils],
|
||||
std/[net, strutils],
|
||||
chronicles,
|
||||
chronos,
|
||||
libp2p/crypto/crypto,
|
||||
@ -36,7 +36,7 @@ type WebSocketSecureConf* {.requiresInit.} = object
|
||||
|
||||
type WebSocketConf* = object
|
||||
port*: Port
|
||||
secureConf*: Option[WebSocketSecureConf]
|
||||
secureConf*: Opt[WebSocketSecureConf]
|
||||
|
||||
type QuicConf* = object
|
||||
port*: Port
|
||||
@ -61,14 +61,14 @@ type MixConf* = ref object
|
||||
mixPubKey*: Curve25519Key
|
||||
mixnodes*: seq[MixNodePubInfo]
|
||||
|
||||
type StoreServiceConf* {.requiresInit.} = object
|
||||
type StoreServiceConf* = object
|
||||
dbMigration*: bool
|
||||
dbURl*: string
|
||||
dbVacuum*: bool
|
||||
maxNumDbConnections*: int
|
||||
retentionPolicies*: seq[string]
|
||||
resume*: bool
|
||||
storeSyncConf*: Option[StoreSyncConf]
|
||||
storeSyncConf*: Opt[StoreSyncConf]
|
||||
|
||||
type FilterServiceConf* {.requiresInit.} = object
|
||||
maxPeersToServe*: uint32
|
||||
@ -78,7 +78,7 @@ type FilterServiceConf* {.requiresInit.} = object
|
||||
type EndpointConf* = object # TODO: make enum
|
||||
natStrategy*: string
|
||||
p2pTcpPort*: Port
|
||||
dns4DomainName*: Option[string]
|
||||
dns4DomainName*: Opt[string]
|
||||
p2pListenAddress*: IpAddress
|
||||
extMultiAddrs*: seq[MultiAddress]
|
||||
extMultiAddrsOnly*: bool
|
||||
@ -87,7 +87,7 @@ type EndpointConf* = object # TODO: make enum
|
||||
## All information needed by a waku node should be contained
|
||||
## In this object. A convenient `validate` method enables doing
|
||||
## sanity checks beyond type enforcement.
|
||||
## If `Option` is `some` it means the related protocol is enabled.
|
||||
## If `Opt` is `some` it means the related protocol is enabled.
|
||||
type WakuConf* {.requiresInit.} = ref object
|
||||
# ref because `getRunningNetConfig` modifies it
|
||||
nodeKey*: crypto.PrivateKey
|
||||
@ -109,17 +109,17 @@ type WakuConf* {.requiresInit.} = ref object
|
||||
rendezvous*: bool
|
||||
circuitRelayClient*: bool
|
||||
|
||||
discv5Conf*: Option[Discv5Conf]
|
||||
dnsDiscoveryConf*: Option[DnsDiscoveryConf]
|
||||
filterServiceConf*: Option[FilterServiceConf]
|
||||
storeServiceConf*: Option[StoreServiceConf]
|
||||
rlnRelayConf*: Option[RlnConf]
|
||||
restServerConf*: Option[RestServerConf]
|
||||
metricsServerConf*: Option[MetricsServerConf]
|
||||
webSocketConf*: Option[WebSocketConf]
|
||||
quicConf*: Option[QuicConf]
|
||||
mixConf*: Option[MixConf]
|
||||
kademliaDiscoveryConf*: Option[KademliaDiscoveryConf]
|
||||
discv5Conf*: Opt[Discv5Conf]
|
||||
dnsDiscoveryConf*: Opt[DnsDiscoveryConf]
|
||||
filterServiceConf*: Opt[FilterServiceConf]
|
||||
storeServiceConf*: Opt[StoreServiceConf]
|
||||
rlnRelayConf*: Opt[RlnConf]
|
||||
restServerConf*: Opt[RestServerConf]
|
||||
metricsServerConf*: Opt[MetricsServerConf]
|
||||
webSocketConf*: Opt[WebSocketConf]
|
||||
quicConf*: Opt[QuicConf]
|
||||
mixConf*: Opt[MixConf]
|
||||
kademliaDiscoveryConf*: Opt[KademliaDiscoveryConf]
|
||||
|
||||
dnsAddrsNameServers*: seq[IpAddress]
|
||||
endpointConf*: EndpointConf
|
||||
@ -127,10 +127,10 @@ type WakuConf* {.requiresInit.} = ref object
|
||||
|
||||
# TODO: could probably make it a `PeerRemoteInfo`
|
||||
staticNodes*: seq[string]
|
||||
remoteStoreNode*: Option[string]
|
||||
remoteLightPushNode*: Option[string]
|
||||
remoteFilterNode*: Option[string]
|
||||
remotePeerExchangeNode*: Option[string]
|
||||
remoteStoreNode*: Opt[string]
|
||||
remoteLightPushNode*: Opt[string]
|
||||
remoteFilterNode*: Opt[string]
|
||||
remotePeerExchangeNode*: Opt[string]
|
||||
|
||||
maxMessageSizeBytes*: uint64
|
||||
|
||||
@ -139,7 +139,7 @@ type WakuConf* {.requiresInit.} = ref object
|
||||
|
||||
peerPersistence*: bool
|
||||
# TODO: should clearly be a uint
|
||||
peerStoreCapacity*: Option[int]
|
||||
peerStoreCapacity*: Opt[int]
|
||||
# TODO: should clearly be a uint
|
||||
maxConnections*: int
|
||||
|
||||
@ -150,7 +150,7 @@ type WakuConf* {.requiresInit.} = ref object
|
||||
rateLimit*: ProtocolRateLimitSettings
|
||||
|
||||
# TODO: those could be in a relay conf object
|
||||
maxRelayPeers*: Option[int]
|
||||
maxRelayPeers*: Opt[int]
|
||||
relayShardedPeerManagement*: bool
|
||||
# TODO: use proper type
|
||||
relayServiceRatio*: string
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import std/options
|
||||
import results
|
||||
|
||||
import logos_delivery/waku/incentivization/rpc
|
||||
|
||||
proc init*(T: type EligibilityStatus, isEligible: bool): T =
|
||||
if isEligible:
|
||||
EligibilityStatus(statusCode: uint32(200), statusDesc: some("OK"))
|
||||
EligibilityStatus(statusCode: uint32(200), statusDesc: Opt.some("OK"))
|
||||
else:
|
||||
EligibilityStatus(statusCode: uint32(402), statusDesc: some("Payment Required"))
|
||||
EligibilityStatus(statusCode: uint32(402), statusDesc: Opt.some("Payment Required"))
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
import std/[options, sets], chronos, web3, stew/byteutils, stint, results, chronicles
|
||||
import std/sets, chronos, web3, stew/byteutils, stint, results
|
||||
|
||||
import chronicles
|
||||
|
||||
import logos_delivery/waku/incentivization/rpc, tests/waku_rln_relay/utils_onchain
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import tables, std/options
|
||||
import results, tables
|
||||
import ../waku_lightpush_legacy/rpc
|
||||
|
||||
type
|
||||
@ -8,26 +8,24 @@ type
|
||||
BadResponse
|
||||
GoodResponse
|
||||
|
||||
# Encode reputation indicator as Option[bool]:
|
||||
# some(true) => GoodRep
|
||||
# some(false) => BadRep
|
||||
# none(bool) => unknown / not set
|
||||
# Encode reputation indicator as Opt[bool]:
|
||||
# Opt.some(true) => GoodRep
|
||||
# Opt.some(false) => BadRep
|
||||
# Opt.none(bool) => unknown / not set
|
||||
ReputationManager* = ref object
|
||||
reputationOf*: Table[PeerId, Option[bool]]
|
||||
reputationOf*: Table[PeerId, Opt[bool]]
|
||||
|
||||
proc init*(T: type ReputationManager): ReputationManager =
|
||||
return ReputationManager(reputationOf: initTable[PeerId, Option[bool]]())
|
||||
return ReputationManager(reputationOf: initTable[PeerId, Opt[bool]]())
|
||||
|
||||
proc setReputation*(
|
||||
manager: var ReputationManager, peer: PeerId, repValue: Option[bool]
|
||||
) =
|
||||
proc setReputation*(manager: var ReputationManager, peer: PeerId, repValue: Opt[bool]) =
|
||||
manager.reputationOf[peer] = repValue
|
||||
|
||||
proc getReputation*(manager: ReputationManager, peer: PeerId): Option[bool] =
|
||||
proc getReputation*(manager: ReputationManager, peer: PeerId): Opt[bool] =
|
||||
if peer in manager.reputationOf:
|
||||
result = manager.reputationOf[peer]
|
||||
else:
|
||||
result = none(bool)
|
||||
result = Opt.none(bool)
|
||||
|
||||
# Evaluate the quality of a PushResponse by checking its isSuccess field
|
||||
proc evaluateResponse*(response: PushResponse): ResponseQuality =
|
||||
@ -43,6 +41,6 @@ proc updateReputationFromResponse*(
|
||||
let respQuality = evaluateResponse(response)
|
||||
case respQuality
|
||||
of BadResponse:
|
||||
manager.setReputation(peer, some(false)) # false => BadRep
|
||||
manager.setReputation(peer, Opt.some(false)) # false => BadRep
|
||||
of GoodResponse:
|
||||
manager.setReputation(peer, some(true)) # true => GoodRep
|
||||
manager.setReputation(peer, Opt.some(true)) # true => GoodRep
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import std/options
|
||||
import results
|
||||
|
||||
# Implementing the RFC:
|
||||
# https://github.com/vacp2p/rfc/tree/master/content/docs/rfcs/73
|
||||
|
||||
type
|
||||
EligibilityProof* = object
|
||||
proofOfPayment*: Option[seq[byte]]
|
||||
proofOfPayment*: Opt[seq[byte]]
|
||||
|
||||
EligibilityStatus* = object
|
||||
statusCode*: uint32
|
||||
statusDesc*: Option[string]
|
||||
statusDesc*: Opt[string]
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import std/options
|
||||
import ../common/protobuf, ./rpc
|
||||
import results, ../common/protobuf, ./rpc
|
||||
|
||||
# Codec for EligibilityProof
|
||||
|
||||
@ -18,9 +17,9 @@ proc decode*(T: type EligibilityProof, buffer: seq[byte]): ProtobufResult[T] =
|
||||
var epRpc = EligibilityProof()
|
||||
var proofOfPayment = newSeq[byte]()
|
||||
if not ?pb.getField(1, proofOfPayment):
|
||||
epRpc.proofOfPayment = none(seq[byte])
|
||||
epRpc.proofOfPayment = Opt.none(seq[byte])
|
||||
else:
|
||||
epRpc.proofOfPayment = some(proofOfPayment)
|
||||
epRpc.proofOfPayment = Opt.some(proofOfPayment)
|
||||
ok(epRpc)
|
||||
|
||||
# Codec for EligibilityStatus
|
||||
@ -45,7 +44,7 @@ proc decode*(T: type EligibilityStatus, buffer: seq[byte]): ProtobufResult[T] =
|
||||
# status description
|
||||
var description = ""
|
||||
if not ?pb.getField(2, description):
|
||||
esRpc.statusDesc = none(string)
|
||||
esRpc.statusDesc = Opt.none(string)
|
||||
else:
|
||||
esRpc.statusDesc = some(description)
|
||||
esRpc.statusDesc = Opt.some(description)
|
||||
ok(esRpc)
|
||||
|
||||
@ -1,31 +1,28 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, sequtils, strutils, net],
|
||||
results,
|
||||
libp2p/[multiaddress, multicodec, wire]
|
||||
import std/[sequtils, strutils, net], results, libp2p/[multiaddress, multicodec, wire]
|
||||
import ../../waku/waku_core/peers
|
||||
import ../waku_enr
|
||||
|
||||
type NetConfig* = object
|
||||
hostAddress*: MultiAddress
|
||||
clusterId*: uint16
|
||||
wsHostAddress*: Option[MultiAddress]
|
||||
quicHostAddress*: Option[MultiAddress]
|
||||
hostExtAddress*: Option[MultiAddress]
|
||||
wsExtAddress*: Option[MultiAddress]
|
||||
wsHostAddress*: Opt[MultiAddress]
|
||||
quicHostAddress*: Opt[MultiAddress]
|
||||
hostExtAddress*: Opt[MultiAddress]
|
||||
wsExtAddress*: Opt[MultiAddress]
|
||||
wssEnabled*: bool
|
||||
extIp*: Option[IpAddress]
|
||||
extPort*: Option[Port]
|
||||
dns4DomainName*: Option[string]
|
||||
extIp*: Opt[IpAddress]
|
||||
extPort*: Opt[Port]
|
||||
dns4DomainName*: Opt[string]
|
||||
dnsNameServers*: seq[IpAddress]
|
||||
announcedAddresses*: seq[MultiAddress]
|
||||
extMultiAddrs*: seq[MultiAddress]
|
||||
enrMultiAddrs*: seq[MultiAddress]
|
||||
enrIp*: Option[IpAddress]
|
||||
enrPort*: Option[Port]
|
||||
discv5UdpPort*: Option[Port]
|
||||
wakuFlags*: Option[CapabilitiesBitfield]
|
||||
enrIp*: Opt[IpAddress]
|
||||
enrPort*: Opt[Port]
|
||||
discv5UdpPort*: Opt[Port]
|
||||
wakuFlags*: Opt[CapabilitiesBitfield]
|
||||
bindIp*: IpAddress
|
||||
bindPort*: Port
|
||||
|
||||
@ -81,24 +78,24 @@ proc isP2pTcpAddress*(ma: MultiAddress): bool =
|
||||
|
||||
proc getPorts*(
|
||||
listenAddrs: seq[MultiAddress]
|
||||
): Result[tuple[tcpPort, websocketPort, quicPort: Option[Port]], string] =
|
||||
var tcpPort, websocketPort, quicPort = none(Port)
|
||||
): Result[tuple[tcpPort, websocketPort, quicPort: Opt[Port]], string] =
|
||||
var tcpPort, websocketPort, quicPort = Opt.none(Port)
|
||||
|
||||
for a in listenAddrs:
|
||||
if a.isWsAddress():
|
||||
if websocketPort.isNone():
|
||||
let wsAddress = initTAddress(a).valueOr:
|
||||
return err("getPorts wsAddr error:" & $error)
|
||||
websocketPort = some(wsAddress.port)
|
||||
websocketPort = Opt.some(wsAddress.port)
|
||||
elif a.isQuicAddress():
|
||||
if quicPort.isNone():
|
||||
let quicAddress = initTAddress(a).valueOr:
|
||||
return err("getPorts quicAddr error:" & $error)
|
||||
quicPort = some(quicAddress.port)
|
||||
quicPort = Opt.some(quicAddress.port)
|
||||
elif tcpPort.isNone():
|
||||
let tcpAddress = initTAddress(a).valueOr:
|
||||
return err("getPorts tcpAddr error:" & $error)
|
||||
tcpPort = some(tcpAddress.port)
|
||||
tcpPort = Opt.some(tcpAddress.port)
|
||||
|
||||
return ok((tcpPort: tcpPort, websocketPort: websocketPort, quicPort: quicPort))
|
||||
|
||||
@ -114,20 +111,20 @@ proc init*(
|
||||
T: type NetConfig,
|
||||
bindIp: IpAddress,
|
||||
bindPort: Port,
|
||||
extIp = none(IpAddress),
|
||||
extPort = none(Port),
|
||||
extIp = Opt.none(IpAddress),
|
||||
extPort = Opt.none(Port),
|
||||
extMultiAddrs = newSeq[MultiAddress](),
|
||||
extMultiAddrsOnly: bool = false,
|
||||
wsBindPort: Option[Port] = some(DefaultWsBindPort),
|
||||
wsBindPort: Opt[Port] = Opt.some(DefaultWsBindPort),
|
||||
wsEnabled: bool = false,
|
||||
wssEnabled: bool = false,
|
||||
quicBindPort = none(Port),
|
||||
quicBindPort = Opt.none(Port),
|
||||
quicEnabled: bool = false,
|
||||
extQuicPort = none(Port),
|
||||
dns4DomainName = none(string),
|
||||
discv5UdpPort = none(Port),
|
||||
extQuicPort = Opt.none(Port),
|
||||
dns4DomainName = Opt.none(string),
|
||||
discv5UdpPort = Opt.none(Port),
|
||||
clusterId: uint16 = 0,
|
||||
wakuFlags = none(CapabilitiesBitfield),
|
||||
wakuFlags = Opt.none(CapabilitiesBitfield),
|
||||
dnsNameServers = @[parseIpAddress("1.1.1.1"), parseIpAddress("1.0.0.1")],
|
||||
): NetConfigResult =
|
||||
## Initialize and validate waku node network configuration
|
||||
@ -135,19 +132,19 @@ proc init*(
|
||||
# Bind addresses
|
||||
let hostAddress = ip4TcpEndPoint(bindIp, bindPort)
|
||||
|
||||
var wsHostAddress = none(MultiAddress)
|
||||
var wsHostAddress = Opt.none(MultiAddress)
|
||||
if wsEnabled or wssEnabled:
|
||||
try:
|
||||
wsHostAddress = some(
|
||||
wsHostAddress = Opt.some(
|
||||
ip4TcpEndPoint(bindIp, wsbindPort.get(DefaultWsBindPort)) & wsFlag(wssEnabled)
|
||||
)
|
||||
except CatchableError:
|
||||
return err(getCurrentExceptionMsg())
|
||||
|
||||
var quicHostAddress = none(MultiAddress)
|
||||
var quicHostAddress = Opt.none(MultiAddress)
|
||||
if quicEnabled:
|
||||
try:
|
||||
quicHostAddress = some(ipQuicEndPoint(bindIp, quicBindPort.get(bindPort)))
|
||||
quicHostAddress = Opt.some(ipQuicEndPoint(bindIp, quicBindPort.get(bindPort)))
|
||||
except CatchableError:
|
||||
return err("failed to initialize quic address: " & getCurrentExceptionMsg())
|
||||
|
||||
@ -155,26 +152,26 @@ proc init*(
|
||||
if extIp.isSome():
|
||||
extIp
|
||||
else:
|
||||
some(bindIp)
|
||||
Opt.some(bindIp)
|
||||
let enrPort =
|
||||
if extPort.isSome():
|
||||
extPort
|
||||
else:
|
||||
some(bindPort)
|
||||
Opt.some(bindPort)
|
||||
|
||||
# Setup external addresses, if available
|
||||
var hostExtAddress, wsExtAddress, quicExtAddress = none(MultiAddress)
|
||||
var hostExtAddress, wsExtAddress, quicExtAddress = Opt.none(MultiAddress)
|
||||
|
||||
if dns4DomainName.isSome():
|
||||
# Use dns4 for externally announced addresses
|
||||
try:
|
||||
hostExtAddress = some(dns4TcpEndPoint(dns4DomainName.get(), extPort.get()))
|
||||
hostExtAddress = Opt.some(dns4TcpEndPoint(dns4DomainName.get(), extPort.get()))
|
||||
except CatchableError:
|
||||
return err(getCurrentExceptionMsg())
|
||||
|
||||
if wsHostAddress.isSome():
|
||||
try:
|
||||
wsExtAddress = some(
|
||||
wsExtAddress = Opt.some(
|
||||
dns4TcpEndPoint(dns4DomainName.get(), wsBindPort.get(DefaultWsBindPort)) &
|
||||
wsFlag(wssEnabled)
|
||||
)
|
||||
@ -183,7 +180,7 @@ proc init*(
|
||||
|
||||
if quicHostAddress.isSome():
|
||||
try:
|
||||
quicExtAddress = some(
|
||||
quicExtAddress = Opt.some(
|
||||
dns4QuicEndPoint(
|
||||
dns4DomainName.get(), extQuicPort.get(quicBindPort.get(bindPort))
|
||||
)
|
||||
@ -193,11 +190,11 @@ proc init*(
|
||||
else:
|
||||
# No public domain name, use ext IP if available
|
||||
if extIp.isSome() and extPort.isSome():
|
||||
hostExtAddress = some(ip4TcpEndPoint(extIp.get(), extPort.get()))
|
||||
hostExtAddress = Opt.some(ip4TcpEndPoint(extIp.get(), extPort.get()))
|
||||
|
||||
if wsHostAddress.isSome():
|
||||
try:
|
||||
wsExtAddress = some(
|
||||
wsExtAddress = Opt.some(
|
||||
ip4TcpEndPoint(extIp.get(), wsBindPort.get(DefaultWsBindPort)) &
|
||||
wsFlag(wssEnabled)
|
||||
)
|
||||
@ -206,7 +203,7 @@ proc init*(
|
||||
|
||||
if quicHostAddress.isSome():
|
||||
try:
|
||||
quicExtAddress = some(
|
||||
quicExtAddress = Opt.some(
|
||||
ipQuicEndPoint(extIp.get(), extQuicPort.get(quicBindPort.get(bindPort)))
|
||||
)
|
||||
except CatchableError:
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, sets, random, sequtils, json, strutils, tables],
|
||||
results,
|
||||
std/[sets, random, sequtils, json, strutils, tables],
|
||||
chronos,
|
||||
chronicles,
|
||||
libp2p/protocols/rendezvous,
|
||||
libp2p/protocols/pubsub,
|
||||
libp2p/protocols/pubsub/rpc/messages,
|
||||
logos_delivery/api/types,
|
||||
logos_delivery/api/events/kernel_events, # EventConnectionStatusChange
|
||||
logos_delivery/api/events/kernel_events,
|
||||
# EventConnectionStatusChange
|
||||
logos_delivery/waku/[
|
||||
waku_relay,
|
||||
api/events/health_events,
|
||||
@ -360,7 +361,7 @@ proc getAllProtocolHealthInfo(
|
||||
proc calculateConnectionState*(
|
||||
protocols: seq[ProtocolHealth],
|
||||
strength: Table[WakuProtocol, int], ## latest connectivity strength (e.g. peer count) for a protocol
|
||||
dLowOpt: Option[int], ## minimum relay peers for Connected status if in Core (Relay) mode
|
||||
dLowOpt: Opt[int], ## minimum relay peers for Connected status if in Core (Relay) mode
|
||||
): ConnectionStatus =
|
||||
var
|
||||
relayCount = 0
|
||||
@ -429,9 +430,9 @@ proc calculateConnectionState*(
|
||||
proc calculateConnectionState*(hm: NodeHealthMonitor): ConnectionStatus =
|
||||
let dLow =
|
||||
if isNil(hm.node.wakuRelay):
|
||||
none(int)
|
||||
Opt.none(int)
|
||||
else:
|
||||
some(hm.node.wakuRelay.parameters.dLow)
|
||||
Opt.some(hm.node.wakuRelay.parameters.dLow)
|
||||
return calculateConnectionState(hm.cachedProtocols, hm.strength, dLow)
|
||||
|
||||
proc getNodeHealthReport*(hm: NodeHealthMonitor): Future[HealthReport] {.async.} =
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import std/[options, strformat]
|
||||
import results, std/strformat
|
||||
import ./health_status
|
||||
import logos_delivery/waku/common/waku_protocol
|
||||
|
||||
@ -7,42 +7,43 @@ export waku_protocol
|
||||
type ProtocolHealth* = object
|
||||
protocol*: string
|
||||
health*: HealthStatus
|
||||
desc*: Option[string] ## describes why a certain protocol is considered `NOT_READY`
|
||||
desc*: Opt[string] ## describes why a certain protocol is considered `NOT_READY`
|
||||
|
||||
proc notReady*(p: var ProtocolHealth, desc: string): ProtocolHealth =
|
||||
p.health = HealthStatus.NOT_READY
|
||||
p.desc = some(desc)
|
||||
p.desc = Opt.some(desc)
|
||||
return p
|
||||
|
||||
proc ready*(p: var ProtocolHealth): ProtocolHealth =
|
||||
p.health = HealthStatus.READY
|
||||
p.desc = none[string]()
|
||||
p.desc = Opt.none(string)
|
||||
return p
|
||||
|
||||
proc notMounted*(p: var ProtocolHealth): ProtocolHealth =
|
||||
p.health = HealthStatus.NOT_MOUNTED
|
||||
p.desc = none[string]()
|
||||
p.desc = Opt.none(string)
|
||||
return p
|
||||
|
||||
proc synchronizing*(p: var ProtocolHealth): ProtocolHealth =
|
||||
p.health = HealthStatus.SYNCHRONIZING
|
||||
p.desc = none[string]()
|
||||
p.desc = Opt.none(string)
|
||||
return p
|
||||
|
||||
proc initializing*(p: var ProtocolHealth): ProtocolHealth =
|
||||
p.health = HealthStatus.INITIALIZING
|
||||
p.desc = none[string]()
|
||||
p.desc = Opt.none(string)
|
||||
return p
|
||||
|
||||
proc shuttingDown*(p: var ProtocolHealth): ProtocolHealth =
|
||||
p.health = HealthStatus.SHUTTING_DOWN
|
||||
p.desc = none[string]()
|
||||
p.desc = Opt.none(string)
|
||||
return p
|
||||
|
||||
proc `$`*(p: ProtocolHealth): string =
|
||||
return fmt"protocol: {p.protocol}, health: {p.health}, description: {p.desc}"
|
||||
let desc = p.desc.get("")
|
||||
return fmt"protocol: {p.protocol}, health: {p.health}, description: {desc}"
|
||||
|
||||
proc init*(p: typedesc[ProtocolHealth], protocol: WakuProtocol): ProtocolHealth =
|
||||
return ProtocolHealth(
|
||||
protocol: $protocol, health: HealthStatus.NOT_MOUNTED, desc: none[string]()
|
||||
protocol: $protocol, health: HealthStatus.NOT_MOUNTED, desc: Opt.none(string)
|
||||
)
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
import logos_delivery/waku/compat/option_valueor
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[
|
||||
options, sets, sequtils, times, strformat, strutils, math, random, tables, algorithm
|
||||
],
|
||||
results,
|
||||
std/[sets, sequtils, times, strformat, strutils, math, random, tables, algorithm],
|
||||
chronos,
|
||||
chronicles,
|
||||
metrics,
|
||||
@ -241,7 +239,7 @@ proc loadFromStorage(pm: PeerManager) {.gcsafe.} =
|
||||
trace "recovered peers from storage", amount = amount
|
||||
|
||||
proc selectPeers*(
|
||||
pm: PeerManager, proto: string, shard: Option[PubsubTopic] = none(PubsubTopic)
|
||||
pm: PeerManager, proto: string, shard: Opt[PubsubTopic] = Opt.none(PubsubTopic)
|
||||
): seq[RemotePeerInfo] =
|
||||
## Returns all peers that support the given protocol (and optionally shard),
|
||||
## shuffled randomly. Callers can further filter or pick from this list.
|
||||
@ -263,8 +261,8 @@ proc selectPeers*(
|
||||
return peers
|
||||
|
||||
proc selectPeer*(
|
||||
pm: PeerManager, proto: string, shard: Option[PubsubTopic] = none(PubsubTopic)
|
||||
): Option[RemotePeerInfo] =
|
||||
pm: PeerManager, proto: string, shard: Opt[PubsubTopic] = Opt.none(PubsubTopic)
|
||||
): Opt[RemotePeerInfo] =
|
||||
## Selects a single peer for a given protocol, checking service slots first
|
||||
## (for non-relay protocols).
|
||||
let peers = pm.selectPeers(proto, shard)
|
||||
@ -275,23 +273,23 @@ proc selectPeer*(
|
||||
if peers.len > 0:
|
||||
trace "Got peer from peerstore",
|
||||
peerId = peers[0].peerId, multi = peers[0].addrs[0], protocol = proto
|
||||
return some(peers[0])
|
||||
return Opt.some(peers[0])
|
||||
trace "No peer found for protocol", protocol = proto
|
||||
return none(RemotePeerInfo)
|
||||
return Opt.none(RemotePeerInfo)
|
||||
|
||||
# For other protocols, we select the peer that is slotted for the given protocol
|
||||
pm.serviceSlots.withValue(proto, serviceSlot):
|
||||
trace "Got peer from service slots",
|
||||
peerId = serviceSlot[].peerId, multi = serviceSlot[].addrs[0], protocol = proto
|
||||
return some(serviceSlot[])
|
||||
return Opt.some(serviceSlot[])
|
||||
|
||||
# If not slotted, we select a random peer for the given protocol
|
||||
if peers.len > 0:
|
||||
trace "Got peer from peerstore",
|
||||
peerId = peers[0].peerId, multi = peers[0].addrs[0], protocol = proto
|
||||
return some(peers[0])
|
||||
return Opt.some(peers[0])
|
||||
trace "No peer found for protocol", protocol = proto
|
||||
return none(RemotePeerInfo)
|
||||
return Opt.none(RemotePeerInfo)
|
||||
|
||||
# Adds a peer to the service slots, which is a list of peers that are slotted for a given protocol
|
||||
proc addServicePeer*(pm: PeerManager, remotePeerInfo: RemotePeerInfo, proto: string) =
|
||||
@ -439,14 +437,14 @@ proc dialPeer(
|
||||
proto: string,
|
||||
dialTimeout = DefaultDialTimeout,
|
||||
source = "api",
|
||||
): Future[Option[Connection]] {.async.} =
|
||||
): Future[Opt[Connection]] {.async.} =
|
||||
if peerId == pm.switch.peerInfo.peerId:
|
||||
error "could not dial self"
|
||||
return none(Connection)
|
||||
return Opt.none(Connection)
|
||||
|
||||
if proto == WakuRelayCodec:
|
||||
error "dial shall not be used to connect to relays"
|
||||
return none(Connection)
|
||||
return Opt.none(Connection)
|
||||
|
||||
trace "Dialing peer", wireAddr = addrs, peerId = peerId, proto = proto
|
||||
|
||||
@ -455,7 +453,7 @@ proc dialPeer(
|
||||
|
||||
let res = catch:
|
||||
if await dialFut.withTimeout(dialTimeout):
|
||||
return some(dialFut.read())
|
||||
return Opt.some(dialFut.read())
|
||||
else:
|
||||
await cancelAndWait(dialFut)
|
||||
|
||||
@ -463,7 +461,7 @@ proc dialPeer(
|
||||
|
||||
trace "Dialing peer failed", peerId = peerId, reason = reasonFailed, proto = proto
|
||||
|
||||
return none(Connection)
|
||||
return Opt.none(Connection)
|
||||
|
||||
proc dialPeer*(
|
||||
pm: PeerManager,
|
||||
@ -471,7 +469,7 @@ proc dialPeer*(
|
||||
proto: string,
|
||||
dialTimeout = DefaultDialTimeout,
|
||||
source = "api",
|
||||
): Future[Option[Connection]] {.async.} =
|
||||
): Future[Opt[Connection]] {.async.} =
|
||||
# Dial a given peer and add it to the list of known peers
|
||||
# TODO: check peer validity and score before continuing. Limit number of peers to be managed.
|
||||
|
||||
@ -492,7 +490,7 @@ proc dialPeer*(
|
||||
proto: string,
|
||||
dialTimeout = DefaultDialTimeout,
|
||||
source = "api",
|
||||
): Future[Option[Connection]] {.async.} =
|
||||
): Future[Opt[Connection]] {.async.} =
|
||||
# Dial an existing peer by looking up it's existing addrs in the switch's peerStore
|
||||
# TODO: check peer validity and score before continuing. Limit number of peers to be managed.
|
||||
|
||||
@ -735,20 +733,20 @@ proc getNumStreams*(pm: PeerManager, protocol: string): (int, int) =
|
||||
numStreamsOut += 1
|
||||
return (numStreamsIn, numStreamsOut)
|
||||
|
||||
proc getPeerIp(pm: PeerManager, peerId: PeerId): Option[string] =
|
||||
proc getPeerIp(pm: PeerManager, peerId: PeerId): Opt[string] =
|
||||
if not pm.switch.connManager.getConnections().hasKey(peerId):
|
||||
return none(string)
|
||||
return Opt.none(string)
|
||||
|
||||
let conns = pm.switch.connManager.getConnections().getOrDefault(peerId)
|
||||
if conns.len == 0:
|
||||
return none(string)
|
||||
return Opt.none(string)
|
||||
|
||||
let obAddr = conns[0].connection.observedAddr.valueOr:
|
||||
return none(string)
|
||||
return Opt.none(string)
|
||||
|
||||
# TODO: think if circuit relay ips should be handled differently
|
||||
|
||||
return some(obAddr.getHostname())
|
||||
return Opt.some(obAddr.getHostname())
|
||||
|
||||
#~~~~~~~~~~~~~~~~~#
|
||||
# Event Handling #
|
||||
@ -1168,8 +1166,8 @@ proc new*(
|
||||
T: type PeerManager,
|
||||
switch: Switch,
|
||||
wakuMetadata: WakuMetadata = nil,
|
||||
maxRelayPeers: Option[int] = none(int),
|
||||
maxServicePeers: Option[int] = none(int),
|
||||
maxRelayPeers: Opt[int] = Opt.none(int),
|
||||
maxServicePeers: Opt[int] = Opt.none(int),
|
||||
relayServiceRatio: string = "50:50",
|
||||
storage: PeerStorage = nil,
|
||||
initialBackoffInSec = InitialBackoffInSec,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user