forked from cerc-io/ipld-eth-server
58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
// Package nilrouting implements a routing client that does nothing.
|
|
package nilrouting
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
cid "github.com/ipfs/go-cid"
|
|
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"
|
|
)
|
|
|
|
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) SearchValue(_ context.Context, _ string, _ ...ropts.Option) (<-chan []byte, error) {
|
|
return nil, errors.New("tried SearchValue from nil routing")
|
|
}
|
|
|
|
func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (pstore.PeerInfo, error) {
|
|
return pstore.PeerInfo{}, nil
|
|
}
|
|
|
|
func (c *nilclient) FindProvidersAsync(_ context.Context, _ cid.Cid, _ int) <-chan pstore.PeerInfo {
|
|
out := make(chan pstore.PeerInfo)
|
|
defer close(out)
|
|
return out
|
|
}
|
|
|
|
func (c *nilclient) Provide(_ context.Context, _ cid.Cid, _ 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{}
|