@cryptotaxi247 / kubo / commits / 15d4f8294

some cleanup, and fix minor bug in dagreader from previous commit

Jeromy committed Nov 21, 2014 at 08:01 UTC 15d4f82945bb8902cea34b4fe987b93de1f4c9ea
3 files changed +18 -14
blockservice/blockservice.go
+3
@@ -95,6 +95,9 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
95 }
96 }
97
98 +// GetBlocks gets a list of blocks asynchronously and returns through
99 +// the returned channel.
100 +// NB: No guarantees are made about order.
101 func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks.Block {
102 out := make(chan *blocks.Block, 32)
103 go func() {
merkledag/merkledag.go
+2 -8
@@ -288,9 +288,8 @@ func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{}
288 }
289
290 // BatchFetch will fill out all of the links of the given Node.
291 -// It returns a channel of indicies, which will be returned in order
292 -// from 0 to len(root.Links) - 1, signalling that the link specified by
293 -// the index has been filled out.
291 +// It returns a channel of nodes, which the caller can receive
292 +// all the child nodes of 'root' on, in proper order.
293 func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
294 sig := make(chan *Node)
295 go func() {
@@ -299,7 +298,6 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
298
299 //
300 next := 0
302 - seen := make(map[int]struct{})
301 //
302
303 for _, lnk := range root.Links {
@@ -314,10 +312,6 @@ func (ds *dagService) BatchFetch(ctx context.Context, root *Node) <-chan *Node {
312 continue
313 }
314
317 - //
318 - seen[i] = struct{}{}
319 - //
320 -
315 nd, err := Decoded(blk.Data)
316 if err != nil {
317 log.Error("Got back bad block!")
unixfs/io/dagreader.go
+13 -6
@@ -61,12 +61,8 @@ func NewDagReader(n *mdag.Node, serv mdag.DAGService) (io.Reader, error) {
61 func (dr *DagReader) precalcNextBuf() error {
62 var nxt *mdag.Node
63 var ok bool
64 - select {
65 - case nxt, ok = <-dr.fetchChan:
66 - if !ok {
67 - return io.EOF
68 - }
69 - default:
64 +
65 + if dr.serv == nil {
66 // Only used when fetchChan is nil,
67 // which only happens when passed in a nil dagservice
68 // TODO: this logic is hard to follow, do it better.
@@ -76,7 +72,18 @@ func (dr *DagReader) precalcNextBuf() error {
72 return io.EOF
73 }
74 nxt = dr.node.Links[dr.linkPosition].Node
75 + if nxt == nil {
76 + return errors.New("Got nil node back from link! and no DAGService!")
77 + }
78 dr.linkPosition++
79 +
80 + } else {
81 + select {
82 + case nxt, ok = <-dr.fetchChan:
83 + if !ok {
84 + return io.EOF
85 + }
86 + }
87 }
88
89 pb := new(ftpb.Data)