diff --git a/core/cmd/berty/daemon.go b/core/cmd/berty/daemon.go index 9469813e25..8f544d4ed3 100644 --- a/core/cmd/berty/daemon.go +++ b/core/cmd/berty/daemon.go @@ -35,19 +35,20 @@ type daemonOptions struct { privateKeyFile string `mapstructure:"private-key-file"` // p2p - identity string `mapstructure:"identity"` - bootstrap []string `mapstructure:"bootstrap"` - noP2P bool `mapstructure:"no-p2p"` - bindP2P []string `mapstructure:"bind-p2p"` - transportP2P []string `mapstructure:"transport-p2p"` - hop bool `mapstructure:"hop"` // relay hop - ble bool `mapstructure:"ble"` - mdns bool `mapstructure:"mdns"` - dhtServer bool `mapstructure:"dht"` - PrivateNetwork bool `mapstructure:"private-network"` - SwarmKeyPath string `mapstructure:"swarm-key"` - - nickname string `mapstructure:"nickname"` + + identity string `mapstructure:"identity"` + bootstrap []string `mapstructure:"bootstrap"` + noP2P bool `mapstructure:"no-p2p"` + bindP2P []string `mapstructure:"bind-p2p"` + transportP2P []string `mapstructure:"transport-p2p"` + hop bool `mapstructure:"hop"` // relay hop + ble bool `mapstructure:"ble"` + mdns bool `mapstructure:"mdns"` + dhtServer bool `mapstructure:"dht"` + PrivateNetwork bool `mapstructure:"private-network"` + SwarmKeyPath string `mapstructure:"swarm-key"` + dhtkvLogDatastore bool `mapstructure:"dhtkv-log-ds"` + nickname string `mapstructure:"nickname"` } func daemonSetupFlags(flags *pflag.FlagSet, opts *daemonOptions) { @@ -60,7 +61,8 @@ func daemonSetupFlags(flags *pflag.FlagSet, opts *daemonOptions) { flags.StringVar(&opts.privateKeyFile, "private-key-file", "", "set private key file for node") flags.BoolVar(&opts.withBot, "bot", false, "enable bot") flags.BoolVar(&opts.mdns, "mdns", true, "enable mdns discovery") - flags.BoolVar(&opts.dhtServer, "dhtkv-server", false, "enable server mode for DHT-CSKV (client mode by default)") + flags.BoolVar(&opts.dhtServer, "dhtkv-server", false, "enable server mode for DHT (Client mode by default)") + flags.BoolVar(&opts.dhtkvLogDatastore, "dhtkv-log-ds", false, "enable logs for DHT-CSKV datastore") flags.BoolVar(&opts.PrivateNetwork, "private-network", true, "enable private network with the default swarm key") flags.StringVar(&opts.SwarmKeyPath, "swarm-key", "", "path to a custom swarm key, only peers that use the same swarm key will be able to talk with you") flags.StringVar(&opts.grpcBind, "grpc-bind", ":1337", "gRPC listening address") @@ -170,6 +172,8 @@ func daemon(opts *daemonOptions) error { Identity: opts.identity, Persist: false, OverridePersist: false, + + DHTKVLogDatastore: opts.dhtkvLogDatastore, }), ), )) diff --git a/core/network/dhtcskv/dht_cskv.go b/core/network/dhtcskv/dht_cskv.go index de6c2b0212..ec025a619e 100644 --- a/core/network/dhtcskv/dht_cskv.go +++ b/core/network/dhtcskv/dht_cskv.go @@ -25,19 +25,19 @@ var defaultServerConfig = dht.BootstrapConfig{ Timeout: 40 * time.Second, } -func New(ctx context.Context, host host.Host, server bool, config dht.BootstrapConfig) (*dht.IpfsDHT, error) { +func New(ctx context.Context, host host.Host, server bool, logDatastore bool, config dht.BootstrapConfig) (*dht.IpfsDHT, error) { var datastore ds.Batching - if server { + if server && config.Queries == 0 { + config = defaultServerConfig + } else if config.Queries == 0 { + config = defaultClientConfig + } + + if logDatastore { datastore = ds.NewLogDatastore(ds.NewMapDatastore(), "DHT_datastore") - if config.Queries == 0 { - config = defaultServerConfig - } } else { datastore = ds.NewMapDatastore() - if config.Queries == 0 { - config = defaultClientConfig - } } dhtkv, err := dht.New( diff --git a/core/network/p2p/driver.go b/core/network/p2p/driver.go index fbcd6e444f..2503a8a506 100644 --- a/core/network/p2p/driver.go +++ b/core/network/p2p/driver.go @@ -58,6 +58,7 @@ type driverConfig struct { // DHT Client-Server Key-Value dhtkvBoostrapConfig dht.BootstrapConfig + dhtkvLogDatastore bool dhtkvServer bool // MDNS @@ -144,7 +145,7 @@ func newDriver(ctx context.Context, cfg driverConfig) (*Driver, error) { return nil, err } - driver.dhtCskv, err = dhtcskv.New(ctx, host, cfg.dhtkvServer, cfg.dhtkvBoostrapConfig) + driver.dhtCskv, err = dhtcskv.New(ctx, host, cfg.dhtkvServer, cfg.dhtkvLogDatastore, cfg.dhtkvBoostrapConfig) if err != nil { if closeErr := host.Close(); closeErr != nil { logger().Error("failed to close host", zap.Error(closeErr)) diff --git a/core/network/p2p/options.go b/core/network/p2p/options.go index 1111efad7c..ca85a18059 100644 --- a/core/network/p2p/options.go +++ b/core/network/p2p/options.go @@ -108,6 +108,14 @@ func WithDHTCSKVBoostrapConfig(bc *dht.BootstrapConfig) Option { } } +// WithDHTCSKVBoostrapConfig specifies parameters used bootstrapping the DHT Client-Server Key-Value. +func WithDHTCSKVLogDatastore() Option { + return func(dc *driverConfig) error { + dc.dhtkvLogDatastore = true + return nil + } +} + // WithClientDHTCSKV enable server mode for the DHT Client-Server Key-Value func WithServerDHTCSKV() Option { return func(dc *driverConfig) error { diff --git a/experiment/scw/berty.service b/experiment/scw/berty.service index c64bb548d6..ef9b017b97 100644 --- a/experiment/scw/berty.service +++ b/experiment/scw/berty.service @@ -5,7 +5,7 @@ After=network.target [Service] User=root Group=root -ExecStart=/bin/bash -c '/usr/bin/berty daemon --dhtkv-server --log-level=debug --mdns=false --hop --bind-p2p /ip4/0.0.0.0/tcp/4004,/ip4/0.0.0.0/tcp/80,/ip4/0.0.0.0/tcp/443,/ip4/0.0.0.0/udp/4004/quic --p2p-identity=`/bin/cat /root/pk`' +ExecStart=/bin/bash -c '/usr/bin/berty daemon --dhtkv-server --dhtkv-log-ds --log-level=debug --mdns=false --hop --bind-p2p /ip4/0.0.0.0/tcp/4004,/ip4/0.0.0.0/tcp/80,/ip4/0.0.0.0/tcp/443,/ip4/0.0.0.0/udp/4004/quic --p2p-identity=`/bin/cat /root/pk`' Restart=always [Install]