2024-05-21 21:03:33 +00:00
|
|
|
import
|
2024-07-09 11:14:28 +00:00
|
|
|
results,
|
2024-05-21 21:03:33 +00:00
|
|
|
chronos,
|
|
|
|
confutils,
|
|
|
|
confutils/defs,
|
|
|
|
confutils/std/net,
|
|
|
|
confutils/toml/defs as confTomlDefs,
|
|
|
|
confutils/toml/std/net as confTomlNet,
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
libp2p/crypto/secp,
|
|
|
|
libp2p/multiaddress,
|
2024-10-25 20:59:02 +00:00
|
|
|
secp256k1
|
|
|
|
|
2024-05-21 21:03:33 +00:00
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[
|
|
|
|
common/confutils/envvar/defs as confEnvvarDefs,
|
|
|
|
common/confutils/envvar/std/net as confEnvvarNet,
|
|
|
|
common/logging,
|
|
|
|
factory/external_config,
|
2024-08-21 12:54:18 +00:00
|
|
|
waku_core,
|
2024-07-05 22:03:38 +00:00
|
|
|
]
|
2024-05-21 21:03:33 +00:00
|
|
|
|
|
|
|
export confTomlDefs, confTomlNet, confEnvvarDefs, confEnvvarNet
|
|
|
|
|
|
|
|
const
|
2024-08-21 12:54:18 +00:00
|
|
|
LitePubsubTopic* = PubsubTopic("/waku/2/rs/66/0")
|
2024-05-21 21:03:33 +00:00
|
|
|
LiteContentTopic* = ContentTopic("/tester/1/light-pubsub-example/proto")
|
2024-08-21 12:54:18 +00:00
|
|
|
DefaultMinTestMessageSizeStr* = "1KiB"
|
|
|
|
DefaultMaxTestMessageSizeStr* = "150KiB"
|
2024-05-21 21:03:33 +00:00
|
|
|
|
|
|
|
type TesterFunctionality* = enum
|
|
|
|
SENDER # pumps messages to the network
|
|
|
|
RECEIVER # gather and analyze messages from the network
|
|
|
|
|
|
|
|
type LiteProtocolTesterConf* = object
|
|
|
|
configFile* {.
|
|
|
|
desc:
|
|
|
|
"Loads configuration from a TOML file (cmd-line parameters take precedence) for the light waku node",
|
|
|
|
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.DEBUG,
|
|
|
|
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-05-21 21:03:33 +00:00
|
|
|
defaultValue: logging.LogFormat.TEXT,
|
|
|
|
name: "log-format"
|
|
|
|
.}: logging.LogFormat
|
|
|
|
|
|
|
|
## Test configuration
|
2024-10-25 20:59:02 +00:00
|
|
|
serviceNode* {.
|
|
|
|
desc: "Peer multiaddr of the service node.", defaultValue: "", name: "service-node"
|
|
|
|
.}: string
|
|
|
|
|
|
|
|
bootstrapNode* {.
|
|
|
|
desc:
|
|
|
|
"Peer multiaddr of the bootstrap node. If `service-node` not set, it is used to retrieve potential service nodes of the network.",
|
|
|
|
defaultValue: "",
|
|
|
|
name: "bootstrap-node"
|
|
|
|
.}: string
|
2024-05-21 21:03:33 +00:00
|
|
|
|
|
|
|
nat* {.
|
|
|
|
desc:
|
|
|
|
"Specify method to use for determining public address. " &
|
|
|
|
"Must be one of: any, none, upnp, pmp, extip:<IP>.",
|
|
|
|
defaultValue: "any"
|
|
|
|
.}: string
|
|
|
|
|
|
|
|
testFunc* {.
|
|
|
|
desc: "Specifies the lite protocol tester side. Supported values: sender, receiver.",
|
|
|
|
defaultValue: TesterFunctionality.RECEIVER,
|
|
|
|
name: "test-func"
|
|
|
|
.}: TesterFunctionality
|
|
|
|
|
|
|
|
numMessages* {.
|
|
|
|
desc: "Number of messages to send.", defaultValue: 120, name: "num-messages"
|
|
|
|
.}: uint32
|
|
|
|
|
2024-08-21 12:54:18 +00:00
|
|
|
startPublishingAfter* {.
|
|
|
|
desc: "Wait number of seconds before start publishing messages.",
|
|
|
|
defaultValue: 5,
|
|
|
|
name: "start-publishing-after"
|
|
|
|
.}: uint32
|
|
|
|
|
2024-11-26 19:42:27 +00:00
|
|
|
messageInterval* {.
|
2024-05-21 21:03:33 +00:00
|
|
|
desc: "Delay between messages in milliseconds.",
|
|
|
|
defaultValue: 1000,
|
2024-11-26 19:42:27 +00:00
|
|
|
name: "message-interval"
|
2024-05-21 21:03:33 +00:00
|
|
|
.}: uint32
|
|
|
|
|
|
|
|
pubsubTopics* {.
|
|
|
|
desc: "Default pubsub topic to subscribe to. Argument may be repeated.",
|
|
|
|
defaultValue: @[LitePubsubTopic],
|
|
|
|
name: "pubsub-topic"
|
|
|
|
.}: seq[PubsubTopic]
|
|
|
|
|
|
|
|
## TODO: extend lite protocol tester configuration based on testing needs
|
|
|
|
# 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-05-21 21:03:33 +00:00
|
|
|
# defaultValue: @[],
|
|
|
|
# name: "shard"
|
2024-06-05 13:32:35 +00:00
|
|
|
# .}: seq[uint16]
|
2024-05-21 21:03:33 +00:00
|
|
|
contentTopics* {.
|
|
|
|
desc: "Default content topic to subscribe to. Argument may be repeated.",
|
|
|
|
defaultValue: @[LiteContentTopic],
|
|
|
|
name: "content-topic"
|
|
|
|
.}: seq[ContentTopic]
|
|
|
|
|
|
|
|
clusterId* {.
|
|
|
|
desc:
|
|
|
|
"Cluster id that the node is running in. Node in a different cluster id is disconnected.",
|
|
|
|
defaultValue: 0,
|
|
|
|
name: "cluster-id"
|
2024-08-21 12:54:18 +00:00
|
|
|
.}: uint16
|
|
|
|
|
|
|
|
minTestMessageSize* {.
|
|
|
|
desc:
|
|
|
|
"Minimum message size. Accepted units: KiB, KB, and B. e.g. 1024KiB; 1500 B; etc.",
|
|
|
|
defaultValue: DefaultMinTestMessageSizeStr,
|
|
|
|
name: "min-test-msg-size"
|
|
|
|
.}: string
|
2024-05-21 21:03:33 +00:00
|
|
|
|
2024-08-21 12:54:18 +00:00
|
|
|
maxTestMessageSize* {.
|
|
|
|
desc:
|
|
|
|
"Maximum message size. Accepted units: KiB, KB, and B. e.g. 1024KiB; 1500 B; etc.",
|
|
|
|
defaultValue: DefaultMaxTestMessageSizeStr,
|
|
|
|
name: "max-test-msg-size"
|
|
|
|
.}: string
|
2024-05-21 21:03:33 +00:00
|
|
|
## Tester REST service configuration
|
|
|
|
restAddress* {.
|
|
|
|
desc: "Listening address of the REST HTTP server.",
|
|
|
|
defaultValue: parseIpAddress("127.0.0.1"),
|
|
|
|
name: "rest-address"
|
|
|
|
.}: IpAddress
|
|
|
|
|
2024-10-25 20:59:02 +00:00
|
|
|
testPeers* {.
|
|
|
|
desc: "Run dial test on gathered PeerExchange peers.",
|
2024-11-26 19:42:27 +00:00
|
|
|
defaultValue: false,
|
2024-10-25 20:59:02 +00:00
|
|
|
name: "test-peers"
|
|
|
|
.}: bool
|
|
|
|
|
|
|
|
reqPxPeers* {.
|
|
|
|
desc: "Number of peers to request on PeerExchange.",
|
|
|
|
defaultValue: 100,
|
|
|
|
name: "req-px-peers"
|
|
|
|
.}: uint16
|
|
|
|
|
2024-05-21 21:03:33 +00:00
|
|
|
restPort* {.
|
|
|
|
desc: "Listening port of the REST HTTP server.",
|
|
|
|
defaultValue: 8654,
|
|
|
|
name: "rest-port"
|
|
|
|
.}: uint16
|
|
|
|
|
2024-11-26 19:42:27 +00:00
|
|
|
fixedServicePeer* {.
|
|
|
|
desc:
|
|
|
|
"Prevent changing the service peer in case of failures, the full test will stict to the first service peer in use.",
|
|
|
|
defaultValue: false,
|
|
|
|
name: "fixed-service-peer"
|
|
|
|
.}: bool
|
|
|
|
|
2024-05-21 21:03:33 +00:00
|
|
|
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: @["*"],
|
|
|
|
name: "rest-allow-origin"
|
|
|
|
.}: seq[string]
|
|
|
|
|
2024-10-25 20:59:02 +00:00
|
|
|
metricsPort* {.
|
|
|
|
desc: "Listening port of the Metrics HTTP server.",
|
|
|
|
defaultValue: 8003,
|
|
|
|
name: "metrics-port"
|
|
|
|
.}: uint16
|
|
|
|
|
2024-05-21 21:03:33 +00:00
|
|
|
{.push warning[ProveInit]: off.}
|
|
|
|
|
|
|
|
proc load*(T: type LiteProtocolTesterConf, version = ""): ConfResult[T] =
|
|
|
|
try:
|
|
|
|
let conf = LiteProtocolTesterConf.load(
|
|
|
|
version = version,
|
|
|
|
secondarySources = proc(
|
|
|
|
conf: LiteProtocolTesterConf, sources: auto
|
|
|
|
) {.gcsafe, raises: [ConfigurationError].} =
|
2024-09-11 01:51:42 +00:00
|
|
|
sources.addConfigFile(Envvar, InputFile("liteprotocoltester")),
|
2024-05-21 21:03:33 +00:00
|
|
|
)
|
|
|
|
ok(conf)
|
|
|
|
except CatchableError:
|
|
|
|
err(getCurrentExceptionMsg())
|
|
|
|
|
|
|
|
{.pop.}
|