@cryptotaxi247 / kubo / commits / 56a8c43aa

add experimental dht client mode flag

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Sep 27, 2016 at 00:40 UTC 56a8c43aafa0fbd22c9e5f0e8c57c6e90162181a
4 files changed +113 -3
cmd/ipfs/daemon.go
+5 -1
@@ -44,6 +44,7 @@ const (
44 offlineKwd = "offline"
45 routingOptionKwd = "routing"
46 routingOptionSupernodeKwd = "supernode"
47 + routingOptionDHTClientKwd = "dhtclient"
48 unencryptTransportKwd = "disable-transport-encryption"
49 unrestrictedApiAccessKwd = "unrestricted-api"
50 writableKwd = "writable"
@@ -280,7 +281,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
281 res.SetError(err, cmds.ErrNormal)
282 return
283 }
283 - if routingOption == routingOptionSupernodeKwd {
284 + switch routingOption {
285 + case routingOptionSupernodeKwd:
286 servers, err := cfg.SupernodeRouting.ServerIPFSAddrs()
287 if err != nil {
288 res.SetError(err, cmds.ErrNormal)
@@ -296,6 +298,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
298 }
299
300 ncfg.Routing = corerouting.SupernodeClient(infos...)
301 + case routingOptionDHTClientKwd:
302 + ncfg.Routing = core.DHTClientOption
303 }
304
305 node, err := core.NewNode(req.Context(), ncfg)
core/core.go
+8
@@ -638,9 +638,17 @@ func constructDHTRouting(ctx context.Context, host p2phost.Host, dstore repo.Dat
638 return dhtRouting, nil
639 }
640
641 +func constructClientDHTRouting(ctx context.Context, host p2phost.Host, dstore repo.Datastore) (routing.IpfsRouting, error) {
642 + dhtRouting := dht.NewDHTClient(ctx, host, dstore)
643 + dhtRouting.Validator[IpnsValidatorTag] = namesys.IpnsRecordValidator
644 + dhtRouting.Selector[IpnsValidatorTag] = namesys.IpnsSelectorFunc
645 + return dhtRouting, nil
646 +}
647 +
648 type RoutingOption func(context.Context, p2phost.Host, repo.Datastore) (routing.IpfsRouting, error)
649
650 type DiscoveryOption func(context.Context, p2phost.Host) (discovery.Service, error)
651
652 var DHTOption RoutingOption = constructDHTRouting
653 +var DHTClientOption RoutingOption = constructClientDHTRouting
654 var NilRouterOption RoutingOption = nilrouting.ConstructNilRouting
package.json
+2 -2
@@ -52,9 +52,9 @@
52 "version": "0.1.0"
53 },
54 {
55 - "hash": "Qma1FrGRasghpuETfCtsKdFtXKQffpNnakv3wG3QaMwCVi",
55 + "hash": "QmPxBCkNrrtx5cmg62TxiE3JUM2zTqTpps3diQ9PgNrcgn",
56 "name": "iptb",
57 - "version": "1.0.0"
57 + "version": "1.1.0"
58 },
59 {
60 "hash": "QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku",
test/sharness/t0131-multinode-client-routing.sh new
+98
@@ -0,0 +1,98 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2015 Jeromy Johnson
4 +# MIT Licensed; see the LICENSE file in this repository.
5 +#
6 +
7 +test_description="Test client mode dht"
8 +
9 +. lib/test-lib.sh
10 +
11 +check_file_fetch() {
12 + node=$1
13 + fhash=$2
14 + fname=$3
15 +
16 + test_expect_success "can fetch file" '
17 + ipfsi $node cat $fhash > fetch_out
18 + '
19 +
20 + test_expect_success "file looks good" '
21 + test_cmp $fname fetch_out
22 + '
23 +}
24 +
25 +check_dir_fetch() {
26 + node=$1
27 + ref=$2
28 +
29 + test_expect_success "node can fetch all refs for dir" '
30 + ipfsi $node refs -r $ref > /dev/null
31 + '
32 +}
33 +
34 +run_single_file_test() {
35 + test_expect_success "add a file on node1" '
36 + random 1000000 > filea &&
37 + FILEA_HASH=$(ipfsi 1 add -q filea)
38 + '
39 +
40 + check_file_fetch 4 $FILEA_HASH filea
41 + check_file_fetch 3 $FILEA_HASH filea
42 + check_file_fetch 2 $FILEA_HASH filea
43 + check_file_fetch 1 $FILEA_HASH filea
44 + check_file_fetch 0 $FILEA_HASH filea
45 +}
46 +
47 +run_random_dir_test() {
48 + test_expect_success "create a bunch of random files" '
49 + random-files -depth=4 -dirs=5 -files=8 foobar > /dev/null
50 + '
51 +
52 + test_expect_success "add those on node 2" '
53 + DIR_HASH=$(ipfsi 2 add -r -q foobar | tail -n1)
54 + '
55 +
56 + check_dir_fetch 0 $DIR_HASH
57 + check_dir_fetch 1 $DIR_HASH
58 + check_dir_fetch 2 $DIR_HASH
59 + check_dir_fetch 3 $DIR_HASH
60 + check_dir_fetch 4 $DIR_HASH
61 +}
62 +
63 +run_advanced_test() {
64 +
65 + run_single_file_test
66 +
67 + run_random_dir_test
68 +
69 + test_expect_success "shut down nodes" '
70 + iptb stop
71 + '
72 +}
73 +
74 +test_expect_success "set up testbed" '
75 + iptb init -n 10 -p 0 -f --bootstrap=none
76 +'
77 +
78 +test_expect_success "start up nodes" '
79 + iptb start [0-7] &&
80 + iptb start [8-9] --args="--routing=dhtclient"
81 +'
82 +
83 +test_expect_success "connect up nodes" '
84 + iptb connect [1-9] 0
85 +'
86 +
87 +test_expect_success "add a file on a node in client mode" '
88 + random 1000000 > filea &&
89 + FILE_HASH=$(ipfsi 8 add -q filea)
90 +'
91 +
92 +test_expect_success "retrieve that file on a client mode node" '
93 + check_file_fetch 9 $FILE_HASH filea
94 +'
95 +
96 +run_advanced_test
97 +
98 +test_done