@cryptotaxi247 / kubo / commits / 19b2f893f

do resolve operations concurrently

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jan 13, 2016 at 11:03 UTC 19b2f893f49663e956f2f89d6469124b75a42e81
1 file changed +35 -16
namesys/routing.go
+35 -16
@@ -11,6 +11,7 @@ import (
11
12 key "github.com/ipfs/go-ipfs/blocks/key"
13 pb "github.com/ipfs/go-ipfs/namesys/pb"
14 + ci "github.com/ipfs/go-ipfs/p2p/crypto"
15 path "github.com/ipfs/go-ipfs/path"
16 routing "github.com/ipfs/go-ipfs/routing"
17 u "github.com/ipfs/go-ipfs/util"
@@ -123,32 +124,50 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
124
125 hash, err := mh.FromB58String(name)
126 if err != nil {
127 + // name should be a multihash. if it isn't, error out here.
128 log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
129 return "", err
130 }
129 - // name should be a multihash. if it isn't, error out here.
131
132 // use the routing system to get the name.
133 // /ipns/<name>
134 h := []byte("/ipns/" + string(hash))
135
135 - ipnsKey := key.Key(h)
136 - val, err := r.routing.GetValue(ctx, ipnsKey)
137 - if err != nil {
138 - log.Warning("RoutingResolve get failed.")
139 - return "", err
140 - }
136 + var entry *pb.IpnsEntry
137 + var pubkey ci.PubKey
138
142 - entry := new(pb.IpnsEntry)
143 - err = proto.Unmarshal(val, entry)
144 - if err != nil {
145 - return "", err
146 - }
139 + resp := make(chan error, 2)
140 + go func() {
141 + ipnsKey := key.Key(h)
142 + val, err := r.routing.GetValue(ctx, ipnsKey)
143 + if err != nil {
144 + log.Warning("RoutingResolve get failed.")
145 + resp <- err
146 + }
147
148 - // name should be a public key retrievable from ipfs
149 - pubkey, err := routing.GetPublicKey(r.routing, ctx, hash)
150 - if err != nil {
151 - return "", err
148 + entry = new(pb.IpnsEntry)
149 + err = proto.Unmarshal(val, entry)
150 + if err != nil {
151 + resp <- err
152 + }
153 + resp <- nil
154 + }()
155 +
156 + go func() {
157 + // name should be a public key retrievable from ipfs
158 + pubk, err := routing.GetPublicKey(r.routing, ctx, hash)
159 + if err != nil {
160 + resp <- err
161 + }
162 + pubkey = pubk
163 + resp <- nil
164 + }()
165 +
166 + for i := 0; i < 2; i++ {
167 + err = <-resp
168 + if err != nil {
169 + return "", err
170 + }
171 }
172
173 hsh, _ := pubkey.Hash()