Skip to content

Commit

Permalink
move quorum config to query config
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Sep 27, 2023
1 parent 60b6959 commit 8b4b920
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
32 changes: 16 additions & 16 deletions v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
//
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand All @@ -403,6 +395,7 @@ func DefaultQueryConfig() *QueryConfig {
Timeout: 5 * time.Minute, // MAGIC
RequestConcurrency: 3, // MAGIC
RequestTimeout: time.Minute, // MAGIC
DefaultQuorum: 0, // MAGIC
}
}

Expand Down Expand Up @@ -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
}
17 changes: 9 additions & 8 deletions v2/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
})
}

0 comments on commit 8b4b920

Please sign in to comment.