mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
Merge pull request #2197 from ipfs/feat/faster-resolve
do resolve operations concurrently
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
key "github.com/ipfs/go-ipfs/blocks/key"
|
key "github.com/ipfs/go-ipfs/blocks/key"
|
||||||
pb "github.com/ipfs/go-ipfs/namesys/pb"
|
pb "github.com/ipfs/go-ipfs/namesys/pb"
|
||||||
|
ci "github.com/ipfs/go-ipfs/p2p/crypto"
|
||||||
path "github.com/ipfs/go-ipfs/path"
|
path "github.com/ipfs/go-ipfs/path"
|
||||||
routing "github.com/ipfs/go-ipfs/routing"
|
routing "github.com/ipfs/go-ipfs/routing"
|
||||||
u "github.com/ipfs/go-ipfs/util"
|
u "github.com/ipfs/go-ipfs/util"
|
||||||
@ -123,32 +124,50 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
|
|||||||
|
|
||||||
hash, err := mh.FromB58String(name)
|
hash, err := mh.FromB58String(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// name should be a multihash. if it isn't, error out here.
|
||||||
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
|
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// name should be a multihash. if it isn't, error out here.
|
|
||||||
|
|
||||||
// use the routing system to get the name.
|
// use the routing system to get the name.
|
||||||
// /ipns/<name>
|
// /ipns/<name>
|
||||||
h := []byte("/ipns/" + string(hash))
|
h := []byte("/ipns/" + string(hash))
|
||||||
|
|
||||||
ipnsKey := key.Key(h)
|
var entry *pb.IpnsEntry
|
||||||
val, err := r.routing.GetValue(ctx, ipnsKey)
|
var pubkey ci.PubKey
|
||||||
if err != nil {
|
|
||||||
log.Warning("RoutingResolve get failed.")
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
entry := new(pb.IpnsEntry)
|
resp := make(chan error, 2)
|
||||||
err = proto.Unmarshal(val, entry)
|
go func() {
|
||||||
if err != nil {
|
ipnsKey := key.Key(h)
|
||||||
return "", err
|
val, err := r.routing.GetValue(ctx, ipnsKey)
|
||||||
}
|
if err != nil {
|
||||||
|
log.Warning("RoutingResolve get failed.")
|
||||||
|
resp <- err
|
||||||
|
}
|
||||||
|
|
||||||
// name should be a public key retrievable from ipfs
|
entry = new(pb.IpnsEntry)
|
||||||
pubkey, err := routing.GetPublicKey(r.routing, ctx, hash)
|
err = proto.Unmarshal(val, entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
resp <- err
|
||||||
|
}
|
||||||
|
resp <- nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// name should be a public key retrievable from ipfs
|
||||||
|
pubk, err := routing.GetPublicKey(r.routing, ctx, hash)
|
||||||
|
if err != nil {
|
||||||
|
resp <- err
|
||||||
|
}
|
||||||
|
pubkey = pubk
|
||||||
|
resp <- nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
err = <-resp
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hsh, _ := pubkey.Hash()
|
hsh, _ := pubkey.Hash()
|
||||||
|
Reference in New Issue
Block a user