@cryptotaxi247 / kubo / commits / 56e0e1829

feat: add a dhtserver option

Steven Allen committed Apr 6, 2020 at 13:55 UTC 56e0e18294e37fdfa5a1ab488a3b9d3dd7ba5d92
2 files changed +17 -33
cmd/ipfs/daemon.go
+3
@@ -53,6 +53,7 @@ const (
53 routingOptionSupernodeKwd = "supernode"
54 routingOptionDHTClientKwd = "dhtclient"
55 routingOptionDHTKwd = "dht"
56 + routingOptionDHTServerKwd = "dhtserver"
57 routingOptionNoneKwd = "none"
58 routingOptionDefaultKwd = "default"
59 unencryptTransportKwd = "disable-transport-encryption"
@@ -330,6 +331,8 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
331 ncfg.Routing = libp2p.DHTClientOption
332 case routingOptionDHTKwd:
333 ncfg.Routing = libp2p.DHTOption
334 + case routingOptionDHTServerKwd:
335 + ncfg.Routing = libp2p.DHTServerOption
336 case routingOptionNoneKwd:
337 ncfg.Routing = libp2p.NilRouterOption
338 default:
core/node/libp2p/routingopt.go
+14 -33
@@ -11,42 +11,23 @@ import (
11 record "github.com/libp2p/go-libp2p-record"
12 )
13
14 -var baseDhtOptions = []dht.Option{
15 - dht.Concurrency(10),
16 - // TODO: Enable this once we have the dual-DHTs. At the moment, this
17 - // will break DHTs on private IP addresses (VPNs, etc.).
18 - //dht.RoutingTableFilter(dht.PublicRoutingTableFilter),
19 - //dht.QueryFilter(dht.PublicQueryFilter),
20 -}
21 -
14 type RoutingOption func(context.Context, host.Host, datastore.Batching, record.Validator) (routing.Routing, error)
15
24 -func constructDHTRouting(ctx context.Context, host host.Host, dstore datastore.Batching, validator record.Validator) (routing.Routing, error) {
25 - return dht.New(
26 - ctx, host,
27 - append([]dht.Option{
28 - // TODO: switch to "auto" when we add dual-dht support.
29 - // Unfortunately, we can't set this to auto yet or
30 - // nobody will become a server when everyone is running
31 - // on a private network.
32 - dht.Mode(dht.ModeServer),
16 +func constructDHTRouting(mode dht.ModeOpt) func(ctx context.Context, host host.Host, dstore datastore.Batching, validator record.Validator) (routing.Routing, error) {
17 + return func(ctx context.Context, host host.Host, dstore datastore.Batching, validator record.Validator) (routing.Routing, error) {
18 + return dht.New(
19 + ctx, host,
20 + dht.Concurrency(10),
21 + dht.Mode(mode),
22 dht.Datastore(dstore),
23 dht.Validator(validator),
35 - }, baseDhtOptions...)...,
36 - )
24 + )
25 + }
26 }
27
39 -func constructClientDHTRouting(ctx context.Context, host host.Host, dstore datastore.Batching, validator record.Validator) (routing.Routing, error) {
40 - return dht.New(
41 - ctx, host,
42 - append([]dht.Option{
43 - dht.Mode(dht.ModeClient),
44 - dht.Datastore(dstore),
45 - dht.Validator(validator),
46 - }, baseDhtOptions...)...,
47 - )
48 -}
49 -
50 -var DHTOption RoutingOption = constructDHTRouting
51 -var DHTClientOption RoutingOption = constructClientDHTRouting
52 -var NilRouterOption RoutingOption = nilrouting.ConstructNilRouting
28 +var (
29 + DHTOption RoutingOption = constructDHTRouting(dht.ModeAuto)
30 + DHTClientOption = constructDHTRouting(dht.ModeClient)
31 + DHTServerOption = constructDHTRouting(dht.ModeServer)
32 + NilRouterOption = nilrouting.ConstructNilRouting
33 +)