From 3c708b1e27c4ced485121094c46b198db20cda61 Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Thu, 20 Aug 2020 14:30:55 -0700 Subject: [PATCH 1/2] allow overwriting builtin dual DHT options --- dual/dual.go | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/dual/dual.go b/dual/dual.go index a291abb06..e51fb49ad 100644 --- a/dual/dual.go +++ b/dual/dual.go @@ -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([]dht.Option{dht.Mode(dht.ModeServer)}, cfg.lan...) } - lan, err := dht.New(ctx, h, lanOpts...) + lan, err := dht.New(ctx, h, cfg.lan...) if err != nil { return nil, err } From ac3582f374a4b5232d11c0e454274f9b4f591b12 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Fri, 21 Aug 2020 00:57:18 -0400 Subject: [PATCH 2/2] LAN DHT ignores user options in determining Client vs Server mode --- dual/dual.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dual/dual.go b/dual/dual.go index e51fb49ad..df88dcd14 100644 --- a/dual/dual.go +++ b/dual/dual.go @@ -129,7 +129,7 @@ func New(ctx context.Context, h host.Host, options ...Option) (*DHT, error) { // Unless overridden by user supplied options, the LAN DHT should default // to 'AutoServer' mode. if wan.Mode() != dht.ModeClient { - cfg.lan = append([]dht.Option{dht.Mode(dht.ModeServer)}, cfg.lan...) + cfg.lan = append(cfg.lan, dht.Mode(dht.ModeServer)) } lan, err := dht.New(ctx, h, cfg.lan...) if err != nil {