From 36d4a61dc497a2ea038a7f7242ed8ecc6519727b Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sun, 19 Jun 2022 17:47:39 -0400 Subject: [PATCH] chore: add missing flags --- Makefile | 4 +++- VERSION | 1 + waku.go | 39 ++++++++++++++++++++++++++++--------- waku/node.go | 27 +++++++++++++++---------- waku/options.go | 9 ++++++--- waku/v2/node/const.go | 3 +++ waku/v2/node/wakunode2.go | 12 +++++++----- waku/v2/node/wakuoptions.go | 2 ++ waku/v2/rpc/debug.go | 3 ++- 9 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 VERSION diff --git a/Makefile b/Makefile index 3982415c..cf1179c0 100644 --- a/Makefile +++ b/Makefile @@ -32,9 +32,11 @@ else endif GIT_COMMIT = $(shell git rev-parse --short HEAD) +VERSION = $(shell cat ./VERSION) BUILD_FLAGS ?= $(shell echo "-ldflags='\ - -X github.com/status-im/go-waku/waku/v2/node.GitCommit=$(GIT_COMMIT)'") + -X github.com/status-im/go-waku/waku/v2/node.GitCommit=$(GIT_COMMIT) \ + -X github.com/status-im/go-waku/waku/v2/node.Version=$(VERSION)'") all: build diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..8a9ecc2e --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/waku.go b/waku.go index 43fd158d..0910ed91 100644 --- a/waku.go +++ b/waku.go @@ -108,6 +108,7 @@ func main() { }, &cli.BoolFlag{ Name: "use-db", + Aliases: []string{"sqlite-store"}, Usage: "Use SQLiteDB to persist information", Destination: &options.UseDB, }, @@ -115,11 +116,19 @@ func main() { Name: "persist-messages", Usage: "Enable message persistence", Destination: &options.Store.PersistMessages, + Value: false, + }, + &cli.BoolFlag{ + Name: "persist-peers", + Usage: "Enable peer persistence", + Destination: &options.PersistPeers, + Value: false, }, &cli.StringFlag{ - Name: "nat", - Usage: "TODO - Not implemented yet.", // This was added so js-waku test don't fail - Destination: &options.NAT, + Name: "nat", // This was added so js-waku test don't fail + Usage: "TODO: Not implemented yet. Specify method to use for determining public address: any, none ('any' will attempt upnp/pmp)", + Value: "any", + Destination: &options.NAT, // TODO: accept none,any,upnp,extaddr }, &cli.StringFlag{ Name: "db-path", @@ -145,6 +154,12 @@ func main() { 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: "version", + Value: false, + Usage: "prints the version", + Destination: &options.Version, + }, &cli.StringFlag{ Name: "log-encoding", Value: "console", @@ -165,7 +180,7 @@ func main() { &cli.BoolFlag{ Name: "relay-peer-exchange", Aliases: []string{"peer-exchange"}, - Value: true, + Value: false, Usage: "Enable GossipSub Peer Exchange", Destination: &options.Relay.PeerExchange, }, @@ -186,10 +201,10 @@ func main() { 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, + Name: "store-seconds", + Value: (86400 * 30), // 30 days + Usage: "maximum number of seconds before a message is removed from the store", + Destination: &options.Store.RetentionMaxSeconds, }, &cli.IntFlag{ Name: "store-capacity", @@ -202,6 +217,12 @@ func main() { Usage: "Multiaddr of a peer that supports store protocol. Option may be repeated", Destination: &options.Store.Nodes, }, + &cli.BoolFlag{ + Name: "swap", + Usage: "Enable swap protocol", + Value: false, + Destination: &options.Swap.Enable, + }, &cli.IntFlag{ Name: "swap-mode", Value: 0, @@ -336,7 +357,7 @@ func main() { }, &cli.IntFlag{ Name: "rpc-port", - Value: 8009, + Value: 8545, Usage: "Listening port of the rpc server", Destination: &options.RPCServer.Port, }, diff --git a/waku/node.go b/waku/node.go index 0b023993..e6f93f69 100644 --- a/waku/node.go +++ b/waku/node.go @@ -160,17 +160,24 @@ func Execute(options Options) { return } + if options.Version { + fmt.Printf("version / git commit hash: %s(%s)\n", node.Version, node.GitCommit) + return + } + if options.UseDB { - // Create persistent peerstore - queries, err := sqlite.NewQueries("peerstore", db) - failOnErr(err, "Peerstore") + if options.PersistPeers { + // Create persistent peerstore + queries, err := sqlite.NewQueries("peerstore", db) + failOnErr(err, "Peerstore") - datastore := dssql.NewDatastore(db, queries) - opts := pstoreds.DefaultOpts() - peerStore, err := pstoreds.NewPeerstore(ctx, datastore, opts) - failOnErr(err, "Peerstore") + datastore := dssql.NewDatastore(db, queries) + opts := pstoreds.DefaultOpts() + peerStore, err := pstoreds.NewPeerstore(ctx, datastore, opts) + failOnErr(err, "Peerstore") - libp2pOpts = append(libp2pOpts, libp2p.Peerstore(peerStore)) + libp2pOpts = append(libp2pOpts, libp2p.Peerstore(peerStore)) + } } nodeOpts = append(nodeOpts, node.WithLibP2POptions(libp2pOpts...)) @@ -194,8 +201,8 @@ func Execute(options Options) { if options.Store.Enable { if options.Store.PersistMessages { - nodeOpts = append(nodeOpts, node.WithWakuStoreAndRetentionPolicy(options.Store.ShouldResume, options.Store.RetentionMaxDaysDuration(), options.Store.RetentionMaxMessages)) - dbStore, err := persistence.NewDBStore(logger, persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxDaysDuration())) + nodeOpts = append(nodeOpts, node.WithWakuStoreAndRetentionPolicy(options.Store.ShouldResume, options.Store.RetentionMaxSecondsDuration(), options.Store.RetentionMaxMessages)) + dbStore, err := persistence.NewDBStore(logger, persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxSecondsDuration())) failOnErr(err, "DBStore") nodeOpts = append(nodeOpts, node.WithMessageProvider(dbStore)) } else { diff --git a/waku/options.go b/waku/options.go index 3f5b6426..ac014b53 100644 --- a/waku/options.go +++ b/waku/options.go @@ -55,20 +55,21 @@ type StoreOptions struct { Enable bool PersistMessages bool ShouldResume bool - RetentionMaxDays int + RetentionMaxSeconds int RetentionMaxMessages int Nodes cli.StringSlice } // SwapOptions are settings used for configuring the swap protocol type SwapOptions struct { + Enable bool Mode int PaymentThreshold int DisconnectThreshold int } -func (s *StoreOptions) RetentionMaxDaysDuration() time.Duration { - return time.Duration(s.RetentionMaxDays) * time.Hour * 24 +func (s *StoreOptions) RetentionMaxSecondsDuration() time.Duration { + return time.Duration(s.RetentionMaxSeconds) * time.Second } // DNSDiscoveryOptions are settings used for enabling DNS-based discovery @@ -121,10 +122,12 @@ type Options struct { UseDB bool DBPath string AdvertiseAddress string + Version bool ShowAddresses bool LogLevel string LogEncoding string NAT string + PersistPeers bool Websocket WSOptions Relay RelayOptions diff --git a/waku/v2/node/const.go b/waku/v2/node/const.go index 0d02b3a4..378473df 100644 --- a/waku/v2/node/const.go +++ b/waku/v2/node/const.go @@ -2,3 +2,6 @@ package node // GitCommit is a commit hash. var GitCommit string + +// Version is the version of go-waku at the time of compilation +var Version string diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index e1b64c7a..eef9c993 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -241,12 +241,14 @@ func (w *WakuNode) checkForAddressChanges() { // Start initializes all the protocols that were setup in the WakuNode func (w *WakuNode) Start() error { - w.log.Info("Version details ", zap.String("commit", GitCommit)) + w.log.Info("Version details ", zap.String("commit", GitCommit), zap.String("version", Version)) - w.swap = swap.NewWakuSwap(w.log, []swap.SwapOption{ - swap.WithMode(w.opts.swapMode), - swap.WithThreshold(w.opts.swapPaymentThreshold, w.opts.swapDisconnectThreshold), - }...) + if w.opts.enableSwap { + w.swap = swap.NewWakuSwap(w.log, []swap.SwapOption{ + swap.WithMode(w.opts.swapMode), + swap.WithThreshold(w.opts.swapPaymentThreshold, w.opts.swapDisconnectThreshold), + }...) + } w.store = w.storeFactory(w) if w.opts.enableStore { diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index 017457fc..70ee54d6 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -60,6 +60,7 @@ type WakuNodeParameters struct { minRelayPeersToPublish int enableStore bool + enableSwap bool shouldResume bool storeMsgs bool messageProvider store.MessageProvider @@ -312,6 +313,7 @@ func WithWakuStoreFactory(factory storeFactory) WakuNodeOption { // WithWakuSwap set the option of the Waku V2 Swap protocol func WithWakuSwap(mode int, disconnectThreshold, paymentThreshold int) WakuNodeOption { return func(params *WakuNodeParameters) error { + params.enableSwap = true params.swapMode = mode params.swapDisconnectThreshold = disconnectThreshold params.swapPaymentThreshold = paymentThreshold diff --git a/waku/v2/rpc/debug.go b/waku/v2/rpc/debug.go index c7a16501..4f0d15e2 100644 --- a/waku/v2/rpc/debug.go +++ b/waku/v2/rpc/debug.go @@ -1,6 +1,7 @@ package rpc import ( + "fmt" "net/http" "github.com/status-im/go-waku/waku/v2/node" @@ -29,6 +30,6 @@ func (d *DebugService) GetV1Info(r *http.Request, args *InfoArgs, reply *InfoRep type VersionResponse string func (d *DebugService) GetV1Version(r *http.Request, args *InfoArgs, reply *VersionResponse) error { - *reply = VersionResponse(node.GitCommit) + *reply = VersionResponse(fmt.Sprintf("%s(%s)", node.Version, node.GitCommit)) return nil }