Extract: routing package to github.com/ipfs/go-ipfs-routing
This extracts the routing package to its own repository (https://github.com/ipfs/go-ipfs-routing). History has been preserved. The new module has been gx'ed and published. Imports have been rewritten and re-ordered accordingly. An internal dependency to go-ipfs/repo has been removed by substituting it with the go-datastore.Batching interface. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
Hector Sanjuan committed
Feb 9, 2018 at 15:06 UTC
54d87b4ce00c2ed3e90d34db6f670f25569d4a9d
24 files changed
+32
-727
blockservice/test/mock.go
+1
-1
@@ -4,9 +4,9 @@ import (
4
. "github.com/ipfs/go-ipfs/blockservice"
5
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
6
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
7
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
7
8
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
9
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
10
)
11
12
// Mocks returns |n| connected mock Blockservices
core/commands/ipns.go
+1
-1
@@ -8,8 +8,8 @@ import (
8
cmds "github.com/ipfs/go-ipfs/commands"
9
e "github.com/ipfs/go-ipfs/core/commands/e"
10
namesys "github.com/ipfs/go-ipfs/namesys"
11
- offline "github.com/ipfs/go-ipfs/routing/offline"
11
12
+ offline "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline"
13
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
14
)
15
core/core.go
+5
-5
@@ -38,8 +38,6 @@ import (
38
pin "github.com/ipfs/go-ipfs/pin"
39
repo "github.com/ipfs/go-ipfs/repo"
40
config "github.com/ipfs/go-ipfs/repo/config"
41
- nilrouting "github.com/ipfs/go-ipfs/routing/none"
42
- offroute "github.com/ipfs/go-ipfs/routing/offline"
41
ft "github.com/ipfs/go-ipfs/unixfs"
42
43
addrutil "gx/ipfs/QmNSWW3Sb4eju4o2djPQ1L1c2Zj9XN9sMYJL8r1cbxdc6b/go-addr-util"
@@ -66,6 +64,8 @@ import (
64
smux "gx/ipfs/QmY9JXR3FupnYAYJWK9aMr9bCpqWKcToQ1tz8DVGTrHpHw/go-stream-muxer"
65
connmgr "gx/ipfs/QmZ1R2LxRZTUaeuMFEtQigzHfFCv3hLYBi5316aZ7YUeyf/go-libp2p-connmgr"
66
ipnet "gx/ipfs/QmZPrWxuM8GHr4cGKbyF5CCT11sFUP9hgqpeUHALvx2nUr/go-libp2p-interface-pnet"
67
+ nilrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/none"
68
+ offroute "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline"
69
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
70
ic "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
71
ifconnmgr "gx/ipfs/Qmax8X1Kfahf5WfSB68EWDG3d3qyS3Sqs1v412fjPTfRwx/go-libp2p-interface-connmgr"
@@ -947,21 +947,21 @@ func startListening(ctx context.Context, host p2phost.Host, cfg *config.Config)
947
return nil
948
}
949
950
-func constructDHTRouting(ctx context.Context, host p2phost.Host, dstore repo.Datastore) (routing.IpfsRouting, error) {
950
+func constructDHTRouting(ctx context.Context, host p2phost.Host, dstore ds.Batching) (routing.IpfsRouting, error) {
951
dhtRouting := dht.NewDHT(ctx, host, dstore)
952
dhtRouting.Validator[IpnsValidatorTag] = namesys.NewIpnsRecordValidator(host.Peerstore())
953
dhtRouting.Selector[IpnsValidatorTag] = namesys.IpnsSelectorFunc
954
return dhtRouting, nil
955
}
956
957
-func constructClientDHTRouting(ctx context.Context, host p2phost.Host, dstore repo.Datastore) (routing.IpfsRouting, error) {
957
+func constructClientDHTRouting(ctx context.Context, host p2phost.Host, dstore ds.Batching) (routing.IpfsRouting, error) {
958
dhtRouting := dht.NewDHTClient(ctx, host, dstore)
959
dhtRouting.Validator[IpnsValidatorTag] = namesys.NewIpnsRecordValidator(host.Peerstore())
960
dhtRouting.Selector[IpnsValidatorTag] = namesys.IpnsSelectorFunc
961
return dhtRouting, nil
962
}
963
964
-type RoutingOption func(context.Context, p2phost.Host, repo.Datastore) (routing.IpfsRouting, error)
964
+type RoutingOption func(context.Context, p2phost.Host, ds.Batching) (routing.IpfsRouting, error)
965
966
type DiscoveryOption func(context.Context, p2phost.Host) (discovery.Service, error)
967
core/coreapi/name.go
+1
-1
@@ -13,8 +13,8 @@ import (
13
keystore "github.com/ipfs/go-ipfs/keystore"
14
namesys "github.com/ipfs/go-ipfs/namesys"
15
ipath "github.com/ipfs/go-ipfs/path"
16
- offline "github.com/ipfs/go-ipfs/routing/offline"
16
17
+ offline "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline"
18
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
19
crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
20
)
exchange/bitswap/bitswap_test.go
+1
-1
@@ -12,12 +12,12 @@ import (
12
blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil"
13
decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
14
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
15
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
15
16
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
17
tu "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
18
travis "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil/ci/travis"
19
p2ptestutil "gx/ipfs/QmYVR3C8DWPHdHxvLtNFYfjsXgaRAdh6hPMNH3KiwCgu4o/go-libp2p-netutil"
20
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
21
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
22
blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
23
detectrace "gx/ipfs/Qmf7HqcW7LtCi1W8y2bdx2eJpze74jkbKqpByxgXikdbLF/go-detect-race"
exchange/bitswap/testnet/network_test.go
+1
-1
@@ -7,10 +7,10 @@ import (
7
8
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
9
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
10
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
10
11
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
12
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
13
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
14
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
15
blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
16
)
exchange/bitswap/testnet/peernet.go
+2
-1
@@ -4,10 +4,11 @@ import (
4
"context"
5
6
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
7
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
7
+
8
mockpeernet "gx/ipfs/QmNh1kGFFdsPu79KNSaL4NUKUPb4Eiz4KHdMtFY6664RDp/go-libp2p/p2p/net/mock"
9
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
10
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
11
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
12
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
13
)
14
exchange/bitswap/testnet/virtual.go
+1
-1
@@ -8,12 +8,12 @@ import (
8
9
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
10
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
11
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
11
12
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
13
logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
14
routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
15
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
16
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
17
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
18
ifconnmgr "gx/ipfs/Qmax8X1Kfahf5WfSB68EWDG3d3qyS3Sqs1v412fjPTfRwx/go-libp2p-interface-connmgr"
19
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
exchange/reprovide/reprovide_test.go
+2
-1
@@ -5,11 +5,12 @@ import (
5
"testing"
6
7
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
8
- mock "github.com/ipfs/go-ipfs/routing/mock"
8
+
9
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
10
dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
11
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
12
pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
13
+ mock "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
14
blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
15
16
. "github.com/ipfs/go-ipfs/exchange/reprovide"
fuse/ipns/ipns_test.go
+3
-3
@@ -14,12 +14,12 @@ import (
14
15
core "github.com/ipfs/go-ipfs/core"
16
namesys "github.com/ipfs/go-ipfs/namesys"
17
- offroute "github.com/ipfs/go-ipfs/routing/offline"
17
19
- ci "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil/ci"
20
- racedet "gx/ipfs/Qmf7HqcW7LtCi1W8y2bdx2eJpze74jkbKqpByxgXikdbLF/go-detect-race"
18
u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
19
+ ci "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil/ci"
20
+ offroute "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline"
21
fstest "gx/ipfs/QmaFNtBAXX4nVMQWbUqNysXyhevUj1k4B1y5uS45LC7Vw9/fuse/fs/fstestutil"
22
+ racedet "gx/ipfs/Qmf7HqcW7LtCi1W8y2bdx2eJpze74jkbKqpByxgXikdbLF/go-detect-race"
23
)
24
25
func maybeSkipFuseTests(t *testing.T) {
fuse/node/mount_test.go
+2
-1
@@ -15,8 +15,9 @@ import (
15
ipns "github.com/ipfs/go-ipfs/fuse/ipns"
16
mount "github.com/ipfs/go-ipfs/fuse/mount"
17
namesys "github.com/ipfs/go-ipfs/namesys"
18
- offroute "github.com/ipfs/go-ipfs/routing/offline"
18
+
19
ci "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil/ci"
20
+ offroute "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline"
21
)
22
23
func maybeSkipFuseTests(t *testing.T) {
namesys/ipns_validate_test.go
+1
-1
@@ -7,7 +7,6 @@ import (
7
"time"
8
9
path "github.com/ipfs/go-ipfs/path"
10
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
10
11
u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
12
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
@@ -18,6 +17,7 @@ import (
17
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
18
pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
19
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
20
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
21
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
22
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
23
)
namesys/namesys_test.go
+1
-1
@@ -7,11 +7,11 @@ import (
7
context "context"
8
9
path "github.com/ipfs/go-ipfs/path"
10
- offroute "github.com/ipfs/go-ipfs/routing/offline"
10
"github.com/ipfs/go-ipfs/unixfs"
11
12
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
13
dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
14
+ offroute "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/offline"
15
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
16
)
17
namesys/publisher_test.go
+1
-1
@@ -7,12 +7,12 @@ import (
7
"time"
8
9
path "github.com/ipfs/go-ipfs/path"
10
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
10
11
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
12
dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
13
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
14
ma "gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr"
15
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
16
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
17
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
18
dshelp "gx/ipfs/QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn/go-ipfs-ds-help"
namesys/pubsub_test.go
+1
-1
@@ -7,7 +7,6 @@ import (
7
"time"
8
9
path "github.com/ipfs/go-ipfs/path"
10
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
10
11
p2phost "gx/ipfs/QmNmJZL7FQySMtE2BQuLMuZg2EB2CLEunJJUSVSc9YnnbV/go-libp2p-host"
12
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
@@ -17,6 +16,7 @@ import (
16
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
17
pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
18
netutil "gx/ipfs/QmYVR3C8DWPHdHxvLtNFYfjsXgaRAdh6hPMNH3KiwCgu4o/go-libp2p-netutil"
19
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
20
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
21
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
22
)
namesys/resolve_test.go
+2
-2
@@ -7,11 +7,11 @@ import (
7
"time"
8
9
path "github.com/ipfs/go-ipfs/path"
10
- mockrouting "github.com/ipfs/go-ipfs/routing/mock"
11
- testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
10
11
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
12
dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
13
+ testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
14
+ mockrouting "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
15
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
16
)
17
package.json
+6
@@ -551,6 +551,12 @@
551
"hash": "QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn",
552
"name": "go-ipfs-ds-help",
553
"version": "0.0.1"
554
+ },
555
+ {
556
+ "author": "hsanjuan",
557
+ "hash": "QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb",
558
+ "name": "go-ipfs-routing",
559
+ "version": "0.0.1"
560
}
561
],
562
"gxVersion": "0.10.0",
routing/mock/centralized_client.go
deleted
-125
@@ -1,125 +0,0 @@
1
-package mockrouting
2
-
3
-import (
4
- "context"
5
- "errors"
6
- "time"
7
-
8
- u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
9
- ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
10
- logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
11
- routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
12
- dhtpb "gx/ipfs/QmUpttFinNDmNPgFwKN8sZK6BUtBmA68Y4KdSBDXa8t9sJ/go-libp2p-record/pb"
13
- "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
14
- ma "gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr"
15
- pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
16
- proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
17
- peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
18
- cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
19
- dshelp "gx/ipfs/QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn/go-ipfs-ds-help"
20
-)
21
-
22
-var log = logging.Logger("mockrouter")
23
-
24
-type client struct {
25
- datastore ds.Datastore
26
- server server
27
- peer testutil.Identity
28
-}
29
-
30
-// FIXME(brian): is this method meant to simulate putting a value into the network?
31
-func (c *client) PutValue(ctx context.Context, key string, val []byte) error {
32
- log.Debugf("PutValue: %s", key)
33
- rec := new(dhtpb.Record)
34
- rec.Value = val
35
- rec.Key = proto.String(string(key))
36
- rec.TimeReceived = proto.String(u.FormatRFC3339(time.Now()))
37
- data, err := proto.Marshal(rec)
38
- if err != nil {
39
- return err
40
- }
41
-
42
- return c.datastore.Put(dshelp.NewKeyFromBinary([]byte(key)), data)
43
-}
44
-
45
-// FIXME(brian): is this method meant to simulate getting a value from the network?
46
-func (c *client) GetValue(ctx context.Context, key string) ([]byte, error) {
47
- log.Debugf("GetValue: %s", key)
48
- v, err := c.datastore.Get(dshelp.NewKeyFromBinary([]byte(key)))
49
- if err != nil {
50
- return nil, err
51
- }
52
-
53
- data, ok := v.([]byte)
54
- if !ok {
55
- return nil, errors.New("could not cast value from datastore")
56
- }
57
-
58
- rec := new(dhtpb.Record)
59
- err = proto.Unmarshal(data, rec)
60
- if err != nil {
61
- return nil, err
62
- }
63
-
64
- return rec.GetValue(), nil
65
-}
66
-
67
-func (c *client) GetValues(ctx context.Context, key string, count int) ([]routing.RecvdVal, error) {
68
- log.Debugf("GetValues: %s", key)
69
- data, err := c.GetValue(ctx, key)
70
- if err != nil {
71
- return nil, err
72
- }
73
-
74
- return []routing.RecvdVal{{Val: data, From: c.peer.ID()}}, nil
75
-}
76
-
77
-func (c *client) FindProviders(ctx context.Context, key *cid.Cid) ([]pstore.PeerInfo, error) {
78
- return c.server.Providers(key), nil
79
-}
80
-
81
-func (c *client) FindPeer(ctx context.Context, pid peer.ID) (pstore.PeerInfo, error) {
82
- log.Debugf("FindPeer: %s", pid)
83
- return pstore.PeerInfo{}, nil
84
-}
85
-
86
-func (c *client) FindProvidersAsync(ctx context.Context, k *cid.Cid, max int) <-chan pstore.PeerInfo {
87
- out := make(chan pstore.PeerInfo)
88
- go func() {
89
- defer close(out)
90
- for i, p := range c.server.Providers(k) {
91
- if max <= i {
92
- return
93
- }
94
- select {
95
- case out <- p:
96
- case <-ctx.Done():
97
- return
98
- }
99
- }
100
- }()
101
- return out
102
-}
103
-
104
-// Provide returns once the message is on the network. Value is not necessarily
105
-// visible yet.
106
-func (c *client) Provide(_ context.Context, key *cid.Cid, brd bool) error {
107
- if !brd {
108
- return nil
109
- }
110
- info := pstore.PeerInfo{
111
- ID: c.peer.ID(),
112
- Addrs: []ma.Multiaddr{c.peer.Address()},
113
- }
114
- return c.server.Announce(info, key)
115
-}
116
-
117
-func (c *client) Ping(ctx context.Context, p peer.ID) (time.Duration, error) {
118
- return 0, nil
119
-}
120
-
121
-func (c *client) Bootstrap(context.Context) error {
122
- return nil
123
-}
124
-
125
-var _ routing.IpfsRouting = &client{}
routing/mock/centralized_server.go
deleted
-92
@@ -1,92 +0,0 @@
1
-package mockrouting
2
-
3
-import (
4
- "context"
5
- "math/rand"
6
- "sync"
7
- "time"
8
-
9
- "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
10
-
11
- ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
12
- dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
13
- pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
14
- peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
15
- cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
16
-)
17
-
18
-// server is the mockrouting.Client's private interface to the routing server
19
-type server interface {
20
- Announce(pstore.PeerInfo, *cid.Cid) error
21
- Providers(*cid.Cid) []pstore.PeerInfo
22
-
23
- Server
24
-}
25
-
26
-// s is an implementation of the private server interface
27
-type s struct {
28
- delayConf DelayConfig
29
-
30
- lock sync.RWMutex
31
- providers map[string]map[peer.ID]providerRecord
32
-}
33
-
34
-type providerRecord struct {
35
- Peer pstore.PeerInfo
36
- Created time.Time
37
-}
38
-
39
-func (rs *s) Announce(p pstore.PeerInfo, c *cid.Cid) error {
40
- rs.lock.Lock()
41
- defer rs.lock.Unlock()
42
-
43
- k := c.KeyString()
44
-
45
- _, ok := rs.providers[k]
46
- if !ok {
47
- rs.providers[k] = make(map[peer.ID]providerRecord)
48
- }
49
- rs.providers[k][p.ID] = providerRecord{
50
- Created: time.Now(),
51
- Peer: p,
52
- }
53
- return nil
54
-}
55
-
56
-func (rs *s) Providers(c *cid.Cid) []pstore.PeerInfo {
57
- rs.delayConf.Query.Wait() // before locking
58
-
59
- rs.lock.RLock()
60
- defer rs.lock.RUnlock()
61
- k := c.KeyString()
62
-
63
- var ret []pstore.PeerInfo
64
- records, ok := rs.providers[k]
65
- if !ok {
66
- return ret
67
- }
68
- for _, r := range records {
69
- if time.Since(r.Created) > rs.delayConf.ValueVisibility.Get() {
70
- ret = append(ret, r.Peer)
71
- }
72
- }
73
-
74
- for i := range ret {
75
- j := rand.Intn(i + 1)
76
- ret[i], ret[j] = ret[j], ret[i]
77
- }
78
-
79
- return ret
80
-}
81
-
82
-func (rs *s) Client(p testutil.Identity) Client {
83
- return rs.ClientWithDatastore(context.Background(), p, dssync.MutexWrap(ds.NewMapDatastore()))
84
-}
85
-
86
-func (rs *s) ClientWithDatastore(_ context.Context, p testutil.Identity, datastore ds.Datastore) Client {
87
- return &client{
88
- peer: p,
89
- datastore: datastore,
90
- server: rs,
91
- }
92
-}
routing/mock/centralized_test.go
deleted
-176
@@ -1,176 +0,0 @@
1
-package mockrouting
2
-
3
-import (
4
- "context"
5
- "testing"
6
- "time"
7
-
8
- u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
9
- delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
10
- testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
11
- pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
12
- cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
13
-)
14
-
15
-func TestKeyNotFound(t *testing.T) {
16
-
17
- var pi = testutil.RandIdentityOrFatal(t)
18
- var key = cid.NewCidV0(u.Hash([]byte("mock key")))
19
- var ctx = context.Background()
20
-
21
- rs := NewServer()
22
- providers := rs.Client(pi).FindProvidersAsync(ctx, key, 10)
23
- _, ok := <-providers
24
- if ok {
25
- t.Fatal("should be closed")
26
- }
27
-}
28
-
29
-func TestClientFindProviders(t *testing.T) {
30
- pi := testutil.RandIdentityOrFatal(t)
31
- rs := NewServer()
32
- client := rs.Client(pi)
33
-
34
- k := cid.NewCidV0(u.Hash([]byte("hello")))
35
- err := client.Provide(context.Background(), k, true)
36
- if err != nil {
37
- t.Fatal(err)
38
- }
39
-
40
- // This is bad... but simulating networks is hard
41
- time.Sleep(time.Millisecond * 300)
42
- max := 100
43
-
44
- providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
45
- isInClient := false
46
- for pi := range providersFromClient {
47
- if pi.ID == pi.ID { // <-- typo?
48
- isInClient = true
49
- }
50
- }
51
- if !isInClient {
52
- t.Fatal("Despite client providing key, client didn't receive peer when finding providers")
53
- }
54
-}
55
-
56
-func TestClientOverMax(t *testing.T) {
57
- rs := NewServer()
58
- k := cid.NewCidV0(u.Hash([]byte("hello")))
59
- numProvidersForHelloKey := 100
60
- for i := 0; i < numProvidersForHelloKey; i++ {
61
- pi := testutil.RandIdentityOrFatal(t)
62
- err := rs.Client(pi).Provide(context.Background(), k, true)
63
- if err != nil {
64
- t.Fatal(err)
65
- }
66
- }
67
-
68
- max := 10
69
- pi := testutil.RandIdentityOrFatal(t)
70
- client := rs.Client(pi)
71
-
72
- providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
73
- i := 0
74
- for range providersFromClient {
75
- i++
76
- }
77
- if i != max {
78
- t.Fatal("Too many providers returned")
79
- }
80
-}
81
-
82
-// TODO does dht ensure won't receive self as a provider? probably not.
83
-func TestCanceledContext(t *testing.T) {
84
- rs := NewServer()
85
- k := cid.NewCidV0(u.Hash([]byte("hello")))
86
-
87
- // avoid leaking goroutine, without using the context to signal
88
- // (we want the goroutine to keep trying to publish on a
89
- // cancelled context until we've tested it doesnt do anything.)
90
- done := make(chan struct{})
91
- defer func() { done <- struct{}{} }()
92
-
93
- t.Log("async'ly announce infinite stream of providers for key")
94
- i := 0
95
- go func() { // infinite stream
96
- for {
97
- select {
98
- case <-done:
99
- t.Log("exiting async worker")
100
- return
101
- default:
102
- }
103
-
104
- pi, err := testutil.RandIdentity()
105
- if err != nil {
106
- t.Error(err)
107
- }
108
- err = rs.Client(pi).Provide(context.Background(), k, true)
109
- if err != nil {
110
- t.Error(err)
111
- }
112
- i++
113
- }
114
- }()
115
-
116
- local := testutil.RandIdentityOrFatal(t)
117
- client := rs.Client(local)
118
-
119
- t.Log("warning: max is finite so this test is non-deterministic")
120
- t.Log("context cancellation could simply take lower priority")
121
- t.Log("and result in receiving the max number of results")
122
- max := 1000
123
-
124
- t.Log("cancel the context before consuming")
125
- ctx, cancelFunc := context.WithCancel(context.Background())
126
- cancelFunc()
127
- providers := client.FindProvidersAsync(ctx, k, max)
128
-
129
- numProvidersReturned := 0
130
- for range providers {
131
- numProvidersReturned++
132
- }
133
- t.Log(numProvidersReturned)
134
-
135
- if numProvidersReturned == max {
136
- t.Fatal("Context cancel had no effect")
137
- }
138
-}
139
-
140
-func TestValidAfter(t *testing.T) {
141
- ctx, cancel := context.WithCancel(context.Background())
142
- defer cancel()
143
-
144
- pi := testutil.RandIdentityOrFatal(t)
145
- key := cid.NewCidV0(u.Hash([]byte("mock key")))
146
- conf := DelayConfig{
147
- ValueVisibility: delay.Fixed(1 * time.Hour),
148
- Query: delay.Fixed(0),
149
- }
150
-
151
- rs := NewServerWithDelay(conf)
152
-
153
- rs.Client(pi).Provide(ctx, key, true)
154
-
155
- var providers []pstore.PeerInfo
156
- max := 100
157
- providersChan := rs.Client(pi).FindProvidersAsync(ctx, key, max)
158
- for p := range providersChan {
159
- providers = append(providers, p)
160
- }
161
- if len(providers) > 0 {
162
- t.Fail()
163
- }
164
-
165
- conf.ValueVisibility.Set(0)
166
- time.Sleep(100 * time.Millisecond)
167
-
168
- providersChan = rs.Client(pi).FindProvidersAsync(ctx, key, max)
169
- t.Log("providers", providers)
170
- for p := range providersChan {
171
- providers = append(providers, p)
172
- }
173
- if len(providers) != 1 {
174
- t.Fail()
175
- }
176
-}
routing/mock/interface.go
deleted
-53
@@ -1,53 +0,0 @@
1
-// Package mockrouting provides a virtual routing server. To use it,
2
-// create a virtual routing server and use the Client() method to get a
3
-// routing client (IpfsRouting). The server quacks like a DHT but is
4
-// really a local in-memory hash table.
5
-package mockrouting
6
-
7
-import (
8
- "context"
9
-
10
- ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
11
- delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
12
- routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
13
- "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
14
- peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
15
-)
16
-
17
-// Server provides mockrouting Clients
18
-type Server interface {
19
- Client(p testutil.Identity) Client
20
- ClientWithDatastore(context.Context, testutil.Identity, ds.Datastore) Client
21
-}
22
-
23
-// Client implements IpfsRouting
24
-type Client interface {
25
- routing.IpfsRouting
26
-}
27
-
28
-// NewServer returns a mockrouting Server
29
-func NewServer() Server {
30
- return NewServerWithDelay(DelayConfig{
31
- ValueVisibility: delay.Fixed(0),
32
- Query: delay.Fixed(0),
33
- })
34
-}
35
-
36
-// NewServerWithDelay returns a mockrouting Server with a delay!
37
-func NewServerWithDelay(conf DelayConfig) Server {
38
- return &s{
39
- providers: make(map[string]map[peer.ID]providerRecord),
40
- delayConf: conf,
41
- }
42
-}
43
-
44
-// DelayConfig can be used to configured the fake delays of a mock server.
45
-// Use with NewServerWithDelay().
46
-type DelayConfig struct {
47
- // ValueVisibility is the time it takes for a value to be visible in the network
48
- // FIXME there _must_ be a better term for this
49
- ValueVisibility delay.D
50
-
51
- // Query is the time it takes to receive a response from a routing query
52
- Query delay.D
53
-}
routing/none/none_client.go
deleted
-56
@@ -1,56 +0,0 @@
1
-// Package nilrouting implements a routing client that does nothing.
2
-package nilrouting
3
-
4
-import (
5
- "context"
6
- "errors"
7
-
8
- repo "github.com/ipfs/go-ipfs/repo"
9
-
10
- p2phost "gx/ipfs/QmNmJZL7FQySMtE2BQuLMuZg2EB2CLEunJJUSVSc9YnnbV/go-libp2p-host"
11
- routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
12
- pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
13
- peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
14
- cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
15
-)
16
-
17
-type nilclient struct {
18
-}
19
-
20
-func (c *nilclient) PutValue(_ context.Context, _ string, _ []byte) error {
21
- return nil
22
-}
23
-
24
-func (c *nilclient) GetValue(_ context.Context, _ string) ([]byte, error) {
25
- return nil, errors.New("tried GetValue from nil routing")
26
-}
27
-
28
-func (c *nilclient) GetValues(_ context.Context, _ string, _ int) ([]routing.RecvdVal, error) {
29
- return nil, errors.New("tried GetValues from nil routing")
30
-}
31
-
32
-func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (pstore.PeerInfo, error) {
33
- return pstore.PeerInfo{}, nil
34
-}
35
-
36
-func (c *nilclient) FindProvidersAsync(_ context.Context, _ *cid.Cid, _ int) <-chan pstore.PeerInfo {
37
- out := make(chan pstore.PeerInfo)
38
- defer close(out)
39
- return out
40
-}
41
-
42
-func (c *nilclient) Provide(_ context.Context, _ *cid.Cid, _ bool) error {
43
- return nil
44
-}
45
-
46
-func (c *nilclient) Bootstrap(_ context.Context) error {
47
- return nil
48
-}
49
-
50
-// ConstructNilRouting creates an IpfsRouting client which does nothing.
51
-func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ repo.Datastore) (routing.IpfsRouting, error) {
52
- return &nilclient{}, nil
53
-}
54
-
55
-// ensure nilclient satisfies interface
56
-var _ routing.IpfsRouting = &nilclient{}
routing/offline/offline.go
deleted
-120
@@ -1,120 +0,0 @@
1
-// Package offline implements IpfsRouting with a client which
2
-// is only able to perform offline operations.
3
-package offline
4
-
5
-import (
6
- "context"
7
- "errors"
8
- "time"
9
-
10
- ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
11
- routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
12
- record "gx/ipfs/QmUpttFinNDmNPgFwKN8sZK6BUtBmA68Y4KdSBDXa8t9sJ/go-libp2p-record"
13
- pb "gx/ipfs/QmUpttFinNDmNPgFwKN8sZK6BUtBmA68Y4KdSBDXa8t9sJ/go-libp2p-record/pb"
14
- pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
15
- proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
16
- "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
17
- ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
18
- cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
19
- dshelp "gx/ipfs/QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn/go-ipfs-ds-help"
20
-)
21
-
22
-// ErrOffline is returned when trying to perform operations that
23
-// require connectivity.
24
-var ErrOffline = errors.New("routing system in offline mode")
25
-
26
-// NewOfflineRouter returns an IpfsRouting implementation which only performs
27
-// offline operations. It allows to Put and Get signed dht
28
-// records to and from the local datastore.
29
-func NewOfflineRouter(dstore ds.Datastore, privkey ci.PrivKey) routing.IpfsRouting {
30
- return &offlineRouting{
31
- datastore: dstore,
32
- sk: privkey,
33
- }
34
-}
35
-
36
-// offlineRouting implements the IpfsRouting interface,
37
-// but only provides the capability to Put and Get signed dht
38
-// records to and from the local datastore.
39
-type offlineRouting struct {
40
- datastore ds.Datastore
41
- sk ci.PrivKey
42
-}
43
-
44
-func (c *offlineRouting) PutValue(ctx context.Context, key string, val []byte) error {
45
- rec, err := record.MakePutRecord(c.sk, key, val, false)
46
- if err != nil {
47
- return err
48
- }
49
- data, err := proto.Marshal(rec)
50
- if err != nil {
51
- return err
52
- }
53
-
54
- return c.datastore.Put(dshelp.NewKeyFromBinary([]byte(key)), data)
55
-}
56
-
57
-func (c *offlineRouting) GetValue(ctx context.Context, key string) ([]byte, error) {
58
- v, err := c.datastore.Get(dshelp.NewKeyFromBinary([]byte(key)))
59
- if err != nil {
60
- return nil, err
61
- }
62
-
63
- byt, ok := v.([]byte)
64
- if !ok {
65
- return nil, errors.New("value stored in datastore not []byte")
66
- }
67
- rec := new(pb.Record)
68
- err = proto.Unmarshal(byt, rec)
69
- if err != nil {
70
- return nil, err
71
- }
72
-
73
- return rec.GetValue(), nil
74
-}
75
-
76
-func (c *offlineRouting) GetValues(ctx context.Context, key string, _ int) ([]routing.RecvdVal, error) {
77
- v, err := c.datastore.Get(dshelp.NewKeyFromBinary([]byte(key)))
78
- if err != nil {
79
- return nil, err
80
- }
81
-
82
- byt, ok := v.([]byte)
83
- if !ok {
84
- return nil, errors.New("value stored in datastore not []byte")
85
- }
86
- rec := new(pb.Record)
87
- err = proto.Unmarshal(byt, rec)
88
- if err != nil {
89
- return nil, err
90
- }
91
-
92
- return []routing.RecvdVal{
93
- {Val: rec.GetValue()},
94
- }, nil
95
-}
96
-
97
-func (c *offlineRouting) FindPeer(ctx context.Context, pid peer.ID) (pstore.PeerInfo, error) {
98
- return pstore.PeerInfo{}, ErrOffline
99
-}
100
-
101
-func (c *offlineRouting) FindProvidersAsync(ctx context.Context, k *cid.Cid, max int) <-chan pstore.PeerInfo {
102
- out := make(chan pstore.PeerInfo)
103
- close(out)
104
- return out
105
-}
106
-
107
-func (c *offlineRouting) Provide(_ context.Context, k *cid.Cid, _ bool) error {
108
- return ErrOffline
109
-}
110
-
111
-func (c *offlineRouting) Ping(ctx context.Context, p peer.ID) (time.Duration, error) {
112
- return 0, ErrOffline
113
-}
114
-
115
-func (c *offlineRouting) Bootstrap(context.Context) error {
116
- return nil
117
-}
118
-
119
-// ensure offlineRouting matches the IpfsRouting interface
120
-var _ routing.IpfsRouting = &offlineRouting{}
routing/offline/offline_test.go
deleted
-82
@@ -1,82 +0,0 @@
1
-package offline
2
-
3
-import (
4
- "bytes"
5
- "context"
6
- "testing"
7
-
8
- ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
9
- "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
10
-)
11
-
12
-func TestOfflineRouterStorage(t *testing.T) {
13
- ctx := context.Background()
14
-
15
- nds := ds.NewMapDatastore()
16
- privkey, _, _ := testutil.RandTestKeyPair(128)
17
- offline := NewOfflineRouter(nds, privkey)
18
-
19
- if err := offline.PutValue(ctx, "key", []byte("testing 1 2 3")); err != nil {
20
- t.Fatal(err)
21
- }
22
-
23
- val, err := offline.GetValue(ctx, "key")
24
- if err != nil {
25
- t.Fatal(err)
26
- }
27
- if !bytes.Equal([]byte("testing 1 2 3"), val) {
28
- t.Fatal("OfflineRouter does not properly store")
29
- }
30
-
31
- _, err = offline.GetValue(ctx, "notHere")
32
- if err == nil {
33
- t.Fatal("Router should throw errors for unfound records")
34
- }
35
-
36
- recVal, err := offline.GetValues(ctx, "key", 0)
37
- if err != nil {
38
- t.Fatal(err)
39
- }
40
-
41
- _, err = offline.GetValues(ctx, "notHere", 0)
42
- if err == nil {
43
- t.Fatal("Router should throw errors for unfound records")
44
- }
45
-
46
- local := recVal[0].Val
47
- if !bytes.Equal([]byte("testing 1 2 3"), local) {
48
- t.Fatal("OfflineRouter does not properly store")
49
- }
50
-}
51
-
52
-func TestOfflineRouterLocal(t *testing.T) {
53
- ctx := context.Background()
54
-
55
- nds := ds.NewMapDatastore()
56
- privkey, _, _ := testutil.RandTestKeyPair(128)
57
- offline := NewOfflineRouter(nds, privkey)
58
-
59
- id, _ := testutil.RandPeerID()
60
- _, err := offline.FindPeer(ctx, id)
61
- if err != ErrOffline {
62
- t.Fatal("OfflineRouting should alert that its offline")
63
- }
64
-
65
- cid, _ := testutil.RandCidV0()
66
- pChan := offline.FindProvidersAsync(ctx, cid, 1)
67
- p, ok := <-pChan
68
- if ok {
69
- t.Fatalf("FindProvidersAsync did not return a closed channel. Instead we got %+v !", p)
70
- }
71
-
72
- cid, _ = testutil.RandCidV0()
73
- err = offline.Provide(ctx, cid, true)
74
- if err != ErrOffline {
75
- t.Fatal("OfflineRouting should alert that its offline")
76
- }
77
-
78
- err = offline.Bootstrap(ctx)
79
- if err != nil {
80
- t.Fatal("You shouldn't be able to bootstrap offline routing.")
81
- }
82
-}