Skip to content

Commit

Permalink
Merge pull request #688 from libp2p/petar/oo
Browse files Browse the repository at this point in the history
allow overwriting builtin dual DHT options
  • Loading branch information
aschmahmann authored Aug 25, 2020
2 parents e788ffc + ac3582f commit 6e04c48
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions dual/dual.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,42 @@ func DHTOption(opts ...dht.Option) Option {
// will be overriden by this constructor.
func New(ctx context.Context, h host.Host, options ...Option) (*DHT, error) {
var cfg config
err := cfg.apply(options...)
err := cfg.apply(
WanDHTOption(
dht.QueryFilter(dht.PublicQueryFilter),
dht.RoutingTableFilter(dht.PublicRoutingTableFilter),
dht.RoutingTablePeerDiversityFilter(dht.NewRTPeerDiversityFilter(h, maxPrefixCountPerCpl, maxPrefixCount)),
),
)
if err != nil {
return nil, err
}
wanOpts := append(cfg.wan,
dht.QueryFilter(dht.PublicQueryFilter),
dht.RoutingTableFilter(dht.PublicRoutingTableFilter),
dht.RoutingTablePeerDiversityFilter(dht.NewRTPeerDiversityFilter(h, maxPrefixCountPerCpl, maxPrefixCount)),
err = cfg.apply(
LanDHTOption(
dht.ProtocolExtension(LanExtension),
dht.QueryFilter(dht.PrivateQueryFilter),
dht.RoutingTableFilter(dht.PrivateRoutingTableFilter),
),
)
wan, err := dht.New(ctx, h, wanOpts...)
if err != nil {
return nil, err
}
err = cfg.apply(options...)
if err != nil {
return nil, err
}

wan, err := dht.New(ctx, h, cfg.wan...)
if err != nil {
return nil, err
}

// Unless overridden by user supplied options, the LAN DHT should default
// to 'AutoServer' mode.
lanOpts := append(cfg.lan,
dht.ProtocolExtension(LanExtension),
dht.QueryFilter(dht.PrivateQueryFilter),
dht.RoutingTableFilter(dht.PrivateRoutingTableFilter),
)
if wan.Mode() != dht.ModeClient {
lanOpts = append(lanOpts, dht.Mode(dht.ModeServer))
cfg.lan = append(cfg.lan, dht.Mode(dht.ModeServer))
}
lan, err := dht.New(ctx, h, lanOpts...)
lan, err := dht.New(ctx, h, cfg.lan...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 6e04c48

Please sign in to comment.