2020-04-29 04:49:27 +00:00
import
2024-05-10 08:56:17 +00:00
std / [ strutils , strformat ] ,
2024-07-09 11:14:28 +00:00
results ,
2022-10-26 15:10:30 +00:00
chronos ,
2022-11-02 14:55:09 +00:00
regex ,
2022-11-03 09:45:06 +00:00
confutils ,
confutils / defs ,
2022-10-18 12:06:54 +00:00
confutils / std / net ,
2022-05-17 15:48:08 +00:00
confutils / toml / defs as confTomlDefs ,
confutils / toml / std / net as confTomlNet ,
2020-05-21 04:16:00 +00:00
libp2p / crypto / crypto ,
libp2p / crypto / secp ,
2023-01-26 10:18:30 +00:00
libp2p / multiaddress ,
2023-05-02 09:45:50 +00:00
nimcrypto / utils ,
2024-05-10 08:56:17 +00:00
secp256k1 ,
json
2022-11-03 16:58:48 +00:00
import
2024-03-03 00:59:53 +00:00
.. / common / confutils / envvar / defs as confEnvvarDefs ,
.. / common / confutils / envvar / std / net as confEnvvarNet ,
.. / common / logging ,
.. / waku_enr ,
2024-08-19 10:56:22 +00:00
.. / node / peer_manager ,
.. / waku_core / topics / pubsub_topic
2022-05-17 15:48:08 +00:00
2024-03-15 23:08:47 +00:00
include .. / waku_core / message / default_values
2024-01-03 12:11:50 +00:00
2024-03-15 23:08:47 +00:00
export confTomlDefs , confTomlNet , confEnvvarDefs , confEnvvarNet
2022-10-26 15:10:30 +00:00
2024-09-25 09:52:02 +00:00
# Git version in git describe format (defined at compile time)
const git_version * {. strdefine . } = " n/a "
2022-10-26 15:10:30 +00:00
type ConfResult * [ T ] = Result [ T , string ]
2022-11-23 09:08:00 +00:00
2024-03-27 14:08:53 +00:00
type EthRpcUrl * = distinct string
2024-02-16 13:06:31 +00:00
2024-08-19 10:56:22 +00:00
type ProtectedShard * = object
shard * : uint16
key * : secp256k1 . SkPublicKey
2023-11-09 09:48:39 +00:00
type StartUpCommand * = enum
2024-03-15 23:08:47 +00:00
noCommand # default, runs waku
generateRlnKeystore # generates a new RLN keystore
inspectRlnDb # Inspects a given RLN tree db, providing essential db stats
type WakuNodeConf * = object
configFile * {.
desc : " Loads configuration from a TOML file (cmd-line parameters take precedence) " ,
name : " config-file "
. } : Option [ InputFile ]
## Log configuration
logLevel * {.
desc :
" Sets the log level for process. Supported levels: TRACE, DEBUG, INFO, NOTICE, WARN, ERROR or FATAL " ,
defaultValue : logging . LogLevel . INFO ,
name : " log-level "
. } : logging . LogLevel
logFormat * {.
desc :
2024-12-09 13:45:26 +00:00
" Specifies what kind of logs should be written to stdout. Supported formats: TEXT, JSON " ,
2024-03-15 23:08:47 +00:00
defaultValue : logging . LogFormat . TEXT ,
name : " log-format "
. } : logging . LogFormat
rlnRelayCredPath * {.
desc : " The path for peristing rln-relay credential " ,
defaultValue : " " ,
name : " rln-relay-cred-path "
. } : string
rlnRelayEthClientAddress * {.
desc : " HTTP address of an Ethereum testnet client e.g., http://localhost:8540/ " ,
defaultValue : " http://localhost:8540/ " ,
name : " rln-relay-eth-client-address "
. } : EthRpcUrl
rlnRelayEthContractAddress * {.
desc : " Address of membership contract on an Ethereum testnet " ,
defaultValue : " " ,
name : " rln-relay-eth-contract-address "
. } : string
2024-06-28 09:19:16 +00:00
rlnRelayChainId * {.
2024-07-09 11:14:28 +00:00
desc :
" Chain ID of the provided contract (optional, will fetch from RPC provider if not used) " ,
2024-06-28 09:19:16 +00:00
defaultValue : 0 ,
name : " rln-relay-chain-id "
. } : uint
2024-03-15 23:08:47 +00:00
rlnRelayCredPassword * {.
desc : " Password for encrypting RLN credentials " ,
defaultValue : " " ,
name : " rln-relay-cred-password "
. } : string
rlnRelayEthPrivateKey * {.
desc : " Private key for broadcasting transactions " ,
defaultValue : " " ,
name : " rln-relay-eth-private-key "
. } : string
rlnRelayUserMessageLimit * {.
desc :
" Set a user message limit for the rln membership registration. Must be a positive integer. Default is 1. " ,
defaultValue : 1 ,
name : " rln-relay-user-message-limit "
. } : uint64
rlnEpochSizeSec * {.
desc :
" Epoch size in seconds used to rate limit RLN memberships. Default is 1 second. " ,
defaultValue : 1 ,
name : " rln-relay-epoch-sec "
. } : uint64
maxMessageSize * {.
desc :
" Maximum message size. Accepted units: KiB, KB, and B. e.g. 1024KiB; 1500 B; etc. " ,
defaultValue : DefaultMaxWakuMessageSizeStr ,
name : " max-msg-size "
. } : string
case cmd * {. command , defaultValue : noCommand . } : StartUpCommand
of inspectRlnDb :
# have to change the name here since it counts as a duplicate, within noCommand
treePath * {.
desc : " Path to the RLN merkle tree sled db (https://github.com/spacejam/sled) " ,
2023-11-09 09:48:39 +00:00
defaultValue : " " ,
2024-03-15 23:08:47 +00:00
name : " rln-relay-tree-path "
. } : string
of generateRlnKeystore :
execute * {.
desc : " Runs the registration function on-chain. By default, a dry-run will occur " ,
defaultValue : false ,
name : " execute "
. } : bool
of noCommand :
## Application-level configuration
2024-08-19 10:56:22 +00:00
protectedShards * {.
desc :
" Shards and its public keys to be used for message validation, shard:pubkey. Argument may be repeated. " ,
defaultValue : newSeq [ ProtectedShard ] ( 0 ) ,
name : " protected-shard "
. } : seq [ ProtectedShard ]
2024-03-15 23:08:47 +00:00
## General node config
clusterId * {.
desc :
" Cluster id that the node is running in. Node in a different cluster id is disconnected. " ,
defaultValue : 0 ,
name : " cluster-id "
2024-06-05 13:32:35 +00:00
. } : uint16
2024-03-15 23:08:47 +00:00
agentString * {.
2024-10-25 20:59:02 +00:00
defaultValue : " nwaku- " & external_config . git_version ,
2024-03-15 23:08:47 +00:00
desc : " Node agent string which is used as identifier in network " ,
name : " agent-string "
. } : string
nodekey * {. desc : " P2P node private key as 64 char hex string. " , name : " nodekey " . } :
Option [ PrivateKey ]
listenAddress * {.
defaultValue : defaultListenAddress ( ) ,
desc : " Listening address for LibP2P (and Discovery v5, if enabled) traffic. " ,
name : " listen-address "
. } : IpAddress
tcpPort * {. desc : " TCP listening port. " , defaultValue : 60000 , name : " tcp-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
extMultiAddrs * {.
desc :
" External multiaddresses to advertise to the network. Argument may be repeated. " ,
name : " ext-multiaddr "
. } : seq [ string ]
extMultiAddrsOnly * {.
desc : " Only announce external multiaddresses " ,
defaultValue : false ,
name : " ext-multiaddr-only "
. } : bool
maxConnections * {.
desc : " Maximum allowed number of libp2p connections. " ,
defaultValue : 50 ,
name : " max-connections "
. } : uint16
colocationLimit * {.
desc :
" Max num allowed peers from the same IP. Set it to 0 to remove the limitation. " ,
defaultValue : defaultColocationLimit ( ) ,
name : " ip-colocation-limit "
. } : int
maxRelayPeers * {.
desc : " Maximum allowed number of relay peers. " , name : " max-relay-peers "
. } : Option [ int ]
peerStoreCapacity * {.
desc : " Maximum stored peers in the peerstore. " , name : " peer-store-capacity "
. } : Option [ int ]
peerPersistence * {.
desc : " Enable peer persistence. " , defaultValue : false , name : " peer-persistence "
. } : bool
## DNS addrs config
dnsAddrs * {.
desc : " Enable resolution of `dnsaddr`, `dns4` or `dns6` multiaddrs " ,
defaultValue : true ,
name : " dns-addrs "
. } : bool
dnsAddrsNameServers * {.
desc :
" DNS name server IPs to query for DNS multiaddrs resolution. Argument may be repeated. " ,
defaultValue : @ [ parseIpAddress ( " 1.1.1.1 " ) , parseIpAddress ( " 1.0.0.1 " ) ] ,
name : " dns-addrs-name-server "
. } : seq [ IpAddress ]
dns4DomainName * {.
desc : " The domain name resolving to the node ' s public IPv4 address " ,
2023-11-09 09:48:39 +00:00
defaultValue : " " ,
2024-03-15 23:08:47 +00:00
name : " dns4-domain-name "
. } : string
2024-10-28 08:17:46 +00:00
## Circuit-relay config
isRelayClient * {.
desc :
""" Set the node as a relay-client.
Set it to true for nodes that run behind a NAT or firewall and
hence would have reachability issues . """ ,
defaultValue : false ,
name : " relay-client "
. } : bool
2024-03-15 23:08:47 +00:00
## Relay config
relay * {.
desc : " Enable relay protocol: true|false " , defaultValue : true , name : " relay "
. } : bool
relayPeerExchange * {.
desc : " Enable gossipsub peer exchange in relay protocol: true|false " ,
defaultValue : false ,
name : " relay-peer-exchange "
. } : bool
relayShardedPeerManagement * {.
desc :
" Enable experimental shard aware peer manager for relay protocol: true|false " ,
defaultValue : false ,
name : " relay-shard-manager "
. } : bool
rlnRelay * {.
desc : " Enable spam protection through rln-relay: true|false " ,
defaultValue : false ,
name : " rln-relay "
. } : bool
rlnRelayCredIndex * {.
desc : " the index of the onchain commitment to use " ,
name : " rln-relay-membership-index "
. } : Option [ uint ]
rlnRelayDynamic * {.
desc : " Enable waku-rln-relay with on-chain dynamic group management: true|false " ,
defaultValue : false ,
name : " rln-relay-dynamic "
. } : bool
rlnRelayIdKey * {.
desc : " Rln relay identity secret key as a Hex string " ,
2023-11-09 09:48:39 +00:00
defaultValue : " " ,
2024-03-15 23:08:47 +00:00
name : " rln-relay-id-key "
. } : string
2022-11-23 09:08:00 +00:00
2024-03-15 23:08:47 +00:00
rlnRelayIdCommitmentKey * {.
desc : " Rln relay identity commitment key as a Hex string " ,
2022-10-27 22:05:02 +00:00
defaultValue : " " ,
2024-03-15 23:08:47 +00:00
name : " rln-relay-id-commitment-key "
. } : string
2024-02-28 16:19:20 +00:00
2024-03-15 23:08:47 +00:00
rlnRelayTreePath * {.
desc : " Path to the RLN merkle tree sled db (https://github.com/spacejam/sled) " ,
defaultValue : " " ,
name : " rln-relay-tree-path "
. } : string
rlnRelayBandwidthThreshold * {.
desc : " Message rate in bytes/sec after which verification of proofs should happen " ,
defaultValue : 0 , # to maintain backwards compatibility
name : " rln-relay-bandwidth-threshold "
. } : int
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
2024-09-10 21:07:12 +00:00
# If numShardsInNetwork is not set, we use the number of shards configured as numShardsInNetwork
numShardsInNetwork * {.
desc : " Number of shards in the network " ,
defaultValue : 0 ,
name : " num-shards-in-network "
. } : uint32
2024-03-15 23:08:47 +00:00
pubsubTopics * {.
2024-09-10 21:07:12 +00:00
desc :
" Deprecated. Default pubsub topic to subscribe to. Argument may be repeated. " ,
2024-07-09 15:36:12 +00:00
defaultValue : @ [ ] ,
2024-03-15 23:08:47 +00:00
name : " pubsub-topic "
. } : seq [ string ]
shards * {.
2024-09-10 21:07:12 +00:00
desc :
" Shards index to subscribe to [0..NUM_SHARDS_IN_NETWORK-1]. Argument may be repeated. " ,
2024-07-09 15:36:12 +00:00
defaultValue :
@ [
uint16 ( 0 ) ,
uint16 ( 1 ) ,
uint16 ( 2 ) ,
uint16 ( 3 ) ,
uint16 ( 4 ) ,
uint16 ( 5 ) ,
uint16 ( 6 ) ,
uint16 ( 7 ) ,
] ,
2024-03-15 23:08:47 +00:00
name : " shard "
2024-06-05 13:32:35 +00:00
. } : seq [ uint16 ]
2024-03-15 23:08:47 +00:00
contentTopics * {.
desc : " Default content topic to subscribe to. Argument may be repeated. " ,
name : " content-topic "
. } : seq [ string ]
## Store and message store config
store * {.
desc : " Enable/disable waku store protocol " , defaultValue : false , name : " store "
. } : bool
2024-07-12 16:19:12 +00:00
legacyStore * {.
desc : " Enable/disable waku store legacy mode " ,
defaultValue : true ,
name : " legacy-store "
. } : bool
2024-03-15 23:08:47 +00:00
storenode * {.
desc : " Peer multiaddress to query for storage " ,
defaultValue : " " ,
name : " storenode "
. } : string
storeMessageRetentionPolicy * {.
desc :
" Message store retention policy. Time retention policy: ' time:<seconds> ' . Capacity retention policy: ' capacity:<count> ' . Size retention policy: ' size:<xMB/xGB> ' . Set to ' none ' to disable. " ,
defaultValue : " time: " & $ 2 . days . seconds ,
name : " store-message-retention-policy "
. } : string
storeMessageDbUrl * {.
desc : " The database connection URL for peristent storage. " ,
defaultValue : " sqlite://store.sqlite3 " ,
name : " store-message-db-url "
. } : string
storeMessageDbVacuum * {.
desc :
" Enable database vacuuming at start. Only supported by SQLite database engine. " ,
defaultValue : false ,
name : " store-message-db-vacuum "
. } : bool
storeMessageDbMigration * {.
desc : " Enable database migration at start. " ,
defaultValue : true ,
name : " store-message-db-migration "
. } : bool
storeMaxNumDbConnections * {.
desc : " Maximum number of simultaneous Postgres connections. " ,
defaultValue : 50 ,
name : " store-max-num-db-connections "
. } : int
2024-07-30 11:23:39 +00:00
storeResume * {.
desc : " Enable store resume functionality " ,
defaultValue : false ,
name : " store-resume "
. } : bool
2024-08-13 11:27:34 +00:00
## Sync config
storeSync * {.
desc : " Enable store sync protocol: true|false " ,
defaultValue : false ,
name : " store-sync "
. } : bool
storeSyncInterval * {.
desc : " Interval between store sync attempts. In seconds. " ,
2024-08-28 14:26:38 +00:00
defaultValue : 300 , # 5 minutes
2024-08-13 11:27:34 +00:00
name : " store-sync-interval "
. } : int64
storeSyncRange * {.
desc : " Amount of time to sync. In seconds. " ,
2024-08-28 14:26:38 +00:00
defaultValue : 3600 , # 1 hours
2024-08-13 11:27:34 +00:00
name : " store-sync-range "
. } : int64
storeSyncRelayJitter * {.
hidden ,
desc : " Time offset to account for message propagation jitter. In seconds. " ,
defaultValue : 20 ,
name : " store-sync-relay-jitter "
. } : int64
storeSyncMaxPayloadSize * {.
hidden ,
desc :
" Max size in bytes of the inner negentropy payload. Cannot be less than 5K, 0 is unlimited. " ,
defaultValue : 0 ,
name : " store-sync-max-payload-size "
. } : int64
2024-03-15 23:08:47 +00:00
## 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
filterSubscriptionTimeout * {.
desc :
" Timeout for filter subscription without ping or refresh it, in seconds. Only for v2 filter protocol. " ,
defaultValue : 300 , # 5 minutes
name : " filter-subscription-timeout "
. } : int64
filterMaxPeersToServe * {.
desc : " Maximum number of peers to serve at a time. Only for v2 filter protocol. " ,
defaultValue : 1000 ,
name : " filter-max-peers-to-serve "
. } : uint32
filterMaxCriteria * {.
desc :
" Maximum number of pubsub- and content topic combination per peers at a time. Only for v2 filter protocol. " ,
defaultValue : 1000 ,
name : " filter-max-criteria "
. } : uint32
## 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
2024-08-27 14:49:46 +00:00
## Reliability config
reliabilityEnabled * {.
desc :
""" Adds an extra effort in the delivery/reception of messages by leveraging store-v3 requests.
2024-12-09 13:45:26 +00:00
with the drawback of consuming some more bandwidth . """ ,
2024-08-27 14:49:46 +00:00
defaultValue : false ,
name : " reliability "
. } : bool
2024-03-15 23:08:47 +00:00
## REST HTTP config
rest * {.
2024-04-23 07:23:13 +00:00
desc : " Enable Waku REST HTTP server: true|false " , defaultValue : true , name : " rest "
2024-03-15 23:08:47 +00:00
. } : bool
restAddress * {.
desc : " Listening address of the REST HTTP server. " ,
defaultValue : parseIpAddress ( " 127.0.0.1 " ) ,
name : " rest-address "
. } : IpAddress
restPort * {.
desc : " Listening port of the REST HTTP server. " ,
defaultValue : 8645 ,
name : " rest-port "
. } : uint16
restRelayCacheCapacity * {.
desc : " Capacity of the Relay REST API message cache. " ,
defaultValue : 30 ,
name : " rest-relay-cache-capacity "
. } : uint32
restAdmin * {.
desc : " Enable access to REST HTTP Admin API: true|false " ,
defaultValue : false ,
name : " rest-admin "
. } : bool
restAllowOrigin * {.
desc :
" Allow cross-origin requests from the specified origin. " &
" Argument may be repeated. " & " Wildcards: * or ? allowed. " &
" Ex.: \" localhost:* \" or \" 127.0.0.1:8080 \" " ,
defaultValue : newSeq [ string ] ( ) ,
name : " rest-allow-origin "
. } : seq [ string ]
## 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 : parseIpAddress ( " 127.0.0.1 " ) ,
name : " metrics-server-address "
. } : IpAddress
metricsServerPort * {.
desc : " Listening HTTP port of the metrics server. " ,
defaultValue : 8008 ,
name : " metrics-server-port "
. } : uint16
metricsLogging * {.
desc : " Enable metrics logging: true|false " ,
defaultValue : true ,
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 : @ [ parseIpAddress ( " 1.1.1.1 " ) , parseIpAddress ( " 1.0.0.1 " ) ] ,
name : " dns-discovery-name-server "
. } : seq [ IpAddress ]
## Discovery v5 config
discv5Discovery * {.
desc : " Enable discovering nodes via Node Discovery v5 " ,
defaultValue : false ,
name : " discv5-discovery "
. } : bool
discv5UdpPort * {.
desc : " Listening UDP port for Node Discovery v5. " ,
defaultValue : 9000 ,
name : " discv5-udp-port "
. } : Port
discv5BootstrapNodes * {.
desc :
" Text-encoded ENR for bootstrap node. Used when connecting to the network. Argument may be repeated. " ,
name : " discv5-bootstrap-node "
. } : seq [ string ]
discv5EnrAutoUpdate * {.
desc :
" Discovery can automatically update its ENR with the IP address " &
" and UDP port as seen by other nodes it communicates with. " &
" This option allows to enable/disable this functionality " ,
defaultValue : false ,
name : " discv5-enr-auto-update "
. } : bool
discv5TableIpLimit * {.
hidden ,
desc : " Maximum amount of nodes with the same IP in discv5 routing tables " ,
defaultValue : 10 ,
name : " discv5-table-ip-limit "
. } : uint
discv5BucketIpLimit * {.
hidden ,
desc : " Maximum amount of nodes with the same IP in discv5 routing table buckets " ,
defaultValue : 2 ,
name : " discv5-bucket-ip-limit "
. } : uint
discv5BitsPerHop * {.
hidden ,
desc : " Kademlia ' s b variable, increase for less hops per lookup " ,
2024-02-09 11:01:45 +00:00
defaultValue : 1 ,
2024-03-15 23:08:47 +00:00
name : " discv5-bits-per-hop "
. } : int
2024-08-01 20:28:00 +00:00
discv5Only * {.
desc : " Disable all protocols other than discv5 " ,
defaultValue : false ,
name : " discv5-only "
. } : bool
2024-03-15 23:08:47 +00:00
## waku peer exchange config
peerExchange * {.
desc : " Enable waku peer exchange protocol (responder side): true|false " ,
defaultValue : false ,
name : " peer-exchange "
. } : bool
peerExchangeNode * {.
desc :
" Peer multiaddr to send peer exchange requests to. (enables peer exchange protocol requester side) " ,
defaultValue : " " ,
name : " peer-exchange-node "
. } : string
2024-12-09 20:22:36 +00:00
## Rendez vous
rendezvous * {.
desc : " Enable waku rendezvous discovery server " ,
defaultValue : true ,
name : " rendezvous "
. } : bool
2024-03-15 23:08:47 +00:00
## websocket config
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 : " Enable secure websocket: true|false " ,
defaultValue : false ,
name : " websocket-secure-support "
. } : bool
websocketSecureKeyPath * {.
desc : " Secure websocket key path: ' /path/to/key.txt ' " ,
defaultValue : " " ,
name : " websocket-secure-key-path "
. } : string
websocketSecureCertPath * {.
desc : " Secure websocket Certificate path: ' /path/to/cert.txt ' " ,
defaultValue : " " ,
name : " websocket-secure-cert-path "
. } : string
2021-11-02 10:29:11 +00:00
2024-09-18 13:58:07 +00:00
## Rate limitation config, if not set, rate limit checks will not be performed
rateLimits * {.
2024-04-15 13:28:35 +00:00
desc :
2024-09-18 13:58:07 +00:00
" Rate limit settings for different protocols. " &
" Format: protocol:volume/period<unit> " &
" Where ' protocol ' can be one of: <store|storev2|storev3|lightpush|px|filter> if not defined it means a global setting " &
" ' volume ' and period must be an integer value. " &
" ' unit ' must be one of <h|m|s|ms> - hours, minutes, seconds, milliseconds respectively. " &
" Argument may be repeated. " ,
defaultValue : newSeq [ string ] ( 0 ) ,
name : " rate-limit "
. } : seq [ string ]
2024-04-15 13:28:35 +00:00
2022-12-07 11:30:32 +00:00
## Parsing
2020-05-21 04:16:00 +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 =
2020-04-29 04:49:27 +00:00
try :
2020-05-26 03:55:53 +00:00
let key = SkPrivateKey . init ( utils . fromHex ( p ) ) . tryGet ( )
2022-11-03 09:45:06 +00:00
crypto . PrivateKey ( scheme : Secp256k1 , skkey : key )
2023-04-04 13:34:53 +00:00
except CatchableError :
2023-09-21 11:12:14 +00:00
raise newException ( ValueError , " Invalid private key " )
2020-04-29 04:49:27 +00:00
2024-05-10 08:56:17 +00:00
proc parseCmdArg * [ T ] ( _ : type seq [ T ] , s : string ) : seq [ T ] {. raises : [ ValueError ] . } =
var
inputSeq : JsonNode
res : seq [ T ] = @ [ ]
try :
inputSeq = s . parseJson ( )
except Exception :
raise newException ( ValueError , fmt" Could not parse sequence: {s} " )
for entry in inputSeq :
let formattedString = ( $ entry ) . strip ( chars = { ' \" ' } )
res . add ( parseCmdArg ( T , formattedString ) )
return res
2022-11-02 13:55:48 +00:00
proc completeCmdArg * ( T : type crypto . PrivateKey , val : string ) : seq [ string ] =
2020-04-29 04:49:27 +00:00
return @ [ ]
2024-08-19 10:56:22 +00:00
# TODO: Remove when removing protected-topic configuration
proc isNumber ( x : string ) : bool =
try :
discard parseInt ( x )
result = true
except ValueError :
result = false
proc parseCmdArg * ( T : type ProtectedShard , p : string ) : T =
2023-05-02 09:45:50 +00:00
let elements = p . split ( " : " )
if elements . len ! = 2 :
2024-03-15 23:08:47 +00:00
raise newException (
2024-08-19 10:56:22 +00:00
ValueError , " Invalid format for protected shard expected shard:publickey "
2024-03-15 23:08:47 +00:00
)
2023-05-02 09:45:50 +00:00
let publicKey = secp256k1 . SkPublicKey . fromHex ( elements [ 1 ] )
if publicKey . isErr :
2023-09-21 11:12:14 +00:00
raise newException ( ValueError , " Invalid public key " )
2023-05-02 09:45:50 +00:00
2024-08-19 10:56:22 +00:00
if isNumber ( elements [ 0 ] ) :
return ProtectedShard ( shard : uint16 . parseCmdArg ( elements [ 0 ] ) , key : publicKey . get ( ) )
# TODO: Remove when removing protected-topic configuration
let shard = RelayShard . parse ( elements [ 0 ] ) . valueOr :
raise newException (
ValueError ,
" Invalid pubsub topic. Pubsub topics must be in the format /waku/2/rs/<cluster-id>/<shard-id> " ,
)
return ProtectedShard ( shard : shard . shardId , key : publicKey . get ( ) )
2023-05-02 09:45:50 +00:00
2024-08-19 10:56:22 +00:00
proc completeCmdArg * ( T : type ProtectedShard , val : string ) : seq [ string ] =
2023-05-02 09:45:50 +00:00
return @ [ ]
2022-12-07 11:30:32 +00:00
2023-12-14 06:16:39 +00:00
proc completeCmdArg * ( T : type IpAddress , val : string ) : seq [ string ] =
2020-04-29 04:49:27 +00:00
return @ [ ]
2020-07-24 01:39:58 +00:00
2023-12-14 06:16:39 +00:00
proc defaultListenAddress * ( ) : IpAddress =
2022-12-07 11:30:32 +00:00
# TODO: How should we select between IPv4 and IPv6
# Maybe there should be a config option for this.
2023-12-14 06:16:39 +00:00
( static parseIpAddress ( " 0.0.0.0 " ) )
2022-12-07 11:30:32 +00:00
2024-01-02 13:01:18 +00:00
proc defaultColocationLimit * ( ) : int =
return DefaultColocationLimit
2022-11-02 13:55:48 +00:00
proc completeCmdArg * ( T : type Port , val : string ) : seq [ string ] =
2020-07-24 01:39:58 +00:00
return @ [ ]
2024-02-16 13:06:31 +00:00
proc completeCmdArg * ( T : type EthRpcUrl , val : string ) : seq [ string ] =
return @ [ ]
proc parseCmdArg * ( T : type EthRpcUrl , s : string ) : T =
## allowed patterns:
## http://url:port
## https://url:port
## http://url:port/path
## https://url:port/path
## http://url/with/path
## http://url:port/path?query
## https://url:port/path?query
## disallowed patterns:
## any valid/invalid ws or wss url
2024-03-15 23:08:47 +00:00
var httpPattern =
2024-04-02 13:14:55 +00:00
re2" ^(https?): \ / \ /([ \ w-]+( \ .[ \ w-]+)*)(:[0-9]{1,5})?( \ /[ \ w.,@?^=%&: \ /~+#-]*)? $ "
2024-03-15 23:08:47 +00:00
var wsPattern =
2024-04-02 13:14:55 +00:00
re2" ^(wss?): \ / \ /([ \ w-]+( \ .[ \ w-]+)+)(:[0-9]{1,5})?( \ /[ \ w.,@?^=%&: \ /~+#-]*)? $ "
2024-02-16 13:06:31 +00:00
if regex . match ( s , wsPattern ) :
2024-03-15 23:08:47 +00:00
raise newException (
ValueError , " Websocket RPC URL is not supported, Please use an HTTP URL "
)
2024-02-16 13:06:31 +00:00
if not regex . match ( s , httpPattern ) :
raise newException ( ValueError , " Invalid HTTP RPC URL " )
return EthRpcUrl ( s )
2022-11-03 09:45:06 +00:00
## Load
2024-03-15 23:08:47 +00:00
proc readValue * (
r : var TomlReader , value : var crypto . PrivateKey
) {. raises : [ SerializationError ] . } =
2022-11-23 09:08:00 +00:00
try :
2022-11-03 09:45:06 +00:00
value = parseCmdArg ( crypto . PrivateKey , r . readValue ( string ) )
except CatchableError :
raise newException ( SerializationError , getCurrentExceptionMsg ( ) )
2024-03-15 23:08:47 +00:00
proc readValue * (
r : var EnvvarReader , value : var crypto . PrivateKey
) {. raises : [ SerializationError ] . } =
2022-11-23 09:08:00 +00:00
try :
2022-11-03 16:58:48 +00:00
value = parseCmdArg ( crypto . PrivateKey , r . readValue ( string ) )
except CatchableError :
raise newException ( SerializationError , getCurrentExceptionMsg ( ) )
2024-03-15 23:08:47 +00:00
proc readValue * (
2024-08-19 10:56:22 +00:00
r : var TomlReader , value : var ProtectedShard
2024-03-15 23:08:47 +00:00
) {. raises : [ SerializationError ] . } =
2023-05-02 09:45:50 +00:00
try :
2024-08-19 10:56:22 +00:00
value = parseCmdArg ( ProtectedShard , r . readValue ( string ) )
2023-05-02 09:45:50 +00:00
except CatchableError :
raise newException ( SerializationError , getCurrentExceptionMsg ( ) )
2024-03-15 23:08:47 +00:00
proc readValue * (
2024-08-19 10:56:22 +00:00
r : var EnvvarReader , value : var ProtectedShard
2024-03-15 23:08:47 +00:00
) {. raises : [ SerializationError ] . } =
2023-05-02 09:45:50 +00:00
try :
2024-08-19 10:56:22 +00:00
value = parseCmdArg ( ProtectedShard , r . readValue ( string ) )
2023-05-02 09:45:50 +00:00
except CatchableError :
raise newException ( SerializationError , getCurrentExceptionMsg ( ) )
2022-11-03 09:45:06 +00:00
2024-03-15 23:08:47 +00:00
proc readValue * (
r : var TomlReader , value : var EthRpcUrl
) {. raises : [ SerializationError ] . } =
2024-02-16 13:06:31 +00:00
try :
value = parseCmdArg ( EthRpcUrl , r . readValue ( string ) )
except CatchableError :
raise newException ( SerializationError , getCurrentExceptionMsg ( ) )
2024-03-15 23:08:47 +00:00
proc readValue * (
r : var EnvvarReader , value : var EthRpcUrl
) {. raises : [ SerializationError ] . } =
2024-02-16 13:06:31 +00:00
try :
value = parseCmdArg ( EthRpcUrl , r . readValue ( string ) )
except CatchableError :
raise newException ( SerializationError , getCurrentExceptionMsg ( ) )
2024-03-15 23:08:47 +00:00
proc load * ( T : type WakuNodeConf , version = " " ) : ConfResult [ T ] =
2022-11-03 09:45:06 +00:00
try :
let conf = WakuNodeConf . load (
2024-03-15 23:08:47 +00:00
version = version ,
secondarySources = proc (
conf : WakuNodeConf , sources : auto
) {. gcsafe , raises : [ ConfigurationError ] . } =
2022-11-03 16:58:48 +00:00
sources . addConfigFile ( Envvar , InputFile ( " wakunode2 " ) )
2022-11-03 09:45:06 +00:00
if conf . configFile . isSome ( ) :
sources . addConfigFile ( Toml , conf . configFile . get ( ) )
2024-03-15 23:08:47 +00:00
,
2022-11-03 09:45:06 +00:00
)
2024-09-18 13:58:07 +00:00
2022-11-03 09:45:06 +00:00
ok ( conf )
except CatchableError :
err ( getCurrentExceptionMsg ( ) )
2024-05-10 08:56:17 +00:00
proc defaultWakuNodeConf * ( ) : ConfResult [ WakuNodeConf ] =
try :
let conf = WakuNodeConf . load ( version = " " , cmdLine = @ [ ] )
return ok ( conf )
except CatchableError :
return err ( " exception in defaultWakuNodeConf: " & getCurrentExceptionMsg ( ) )