2021-05-26 13:48:09 +00:00
|
|
|
import
|
|
|
|
std/strutils,
|
|
|
|
confutils, confutils/defs, confutils/std/net,
|
|
|
|
chronicles, chronos,
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
libp2p/crypto/secp,
|
|
|
|
nimcrypto/utils,
|
2022-10-12 19:41:25 +00:00
|
|
|
eth/keys
|
|
|
|
import
|
2023-04-18 13:22:10 +00:00
|
|
|
../../../waku/v2/waku_message
|
2022-09-07 01:51:10 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
type
|
|
|
|
Fleet* = enum
|
|
|
|
none
|
|
|
|
prod
|
|
|
|
test
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
Chat2Conf* = object
|
|
|
|
## General node config
|
|
|
|
|
|
|
|
logLevel* {.
|
|
|
|
desc: "Sets the log level."
|
|
|
|
defaultValue: LogLevel.INFO
|
|
|
|
name: "log-level" }: LogLevel
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
nodekey* {.
|
|
|
|
desc: "P2P node private key as 64 char hex string.",
|
2023-02-06 11:53:05 +00:00
|
|
|
name: "nodekey" }: Option[crypto.PrivateKey]
|
2021-05-26 13:48:09 +00:00
|
|
|
|
|
|
|
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
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
## Persistence config
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
dbPath* {.
|
|
|
|
desc: "The database path for peristent storage",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "db-path" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
persistPeers* {.
|
|
|
|
desc: "Enable peer persistence: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "persist-peers" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
persistMessages* {.
|
|
|
|
desc: "Enable message persistence: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "persist-messages" }: bool
|
|
|
|
|
|
|
|
## Relay config
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
relay* {.
|
|
|
|
desc: "Enable relay protocol: true|false",
|
|
|
|
defaultValue: true
|
|
|
|
name: "relay" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
staticnodes* {.
|
|
|
|
desc: "Peer multiaddr to directly connect with. Argument may be repeated."
|
|
|
|
name: "staticnode" }: seq[string]
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
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
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
## Filter config
|
|
|
|
|
|
|
|
filter* {.
|
|
|
|
desc: "Enable filter protocol: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "filter" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
filternode* {.
|
|
|
|
desc: "Peer multiaddr to request content filtering of messages.",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "filternode" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
## Lightpush config
|
|
|
|
|
|
|
|
lightpush* {.
|
|
|
|
desc: "Enable lightpush protocol: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "lightpush" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-06-04 10:02:47 +00:00
|
|
|
lightpushnode* {.
|
|
|
|
desc: "Peer multiaddr to request lightpush of published messages.",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "lightpushnode" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
## 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
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
rpcAdmin* {.
|
|
|
|
desc: "Enable access to JSON-RPC Admin API: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rpc-admin" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
rpcPrivate* {.
|
|
|
|
desc: "Enable access to JSON-RPC Private API: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rpc-private" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
## 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"
|
2022-10-21 08:33:36 +00:00
|
|
|
defaultValue: true
|
2021-05-26 13:48:09 +00:00
|
|
|
name: "metrics-logging" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-08-25 11:57:35 +00:00
|
|
|
## DNS discovery config
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-08-25 11:57:35 +00:00
|
|
|
dnsDiscovery* {.
|
|
|
|
desc: "Enable discovering nodes via DNS"
|
|
|
|
defaultValue: false
|
|
|
|
name: "dns-discovery" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-08-25 11:57:35 +00:00
|
|
|
dnsDiscoveryUrl* {.
|
|
|
|
desc: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "dns-discovery-url" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-08-25 11:57:35 +00:00
|
|
|
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]
|
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
## Chat2 configuration
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
fleet* {.
|
2022-02-22 12:36:38 +00:00
|
|
|
desc: "Select the fleet to connect to. This sets the DNS discovery URL to the selected fleet."
|
2021-05-26 13:48:09 +00:00
|
|
|
defaultValue: Fleet.prod
|
|
|
|
name: "fleet" }: Fleet
|
|
|
|
|
|
|
|
contentTopic* {.
|
|
|
|
desc: "Content topic for chat messages."
|
2021-06-02 08:59:15 +00:00
|
|
|
defaultValue: "/toy-chat/2/huilong/proto"
|
2021-05-26 13:48:09 +00:00
|
|
|
name: "content-topic" }: string
|
|
|
|
|
2021-11-02 10:29:11 +00:00
|
|
|
## Websocket Configuration
|
|
|
|
websocketSupport* {.
|
|
|
|
desc: "Enable websocket: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "websocket-support"}: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-11-02 10:29:11 +00:00
|
|
|
websocketPort* {.
|
|
|
|
desc: "WebSocket listening port."
|
|
|
|
defaultValue: 8000
|
|
|
|
name: "websocket-port" }: Port
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-11-10 12:05:36 +00:00
|
|
|
websocketSecureSupport* {.
|
|
|
|
desc: "WebSocket Secure Support."
|
|
|
|
defaultValue: false
|
|
|
|
name: "websocket-secure-support" }: bool
|
2021-11-02 10:29:11 +00:00
|
|
|
|
2022-02-04 23:58:27 +00:00
|
|
|
## rln-relay configuration
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-02-04 23:58:27 +00:00
|
|
|
rlnRelay* {.
|
|
|
|
desc: "Enable spam protection through rln-relay: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rln-relay" }: bool
|
2022-08-18 17:35:02 +00:00
|
|
|
|
|
|
|
rlnRelayCredPath* {.
|
|
|
|
desc: "The path for peristing rln-relay credential",
|
|
|
|
defaultValue: ""
|
|
|
|
name: "rln-relay-cred-path" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayMembershipIndex* {.
|
2022-02-04 23:58:27 +00:00
|
|
|
desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
|
2022-09-07 01:51:10 +00:00
|
|
|
defaultValue: 0
|
|
|
|
name: "rln-relay-membership-index" }: uint
|
2022-02-04 23:58:27 +00:00
|
|
|
|
|
|
|
rlnRelayContentTopic* {.
|
|
|
|
desc: "the pubsub topic for which rln-relay gets enabled",
|
2022-02-16 22:52:21 +00:00
|
|
|
defaultValue: "/toy-chat/2/luzhou/proto"
|
2022-02-04 23:58:27 +00:00
|
|
|
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
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-07-14 10:23:52 +00:00
|
|
|
rlnRelayDynamic* {.
|
|
|
|
desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false",
|
|
|
|
defaultValue: false
|
|
|
|
name: "rln-relay-dynamic" }: bool
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-07-14 10:23:52 +00:00
|
|
|
rlnRelayIdKey* {.
|
2023-02-06 11:53:05 +00:00
|
|
|
desc: "Rln relay identity secret key as a Hex string",
|
2022-07-14 10:23:52 +00:00
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-id-key" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-07-14 10:23:52 +00:00
|
|
|
rlnRelayIdCommitmentKey* {.
|
2023-02-06 11:53:05 +00:00
|
|
|
desc: "Rln relay identity commitment key as a Hex string",
|
2022-07-14 10:23:52 +00:00
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-id-commitment-key" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayEthAccountAddress* {.
|
|
|
|
desc: "Ethereum account address for an Ethereum testnet",
|
|
|
|
# NOTE: This can be derived from the private key, but kept for future use
|
2022-07-14 10:23:52 +00:00
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-account-address" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayEthAccountPrivateKey* {.
|
2022-07-14 10:23:52 +00:00
|
|
|
desc: "Account private key for an Ethereum testnet",
|
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-account-private-key" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-07-14 10:23:52 +00:00
|
|
|
rlnRelayEthClientAddress* {.
|
2022-09-24 04:57:28 +00:00
|
|
|
desc: "WebSocket address of an Ethereum testnet client e.g., ws://localhost:8540/",
|
2022-07-14 10:23:52 +00:00
|
|
|
defaultValue: "ws://localhost:8540/"
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-client-address" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2022-10-03 20:25:56 +00:00
|
|
|
rlnRelayEthContractAddress* {.
|
2023-02-06 11:53:05 +00:00
|
|
|
desc: "Address of membership contract on an Ethereum testnet",
|
2022-07-14 10:23:52 +00:00
|
|
|
defaultValue: ""
|
2022-10-03 20:25:56 +00:00
|
|
|
name: "rln-relay-eth-contract-address" }: string
|
2022-10-28 09:13:05 +00:00
|
|
|
|
|
|
|
rlnRelayCredentialsPassword* {.
|
2023-02-06 11:53:05 +00:00
|
|
|
desc: "Password for encrypting RLN credentials",
|
2022-10-28 09:13:05 +00:00
|
|
|
defaultValue: ""
|
|
|
|
name: "rln-relay-cred-password" }: string
|
2023-02-06 11:53:05 +00:00
|
|
|
|
2021-05-26 13:48:09 +00:00
|
|
|
# NOTE: Keys are different in nim-libp2p
|
2022-11-02 13:55:48 +00:00
|
|
|
proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
|
2021-05-26 13:48:09 +00:00
|
|
|
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")
|
|
|
|
|
2022-11-02 13:55:48 +00:00
|
|
|
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
|
2021-05-26 13:48:09 +00:00
|
|
|
return @[]
|
|
|
|
|
2022-11-02 13:55:48 +00:00
|
|
|
proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
|
2021-05-26 13:48:09 +00:00
|
|
|
try:
|
|
|
|
result = ValidIpAddress.init(p)
|
|
|
|
except CatchableError as e:
|
|
|
|
raise newException(ConfigurationError, "Invalid IP address")
|
|
|
|
|
2022-11-02 13:55:48 +00:00
|
|
|
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
2021-05-26 13:48:09 +00:00
|
|
|
return @[]
|
|
|
|
|
2022-11-02 13:55:48 +00:00
|
|
|
proc parseCmdArg*(T: type Port, p: string): T =
|
2021-05-26 13:48:09 +00:00
|
|
|
try:
|
|
|
|
result = Port(parseInt(p))
|
|
|
|
except CatchableError as e:
|
|
|
|
raise newException(ConfigurationError, "Invalid Port number")
|
|
|
|
|
2022-11-02 13:55:48 +00:00
|
|
|
proc completeCmdArg*(T: type Port, val: string): seq[string] =
|
2021-05-26 13:48:09 +00:00
|
|
|
return @[]
|
|
|
|
|
|
|
|
func defaultListenAddress*(conf: Chat2Conf): ValidIpAddress =
|
|
|
|
# TODO: How should we select between IPv4 and IPv6
|
|
|
|
# Maybe there should be a config option for this.
|
2021-06-02 08:59:15 +00:00
|
|
|
(static ValidIpAddress.init("0.0.0.0"))
|