fix: flag naming inconsistency (#194)

Fixes #80
This commit is contained in:
Richard Ramos 2022-02-21 11:23:52 -04:00 committed by GitHub
parent 0db40c7de5
commit 3e5d0d0843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 406 additions and 97 deletions

View File

@ -166,6 +166,7 @@ github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d h1:bE1UyBQ5aE6FjhNY4lbPtMqh7VDldoVkvZMtFEbd+CE=
@ -998,6 +999,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=

View File

@ -166,6 +166,7 @@ github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d h1:bE1UyBQ5aE6FjhNY4lbPtMqh7VDldoVkvZMtFEbd+CE=
@ -1015,6 +1016,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=

View File

@ -166,6 +166,7 @@ github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d h1:bE1UyBQ5aE6FjhNY4lbPtMqh7VDldoVkvZMtFEbd+CE=
@ -998,6 +999,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=

3
go.mod
View File

@ -6,6 +6,7 @@ replace github.com/ethereum/go-ethereum v1.10.4 => github.com/status-im/go-ether
require (
contrib.go.opencensus.io/exporter/prometheus v0.4.0
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d
github.com/ethereum/go-ethereum v1.10.13
github.com/gogo/protobuf v1.3.2
@ -13,7 +14,6 @@ require (
github.com/gorilla/rpc v1.2.0
github.com/ipfs/go-ds-sql v0.2.0
github.com/ipfs/go-log v1.0.5
github.com/jessevdk/go-flags v1.4.0
github.com/libp2p/go-libp2p v0.15.1
github.com/libp2p/go-libp2p-connmgr v0.2.4
github.com/libp2p/go-libp2p-core v0.9.0
@ -27,6 +27,7 @@ require (
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/urfave/cli/v2 v2.3.0
go.opencensus.io v0.23.0
go.uber.org/zap v1.19.0
)

11
go.sum
View File

@ -167,8 +167,11 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d h1:bE1UyBQ5aE6FjhNY4lbPtMqh7VDldoVkvZMtFEbd+CE=
@ -489,7 +492,6 @@ github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
@ -1014,8 +1016,11 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
@ -1071,8 +1076,6 @@ github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc=
github.com/status-im/go-discover v0.0.0-20211207172452-f99706cd09e3 h1:F6JbJ4bg8vCUwueAjM1ssdbmuzmJIrF5253DsK6VO9U=
github.com/status-im/go-discover v0.0.0-20211207172452-f99706cd09e3/go.mod h1:sfq3nyUDYY7Z4SnmDZ/KxTNj/7vu+Eyp4bsm1Hfj1QQ=
github.com/status-im/go-discover v0.0.0-20211207185514-87bd8c3fe429 h1:9WvvSmX33Cng0sldAFmnkB9yzsfs5tSHP4BpM2NFTB0=
github.com/status-im/go-discover v0.0.0-20211207185514-87bd8c3fe429/go.mod h1:sfq3nyUDYY7Z4SnmDZ/KxTNj/7vu+Eyp4bsm1Hfj1QQ=
github.com/status-im/go-waku-rendezvous v0.0.0-20211018070416-a93f3b70c432 h1:cbNFU38iimo9fY4B7CdF/fvIF6tNPJIZjBbpfmW2EY4=
@ -1102,7 +1105,9 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=

330
waku.go
View File

@ -1,37 +1,329 @@
package main
import (
"fmt"
"os"
logging "github.com/ipfs/go-log"
"github.com/jessevdk/go-flags"
"github.com/status-im/go-waku/waku"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/urfave/cli/v2"
)
var options waku.Options
var parser = flags.NewParser(&options, flags.Default)
func main() {
if _, err := parser.Parse(); err != nil {
os.Exit(1)
app := &cli.App{
Flags: []cli.Flag{
&cli.IntFlag{
Name: "tcp-port",
Aliases: []string{"port", "p"},
Value: 60000,
Usage: "Libp2p TCP listening port (0 for random)",
Destination: &options.Port,
},
&cli.StringFlag{
Name: "address",
Value: "0.0.0.0",
Usage: "Listening address",
Destination: &options.Address,
},
&cli.BoolFlag{
Name: "websocket-support",
Aliases: []string{"ws"},
Usage: "Enable websockets support",
Destination: &options.EnableWS,
},
&cli.IntFlag{
Name: "websocket-port",
Aliases: []string{"ws-port"},
Value: 60001,
Usage: "Libp2p TCP listening port for websocket connection (0 for random)",
Destination: &options.WSPort,
},
&cli.StringFlag{
Name: "websocket-address",
Aliases: []string{"ws-address"},
Value: "0.0.0.0",
Usage: "Listening address for websocket connections",
Destination: &options.WSAddress,
},
&cli.StringFlag{
Name: "nodekey",
Usage: "P2P node private key as hex. Can also be set with GOWAKU-NODEKEY env variable (default random)",
Destination: &options.NodeKey,
},
&cli.StringFlag{
Name: "key-file",
Value: "./nodekey",
Usage: "Path to a file containing the private key for the P2P node",
Destination: &options.KeyFile,
},
&cli.BoolFlag{
Name: "generate-key",
Usage: "Generate private key file at path specified in --key-file",
Destination: &options.GenerateKey,
},
&cli.BoolFlag{
Name: "overwrite",
Usage: "When generating a keyfile, overwrite the nodekey file if it already exists",
Destination: &options.Overwrite,
},
&cli.StringSliceFlag{
Name: "staticnode",
Usage: "Multiaddr of peer to directly connect with. Option may be repeated",
Destination: &options.StaticNodes,
},
&cli.IntFlag{
Name: "keep-alive",
Value: 20,
Usage: "Interval in seconds for pinging peers to keep the connection alive.",
Destination: &options.KeepAlive,
},
&cli.BoolFlag{
Name: "use-db",
Usage: "Use SQLiteDB to persist information",
Destination: &options.UseDB,
},
&cli.StringFlag{
Name: "db-path",
Aliases: []string{"dbpath"},
Value: "./store.db",
Usage: "Path to DB file",
Destination: &options.DBPath,
},
&cli.StringFlag{
Name: "advertise-address",
Usage: "External address to advertise to other nodes (overrides --address and --ws-address flags)",
Destination: &options.AdvertiseAddress,
},
&cli.BoolFlag{
Name: "show-addresses",
Usage: "Display listening addresses according to current configuration",
Destination: &options.ShowAddresses,
},
&cli.StringFlag{
Name: "log-level",
Aliases: []string{"l"},
Value: "INFO",
Usage: "Define the logging level, supported strings are: DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, and their lower-case forms.",
Destination: &options.LogLevel,
},
&cli.BoolFlag{
Name: "relay",
Value: true,
Usage: "Enable relay protocol",
Destination: &options.Relay.Enable,
},
&cli.StringSliceFlag{
Name: "topics",
Usage: "List of topics to listen",
Destination: &options.Relay.Topics,
},
&cli.BoolFlag{
Name: "peer-exchange",
Value: true,
Usage: "Enable GossipSub Peer Exchange",
Destination: &options.Relay.PeerExchange,
},
&cli.IntFlag{
Name: "min-relay-peers-to-publish",
Value: 1,
Usage: "Minimum number of peers to publish to Relay",
Destination: &options.Relay.MinRelayPeersToPublish,
},
&cli.BoolFlag{
Name: "store",
Usage: "Enable relay protocol",
Destination: &options.Store.Enable,
},
&cli.BoolFlag{
Name: "resume",
Usage: "Fix the gaps in message history",
Destination: &options.Store.ShouldResume,
},
&cli.IntFlag{
Name: "store-days",
Value: 30,
Usage: "maximum number of days before a message is removed from the store",
Destination: &options.Store.RetentionMaxDays,
},
&cli.IntFlag{
Name: "store-capacity",
Value: 50000,
Usage: "maximum number of messages to store",
Destination: &options.Store.RetentionMaxMessages,
},
&cli.StringSliceFlag{
Name: "storenode",
Usage: "Multiaddr of a peer that supports store protocol. Option may be repeated",
Destination: &options.Store.Nodes,
},
&cli.IntFlag{
Name: "swap-mode",
Value: 0,
Usage: "Swap mode: 0=soft, 1=mock, 2=hard",
Destination: &options.Swap.Mode,
},
&cli.IntFlag{
Name: "swap-payment-threshold",
Value: 100,
Usage: "Threshold for payment",
Destination: &options.Swap.PaymentThreshold,
},
&cli.IntFlag{
Name: "swap-disconnect-threshold",
Value: -100,
Usage: "Threshold for disconnecting",
Destination: &options.Swap.DisconnectThreshold,
},
&cli.BoolFlag{
Name: "filter",
Usage: "Enable filter protocol",
Destination: &options.Filter.Enable,
},
&cli.BoolFlag{
Name: "light-client",
Usage: "Don't accept filter subscribers",
Destination: &options.Filter.DisableFullNode,
},
&cli.StringSliceFlag{
Name: "filternode",
Usage: "Multiaddr of a peer that supports filter protocol. Option may be repeated",
Destination: &options.Filter.Nodes,
},
&cli.IntFlag{
Name: "filter-timeout",
Value: 14400,
Usage: "Timeout for filter node in seconds",
Destination: &options.Filter.Timeout,
},
&cli.BoolFlag{
Name: "lightpush",
Usage: "Enable lightpush protocol",
Destination: &options.LightPush.Enable,
},
&cli.StringSliceFlag{
Name: "lightpushnode",
Usage: "Multiaddr of a peer that supports lightpush protocol. Option may be repeated",
Destination: &options.LightPush.Nodes,
},
&cli.BoolFlag{
Name: "discv5-discovery",
Usage: "Enable discovering nodes via Node Discovery v5",
Destination: &options.DiscV5.Enable,
},
&cli.StringSliceFlag{
Name: "discv5-bootstrap-node",
Usage: "Text-encoded ENR for bootstrap node. Used when connecting to the network. Option may be repeated",
Destination: &options.DiscV5.Nodes,
},
&cli.IntFlag{
Name: "discv5-udp-port",
Value: 9000,
Usage: "Listening UDP port for Node Discovery v5.",
Destination: &options.DiscV5.Port,
},
&cli.BoolFlag{
Name: "discv5-enr-auto-update",
Usage: "Discovery can automatically update its ENR with the IP address as seen by other nodes it communicates with.",
Destination: &options.DiscV5.AutoUpdate,
},
&cli.BoolFlag{
Name: "rendezvous",
Usage: "Enable rendezvous protocol for peer discovery",
Destination: &options.Rendezvous.Enable,
},
&cli.StringSliceFlag{
Name: "rendezvous-node",
Usage: "Multiaddr of a waku2 rendezvous node. Option may be repeated",
Destination: &options.Rendezvous.Nodes,
},
&cli.BoolFlag{
Name: "rendezvous-server",
Usage: "Node will act as rendezvous server",
Destination: &options.RendezvousServer.Enable,
},
&cli.StringFlag{
Name: "rendezvous-db-path",
Value: "/tmp/rendezvous",
Usage: "Path where peer records database will be stored",
Destination: &options.RendezvousServer.DBPath,
},
&cli.BoolFlag{
Name: "dns-discovery",
Usage: "Enable DNS discovery",
Destination: &options.DNSDiscovery.Enable,
},
&cli.StringFlag{
Name: "dns-discovery-url",
Usage: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
Destination: &options.DNSDiscovery.URL,
},
&cli.StringFlag{
Name: "dns-discovery-name-server",
Aliases: []string{"dns-discovery-nameserver"},
Usage: "DNS nameserver IP to query (empty to use system's default)",
Destination: &options.DNSDiscovery.Nameserver,
},
&cli.BoolFlag{
Name: "metrics-server",
Aliases: []string{"metrics"},
Usage: "Enable the metrics server",
Destination: &options.Metrics.Enable,
},
&cli.StringFlag{
Name: "metrics-server-address",
Aliases: []string{"metrics-address"},
Value: "127.0.0.1",
Usage: "Listening address of the metrics server",
Destination: &options.Metrics.Address,
},
&cli.IntFlag{
Name: "metrics-server-port",
Aliases: []string{"metrics-port"},
Value: 8008,
Usage: "Listening HTTP port of the metrics server",
Destination: &options.Metrics.Port,
},
&cli.BoolFlag{
Name: "rpc",
Usage: "Enable the rpc server",
Destination: &options.RPCServer.Enable,
},
&cli.IntFlag{
Name: "rpc-port",
Value: 8009,
Usage: "Listening port of the rpc server",
Destination: &options.RPCServer.Port,
},
&cli.StringFlag{
Name: "rpc-address",
Value: "127.0.0.1",
Usage: "Listening address of the rpc server",
Destination: &options.RPCServer.Address,
},
},
Action: func(c *cli.Context) error {
// for go-libp2p loggers
lvl, err := logging.LevelFromString(options.LogLevel)
if err != nil {
return err
}
logging.SetAllLoggers(lvl)
// go-waku logger
err = utils.SetLogLevel(options.LogLevel)
if err != nil {
return err
}
waku.Execute(options)
return nil
},
}
// for go-libp2p loggers
lvl, err := logging.LevelFromString(options.LogLevel)
err := app.Run(os.Args)
if err != nil {
os.Exit(1)
panic(err)
}
logging.SetAllLoggers(lvl)
// go-waku logger
fmt.Println(options.LogLevel)
err = utils.SetLogLevel(options.LogLevel)
if err != nil {
os.Exit(1)
}
waku.Execute(options)
}

View File

@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p/enode"
dssql "github.com/ipfs/go-ds-sql"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"github.com/libp2p/go-libp2p"
@ -160,7 +161,7 @@ func Execute(options Options) {
nodeOpts = append(nodeOpts, node.WithLibP2POptions(libp2pOpts...))
if !options.Relay.Disable {
if options.Relay.Enable {
var wakurelayopts []pubsub.Option
wakurelayopts = append(wakurelayopts, pubsub.WithPeerExchange(options.Relay.PeerExchange))
nodeOpts = append(nodeOpts, node.WithWakuRelayAndMinPeers(options.Relay.MinRelayPeersToPublish, wakurelayopts...))
@ -198,7 +199,7 @@ func Execute(options Options) {
if options.DiscV5.Enable {
var bootnodes []*enode.Node
for _, addr := range options.DiscV5.Nodes {
for _, addr := range options.DiscV5.Nodes.Value() {
bootnode, err := enode.Parse(enode.ValidSchemes, addr)
if err != nil {
utils.Logger().Fatal("could not parse enr: ", zap.Error(err))
@ -212,10 +213,10 @@ func Execute(options Options) {
failOnErr(err, "Wakunode")
addPeers(wakuNode, options.Rendezvous.Nodes, rendezvous.RendezvousID_v001)
addPeers(wakuNode, options.Store.Nodes, store.StoreID_v20beta3)
addPeers(wakuNode, options.LightPush.Nodes, lightpush.LightPushID_v20beta1)
addPeers(wakuNode, options.Filter.Nodes, filter.FilterID_v20beta1)
addPeers(wakuNode, options.Rendezvous.Nodes.Value(), rendezvous.RendezvousID_v001)
addPeers(wakuNode, options.Store.Nodes.Value(), store.StoreID_v20beta3)
addPeers(wakuNode, options.LightPush.Nodes.Value(), lightpush.LightPushID_v20beta1)
addPeers(wakuNode, options.Filter.Nodes.Value(), filter.FilterID_v20beta1)
if err = wakuNode.Start(); err != nil {
utils.Logger().Fatal(fmt.Errorf("could not start waku node, %w", err).Error())
@ -227,19 +228,19 @@ func Execute(options Options) {
}
}
if len(options.Relay.Topics) == 0 {
options.Relay.Topics = []string{string(relay.DefaultWakuTopic)}
if len(options.Relay.Topics.Value()) == 0 {
options.Relay.Topics = *cli.NewStringSlice(relay.DefaultWakuTopic)
}
if !options.Relay.Disable {
for _, nodeTopic := range options.Relay.Topics {
if options.Relay.Enable {
for _, nodeTopic := range options.Relay.Topics.Value() {
sub, err := wakuNode.Relay().SubscribeToTopic(ctx, nodeTopic)
failOnErr(err, "Error subscring to topic")
wakuNode.Broadcaster().Unregister(sub.C)
}
}
for _, n := range options.StaticNodes {
for _, n := range options.StaticNodes.Value() {
go func(node string) {
err = wakuNode.DialPeer(ctx, node)
if err != nil {

View File

@ -1,36 +1,40 @@
package waku
import "time"
import (
"time"
"github.com/urfave/cli/v2"
)
type RendezvousOptions struct {
Enable bool `long:"rendezvous" description:"Enable rendezvous protocol for peer discovery"`
Nodes []string `long:"rendezvous-node" description:"Multiaddr of a waku2 rendezvous node. Option may be repeated"`
Enable bool
Nodes cli.StringSlice
}
type RendezvousServerOptions struct {
Enable bool `long:"rendezvous-server" description:"Node will act as rendezvous server"`
DBPath string `long:"rendezvous-db-path" description:"Path where peer records database will be stored" default:"/tmp/rendezvous"`
Enable bool
DBPath string
}
type DiscV5Options struct {
Enable bool `long:"discv5-discovery" description:"Enable discovering nodes via Node Discovery v5"`
Nodes []string `long:"discv5-bootstrap-node" description:"Text-encoded ENR for bootstrap node. Used when connecting to the network. Option may be repeated"`
Port int `long:"discv5-udp-port" description:"Listening UDP port for Node Discovery v5." default:"9000"`
AutoUpdate bool `long:"discv5-enr-auto-update" description:"Discovery can automatically update its ENR with the IP address as seen by other nodes it communicates with." `
Enable bool
Nodes cli.StringSlice
Port int
AutoUpdate bool
}
type RelayOptions struct {
Disable bool `long:"no-relay" description:"Disable relay protocol"`
Topics []string `long:"topics" description:"List of topics to listen"`
PeerExchange bool `long:"peer-exchange" description:"Enable GossipSub Peer Exchange"`
MinRelayPeersToPublish int `long:"min-relay-peers-to-publish" description:"Minimum number of peers to publish to Relay" default:"1"`
Enable bool
Topics cli.StringSlice
PeerExchange bool
MinRelayPeersToPublish int
}
type FilterOptions struct {
Enable bool `long:"filter" description:"Enable filter protocol"`
DisableFullNode bool `long:"light-client" description:"Don't accept filter subscribers"`
Nodes []string `long:"filter-node" description:"Multiaddr of a peer that supports filter protocol. Option may be repeated"`
Timeout int `long:"filter-timeout" description:"Timeout for filter node in seconds" default:"14400"`
Enable bool
DisableFullNode bool
Nodes cli.StringSlice
Timeout int
}
// LightpushOptions are settings used to enable the lightpush protocol. This is
@ -40,26 +44,26 @@ type FilterOptions struct {
// broadcast the message and return a confirmation that the message was
// broadcasted
type LightpushOptions struct {
Enable bool `long:"lightpush" description:"Enable lightpush protocol"`
Nodes []string `long:"lightpush-node" description:"Multiaddr of a peer that supports lightpush protocol. Option may be repeated"`
Enable bool
Nodes cli.StringSlice
}
// StoreOptions are settings used for enabling the store protocol, used to
// retrieve message history from other nodes as well as acting as a store
// node and provide message history to nodes that ask for it.
type StoreOptions struct {
Enable bool `long:"store" description:"Enable store protocol"`
ShouldResume bool `long:"resume" description:"fix the gap in message history"`
RetentionMaxDays int `long:"keep-history-days" description:"maximum number of days before a message is removed from the store" default:"30"`
RetentionMaxMessages int `long:"max-history-messages" description:"maximum number of messages to store" default:"50000"`
Nodes []string `long:"store-node" description:"Multiaddr of a peer that supports store protocol. Option may be repeated"`
Enable bool
ShouldResume bool
RetentionMaxDays int
RetentionMaxMessages int
Nodes cli.StringSlice
}
// SwapOptions are settings used for configuring the swap protocol
type SwapOptions struct {
Mode int `long:"swap-mode" description:"Swap mode: 0=soft, 1=mock, 2=hard" default:"0"`
PaymentThreshold int `long:"swap-payment-threshold" description:"Threshold for payment" default:"100"`
DisconnectThreshold int `long:"swap-disconnect-threshold" description:"Threshold for disconnecting" default:"-100"`
Mode int
PaymentThreshold int
DisconnectThreshold int
}
func (s *StoreOptions) RetentionMaxDaysDuration() time.Duration {
@ -70,55 +74,55 @@ func (s *StoreOptions) RetentionMaxDaysDuration() time.Duration {
// protocol that stores merkle trees in DNS records which contain connection
// information for nodes. It's very useful for bootstrapping a p2p network.
type DNSDiscoveryOptions struct {
Enable bool `long:"dns-discovery" description:"Enable DNS discovery"`
URL string `long:"dns-discovery-url" description:"URL for DNS node list in format 'enrtree://<key>@<fqdn>'"`
Nameserver string `long:"dns-discovery-nameserver" description:"DNS nameserver IP to query (empty to use system's default)"`
Enable bool
URL string
Nameserver string
}
// MetricsOptions are settings used to start a prometheus server for obtaining
// useful node metrics to monitor the health of behavior of the go-waku node.
type MetricsOptions struct {
Enable bool `long:"metrics" description:"Enable the metrics server"`
Address string `long:"metrics-address" description:"Listening address of the metrics server" default:"127.0.0.1"`
Port int `long:"metrics-port" description:"Listening HTTP port of the metrics server" default:"8008"`
Enable bool
Address string
Port int
}
// RPCServerOptions are settings used to start a json rpc server
type RPCServerOptions struct {
Enable bool `long:"rpc" description:"Enable the rpc server"`
Port int `long:"rpc-port" description:"Listening port of the rpc server" default:"8009"`
Address string `long:"rpc-address" description:"Listening address of the rpc server" default:"127.0.0.1"`
Enable bool
Port int
Address string
}
// Options contains all the available features and settings that can be
// configured via flags when executing go-waku as a service.
type Options struct {
Port int `short:"p" long:"port" description:"Libp2p TCP listening port (0 for random)" default:"60000"`
Address string `long:"address" description:"Listening address" default:"0.0.0.0"`
EnableWS bool `long:"ws" description:"Enable websockets support"`
WSPort int `long:"ws-port" description:"Libp2p TCP listening port for websocket connection (0 for random)" default:"60001"`
WSAddress string `long:"ws-address" description:"Listening address for websocket connections" default:"0.0.0.0"`
NodeKey string `long:"nodekey" description:"P2P node private key as hex. Can also be set with GOWAKU-NODEKEY env variable (default random)"`
KeyFile string `long:"key-file" description:"Path to a file containing the private key for the P2P node" default:"./nodekey"`
GenerateKey bool `long:"generate-key" description:"Generate private key file at path specified in --key-file"`
Overwrite bool `long:"overwrite" description:"When generating a keyfile, overwrite the nodekey file if it already exists"`
StaticNodes []string `long:"static-node" description:"Multiaddr of peer to directly connect with. Option may be repeated"`
KeepAlive int `long:"keep-alive" default:"20" description:"Interval in seconds for pinging peers to keep the connection alive."`
UseDB bool `long:"use-db" description:"Use SQLiteDB to persist information"`
DBPath string `long:"dbpath" default:"./store.db" description:"Path to DB file"`
AdvertiseAddress string `long:"advertise-address" default:"" description:"External address to advertise to other nodes (overrides --address and --ws-address flags)"`
ShowAddresses bool `long:"show-addresses" description:"Display listening addresses according to current configuration"`
LogLevel string `short:"l" long:"log-level" description:"Define the logging level, supported strings are: DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, and their lower-case forms." default:"INFO"`
Port int
Address string
EnableWS bool
WSPort int
WSAddress string
NodeKey string
KeyFile string
GenerateKey bool
Overwrite bool
StaticNodes cli.StringSlice
KeepAlive int
UseDB bool
DBPath string
AdvertiseAddress string
ShowAddresses bool
LogLevel string
Relay RelayOptions `group:"Relay Options"`
Store StoreOptions `group:"Store Options"`
Swap SwapOptions `group:"Swap Options"`
Filter FilterOptions `group:"Filter Options"`
LightPush LightpushOptions `group:"LightPush Options"`
DiscV5 DiscV5Options `group:"DiscoveryV5 Options"`
Rendezvous RendezvousOptions `group:"Rendezvous Options"`
RendezvousServer RendezvousServerOptions `group:"Rendezvous Server Options"`
DNSDiscovery DNSDiscoveryOptions `group:"DNS Discovery Options"`
Metrics MetricsOptions `group:"Metrics Options"`
RPCServer RPCServerOptions `group:"RPC Server Options"`
Relay RelayOptions
Store StoreOptions
Swap SwapOptions
Filter FilterOptions
LightPush LightpushOptions
DiscV5 DiscV5Options
Rendezvous RendezvousOptions
RendezvousServer RendezvousServerOptions
DNSDiscovery DNSDiscoveryOptions
Metrics MetricsOptions
RPCServer RPCServerOptions
}