mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-11 19:27:51 +08:00
some cleanup, and fix minor bug in dagreader from previous commit
This commit is contained in:
parent
d53deebada
commit
15d4f82945
@ -95,6 +95,9 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
|
||||
}
|
||||
}
|
||||
|
||||
// GetBlocks gets a list of blocks asynchronously and returns through
|
||||
// the returned channel.
|
||||
// NB: No guarantees are made about order.
|
||||
func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks.Block {
|
||||
out := make(chan *blocks.Block, 32)
|
||||
go func() {
|
||||
|
||||
@ -288,9 +288,8 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
|
||||
}
|
||||
|
||||
// BatchFetch will fill out all of the links of the given Node.
|
||||
// It returns a channel of indicies, which will be returned in order
|
||||
// from 0 to len(root.Links) - 1, signalling that the link specified by
|
||||
// the index has been filled out.
|
||||
// It returns a channel of nodes, which the caller can receive
|
||||
// all the child nodes of 'root' on, in proper order.
|
||||
func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
|
||||
sig := make(chan *Node)
|
||||
go func() {
|
||||
@ -299,7 +298,6 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
|
||||
|
||||
//
|
||||
next := 0
|
||||
seen := make(map[int]struct{})
|
||||
//
|
||||
|
||||
for _, lnk := range root.Links {
|
||||
@ -314,10 +312,6 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
|
||||
continue
|
||||
}
|
||||
|
||||
//
|
||||
seen[i] = struct{}{}
|
||||
//
|
||||
|
||||
nd, err := Decoded(blk.Data)
|
||||
if err != nil {
|
||||
log.Error("Got back bad block!")
|
||||
|
||||
@ -61,12 +61,8 @@ func NewDagReader(n *mdag.Node, serv mdag.DAGService) (io.Reader, error) {
|
||||
func (dr *DagReader) precalcNextBuf() error {
|
||||
var nxt *mdag.Node
|
||||
var ok bool
|
||||
select {
|
||||
case nxt, ok = <-dr.fetchChan:
|
||||
if !ok {
|
||||
return io.EOF
|
||||
}
|
||||
default:
|
||||
|
||||
if dr.serv == nil {
|
||||
// Only used when fetchChan is nil,
|
||||
// which only happens when passed in a nil dagservice
|
||||
// TODO: this logic is hard to follow, do it better.
|
||||
@ -76,7 +72,18 @@ func (dr *DagReader) precalcNextBuf() error {
|
||||
return io.EOF
|
||||
}
|
||||
nxt = dr.node.Links[dr.linkPosition].Node
|
||||
if nxt == nil {
|
||||
return errors.New("Got nil node back from link! and no DAGService!")
|
||||
}
|
||||
dr.linkPosition++
|
||||
|
||||
} else {
|
||||
select {
|
||||
case nxt, ok = <-dr.fetchChan:
|
||||
if !ok {
|
||||
return io.EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pb := new(ftpb.Data)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user