@cryptotaxi247 / kubo / commits / 55c232fc7

commands: return a helpful error when the daemon is offline

fixes #3415 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Dec 17, 2018 at 17:24 UTC 55c232fc7238fea7e2dde9f8556762b7f9184e5f
2 files changed +14 -5
core/commands/dht.go
+5 -5
@@ -141,7 +141,7 @@ var findProvidersDhtCmd = &cmds.Command{
141 return err
142 }
143
144 - if n.Routing == nil {
144 + if !n.OnlineMode() {
145 return ErrNotOnline
146 }
147
@@ -235,7 +235,7 @@ var provideRefDhtCmd = &cmds.Command{
235 return err
236 }
237
238 - if nd.Routing == nil {
238 + if !nd.OnlineMode() {
239 return ErrNotOnline
240 }
241
@@ -364,7 +364,7 @@ var findPeerDhtCmd = &cmds.Command{
364 return err
365 }
366
367 - if nd.Routing == nil {
367 + if !nd.OnlineMode() {
368 return ErrNotOnline
369 }
370
@@ -446,7 +446,7 @@ Different key types can specify other 'best' rules.
446 return err
447 }
448
449 - if nd.Routing == nil {
449 + if !nd.OnlineMode() {
450 return ErrNotOnline
451 }
452
@@ -538,7 +538,7 @@ NOTE: A value may not exceed 2048 bytes.
538 return err
539 }
540
541 - if nd.Routing == nil {
541 + if !nd.OnlineMode() {
542 return ErrNotOnline
543 }
544
test/sharness/t0170-dht.sh
+9
@@ -91,6 +91,15 @@ test_dht() {
91 test_expect_success 'stop iptb' '
92 iptb stop
93 '
94 +
95 + test_expect_success "dht commands fail when offline" '
96 + test_must_fail ipfsi 0 dht findprovs "$HASH" 2>err_findprovs &&
97 + test_must_fail ipfsi 0 dht findpeer "$HASH" 2>err_findpeer &&
98 + test_must_fail ipfsi 0 dht put "$TEST_DHT_PATH" "$TEST_DHT_VALUE" 2>err_put &&
99 + test_should_contain "this command must be run in online mode" err_findprovs &&
100 + test_should_contain "this command must be run in online mode" err_findpeer &&
101 + test_should_contain "this command must be run in online mode" err_put
102 + '
103 }
104
105 test_dht