From 65c66fd09b75d13f3b663db0fd2420e152ea6869 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 14 Feb 2016 23:58:45 -0800 Subject: [PATCH 1/3] fix dht command key escaping License: MIT Signed-off-by: Jeromy --- core/commands/dht.go | 4 +++- namesys/publisher.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/commands/dht.go b/core/commands/dht.go index 8c77b0235..0a14d7a8a 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -354,6 +354,8 @@ GetValue will return the value stored in the DHT at the given key. return } + log.Error("RESOLVE KEY: ", []byte(dhtkey)) + go func() { defer close(outChan) for e := range events { @@ -573,7 +575,7 @@ func escapeDhtKey(s string) (key.Key, error) { return key.B58KeyDecode(s), nil case 3: k := key.B58KeyDecode(parts[2]) - return key.Key(path.Join(append(parts[:2], k.String()))), nil + return key.Key(path.Join(append(parts[:2], string(k)))), nil default: return "", errors.New("invalid key") } diff --git a/namesys/publisher.go b/namesys/publisher.go index 6b5433561..ba7353f6a 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -141,6 +141,7 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn return err } + log.Error("KEY: ", []byte(namekey)) ttl, ok := checkCtxTTL(ctx) if ok { entry.Ttl = proto.Uint64(uint64(ttl.Nanoseconds())) From c5b2e09708921721e2a5fb6ba753b1b220667098 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 15 Feb 2016 00:00:09 -0800 Subject: [PATCH 2/3] test for the dht key escaping License: MIT Signed-off-by: Jeromy --- core/commands/dht_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 core/commands/dht_test.go diff --git a/core/commands/dht_test.go b/core/commands/dht_test.go new file mode 100644 index 000000000..bf75aff98 --- /dev/null +++ b/core/commands/dht_test.go @@ -0,0 +1,31 @@ +package commands + +import ( + "testing" + + "github.com/ipfs/go-ipfs/namesys" + tu "github.com/ipfs/go-ipfs/thirdparty/testutil" +) + +func TestKeyTranslation(t *testing.T) { + pid := tu.RandPeerIDFatal(t) + a, b := namesys.IpnsKeysForID(pid) + + pkk, err := escapeDhtKey("/pk/" + pid.Pretty()) + if err != nil { + t.Fatal(err) + } + + ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty()) + if err != nil { + t.Fatal(err) + } + + if pkk != a { + t.Fatal("keys didnt match!") + } + + if ipnsk != b { + t.Fatal("keys didnt match!") + } +} From 00e4472dff9e7223095e00944d8e0167b57f3261 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 15 Feb 2016 00:49:06 -0800 Subject: [PATCH 3/3] Remove debug log License: MIT Signed-off-by: Jeromy --- core/commands/dht.go | 2 -- namesys/publisher.go | 1 - 2 files changed, 3 deletions(-) diff --git a/core/commands/dht.go b/core/commands/dht.go index 0a14d7a8a..4319b15da 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -354,8 +354,6 @@ GetValue will return the value stored in the DHT at the given key. return } - log.Error("RESOLVE KEY: ", []byte(dhtkey)) - go func() { defer close(outChan) for e := range events { diff --git a/namesys/publisher.go b/namesys/publisher.go index ba7353f6a..6b5433561 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -141,7 +141,6 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn return err } - log.Error("KEY: ", []byte(namekey)) ttl, ok := checkCtxTTL(ctx) if ok { entry.Ttl = proto.Uint64(uint64(ttl.Nanoseconds()))