Add router that does nothing for bitswap_wo_routing test
License: MIT Signed-off-by: Karthik Bala <karthikbala444@gmail.com>
Karthik Bala committed
Aug 14, 2015 at 20:02 UTC
d140b8aae1b5181d4879226c27dc6f71bd79bb3c
3 files changed
+54
-1
core/core.go
+2
@@ -40,6 +40,7 @@ import (
40
dht "github.com/ipfs/go-ipfs/routing/dht"
41
kb "github.com/ipfs/go-ipfs/routing/kbucket"
42
offroute "github.com/ipfs/go-ipfs/routing/offline"
43
+ nilrouting "github.com/ipfs/go-ipfs/routing/none"
44
45
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
46
bserv "github.com/ipfs/go-ipfs/blockservice"
@@ -613,3 +614,4 @@ type RoutingOption func(context.Context, p2phost.Host, ds.ThreadSafeDatastore) (
614
type DiscoveryOption func(p2phost.Host) (discovery.Service, error)
615
616
var DHTOption RoutingOption = constructDHTRouting
617
+var NilRouterOption RoutingOption = nilrouting.ConstructNilRouting
routing/none/none_client.go
new
+51
@@ -0,0 +1,51 @@
1
+package nilrouting
2
+
3
+import (
4
+ "errors"
5
+
6
+ ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
7
+ context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
8
+ key "github.com/ipfs/go-ipfs/blocks/key"
9
+ p2phost "github.com/ipfs/go-ipfs/p2p/host"
10
+ peer "github.com/ipfs/go-ipfs/p2p/peer"
11
+ routing "github.com/ipfs/go-ipfs/routing"
12
+ u "github.com/ipfs/go-ipfs/util"
13
+)
14
+
15
+var log = u.Logger("mockrouter")
16
+
17
+type nilclient struct {
18
+}
19
+
20
+func (c *nilclient) PutValue(_ context.Context, _ key.Key, _ []byte) error {
21
+ return nil
22
+}
23
+
24
+func (c *nilclient) GetValue(_ context.Context, _ key.Key) ([]byte, error) {
25
+ return nil, errors.New("Tried GetValue from nil routing.")
26
+}
27
+
28
+func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (peer.PeerInfo, error) {
29
+ return peer.PeerInfo{}, nil
30
+}
31
+
32
+func (c *nilclient) FindProvidersAsync(_ context.Context, _ key.Key, _ int) <-chan peer.PeerInfo {
33
+ out := make(chan peer.PeerInfo)
34
+ defer close(out)
35
+ return out
36
+}
37
+
38
+func (c *nilclient) Provide(_ context.Context, _ key.Key) error {
39
+ return nil
40
+}
41
+
42
+func (c *nilclient) Bootstrap(_ context.Context) error {
43
+ return nil
44
+}
45
+
46
+func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ ds.ThreadSafeDatastore) (routing.IpfsRouting, error) {
47
+ return &nilclient{}, nil
48
+}
49
+
50
+// ensure nilclient satisfies interface
51
+var _ routing.IpfsRouting = &nilclient{}
test/integration/bitswap_wo_routing_test.go
+1
-1
@@ -34,7 +34,7 @@ func TestBitswapWithoutRouting(t *testing.T) {
34
35
var nodes []*core.IpfsNode
36
for _, p := range peers {
37
- n, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(p, mn.Host(p), conf, core.DHTOption)))
37
+ n, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(p, mn.Host(p), conf, core.NilRouterOption)))
38
if err != nil {
39
t.Fatal(err)
40
}