Commit ed450992 authored by Jeromy's avatar Jeromy

tracking down a bug dhthell found, added asserts and better logging.

parent 15d4f829
...@@ -101,7 +101,6 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er ...@@ -101,7 +101,6 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks.Block { func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks.Block {
out := make(chan *blocks.Block, 32) out := make(chan *blocks.Block, 32)
go func() { go func() {
defer close(out)
var toFetch []u.Key var toFetch []u.Key
for _, k := range ks { for _, k := range ks {
block, err := s.Blockstore.Get(k) block, err := s.Blockstore.Get(k)
...@@ -121,6 +120,7 @@ func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks ...@@ -121,6 +120,7 @@ func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks
for blk := range nblocks { for blk := range nblocks {
out <- blk out <- blk
} }
close(out)
}() }()
return out return out
} }
......
...@@ -197,13 +197,19 @@ func (bs *bitswap) loop(parent context.Context) { ...@@ -197,13 +197,19 @@ func (bs *bitswap) loop(parent context.Context) {
} }
} }
case ks := <-bs.batchRequests: case ks := <-bs.batchRequests:
// TODO: implement batching on len(ks) > X for some X
if len(ks) == 0 {
log.Warning("Received batch request for zero blocks")
continue
}
for _, k := range ks { for _, k := range ks {
bs.wantlist.Add(k) bs.wantlist.Add(k)
providers := bs.routing.FindProvidersAsync(ctx, k, maxProvidersPerRequest) }
err := bs.sendWantListTo(ctx, providers) providers := bs.routing.FindProvidersAsync(ctx, ks[0], maxProvidersPerRequest)
if err != nil {
log.Errorf("error sending wantlist: %s", err) err := bs.sendWantListTo(ctx, providers)
} if err != nil {
log.Errorf("error sending wantlist: %s", err)
} }
case <-parent.Done(): case <-parent.Done():
return return
......
...@@ -182,7 +182,7 @@ func (s *Swarm) fanOut() { ...@@ -182,7 +182,7 @@ func (s *Swarm) fanOut() {
return return
} }
if len(msg.Data()) >= conn.MaxMessageSize { if len(msg.Data()) >= conn.MaxMessageSize {
log.Critical("Attempted to send message bigger than max size.") log.Criticalf("Attempted to send message bigger than max size. (%d)", len(msg.Data()))
} }
s.connsLock.RLock() s.connsLock.RLock()
......
...@@ -68,6 +68,7 @@ func (dr *DagReader) precalcNextBuf() error { ...@@ -68,6 +68,7 @@ func (dr *DagReader) precalcNextBuf() error {
// TODO: this logic is hard to follow, do it better. // TODO: this logic is hard to follow, do it better.
// NOTE: the only time this code is used, is during the // NOTE: the only time this code is used, is during the
// importer tests, consider just changing those tests // importer tests, consider just changing those tests
log.Warning("Running DAGReader with nil DAGService!")
if dr.linkPosition >= len(dr.node.Links) { if dr.linkPosition >= len(dr.node.Links) {
return io.EOF return io.EOF
} }
...@@ -78,6 +79,9 @@ func (dr *DagReader) precalcNextBuf() error { ...@@ -78,6 +79,9 @@ func (dr *DagReader) precalcNextBuf() error {
dr.linkPosition++ dr.linkPosition++
} else { } else {
if dr.fetchChan == nil {
panic("this is wrong.")
}
select { select {
case nxt, ok = <-dr.fetchChan: case nxt, ok = <-dr.fetchChan:
if !ok { if !ok {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment