diff --git a/dht_test.go b/dht_test.go index 91ea22368..545928ec4 100644 --- a/dht_test.go +++ b/dht_test.go @@ -1560,6 +1560,9 @@ func TestProvideDisabled(t *testing.T) { var ( optsA, optsB []opts.Option ) + optsA = append(optsA, opts.Protocols("/dht/provMaybeDisabled")) + optsB = append(optsB, opts.Protocols("/dht/provMaybeDisabled")) + if !enabledA { optsA = append(optsA, opts.DisableProviders()) } diff --git a/opts/options.go b/opts/options.go index a6b4ca675..ff8487fad 100644 --- a/opts/options.go +++ b/opts/options.go @@ -68,6 +68,8 @@ func (o *Options) Apply(opts ...Option) error { // Option DHT option type. type Option func(*Options) error +const defaultBucketSize = 20 + // Defaults are the default DHT options. This option will be automatically // prepended to any options you pass to the DHT constructor. var Defaults = func(o *Options) error { @@ -84,7 +86,7 @@ var Defaults = func(o *Options) error { o.RoutingTable.AutoRefresh = true o.MaxRecordAge = time.Hour * 36 - o.BucketSize = 20 + o.BucketSize = defaultBucketSize o.Concurrency = 3 return nil @@ -107,6 +109,20 @@ func UnsetDefaults(o *Options) error { o.DisjointPaths = o.BucketSize / 2 } + for _, p := range o.Protocols { + if p == ProtocolDHT { + if o.BucketSize != defaultBucketSize { + return fmt.Errorf("protocol %s must use bucket size %d", ProtocolDHT, defaultBucketSize) + } + if !o.EnableProviders { + return fmt.Errorf("protocol %s must have providers enabled", ProtocolDHT) + } + if !o.EnableValues { + return fmt.Errorf("protocol %s must have values enabled", ProtocolDHT) + } + } + } + return nil } diff --git a/records_test.go b/records_test.go index 458de2b91..6739bbfa1 100644 --- a/records_test.go +++ b/records_test.go @@ -320,6 +320,9 @@ func TestValuesDisabled(t *testing.T) { var ( optsA, optsB []dhtopt.Option ) + optsA = append(optsA, dhtopt.Protocols("/dht/valuesMaybeDisabled")) + optsB = append(optsB, dhtopt.Protocols("/dht/valuesMaybeDisabled")) + if !enabledA { optsA = append(optsA, dhtopt.DisableValues()) }