Skip to content

Commit fececcc

Browse files
author
Vibhav Pant
committed
Make the Routing Table's latency tolerance configurable.
1 parent 2bceee5 commit fececcc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

dht.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func New(ctx context.Context, h host.Host, options ...opts.Option) (*IpfsDHT, er
9999
if err := cfg.Apply(append([]opts.Option{opts.Defaults}, options...)...); err != nil {
100100
return nil, err
101101
}
102-
dht := makeDHT(ctx, h, cfg.Datastore, cfg.Protocols, cfg.BucketSize)
102+
dht := makeDHT(ctx, h, cfg.Datastore, cfg.Protocols, cfg.BucketSize, cfg.RoutingTable.LatencyTolerance)
103103
dht.autoRefresh = cfg.RoutingTable.AutoRefresh
104104
dht.rtRefreshPeriod = cfg.RoutingTable.RefreshPeriod
105105
dht.rtRefreshQueryTimeout = cfg.RoutingTable.RefreshQueryTimeout
@@ -152,9 +152,9 @@ func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT
152152
return dht
153153
}
154154

155-
func makeDHT(ctx context.Context, h host.Host, dstore ds.Batching, protocols []protocol.ID, bucketSize int) *IpfsDHT {
155+
func makeDHT(ctx context.Context, h host.Host, dstore ds.Batching, protocols []protocol.ID, bucketSize int, latency time.Duration) *IpfsDHT {
156156
self := kb.ConvertPeerID(h.ID())
157-
rt := kb.NewRoutingTable(bucketSize, self, time.Minute, h.Peerstore())
157+
rt := kb.NewRoutingTable(bucketSize, self, latency, h.Peerstore())
158158
cmgr := h.ConnManager()
159159

160160
rt.PeerAdded = func(p peer.ID) {

opts/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Options struct {
3434
RefreshQueryTimeout time.Duration
3535
RefreshPeriod time.Duration
3636
AutoRefresh bool
37+
LatencyTolerance time.Duration
3738
}
3839
}
3940

@@ -69,6 +70,13 @@ var Defaults = func(o *Options) error {
6970
return nil
7071
}
7172

73+
func RoutingTableLatencyTolerance(latency time.Duration) Option {
74+
return func(o *Options) error {
75+
o.RoutingTable.LatencyTolerance = latency
76+
return nil
77+
}
78+
}
79+
7280
// RoutingTableRefreshQueryTimeout sets the timeout for routing table refresh
7381
// queries.
7482
func RoutingTableRefreshQueryTimeout(timeout time.Duration) Option {

0 commit comments

Comments
 (0)