mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
namesys: review fixes
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
94bbeffaa9
commit
7dbeb27e5b
@ -2,7 +2,6 @@ package iface
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"errors"
|
||||
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
@ -7,8 +7,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ipath "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
@ -18,6 +16,7 @@ import (
|
||||
"gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
|
||||
"gx/ipfs/QmQ9PR61a8rwEFuFNs7JMA1QtQC9yZnBwoDn51JWXDbaTd/go-ipfs-routing/offline"
|
||||
"gx/ipfs/QmbNepETomvmXfz1X5pHNFD2QuPqnqi47dTd94QJWSorQ3/go-libp2p-peer"
|
||||
ipath "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
|
||||
)
|
||||
|
||||
type NameAPI CoreAPI
|
||||
|
||||
@ -62,7 +62,7 @@ func (m mockNamesys) ResolveAsync(ctx context.Context, name string, opts ...nsop
|
||||
v, err := m.Resolve(ctx, name, opts...)
|
||||
out <- namesys.Result{Path: v, Err: err}
|
||||
close(out)
|
||||
return nil
|
||||
return out
|
||||
}
|
||||
|
||||
func (m mockNamesys) Publish(ctx context.Context, name ci.PrivKey, value path.Path) error {
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package namesys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
context "context"
|
||||
|
||||
opts "github.com/ipfs/go-ipfs/namesys/opts"
|
||||
|
||||
path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
|
||||
)
|
||||
|
||||
@ -40,13 +40,10 @@ func resolve(ctx context.Context, r resolver, name string, options opts.ResolveO
|
||||
return p, err
|
||||
}
|
||||
|
||||
//TODO:
|
||||
// - better error handling
|
||||
// - select on writes
|
||||
func resolveAsync(ctx context.Context, r resolver, name string, options opts.ResolveOpts, prefix string) <-chan Result {
|
||||
resCh := r.resolveOnceAsync(ctx, name, options)
|
||||
depth := options.Depth
|
||||
outCh := make(chan Result)
|
||||
outCh := make(chan Result, 1)
|
||||
|
||||
go func() {
|
||||
defer close(outCh)
|
||||
@ -97,8 +94,13 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
|
||||
break
|
||||
}
|
||||
|
||||
outCh <- res
|
||||
select {
|
||||
case outCh <- res:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
if resCh == nil && subCh == nil {
|
||||
return
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
opts "github.com/ipfs/go-ipfs/namesys/opts"
|
||||
|
||||
isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain"
|
||||
path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
|
||||
)
|
||||
|
||||
@ -5,9 +5,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
opts "github.com/ipfs/go-ipfs/namesys/opts"
|
||||
path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
|
||||
|
||||
opts "github.com/ipfs/go-ipfs/namesys/opts"
|
||||
|
||||
routing "gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
|
||||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
||||
ci "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
|
||||
@ -138,10 +139,21 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
|
||||
|
||||
// Attach rest of the path
|
||||
if len(segments) > 3 {
|
||||
p, _ = path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3])
|
||||
p, err := path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3])
|
||||
if err != nil {
|
||||
select {
|
||||
case out <- onceResult{value: p, err: err}:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
out <- onceResult{value: p, err: res.err}
|
||||
select {
|
||||
case out <- onceResult{value: p, ttl: res.ttl, err: res.err}:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user