Skip to content

Commit 84c807f

Browse files
committed
simplify and support more of existing behavior
1 parent df46bee commit 84c807f

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

dht_options.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,10 @@ func (c *config) apply(opts ...Option) error {
7272
// applyFallbacks sets default values that could not be applied during config creation since they are dependent
7373
// on other configuration parameters (e.g. optA is by default 2x optB) and/or on the Host
7474
func (c *config) applyFallbacks(h host.Host) {
75-
if c.validator == nil {
76-
if c.protocolPrefix == DefaultPrefix {
77-
c.validator = record.NamespacedValidator{
78-
"pk": record.PublicKeyValidator{},
79-
"ipns": ipns.Validator{KeyBook: h.Peerstore()},
80-
}
81-
} else {
82-
c.validator = record.NamespacedValidator{
83-
"pk": record.PublicKeyValidator{},
84-
}
75+
if c.protocolPrefix == DefaultPrefix {
76+
nsval, ok := c.validator.(record.NamespacedValidator)
77+
if ok {
78+
nsval["ipns"] = ipns.Validator{KeyBook: h.Peerstore()}
8579
}
8680
}
8781
}
@@ -94,6 +88,9 @@ const defaultBucketSize = 20
9488
// defaults are the default DHT options. This option will be automatically
9589
// prepended to any options you pass to the DHT constructor.
9690
var defaults = func(o *config) error {
91+
o.validator = record.NamespacedValidator{
92+
"pk": record.PublicKeyValidator{},
93+
}
9794
o.datastore = dssync.MutexWrap(ds.NewMapDatastore())
9895
o.protocolPrefix = DefaultPrefix
9996
o.enableProviders = true

0 commit comments

Comments
 (0)