Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add experimental dht client mode flag #3269

Merged
merged 3 commits into from
Oct 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
offlineKwd = "offline"
routingOptionKwd = "routing"
routingOptionSupernodeKwd = "supernode"
routingOptionDHTClientKwd = "dhtclient"
unencryptTransportKwd = "disable-transport-encryption"
unrestrictedApiAccessKwd = "unrestricted-api"
writableKwd = "writable"
Expand Down Expand Up @@ -120,6 +121,17 @@ environment variable:

export IPFS_PATH=/path/to/ipfsrepo

Routing

IPFS by default will use a DHT for content routing. There is a highly
experimental alternative that operates the DHT in a 'client only' mode that can
be enabled by running the daemon as:

ipfs daemon --routing=dhtclient

This will later be transitioned into a config option once it gets out of the
'experimental' stage.

DEPRECATION NOTICE

Previously, IPFS used an environment variable as seen below:
Expand Down Expand Up @@ -280,7 +292,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
res.SetError(err, cmds.ErrNormal)
return
}
if routingOption == routingOptionSupernodeKwd {
switch routingOption {
case routingOptionSupernodeKwd:
servers, err := cfg.SupernodeRouting.ServerIPFSAddrs()
if err != nil {
res.SetError(err, cmds.ErrNormal)
Expand All @@ -296,6 +309,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
}

ncfg.Routing = corerouting.SupernodeClient(infos...)
case routingOptionDHTClientKwd:
ncfg.Routing = core.DHTClientOption
}

node, err := core.NewNode(req.Context(), ncfg)
Expand Down
8 changes: 8 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,17 @@ func constructDHTRouting(ctx context.Context, host p2phost.Host, dstore repo.Dat
return dhtRouting, nil
}

func constructClientDHTRouting(ctx context.Context, host p2phost.Host, dstore repo.Datastore) (routing.IpfsRouting, error) {
dhtRouting := dht.NewDHTClient(ctx, host, dstore)
dhtRouting.Validator[IpnsValidatorTag] = namesys.IpnsRecordValidator
dhtRouting.Selector[IpnsValidatorTag] = namesys.IpnsSelectorFunc
return dhtRouting, nil
}

type RoutingOption func(context.Context, p2phost.Host, repo.Datastore) (routing.IpfsRouting, error)

type DiscoveryOption func(context.Context, p2phost.Host) (discovery.Service, error)

var DHTOption RoutingOption = constructDHTRouting
var DHTClientOption RoutingOption = constructClientDHTRouting
var NilRouterOption RoutingOption = nilrouting.ConstructNilRouting
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"version": "0.1.0"
},
{
"hash": "Qma1FrGRasghpuETfCtsKdFtXKQffpNnakv3wG3QaMwCVi",
"hash": "QmPxBCkNrrtx5cmg62TxiE3JUM2zTqTpps3diQ9PgNrcgn",
"name": "iptb",
"version": "1.0.0"
"version": "1.1.0"
},
{
"hash": "QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku",
Expand Down
73 changes: 73 additions & 0 deletions test/sharness/t0131-multinode-client-routing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh
#
# Copyright (c) 2015 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test client mode dht"

. lib/test-lib.sh

check_file_fetch() {
node=$1
fhash=$2
fname=$3

test_expect_success "can fetch file" '
ipfsi $node cat $fhash > fetch_out
'

test_expect_success "file looks good" '
test_cmp $fname fetch_out
'
}

run_single_file_test() {
test_expect_success "add a file on node1" '
random 1000000 > filea &&
FILEA_HASH=$(ipfsi 1 add -q filea)
'

check_file_fetch 9 $FILEA_HASH filea
check_file_fetch 8 $FILEA_HASH filea
check_file_fetch 7 $FILEA_HASH filea
check_file_fetch 6 $FILEA_HASH filea
check_file_fetch 5 $FILEA_HASH filea
check_file_fetch 4 $FILEA_HASH filea
check_file_fetch 3 $FILEA_HASH filea
check_file_fetch 2 $FILEA_HASH filea
check_file_fetch 1 $FILEA_HASH filea
check_file_fetch 0 $FILEA_HASH filea
}

NNODES=10

test_expect_success "set up testbed" '
iptb init -n $NNODES -p 0 -f --bootstrap=none
'

test_expect_success "start up nodes" '
iptb start [0-7] &&
iptb start [8-9] --args="--routing=dhtclient"
'

test_expect_success "connect up nodes" '
iptb connect [1-9] 0
'

test_expect_success "add a file on a node in client mode" '
random 1000000 > filea &&
FILE_HASH=$(ipfsi 8 add -q filea)
'

test_expect_success "retrieve that file on a client mode node" '
check_file_fetch 9 $FILE_HASH filea
'

run_single_file_test

test_expect_success "shut down nodes" '
iptb stop
'

test_done