mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
* adds ProofMetadata * adds EPOCH_INTERVAL * adds messageLog field * adds updateLog, toEpoch, fromEpoch, getEpoch, compareTo * adds unit test for toEpoch and fromEpoch * adds unit test for Epoch comparison * adds result codes for updateLog * adds unit test for update log * renames epoch related consts * modifies updateLog with new return type and new logic of spam detection * adds unit text for the modified updateLog * changes max epoch gap type size * splits updateLog into two procs isSpam and updateLog * updates unittests * fixes a bug, returns false when the message is not spam * renames messageLog to nullifierLog * renames isSpam to hasDuplicate * updates the rln validator, adds comments * adds appendRLNProof proc plus some code beatification * unit test for validate message * adds unhappy test to validateMessage unit test * renames EPOCH_UNIT_SECONDS * renames MAX_CLOCK_GAP_SECONDS * WIP: integration test * fixes compile errors * sets a real epoch value * updates on old unittests * adds comments to the rln relay tests * adds more comments * makes rln import conditional * adds todos * adds more todos * adds rln-relay mount process into chat2 * further todos * logs contentTopic * introduces rln relay configs * changes default pubsub topic * adds contentTopic config * imports rln relay dependencies * consolidates imports * removes module identifier from ContentTopic * adds contentTopic field * adds contentTopic argument to mountRlnRelay calls * appends rln proof to chat2 messages * changes the default chat2 contentTopic * adds missing content topic fields * fixes a bug * adds a new logic about empty content topics * appends proof only when rln flag is active * removes unnecessary todos * fixes an indentation issue * adds log messages * verifies the proof against the concatenation of msg payload and content topic * a bug fix * removes duplicate epoch time calculation * updates log level to trace * updates default rln-relay content topic * adds support for empty content topics * updates changelog * changelog updates * removes a commented code block * updates addRLNRelayValidator string doc
286 lines
8.1 KiB
Nim
286 lines
8.1 KiB
Nim
import
|
|
std/strutils,
|
|
confutils, confutils/defs, confutils/std/net,
|
|
chronicles, chronos,
|
|
libp2p/crypto/crypto,
|
|
libp2p/crypto/secp,
|
|
nimcrypto/utils,
|
|
eth/keys,
|
|
../../waku/v2/protocol/waku_rln_relay/waku_rln_relay_types,
|
|
../../waku/v2/protocol/waku_message
|
|
type
|
|
Fleet* = enum
|
|
none
|
|
prod
|
|
test
|
|
|
|
Chat2Conf* = object
|
|
## General node config
|
|
|
|
logLevel* {.
|
|
desc: "Sets the log level."
|
|
defaultValue: LogLevel.INFO
|
|
name: "log-level" }: LogLevel
|
|
|
|
nodekey* {.
|
|
desc: "P2P node private key as 64 char hex string.",
|
|
defaultValue: crypto.PrivateKey.random(Secp256k1, keys.newRng()[]).tryGet()
|
|
name: "nodekey" }: crypto.PrivateKey
|
|
|
|
listenAddress* {.
|
|
defaultValue: defaultListenAddress(config)
|
|
desc: "Listening address for the LibP2P traffic."
|
|
name: "listen-address"}: ValidIpAddress
|
|
|
|
tcpPort* {.
|
|
desc: "TCP listening port."
|
|
defaultValue: 60000
|
|
name: "tcp-port" }: Port
|
|
|
|
udpPort* {.
|
|
desc: "UDP listening port."
|
|
defaultValue: 60000
|
|
name: "udp-port" }: Port
|
|
|
|
portsShift* {.
|
|
desc: "Add a shift to all port numbers."
|
|
defaultValue: 0
|
|
name: "ports-shift" }: uint16
|
|
|
|
nat* {.
|
|
desc: "Specify method to use for determining public address. " &
|
|
"Must be one of: any, none, upnp, pmp, extip:<IP>."
|
|
defaultValue: "any" }: string
|
|
|
|
## Persistence config
|
|
|
|
dbPath* {.
|
|
desc: "The database path for peristent storage",
|
|
defaultValue: ""
|
|
name: "db-path" }: string
|
|
|
|
persistPeers* {.
|
|
desc: "Enable peer persistence: true|false",
|
|
defaultValue: false
|
|
name: "persist-peers" }: bool
|
|
|
|
persistMessages* {.
|
|
desc: "Enable message persistence: true|false",
|
|
defaultValue: false
|
|
name: "persist-messages" }: bool
|
|
|
|
## Relay config
|
|
|
|
relay* {.
|
|
desc: "Enable relay protocol: true|false",
|
|
defaultValue: true
|
|
name: "relay" }: bool
|
|
|
|
staticnodes* {.
|
|
desc: "Peer multiaddr to directly connect with. Argument may be repeated."
|
|
name: "staticnode" }: seq[string]
|
|
|
|
keepAlive* {.
|
|
desc: "Enable keep-alive for idle connections: true|false",
|
|
defaultValue: false
|
|
name: "keep-alive" }: bool
|
|
|
|
topics* {.
|
|
desc: "Default topics to subscribe to (space separated list)."
|
|
defaultValue: "/waku/2/default-waku/proto"
|
|
name: "topics" .}: string
|
|
|
|
## Store config
|
|
|
|
store* {.
|
|
desc: "Enable store protocol: true|false",
|
|
defaultValue: true
|
|
name: "store" }: bool
|
|
|
|
storenode* {.
|
|
desc: "Peer multiaddr to query for storage.",
|
|
defaultValue: ""
|
|
name: "storenode" }: string
|
|
|
|
## Filter config
|
|
|
|
filter* {.
|
|
desc: "Enable filter protocol: true|false",
|
|
defaultValue: false
|
|
name: "filter" }: bool
|
|
|
|
filternode* {.
|
|
desc: "Peer multiaddr to request content filtering of messages.",
|
|
defaultValue: ""
|
|
name: "filternode" }: string
|
|
|
|
## Swap config
|
|
|
|
swap* {.
|
|
desc: "Enable swap protocol: true|false",
|
|
defaultValue: true
|
|
name: "swap" }: bool
|
|
|
|
## Lightpush config
|
|
|
|
lightpush* {.
|
|
desc: "Enable lightpush protocol: true|false",
|
|
defaultValue: false
|
|
name: "lightpush" }: bool
|
|
|
|
lightpushnode* {.
|
|
desc: "Peer multiaddr to request lightpush of published messages.",
|
|
defaultValue: ""
|
|
name: "lightpushnode" }: string
|
|
|
|
## JSON-RPC config
|
|
|
|
rpc* {.
|
|
desc: "Enable Waku JSON-RPC server: true|false",
|
|
defaultValue: true
|
|
name: "rpc" }: bool
|
|
|
|
rpcAddress* {.
|
|
desc: "Listening address of the JSON-RPC server.",
|
|
defaultValue: ValidIpAddress.init("127.0.0.1")
|
|
name: "rpc-address" }: ValidIpAddress
|
|
|
|
rpcPort* {.
|
|
desc: "Listening port of the JSON-RPC server.",
|
|
defaultValue: 8545
|
|
name: "rpc-port" }: uint16
|
|
|
|
rpcAdmin* {.
|
|
desc: "Enable access to JSON-RPC Admin API: true|false",
|
|
defaultValue: false
|
|
name: "rpc-admin" }: bool
|
|
|
|
rpcPrivate* {.
|
|
desc: "Enable access to JSON-RPC Private API: true|false",
|
|
defaultValue: false
|
|
name: "rpc-private" }: bool
|
|
|
|
## Metrics config
|
|
|
|
metricsServer* {.
|
|
desc: "Enable the metrics server: true|false"
|
|
defaultValue: false
|
|
name: "metrics-server" }: bool
|
|
|
|
metricsServerAddress* {.
|
|
desc: "Listening address of the metrics server."
|
|
defaultValue: ValidIpAddress.init("127.0.0.1")
|
|
name: "metrics-server-address" }: ValidIpAddress
|
|
|
|
metricsServerPort* {.
|
|
desc: "Listening HTTP port of the metrics server."
|
|
defaultValue: 8008
|
|
name: "metrics-server-port" }: uint16
|
|
|
|
metricsLogging* {.
|
|
desc: "Enable metrics logging: true|false"
|
|
defaultValue: false
|
|
name: "metrics-logging" }: bool
|
|
|
|
## DNS discovery config
|
|
|
|
dnsDiscovery* {.
|
|
desc: "Enable discovering nodes via DNS"
|
|
defaultValue: false
|
|
name: "dns-discovery" }: bool
|
|
|
|
dnsDiscoveryUrl* {.
|
|
desc: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
|
|
defaultValue: ""
|
|
name: "dns-discovery-url" }: string
|
|
|
|
dnsDiscoveryNameServers* {.
|
|
desc: "DNS name server IPs to query. Argument may be repeated."
|
|
defaultValue: @[ValidIpAddress.init("1.1.1.1"), ValidIpAddress.init("1.0.0.1")]
|
|
name: "dns-discovery-name-server" }: seq[ValidIpAddress]
|
|
|
|
## Chat2 configuration
|
|
|
|
fleet* {.
|
|
desc: "Select the fleet to connect to."
|
|
defaultValue: Fleet.prod
|
|
name: "fleet" }: Fleet
|
|
|
|
contentTopic* {.
|
|
desc: "Content topic for chat messages."
|
|
defaultValue: "/toy-chat/2/huilong/proto"
|
|
name: "content-topic" }: string
|
|
|
|
## Websocket Configuration
|
|
websocketSupport* {.
|
|
desc: "Enable websocket: true|false",
|
|
defaultValue: false
|
|
name: "websocket-support"}: bool
|
|
|
|
websocketPort* {.
|
|
desc: "WebSocket listening port."
|
|
defaultValue: 8000
|
|
name: "websocket-port" }: Port
|
|
|
|
websocketSecureSupport* {.
|
|
desc: "WebSocket Secure Support."
|
|
defaultValue: false
|
|
name: "websocket-secure-support" }: bool
|
|
|
|
## rln-relay configuration
|
|
|
|
rlnRelay* {.
|
|
desc: "Enable spam protection through rln-relay: true|false",
|
|
defaultValue: false
|
|
name: "rln-relay" }: bool
|
|
|
|
rlnRelayMemIndex* {.
|
|
desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
|
|
defaultValue: MembershipIndex(0)
|
|
name: "rln-relay-membership-index" }: MembershipIndex
|
|
|
|
rlnRelayContentTopic* {.
|
|
desc: "the pubsub topic for which rln-relay gets enabled",
|
|
defaultValue: "waku/2/rln-relay/proto"
|
|
name: "rln-relay-content-topic" }: ContentTopic
|
|
|
|
rlnRelayPubsubTopic* {.
|
|
desc: "the pubsub topic for which rln-relay gets enabled",
|
|
defaultValue: "/waku/2/default-waku/proto"
|
|
name: "rln-relay-pubsub-topic" }: string
|
|
|
|
# NOTE: Keys are different in nim-libp2p
|
|
proc parseCmdArg*(T: type crypto.PrivateKey, p: TaintedString): T =
|
|
try:
|
|
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
|
|
# XXX: Here at the moment
|
|
result = crypto.PrivateKey(scheme: Secp256k1, skkey: key)
|
|
except CatchableError as e:
|
|
raise newException(ConfigurationError, "Invalid private key")
|
|
|
|
proc completeCmdArg*(T: type crypto.PrivateKey, val: TaintedString): seq[string] =
|
|
return @[]
|
|
|
|
proc parseCmdArg*(T: type ValidIpAddress, p: TaintedString): T =
|
|
try:
|
|
result = ValidIpAddress.init(p)
|
|
except CatchableError as e:
|
|
raise newException(ConfigurationError, "Invalid IP address")
|
|
|
|
proc completeCmdArg*(T: type ValidIpAddress, val: TaintedString): seq[string] =
|
|
return @[]
|
|
|
|
proc parseCmdArg*(T: type Port, p: TaintedString): T =
|
|
try:
|
|
result = Port(parseInt(p))
|
|
except CatchableError as e:
|
|
raise newException(ConfigurationError, "Invalid Port number")
|
|
|
|
proc completeCmdArg*(T: type Port, val: TaintedString): seq[string] =
|
|
return @[]
|
|
|
|
func defaultListenAddress*(conf: Chat2Conf): ValidIpAddress =
|
|
# TODO: How should we select between IPv4 and IPv6
|
|
# Maybe there should be a config option for this.
|
|
(static ValidIpAddress.init("0.0.0.0"))
|