diff --git a/v2/config.go b/v2/config.go index bdfe3169f..de352c501 100644 --- a/v2/config.go +++ b/v2/config.go @@ -171,14 +171,6 @@ type Config struct { // used to filter out private addresses. AddressFilter AddressFilter - // DefaultQuorum specifies the minimum number of identical responses before - // a SearchValue/GetValue operation returns. The responses must not only be - // identical, but the responses must also correspond to the "best" records - // we have observed in the network during the SearchValue/GetValue - // operation. A DefaultQuorum of 0 means that we search the network until - // we have exhausted the keyspace. - DefaultQuorum int // TODO: put on QueryConfig? - // MeterProvider provides access to named Meter instances. It's used to, // e.g., expose prometheus metrics. Check out the [opentelemetry docs]: // @@ -209,7 +201,6 @@ func DefaultConfig() *Config { Logger: slog.New(zapslog.NewHandler(logging.Logger("dht").Desugar().Core())), TimeoutStreamIdle: time.Minute, // MAGIC AddressFilter: AddrFilterPrivate, - DefaultQuorum: 0, MeterProvider: otel.GetMeterProvider(), TracerProvider: otel.GetTracerProvider(), Query: DefaultQueryConfig(), @@ -350,13 +341,6 @@ func (c *Config) Validate() error { } } - if c.DefaultQuorum < 0 { - return &ConfigurationError{ - Component: "Config", - Err: fmt.Errorf("default quorum must not be negative"), - } - } - return nil } @@ -394,6 +378,14 @@ type QueryConfig struct { // RequestTimeout defines the time to wait before terminating a request to a node that has not responded. RequestTimeout time.Duration + + // DefaultQuorum specifies the minimum number of identical responses before + // a SearchValue/GetValue operation returns. The responses must not only be + // identical, but the responses must also correspond to the "best" records + // we have observed in the network during the SearchValue/GetValue + // operation. A DefaultQuorum of 0 means that we search the network until + // we have exhausted the keyspace. + DefaultQuorum int } // DefaultQueryConfig returns the default query configuration options for a DHT. @@ -403,6 +395,7 @@ func DefaultQueryConfig() *QueryConfig { Timeout: 5 * time.Minute, // MAGIC RequestConcurrency: 3, // MAGIC RequestTimeout: time.Minute, // MAGIC + DefaultQuorum: 0, // MAGIC } } @@ -435,5 +428,12 @@ func (cfg *QueryConfig) Validate() error { } } + if cfg.DefaultQuorum < 0 { + return &ConfigurationError{ + Component: "QueryConfig", + Err: fmt.Errorf("default quorum must not be negative"), + } + } + return nil } diff --git a/v2/config_test.go b/v2/config_test.go index fd5d4be1f..7c4ee1a63 100644 --- a/v2/config_test.go +++ b/v2/config_test.go @@ -140,14 +140,6 @@ func TestConfig_Validate(t *testing.T) { cfg.BootstrapPeers = []peer.AddrInfo{} assert.Error(t, cfg.Validate()) }) - - t.Run("negative default quorum", func(t *testing.T) { - cfg := DefaultConfig() - cfg.DefaultQuorum = 0 - assert.NoError(t, cfg.Validate()) - cfg.DefaultQuorum = -1 - assert.Error(t, cfg.Validate()) - }) } func TestQueryConfig_Validate(t *testing.T) { @@ -191,4 +183,13 @@ func TestQueryConfig_Validate(t *testing.T) { cfg.RequestTimeout = -1 assert.Error(t, cfg.Validate()) }) + + t.Run("negative default quorum", func(t *testing.T) { + cfg := DefaultQueryConfig() + + cfg.DefaultQuorum = 0 + assert.NoError(t, cfg.Validate()) + cfg.DefaultQuorum = -1 + assert.Error(t, cfg.Validate()) + }) }