cleanup: documentation and code cleanup for search/getvalue quorum defaulting to zero

This commit is contained in:
Adin Schmahmann 2020-03-20 05:40:00 -04:00
parent 075afe8528
commit 147dc1244d
3 changed files with 5 additions and 4 deletions

View File

@ -465,7 +465,7 @@ func TestSearchValue(t *testing.T) {
ctxT, cancel = context.WithTimeout(ctx, time.Second*2) ctxT, cancel = context.WithTimeout(ctx, time.Second*2)
defer cancel() defer cancel()
valCh, err := dhtA.SearchValue(ctxT, "/v/hello", Quorum(-1)) valCh, err := dhtA.SearchValue(ctxT, "/v/hello", Quorum(0))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -168,7 +168,7 @@ func (dht *IpfsDHT) SearchValue(ctx context.Context, key string, opts ...routing
responsesNeeded := 0 responsesNeeded := 0
if !cfg.Offline { if !cfg.Offline {
responsesNeeded = getQuorum(&cfg, 0) responsesNeeded = getQuorum(&cfg, defaultQuorum)
} }
stopCh := make(chan struct{}) stopCh := make(chan struct{})

View File

@ -7,9 +7,10 @@ type quorumOptionKey struct{}
const defaultQuorum = 0 const defaultQuorum = 0
// Quorum is a DHT option that tells the DHT how many peers it needs to get // Quorum is a DHT option that tells the DHT how many peers it needs to get
// values from before returning the best one. // values from before returning the best one. Zero means the DHT query
// should complete instead of returning early.
// //
// Default: 16 // Default: 0
func Quorum(n int) routing.Option { func Quorum(n int) routing.Option {
return func(opts *routing.Options) error { return func(opts *routing.Options) error {
if opts.Other == nil { if opts.Other == nil {