-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathnull.go
56 lines (44 loc) · 1.42 KB
/
null.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
54
55
56
package routinghelpers
import (
"context"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/routing"
)
// Null is a router that doesn't do anything.
type Null struct{}
// PutValue always returns ErrNotSupported
func (nr Null) PutValue(context.Context, string, []byte, ...routing.Option) error {
return routing.ErrNotSupported
}
// GetValue always returns ErrNotFound
func (nr Null) GetValue(context.Context, string, ...routing.Option) ([]byte, error) {
return nil, routing.ErrNotFound
}
// SearchValue always returns ErrNotFound
func (nr Null) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error) {
return nil, routing.ErrNotFound
}
// Provide always returns ErrNotSupported
func (nr Null) Provide(context.Context, cid.Cid, bool) error {
return routing.ErrNotSupported
}
// FindProvidersAsync always returns a closed channel
func (nr Null) FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo {
ch := make(chan peer.AddrInfo)
close(ch)
return ch
}
// FindPeer always returns ErrNotFound
func (nr Null) FindPeer(context.Context, peer.ID) (peer.AddrInfo, error) {
return peer.AddrInfo{}, routing.ErrNotFound
}
// Bootstrap always succeeds instantly
func (nr Null) Bootstrap(context.Context) error {
return nil
}
// Close always succeeds instantly
func (nr Null) Close() error {
return nil
}
var _ routing.Routing = Null{}