From cac6b376c3c30cbd2ab7fb84a393400ae3a7a71c Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 18 Oct 2015 10:14:30 -0700 Subject: [PATCH 1/2] allow ipfs id to work on self License: MIT Signed-off-by: Jeromy --- core/commands/id.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/commands/id.go b/core/commands/id.go index 407eea138..ad76e027a 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -62,7 +62,18 @@ ipfs id supports the format option for output with the following keys: return } - if len(req.Arguments()) == 0 { + var id peer.ID + if len(req.Arguments()) > 0 { + id = peer.ID(b58.Decode(req.Arguments()[0])) + if len(id) == 0 { + res.SetError(cmds.ClientError("Invalid peer id"), cmds.ErrClient) + return + } + } else { + id = node.Identity + } + + if id == node.Identity { output, err := printSelf(node) if err != nil { res.SetError(err, cmds.ErrNormal) @@ -72,14 +83,6 @@ ipfs id supports the format option for output with the following keys: return } - pid := req.Arguments()[0] - - id := peer.ID(b58.Decode(pid)) - if len(id) == 0 { - res.SetError(cmds.ClientError("Invalid peer id"), cmds.ErrClient) - return - } - // TODO handle offline mode with polymorphism instead of conditionals if !node.OnlineMode() { res.SetError(errors.New(offlineIdErrorMessage), cmds.ErrClient) From 71288160b18abaddad1eed2729568d206fba8803 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 19 Oct 2015 22:07:39 -0700 Subject: [PATCH 2/2] add small test to ensure ipfs id works License: MIT Signed-off-by: Jeromy --- test/sharness/t0140-swarm.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/sharness/t0140-swarm.sh b/test/sharness/t0140-swarm.sh index 229ba1676..0fd548984 100755 --- a/test/sharness/t0140-swarm.sh +++ b/test/sharness/t0140-swarm.sh @@ -28,6 +28,16 @@ test_expect_success 'disconnected: addrs local matches ipfs id' ' test_cmp expected actual ' +test_expect_success "ipfs id self works" ' + myid=$(ipfs id -f="") && + ipfs id --timeout=1s $myid > output +' + +test_expect_success "output looks good" ' + grep $myid output && + grep PublicKey output +' + test_kill_ipfs_daemon test_done