Skip to content

Commit

Permalink
fix: ipfs dht put/get commands now work on keys encoded as peerIDs an…
Browse files Browse the repository at this point in the history
…d fail early for namespaces other than /pk or /ipns
  • Loading branch information
aschmahmann committed Aug 30, 2020
1 parent c5825c2 commit ba1d225
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
24 changes: 9 additions & 15 deletions core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
path "github.com/ipfs/go-path"
peer "github.com/libp2p/go-libp2p-core/peer"
routing "github.com/libp2p/go-libp2p-core/routing"
b58 "github.com/mr-tron/base58/base58"
)

var ErrNotDHT = errors.New("routing service is not a DHT")
Expand Down Expand Up @@ -676,20 +675,15 @@ func printEvent(obj *routing.QueryEvent, out io.Writer, verbose bool, override p

func escapeDhtKey(s string) (string, error) {
parts := path.SplitList(s)
switch len(parts) {
case 1:
k, err := b58.Decode(s)
if err != nil {
return "", err
}
return string(k), nil
case 3:
k, err := b58.Decode(parts[2])
if err != nil {
return "", err
}
return path.Join(append(parts[:2], string(k))), nil
default:
if len(parts) != 3 ||
parts[0] != "" ||
!(parts[1] == "ipns" || parts[1] == "pk") {
return "", errors.New("invalid key")
}

k, err := peer.Decode(parts[2])
if err != nil {
return "", err
}
return path.Join(append(parts[:2], string(k))), nil
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ require (
github.com/lucas-clemente/quic-go v0.18.0
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multiaddr-dns v0.2.0
github.com/multiformats/go-multibase v0.0.3
Expand Down

0 comments on commit ba1d225

Please sign in to comment.