mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
Merge pull request #7633 from ipfs/fix/dht-cmd-cid-ipns
fix: ipfs dht put/get commands with peerIDs encoded as CIDs
This commit is contained in:
commit
b7d00a0e4e
@ -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