mirror of https://github.com/status-im/go-waku.git
chore: add missing flags
This commit is contained in:
parent
27b5ab9c51
commit
36d4a61dc4
4
Makefile
4
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
|
||||
|
||||
|
|
39
waku.go
39
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,
|
||||
},
|
||||
|
|
11
waku/node.go
11
waku/node.go
|
@ -160,7 +160,13 @@ 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 {
|
||||
if options.PersistPeers {
|
||||
// Create persistent peerstore
|
||||
queries, err := sqlite.NewQueries("peerstore", db)
|
||||
failOnErr(err, "Peerstore")
|
||||
|
@ -172,6 +178,7 @@ func Execute(options Options) {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue