This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package iface | ||
|
||
import ( | ||
"context" | ||
|
||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options" | ||
|
||
ma "gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr" | ||
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer" | ||
) | ||
|
||
// DhtAPI specifies the interface to the DHT | ||
type DhtAPI interface { | ||
// FindPeer queries the DHT for all of the multiaddresses associated with a | ||
// Peer ID | ||
FindPeer(context.Context, peer.ID) (<-chan ma.Multiaddr, error) | ||
|
||
// FindProviders finds peers in the DHT who can provide a specific value | ||
// given a key. | ||
FindProviders(context.Context, Path) (<-chan peer.ID, error) //TODO: is path the right choice here? | ||
|
||
// Provide announces to the network that you are providing given values | ||
Provide(context.Context, Path, ...options.DhtProvideOption) error | ||
|
||
// WithRecursive is an option for Provide which specifies whether to provide | ||
// the given path recursively | ||
WithRecursive(recursive bool) options.DhtProvideOption | ||
} |
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,30 @@ | ||
package options | ||
|
||
type DhtProvideSettings struct { | ||
Recursive bool | ||
} | ||
|
||
type DhtProvideOption func(*DhtProvideSettings) error | ||
|
||
func DhtProvideOptions(opts ...DhtProvideOption) (*DhtProvideSettings, error) { | ||
options := &DhtProvideSettings{ | ||
Recursive: false, | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return options, nil | ||
} | ||
|
||
type DhtOptions struct{} | ||
|
||
func (api *DhtOptions) WithRecursive(recursive bool) DhtProvideOption { | ||
return func(settings *DhtProvideSettings) error { | ||
settings.Recursive = recursive | ||
return nil | ||
} | ||
} |