Skip to content

Commit

Permalink
namesys: use routing.SearchValue
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
  • Loading branch information
magik6k committed Sep 24, 2018
1 parent fc59660 commit f030357
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
19 changes: 10 additions & 9 deletions core/commands/name/ipns.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,17 @@ Resolve the value of a dnslink:
}

return cmds.EmitOnce(res, &ResolvedPath{output})
} else {
output := resolver.ResolveAsync(req.Context, name, ropts...)
for v := range output {
if v.Err != nil {
return err
}
if err := res.Emit(&ResolvedPath{v.Path}); err != nil {
return err
}
}

output := resolver.ResolveAsync(req.Context, name, ropts...)
for v := range output {
if v.Err != nil {
return err
}
if err := res.Emit(&ResolvedPath{v.Path}); err != nil {
return err
}

}
return nil
},
Expand Down
14 changes: 1 addition & 13 deletions namesys/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
routing "gx/ipfs/QmVBnJDKhtFXTRVjXKinqpwGu8t1DyNqPKan2iGX8PR8xG/go-libp2p-routing"
ropts "gx/ipfs/QmVBnJDKhtFXTRVjXKinqpwGu8t1DyNqPKan2iGX8PR8xG/go-libp2p-routing/options"
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
dht "gx/ipfs/QmZVakpN44VAUxs9eXAuUGLFYTCGmSyqSy6hyEKfMv68ME/go-libp2p-kad-dht"
ipns "gx/ipfs/QmZrmn2BPZbSviQAWeyY2iXkCukmJHv9n7zrLgWU5KgbTb/go-ipns"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (r *IpnsResolver) resolveOnceAsync(ctx context.Context, name string, option
// the value, which in turn verifies the ipns record signature
ipnsKey := ipns.RecordKey(pid)

vals, err := r.searchValue(ctx, ipnsKey, dht.Quorum(int(options.DhtRecordCount)))
vals, err := r.routing.SearchValue(ctx, ipnsKey, dht.Quorum(int(options.DhtRecordCount)))
if err != nil {
log.Debugf("RoutingResolver: dht get for name %s failed: %s", name, err)
out <- onceResult{err: err}
Expand Down Expand Up @@ -173,14 +172,3 @@ func (r *IpnsResolver) resolveOnceAsync(ctx context.Context, name string, option

return out
}

func (r *IpnsResolver) searchValue(ctx context.Context, key string, opts ...ropts.Option) (<-chan []byte, error) {
if ir, ok := r.routing.(*dht.IpfsDHT); ok {
return ir.SearchValue(ctx, key, opts...)
}
out := make(chan []byte, 1)
val, err := r.routing.GetValue(ctx, key, opts...)
out <- val
close(out)
return out, err
}

0 comments on commit f030357

Please sign in to comment.