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
|
endif
|
||||||
|
|
||||||
GIT_COMMIT = $(shell git rev-parse --short HEAD)
|
GIT_COMMIT = $(shell git rev-parse --short HEAD)
|
||||||
|
VERSION = $(shell cat ./VERSION)
|
||||||
|
|
||||||
BUILD_FLAGS ?= $(shell echo "-ldflags='\
|
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
|
all: build
|
||||||
|
|
||||||
|
|
39
waku.go
39
waku.go
|
@ -108,6 +108,7 @@ func main() {
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "use-db",
|
Name: "use-db",
|
||||||
|
Aliases: []string{"sqlite-store"},
|
||||||
Usage: "Use SQLiteDB to persist information",
|
Usage: "Use SQLiteDB to persist information",
|
||||||
Destination: &options.UseDB,
|
Destination: &options.UseDB,
|
||||||
},
|
},
|
||||||
|
@ -115,11 +116,19 @@ func main() {
|
||||||
Name: "persist-messages",
|
Name: "persist-messages",
|
||||||
Usage: "Enable message persistence",
|
Usage: "Enable message persistence",
|
||||||
Destination: &options.Store.PersistMessages,
|
Destination: &options.Store.PersistMessages,
|
||||||
|
Value: false,
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "persist-peers",
|
||||||
|
Usage: "Enable peer persistence",
|
||||||
|
Destination: &options.PersistPeers,
|
||||||
|
Value: false,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "nat",
|
Name: "nat", // This was added so js-waku test don't fail
|
||||||
Usage: "TODO - Not implemented yet.", // 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)",
|
||||||
Destination: &options.NAT,
|
Value: "any",
|
||||||
|
Destination: &options.NAT, // TODO: accept none,any,upnp,extaddr
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "db-path",
|
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.",
|
Usage: "Define the logging level, supported strings are: DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, and their lower-case forms.",
|
||||||
Destination: &options.LogLevel,
|
Destination: &options.LogLevel,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "version",
|
||||||
|
Value: false,
|
||||||
|
Usage: "prints the version",
|
||||||
|
Destination: &options.Version,
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "log-encoding",
|
Name: "log-encoding",
|
||||||
Value: "console",
|
Value: "console",
|
||||||
|
@ -165,7 +180,7 @@ func main() {
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "relay-peer-exchange",
|
Name: "relay-peer-exchange",
|
||||||
Aliases: []string{"peer-exchange"},
|
Aliases: []string{"peer-exchange"},
|
||||||
Value: true,
|
Value: false,
|
||||||
Usage: "Enable GossipSub Peer Exchange",
|
Usage: "Enable GossipSub Peer Exchange",
|
||||||
Destination: &options.Relay.PeerExchange,
|
Destination: &options.Relay.PeerExchange,
|
||||||
},
|
},
|
||||||
|
@ -186,10 +201,10 @@ func main() {
|
||||||
Destination: &options.Store.ShouldResume,
|
Destination: &options.Store.ShouldResume,
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "store-days",
|
Name: "store-seconds",
|
||||||
Value: 30,
|
Value: (86400 * 30), // 30 days
|
||||||
Usage: "maximum number of days before a message is removed from the store",
|
Usage: "maximum number of seconds before a message is removed from the store",
|
||||||
Destination: &options.Store.RetentionMaxDays,
|
Destination: &options.Store.RetentionMaxSeconds,
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "store-capacity",
|
Name: "store-capacity",
|
||||||
|
@ -202,6 +217,12 @@ func main() {
|
||||||
Usage: "Multiaddr of a peer that supports store protocol. Option may be repeated",
|
Usage: "Multiaddr of a peer that supports store protocol. Option may be repeated",
|
||||||
Destination: &options.Store.Nodes,
|
Destination: &options.Store.Nodes,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "swap",
|
||||||
|
Usage: "Enable swap protocol",
|
||||||
|
Value: false,
|
||||||
|
Destination: &options.Swap.Enable,
|
||||||
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "swap-mode",
|
Name: "swap-mode",
|
||||||
Value: 0,
|
Value: 0,
|
||||||
|
@ -336,7 +357,7 @@ func main() {
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "rpc-port",
|
Name: "rpc-port",
|
||||||
Value: 8009,
|
Value: 8545,
|
||||||
Usage: "Listening port of the rpc server",
|
Usage: "Listening port of the rpc server",
|
||||||
Destination: &options.RPCServer.Port,
|
Destination: &options.RPCServer.Port,
|
||||||
},
|
},
|
||||||
|
|
27
waku/node.go
27
waku/node.go
|
@ -160,17 +160,24 @@ func Execute(options Options) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Version {
|
||||||
|
fmt.Printf("version / git commit hash: %s(%s)\n", node.Version, node.GitCommit)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if options.UseDB {
|
if options.UseDB {
|
||||||
// Create persistent peerstore
|
if options.PersistPeers {
|
||||||
queries, err := sqlite.NewQueries("peerstore", db)
|
// Create persistent peerstore
|
||||||
failOnErr(err, "Peerstore")
|
queries, err := sqlite.NewQueries("peerstore", db)
|
||||||
|
failOnErr(err, "Peerstore")
|
||||||
|
|
||||||
datastore := dssql.NewDatastore(db, queries)
|
datastore := dssql.NewDatastore(db, queries)
|
||||||
opts := pstoreds.DefaultOpts()
|
opts := pstoreds.DefaultOpts()
|
||||||
peerStore, err := pstoreds.NewPeerstore(ctx, datastore, opts)
|
peerStore, err := pstoreds.NewPeerstore(ctx, datastore, opts)
|
||||||
failOnErr(err, "Peerstore")
|
failOnErr(err, "Peerstore")
|
||||||
|
|
||||||
libp2pOpts = append(libp2pOpts, libp2p.Peerstore(peerStore))
|
libp2pOpts = append(libp2pOpts, libp2p.Peerstore(peerStore))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeOpts = append(nodeOpts, node.WithLibP2POptions(libp2pOpts...))
|
nodeOpts = append(nodeOpts, node.WithLibP2POptions(libp2pOpts...))
|
||||||
|
@ -194,8 +201,8 @@ func Execute(options Options) {
|
||||||
|
|
||||||
if options.Store.Enable {
|
if options.Store.Enable {
|
||||||
if options.Store.PersistMessages {
|
if options.Store.PersistMessages {
|
||||||
nodeOpts = append(nodeOpts, node.WithWakuStoreAndRetentionPolicy(options.Store.ShouldResume, options.Store.RetentionMaxDaysDuration(), options.Store.RetentionMaxMessages))
|
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.RetentionMaxDaysDuration()))
|
dbStore, err := persistence.NewDBStore(logger, persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxSecondsDuration()))
|
||||||
failOnErr(err, "DBStore")
|
failOnErr(err, "DBStore")
|
||||||
nodeOpts = append(nodeOpts, node.WithMessageProvider(dbStore))
|
nodeOpts = append(nodeOpts, node.WithMessageProvider(dbStore))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,20 +55,21 @@ type StoreOptions struct {
|
||||||
Enable bool
|
Enable bool
|
||||||
PersistMessages bool
|
PersistMessages bool
|
||||||
ShouldResume bool
|
ShouldResume bool
|
||||||
RetentionMaxDays int
|
RetentionMaxSeconds int
|
||||||
RetentionMaxMessages int
|
RetentionMaxMessages int
|
||||||
Nodes cli.StringSlice
|
Nodes cli.StringSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
// SwapOptions are settings used for configuring the swap protocol
|
// SwapOptions are settings used for configuring the swap protocol
|
||||||
type SwapOptions struct {
|
type SwapOptions struct {
|
||||||
|
Enable bool
|
||||||
Mode int
|
Mode int
|
||||||
PaymentThreshold int
|
PaymentThreshold int
|
||||||
DisconnectThreshold int
|
DisconnectThreshold int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StoreOptions) RetentionMaxDaysDuration() time.Duration {
|
func (s *StoreOptions) RetentionMaxSecondsDuration() time.Duration {
|
||||||
return time.Duration(s.RetentionMaxDays) * time.Hour * 24
|
return time.Duration(s.RetentionMaxSeconds) * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNSDiscoveryOptions are settings used for enabling DNS-based discovery
|
// DNSDiscoveryOptions are settings used for enabling DNS-based discovery
|
||||||
|
@ -121,10 +122,12 @@ type Options struct {
|
||||||
UseDB bool
|
UseDB bool
|
||||||
DBPath string
|
DBPath string
|
||||||
AdvertiseAddress string
|
AdvertiseAddress string
|
||||||
|
Version bool
|
||||||
ShowAddresses bool
|
ShowAddresses bool
|
||||||
LogLevel string
|
LogLevel string
|
||||||
LogEncoding string
|
LogEncoding string
|
||||||
NAT string
|
NAT string
|
||||||
|
PersistPeers bool
|
||||||
|
|
||||||
Websocket WSOptions
|
Websocket WSOptions
|
||||||
Relay RelayOptions
|
Relay RelayOptions
|
||||||
|
|
|
@ -2,3 +2,6 @@ package node
|
||||||
|
|
||||||
// GitCommit is a commit hash.
|
// GitCommit is a commit hash.
|
||||||
var GitCommit string
|
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
|
// Start initializes all the protocols that were setup in the WakuNode
|
||||||
func (w *WakuNode) Start() error {
|
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{
|
if w.opts.enableSwap {
|
||||||
swap.WithMode(w.opts.swapMode),
|
w.swap = swap.NewWakuSwap(w.log, []swap.SwapOption{
|
||||||
swap.WithThreshold(w.opts.swapPaymentThreshold, w.opts.swapDisconnectThreshold),
|
swap.WithMode(w.opts.swapMode),
|
||||||
}...)
|
swap.WithThreshold(w.opts.swapPaymentThreshold, w.opts.swapDisconnectThreshold),
|
||||||
|
}...)
|
||||||
|
}
|
||||||
|
|
||||||
w.store = w.storeFactory(w)
|
w.store = w.storeFactory(w)
|
||||||
if w.opts.enableStore {
|
if w.opts.enableStore {
|
||||||
|
|
|
@ -60,6 +60,7 @@ type WakuNodeParameters struct {
|
||||||
minRelayPeersToPublish int
|
minRelayPeersToPublish int
|
||||||
|
|
||||||
enableStore bool
|
enableStore bool
|
||||||
|
enableSwap bool
|
||||||
shouldResume bool
|
shouldResume bool
|
||||||
storeMsgs bool
|
storeMsgs bool
|
||||||
messageProvider store.MessageProvider
|
messageProvider store.MessageProvider
|
||||||
|
@ -312,6 +313,7 @@ func WithWakuStoreFactory(factory storeFactory) WakuNodeOption {
|
||||||
// WithWakuSwap set the option of the Waku V2 Swap protocol
|
// WithWakuSwap set the option of the Waku V2 Swap protocol
|
||||||
func WithWakuSwap(mode int, disconnectThreshold, paymentThreshold int) WakuNodeOption {
|
func WithWakuSwap(mode int, disconnectThreshold, paymentThreshold int) WakuNodeOption {
|
||||||
return func(params *WakuNodeParameters) error {
|
return func(params *WakuNodeParameters) error {
|
||||||
|
params.enableSwap = true
|
||||||
params.swapMode = mode
|
params.swapMode = mode
|
||||||
params.swapDisconnectThreshold = disconnectThreshold
|
params.swapDisconnectThreshold = disconnectThreshold
|
||||||
params.swapPaymentThreshold = paymentThreshold
|
params.swapPaymentThreshold = paymentThreshold
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/status-im/go-waku/waku/v2/node"
|
"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
|
type VersionResponse string
|
||||||
|
|
||||||
func (d *DebugService) GetV1Version(r *http.Request, args *InfoArgs, reply *VersionResponse) error {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue