This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from libp2p/feat/getvalue
make routing less DHT specific
- Loading branch information
Showing
4 changed files
with
98 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2.22: QmZix3EdeAdc4wnRksRXWEQ6kbqiFAP16h3Sq9JnEiP71N | ||
2.3.0: QmUHRKTeaoASDvDj7cTAXsmjAY7KQ13ErtzkQHZQq6uFUz |
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,50 @@ | ||
package ropts | ||
|
||
// Option is a single routing option. | ||
type Option func(opts *Options) error | ||
|
||
// Options is a set of routing options | ||
type Options struct { | ||
// Allow expired values. | ||
Expired bool | ||
Offline bool | ||
// Other (ValueStore implementation specific) options. | ||
Other map[interface{}]interface{} | ||
} | ||
|
||
// Apply applies the given options to this Options | ||
func (opts *Options) Apply(options ...Option) error { | ||
for _, o := range options { | ||
if err := o(opts); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// ToOption converts this Options to a single Option. | ||
func (opts *Options) ToOption() Option { | ||
return func(nopts *Options) error { | ||
*nopts = *opts | ||
if opts.Other != nil { | ||
nopts.Other = make(map[interface{}]interface{}, len(opts.Other)) | ||
for k, v := range opts.Other { | ||
nopts.Other[k] = v | ||
} | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// Expired is an option that tells the routing system to return expired records | ||
// when no newer records are known. | ||
var Expired Option = func(opts *Options) error { | ||
opts.Expired = true | ||
return nil | ||
} | ||
|
||
// Offline is an option that tells the routing system to operate offline (i.e., rely on cached/local data only). | ||
var Offline Option = func(opts *Options) error { | ||
opts.Offline = true | ||
return nil | ||
} |
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