Skip to content

Commit

Permalink
fixes to routing put command (#10205)
Browse files Browse the repository at this point in the history
* fix(commands): routing put command returns the IPNS ID rather than the host's ID

* fix(commands): routing put command errors with the allow-offline hint if the error is an offline error

* fix: test expects correct error message

---------

Co-authored-by: Henrique Dias <[email protected]>
  • Loading branch information
aschmahmann and hacdias authored Nov 8, 2023
1 parent 068f176 commit 9371d18
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions core/commands/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
iface "github.com/ipfs/boxo/coreiface"
"github.com/ipfs/boxo/coreiface/options"
dag "github.com/ipfs/boxo/ipld/merkledag"
"github.com/ipfs/boxo/ipns"
cid "github.com/ipfs/go-cid"
cmds "github.com/ipfs/go-ipfs-cmds"
ipld "github.com/ipfs/go-ipld-format"
Expand Down Expand Up @@ -451,12 +452,12 @@ identified by QmFoo.
options.Put.AllowOffline(allowOffline),
}

err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
ipnsName, err := ipns.NameFromString(req.Arguments[0])
if err != nil {
return err
}

id, err := api.Key().Self(req.Context)
err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
if err != nil {
if err == iface.ErrOffline {
err = errAllowOffline
Expand All @@ -466,7 +467,7 @@ identified by QmFoo.

return res.Emit(routing.QueryEvent{
Type: routing.Value,
ID: id.ID(),
ID: ipnsName.Peer(),
})
},
Encoders: cmds.EncoderMap{
Expand Down
2 changes: 1 addition & 1 deletion test/cli/dht_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestLegacyDHT(t *testing.T) {
node.WriteBytes("foo", []byte("foo"))
res := node.RunIPFS("dht", "put", "/ipns/"+node.PeerID().String(), "foo")
assert.Equal(t, 1, res.ExitCode())
assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
})
})
}
2 changes: 1 addition & 1 deletion test/cli/routing_dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func testRoutingDHT(t *testing.T, enablePubsub bool) {
node.WriteBytes("foo", []byte("foo"))
res := node.RunIPFS("routing", "put", "/ipns/"+node.PeerID().String(), "foo")
assert.Equal(t, 1, res.ExitCode())
assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
})
})
})
Expand Down

0 comments on commit 9371d18

Please sign in to comment.