Commit e967acad authored by Adin Schmahmann's avatar Adin Schmahmann Committed by Steven Allen

options: KValue and AlphaValue global variables no longer used internally....

options: KValue and AlphaValue global variables no longer used internally. Concurrency option now sets alpha. DisjointPaths option now sets d. Default number of disjoint paths is now bucketSize/2.
parent 11776e03
......@@ -70,6 +70,7 @@ type IpfsDHT struct {
protocols []protocol.ID // DHT protocols
bucketSize int
alpha int // The concurrency parameter per path
d int // Number of Disjoint Paths to query
autoRefresh bool
......@@ -98,11 +99,13 @@ var (
// New creates a new DHT with the specified host and options.
func New(ctx context.Context, h host.Host, options ...opts.Option) (*IpfsDHT, error) {
var cfg opts.Options
cfg.BucketSize = KValue
if err := cfg.Apply(append([]opts.Option{opts.Defaults}, options...)...); err != nil {
return nil, err
}
dht := makeDHT(ctx, h, &cfg)
if cfg.DisjointPaths == 0 {
cfg.DisjointPaths = cfg.BucketSize / 2
}
dht := makeDHT(ctx, h, cfg)
dht.autoRefresh = cfg.RoutingTable.AutoRefresh
dht.rtRefreshPeriod = cfg.RoutingTable.RefreshPeriod
dht.rtRefreshQueryTimeout = cfg.RoutingTable.RefreshQueryTimeout
......@@ -149,7 +152,7 @@ func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT
return dht
}
func makeDHT(ctx context.Context, h host.Host, cfg *opts.Options) *IpfsDHT {
func makeDHT(ctx context.Context, h host.Host, cfg opts.Options) *IpfsDHT {
self := kb.ConvertPeerID(h.ID())
rt := kb.NewRoutingTable(cfg.BucketSize, self, cfg.RoutingTable.LatencyTolerance, h.Peerstore())
cmgr := h.ConnManager()
......@@ -174,7 +177,8 @@ func makeDHT(ctx context.Context, h host.Host, cfg *opts.Options) *IpfsDHT {
routingTable: rt,
protocols: cfg.Protocols,
bucketSize: cfg.BucketSize,
d: 8,
alpha: cfg.Concurrency,
d: cfg.DisjointPaths,
triggerRtRefresh: make(chan chan<- error),
}
......
......@@ -1479,8 +1479,8 @@ func testFindPeerQuery(t *testing.T,
val := "foobar"
rtval := kb.ConvertKey(val)
rtablePeers := guy.routingTable.NearestPeers(rtval, AlphaValue)
assert.Len(t, rtablePeers, minInt(bootstrappers, AlphaValue))
rtablePeers := guy.routingTable.NearestPeers(rtval, guy.alpha)
assert.Len(t, rtablePeers, minInt(bootstrappers, guy.alpha))
assert.Len(t, guy.host.Network().Peers(), bootstrappers)
......
......@@ -26,6 +26,8 @@ type Options struct {
Client bool
Protocols []protocol.ID
BucketSize int
DisjointPaths int
Concurrency int
MaxRecordAge time.Duration
EnableProviders bool
EnableValues bool
......@@ -68,6 +70,9 @@ var Defaults = func(o *Options) error {
o.RoutingTable.AutoRefresh = true
o.MaxRecordAge = time.Hour * 36
o.BucketSize = 20
o.Concurrency = 3
return nil
}
......@@ -160,7 +165,7 @@ func Protocols(protocols ...protocol.ID) Option {
}
}
// BucketSize configures the bucket size of the routing table.
// BucketSize configures the bucket size (k in the Kademlia paper) of the routing table.
//
// The default value is 20.
func BucketSize(bucketSize int) Option {
......@@ -170,6 +175,26 @@ func BucketSize(bucketSize int) Option {
}
}
// Concurrency configures the number of concurrent requests (alpha in the Kademlia paper) for a given query path.
//
// The default value is 3.
func Concurrency(alpha int) Option {
return func(o *Options) error {
o.Concurrency = alpha
return nil
}
}
// DisjointPaths configures the number of disjoint paths (d in the S/Kademlia paper) taken per query.
//
// The default value is BucketSize/2.
func DisjointPaths(d int) Option {
return func(o *Options) error {
o.DisjointPaths = d
return nil
}
}
// MaxRecordAge specifies the maximum time that any node will hold onto a record ("PutValue record")
// from the time its received. This does not apply to any other forms of validity that
// the record may contain.
......
......@@ -117,7 +117,7 @@ func strictParallelismQuery(q *qu) {
}
// TODO: Is it finding a closer peer if it's closer than one we know about or one we have queried?
numQuery := AlphaValue
numQuery := q.dht.alpha
if foundCloser {
numQuery = len(peersToQuery)
} else if pqLen := len(peersToQuery); pqLen < numQuery {
......@@ -169,7 +169,7 @@ func simpleQuery(q *qu) {
return
}
numQuery := AlphaValue
numQuery := q.dht.alpha
if lastPeers != nil && peerSlicesEqual(lastPeers, peersToQuery) {
numQuery = len(peersToQuery)
} else if pqLen := len(peersToQuery); pqLen < numQuery {
......@@ -228,7 +228,7 @@ func boundedDialQuery(q *qu) {
return
}
numQuery := AlphaValue
numQuery := q.dht.alpha
if lastPeers != nil && peerSlicesEqual(lastPeers, peersToQuery) {
numQuery = len(peersToQuery)
}
......
package dht
// Deprecated: No longer used
// Pool size is the number of nodes used for group find/set RPC calls
var PoolSize = 6
// Deprecated: This value is still the default, but changing this parameter no longer does anything.
// K is the maximum number of requests to perform before returning failure.
var KValue = 20
// Deprecated: This value is still the default, but changing this parameter no longer does anything.
// Alpha is the concurrency factor for asynchronous requests.
var AlphaValue = 3
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment