This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnone_client.go
53 lines (42 loc) · 1.51 KB
/
none_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Package nilrouting implements a routing client that does nothing.
package nilrouting
import (
"context"
"errors"
ds "github.com/ipfs/go-datastore"
p2phost "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
record "github.com/libp2p/go-libp2p-record"
routing "github.com/libp2p/go-libp2p-routing"
ropts "github.com/libp2p/go-libp2p-routing/options"
mh "github.com/multiformats/go-multihash"
)
type nilclient struct {
}
func (c *nilclient) PutValue(_ context.Context, _ string, _ []byte, _ ...ropts.Option) error {
return nil
}
func (c *nilclient) GetValue(_ context.Context, _ string, _ ...ropts.Option) ([]byte, error) {
return nil, errors.New("tried GetValue from nil routing")
}
func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (pstore.PeerInfo, error) {
return pstore.PeerInfo{}, nil
}
func (c *nilclient) FindProvidersAsync(_ context.Context, _ mh.Multihash, _ int) <-chan pstore.PeerInfo {
out := make(chan pstore.PeerInfo)
defer close(out)
return out
}
func (c *nilclient) Provide(_ context.Context, _ mh.Multihash, _ bool) error {
return nil
}
func (c *nilclient) Bootstrap(_ context.Context) error {
return nil
}
// ConstructNilRouting creates an IpfsRouting client which does nothing.
func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ ds.Batching, _ record.Validator) (routing.IpfsRouting, error) {
return &nilclient{}, nil
}
// ensure nilclient satisfies interface
var _ routing.IpfsRouting = &nilclient{}