Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding json string support to bindings config #2685

Merged
merged 18 commits into from
May 10, 2024

Conversation

gabrielmer
Copy link
Contributor

@gabrielmer gabrielmer commented May 8, 2024

Description

Supporting setting a node's configuration using a json string

Changes

  • parsing json string and setting it to a WakuNodeConf object in createWaku
  • implemented function defaultWakuNodeConf() to create a WakuNodeConf instance with the default values defined in external_config.nim
  • remove parseCmdArg() functions which are already defined in confutils
  • implemented parseCmdArg() for sequences
  • removed library/waku_thread/config.nim

How to test

Build libwaku:

make libwaku POSTGRES=1

Set your desired configurations in the following json string:

snprintf(jsonConfig, 2048, "{ \
\"host\": \"%s\", \
\"port\": %d, \
\"key\": \"%s\", \
\"relay\": %s, \
\"store\": %s, \
\"storeDbUrl\": \"%s\", \
\"storeRetentionPolicy\": \"%s\", \
\"storeMaxNumDbConnections\": %d \
}", cfgNode.host,
cfgNode.port,
cfgNode.key,
cfgNode.relay ? "true":"false",
cfgNode.store ? "true":"false",
cfgNode.storeDbUrl,
cfgNode.storeRetentionPolicy,
cfgNode.storeMaxNumDbConnections);

For example

snprintf(jsonConfig, 2048, "{ \
                                    \"listenAddress\": \"%s\",    \
                                    \"tcpPort\": %d,        \
                                    \"nodekey\": \"%s\",     \
                                    \"relay\": %s,       \
                                    \"store\": %s,       \
                                    \"storeMessageDbUrl\": \"%s\",  \
                                    \"storeMessageRetentionPolicy\": \"%s\",  \
                                    \"storeMaxNumDbConnections\": %d, \
                                    \"pubsubTopics\": %s  \
                                }", cfgNode.host,
                                    cfgNode.port,
                                    cfgNode.key,
                                    cfgNode.relay ? "true":"false",
                                    cfgNode.store ? "true":"false",
                                    cfgNode.storeDbUrl,
                                    cfgNode.storeRetentionPolicy,
                                    cfgNode.storeMaxNumDbConnections,
                                    "[\"/waku/2/rs/1/0\", \"/waku/2/rs/1/1\", \"/waku/2/rs/1/2\", \"/waku/2/rs/1/3\"]"
                                    );

Build waku_example.c:

make cwaku_example

Run waku_example:

./build/cwaku_example --host=0.0.0.0 --peers=/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ --port=60001 --key=<your_key> 

Issue

closes #2677

@gabrielmer gabrielmer self-assigned this May 8, 2024
Copy link

github-actions bot commented May 8, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2685-rln-v2

Built from 3cabc02

Copy link

github-actions bot commented May 8, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2685-rln-v1

Built from 3cabc02

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!!!! Thank you!!!

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Super elegant and concise!
Thanks for it! 💯

I just added some nitpick comments that I hope you find useful

waku/factory/external_config.nim Outdated Show resolved Hide resolved
waku/factory/external_config.nim Outdated Show resolved Hide resolved
waku/factory/external_config.nim Outdated Show resolved Hide resolved
@gabrielmer gabrielmer force-pushed the feat-adding-json-string-support-to-bindings-config branch 2 times, most recently from eb04391 to 9f1d5f0 Compare May 9, 2024 17:16
@gabrielmer gabrielmer force-pushed the feat-adding-json-string-support-to-bindings-config branch from 9f1d5f0 to e1bc28b Compare May 10, 2024 07:54
@gabrielmer gabrielmer merged commit be5471c into master May 10, 2024
14 of 15 checks passed
@gabrielmer gabrielmer deleted the feat-adding-json-string-support-to-bindings-config branch May 10, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: support node configuration from json-string
3 participants