-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace GetValues with a GetValue that takes options
Changes for: libp2p/go-libp2p-routing#21 (also fixes some test issues)
- Loading branch information
Showing
4 changed files
with
137 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dht | ||
|
||
import ( | ||
ropts "github.com/libp2p/go-libp2p-routing/options" | ||
) | ||
|
||
type quorumOptionKey struct{} | ||
|
||
// Quorum is a DHT option that tells the DHT how many peers it needs to get | ||
// values from before returning the best one. | ||
// | ||
// Default: 16 | ||
func Quorum(n int) ropts.Option { | ||
return func(opts *ropts.Options) error { | ||
if opts.Other == nil { | ||
opts.Other = make(map[interface{}]interface{}, 1) | ||
} | ||
opts.Other[quorumOptionKey{}] = n | ||
return nil | ||
} | ||
} | ||
|
||
func getQuorum(opts *ropts.Options) int64 { | ||
responsesNeeded, ok := opts.Other[quorumOptionKey{}].(int) | ||
if !ok { | ||
responsesNeeded = 16 | ||
} | ||
return int64(responsesNeeded) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters