@cryptotaxi247 / kubo / commits / 0787fb8f3

coreapi: dht interface

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@bbd736fdecec3e18d61e72b5a4beb9234f66c1ec This commit was moved from ipfs/boxo@6c40247cc1931a891782c579d48f517a7945569b

Łukasz Magiera committed Mar 10, 2018 at 19:07 UTC 0787fb8f31349a102368878f3ea92ea59b0385bc
2 files changed +58
core/coreiface/dht.go new
+28
@@ -0,0 +1,28 @@
1 +package iface
2 +
3 +import (
4 + "context"
5 +
6 + options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
7 +
8 + ma "gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr"
9 + peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
10 +)
11 +
12 +// DhtAPI specifies the interface to the DHT
13 +type DhtAPI interface {
14 + // FindPeer queries the DHT for all of the multiaddresses associated with a
15 + // Peer ID
16 + FindPeer(context.Context, peer.ID) (<-chan ma.Multiaddr, error)
17 +
18 + // FindProviders finds peers in the DHT who can provide a specific value
19 + // given a key.
20 + FindProviders(context.Context, Path) (<-chan peer.ID, error) //TODO: is path the right choice here?
21 +
22 + // Provide announces to the network that you are providing given values
23 + Provide(context.Context, Path, ...options.DhtProvideOption) error
24 +
25 + // WithRecursive is an option for Provide which specifies whether to provide
26 + // the given path recursively
27 + WithRecursive(recursive bool) options.DhtProvideOption
28 +}
core/coreiface/options/dht.go new
+30
@@ -0,0 +1,30 @@
1 +package options
2 +
3 +type DhtProvideSettings struct {
4 + Recursive bool
5 +}
6 +
7 +type DhtProvideOption func(*DhtProvideSettings) error
8 +
9 +func DhtProvideOptions(opts ...DhtProvideOption) (*DhtProvideSettings, error) {
10 + options := &DhtProvideSettings{
11 + Recursive: false,
12 + }
13 +
14 + for _, opt := range opts {
15 + err := opt(options)
16 + if err != nil {
17 + return nil, err
18 + }
19 + }
20 + return options, nil
21 +}
22 +
23 +type DhtOptions struct{}
24 +
25 +func (api *DhtOptions) WithRecursive(recursive bool) DhtProvideOption {
26 + return func(settings *DhtProvideSettings) error {
27 + settings.Recursive = recursive
28 + return nil
29 + }
30 +}