From d140b8aae1b5181d4879226c27dc6f71bd79bb3c Mon Sep 17 00:00:00 2001 From: Karthik Bala Date: Fri, 14 Aug 2015 20:02:16 -0700 Subject: [PATCH] Add router that does nothing for bitswap_wo_routing test License: MIT Signed-off-by: Karthik Bala --- core/core.go | 2 + routing/none/none_client.go | 51 +++++++++++++++++++++ test/integration/bitswap_wo_routing_test.go | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 routing/none/none_client.go diff --git a/core/core.go b/core/core.go index 7d5703acc..56647fc53 100644 --- a/core/core.go +++ b/core/core.go @@ -40,6 +40,7 @@ import ( dht "github.com/ipfs/go-ipfs/routing/dht" kb "github.com/ipfs/go-ipfs/routing/kbucket" offroute "github.com/ipfs/go-ipfs/routing/offline" + nilrouting "github.com/ipfs/go-ipfs/routing/none" bstore "github.com/ipfs/go-ipfs/blocks/blockstore" bserv "github.com/ipfs/go-ipfs/blockservice" @@ -613,3 +614,4 @@ type RoutingOption func(context.Context, p2phost.Host, ds.ThreadSafeDatastore) ( type DiscoveryOption func(p2phost.Host) (discovery.Service, error) var DHTOption RoutingOption = constructDHTRouting +var NilRouterOption RoutingOption = nilrouting.ConstructNilRouting diff --git a/routing/none/none_client.go b/routing/none/none_client.go new file mode 100644 index 000000000..ce50d7357 --- /dev/null +++ b/routing/none/none_client.go @@ -0,0 +1,51 @@ +package nilrouting + +import ( + "errors" + + ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" + context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" + key "github.com/ipfs/go-ipfs/blocks/key" + p2phost "github.com/ipfs/go-ipfs/p2p/host" + peer "github.com/ipfs/go-ipfs/p2p/peer" + routing "github.com/ipfs/go-ipfs/routing" + u "github.com/ipfs/go-ipfs/util" +) + +var log = u.Logger("mockrouter") + +type nilclient struct { +} + +func (c *nilclient) PutValue(_ context.Context, _ key.Key, _ []byte) error { + return nil +} + +func (c *nilclient) GetValue(_ context.Context, _ key.Key) ([]byte, error) { + return nil, errors.New("Tried GetValue from nil routing.") +} + +func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (peer.PeerInfo, error) { + return peer.PeerInfo{}, nil +} + +func (c *nilclient) FindProvidersAsync(_ context.Context, _ key.Key, _ int) <-chan peer.PeerInfo { + out := make(chan peer.PeerInfo) + defer close(out) + return out +} + +func (c *nilclient) Provide(_ context.Context, _ key.Key) error { + return nil +} + +func (c *nilclient) Bootstrap(_ context.Context) error { + return nil +} + +func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ ds.ThreadSafeDatastore) (routing.IpfsRouting, error) { + return &nilclient{}, nil +} + +// ensure nilclient satisfies interface +var _ routing.IpfsRouting = &nilclient{} diff --git a/test/integration/bitswap_wo_routing_test.go b/test/integration/bitswap_wo_routing_test.go index 560e20ec3..76dc96be3 100644 --- a/test/integration/bitswap_wo_routing_test.go +++ b/test/integration/bitswap_wo_routing_test.go @@ -34,7 +34,7 @@ func TestBitswapWithoutRouting(t *testing.T) { var nodes []*core.IpfsNode for _, p := range peers { - n, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(p, mn.Host(p), conf, core.DHTOption))) + n, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(p, mn.Host(p), conf, core.NilRouterOption))) if err != nil { t.Fatal(err) }