Skip to content

Commit

Permalink
do resolve operations concurrently
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Jan 14, 2016
1 parent 3c6a40a commit 19b2f89
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions namesys/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

key "github.com/ipfs/go-ipfs/blocks/key"
pb "github.com/ipfs/go-ipfs/namesys/pb"
ci "github.com/ipfs/go-ipfs/p2p/crypto"
path "github.com/ipfs/go-ipfs/path"
routing "github.com/ipfs/go-ipfs/routing"
u "github.com/ipfs/go-ipfs/util"
Expand Down Expand Up @@ -123,32 +124,50 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa

hash, err := mh.FromB58String(name)
if err != nil {
// name should be a multihash. if it isn't, error out here.
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
return "", err
}
// name should be a multihash. if it isn't, error out here.

// use the routing system to get the name.
// /ipns/<name>
h := []byte("/ipns/" + string(hash))

ipnsKey := key.Key(h)
val, err := r.routing.GetValue(ctx, ipnsKey)
if err != nil {
log.Warning("RoutingResolve get failed.")
return "", err
}
var entry *pb.IpnsEntry
var pubkey ci.PubKey

entry := new(pb.IpnsEntry)
err = proto.Unmarshal(val, entry)
if err != nil {
return "", err
}
resp := make(chan error, 2)
go func() {
ipnsKey := key.Key(h)
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
pubkey, err := routing.GetPublicKey(r.routing, ctx, hash)
if err != nil {
return "", err
entry = new(pb.IpnsEntry)
err = proto.Unmarshal(val, entry)
if err != nil {
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()
Expand Down

0 comments on commit 19b2f89

Please sign in to comment.