diff --git a/core/commands/dht.go b/core/commands/dht.go index 37ebc8b77..c4a368204 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -141,7 +141,7 @@ var findProvidersDhtCmd = &cmds.Command{ return err } - if n.Routing == nil { + if !n.OnlineMode() { return ErrNotOnline } @@ -235,7 +235,7 @@ var provideRefDhtCmd = &cmds.Command{ return err } - if nd.Routing == nil { + if !nd.OnlineMode() { return ErrNotOnline } @@ -364,7 +364,7 @@ var findPeerDhtCmd = &cmds.Command{ return err } - if nd.Routing == nil { + if !nd.OnlineMode() { return ErrNotOnline } @@ -446,7 +446,7 @@ Different key types can specify other 'best' rules. return err } - if nd.Routing == nil { + if !nd.OnlineMode() { return ErrNotOnline } @@ -538,7 +538,7 @@ NOTE: A value may not exceed 2048 bytes. return err } - if nd.Routing == nil { + if !nd.OnlineMode() { return ErrNotOnline } diff --git a/test/sharness/t0170-dht.sh b/test/sharness/t0170-dht.sh index 727bbccf2..6a1a0ed0b 100755 --- a/test/sharness/t0170-dht.sh +++ b/test/sharness/t0170-dht.sh @@ -91,6 +91,15 @@ test_dht() { test_expect_success 'stop iptb' ' iptb stop ' + + test_expect_success "dht commands fail when offline" ' + test_must_fail ipfsi 0 dht findprovs "$HASH" 2>err_findprovs && + test_must_fail ipfsi 0 dht findpeer "$HASH" 2>err_findpeer && + test_must_fail ipfsi 0 dht put "$TEST_DHT_PATH" "$TEST_DHT_VALUE" 2>err_put && + test_should_contain "this command must be run in online mode" err_findprovs && + test_should_contain "this command must be run in online mode" err_findpeer && + test_should_contain "this command must be run in online mode" err_put + ' } test_dht