mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-11 03:09:41 +08:00
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 ba1d225212)
This commit is contained in:
parent
901c58b991
commit
255d7f41cc
@ -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")
|
||||
@ -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
go.mod
1
go.mod
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user