@cryptotaxi247 / kubo / commits / 255d7f41c

fix: ipfs dht put/get commands now work on keys encoded as peerIDs and fail early for namespaces other than /pk or /ipns

(cherry picked from commit ba1d2252125826939d33c3d254d67ff18c46918b)

Adin Schmahmann committed Aug 30, 2020 at 02:16 UTC 255d7f41cc7d3f9f214b8fac1f6852da43f5aec1
2 files changed +9 -16
core/commands/dht.go
+9 -15
@@ -18,7 +18,6 @@ import (
18 path "github.com/ipfs/go-path"
19 peer "github.com/libp2p/go-libp2p-core/peer"
20 routing "github.com/libp2p/go-libp2p-core/routing"
21 - b58 "github.com/mr-tron/base58/base58"
21 )
22
23 var ErrNotDHT = errors.New("routing service is not a DHT")
@@ -676,20 +675,15 @@ func printEvent(obj *routing.QueryEvent, out io.Writer, verbose bool, override p
675
676 func escapeDhtKey(s string) (string, error) {
677 parts := path.SplitList(s)
679 - switch len(parts) {
680 - case 1:
681 - k, err := b58.Decode(s)
682 - if err != nil {
683 - return "", err
684 - }
685 - return string(k), nil
686 - case 3:
687 - k, err := b58.Decode(parts[2])
688 - if err != nil {
689 - return "", err
690 - }
691 - return path.Join(append(parts[:2], string(k))), nil
692 - default:
678 + if len(parts) != 3 ||
679 + parts[0] != "" ||
680 + !(parts[1] == "ipns" || parts[1] == "pk") {
681 return "", errors.New("invalid key")
682 }
683 +
684 + k, err := peer.Decode(parts[2])
685 + if err != nil {
686 + return "", err
687 + }
688 + return path.Join(append(parts[:2], string(k))), nil
689 }
go.mod
-1
@@ -88,7 +88,6 @@ require (
88 github.com/lucas-clemente/quic-go v0.18.0
89 github.com/mattn/go-runewidth v0.0.9 // indirect
90 github.com/mitchellh/go-homedir v1.1.0
91 - github.com/mr-tron/base58 v1.2.0
91 github.com/multiformats/go-multiaddr v0.3.1
92 github.com/multiformats/go-multiaddr-dns v0.2.0
93 github.com/multiformats/go-multibase v0.0.3