refac(bitswap) less concurrency while testing and iterating
Brian Tiger Chow committed
Sep 19, 2014 at 12:57 UTC
543dfeea35a616204d3798215e5dbb16ab2e87ff
1 file changed
+8
-9
exchange/bitswap/bitswap.go
+8
-9
@@ -79,7 +79,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
79
message := bsmsg.New()
80
message.AppendWanted(k)
81
for i := range peersToQuery {
82
- go func(p *peer.Peer) {
82
+ func(p *peer.Peer) {
83
response, err := bs.sender.SendRequest(ctx, p, message)
84
if err != nil {
85
return
@@ -109,7 +109,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error)
109
// HasBlock announces the existance of a block to bitswap, potentially sending
110
// it to peers (Partners) whose WantLists include it.
111
func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
112
- go bs.sendToPeersThatWant(ctx, blk)
112
+ bs.sendToPeersThatWant(ctx, blk)
113
return bs.routing.Provide(blk.Key())
114
}
115
@@ -128,9 +128,9 @@ func (bs *bitswap) ReceiveMessage(
128
129
if incoming.Blocks() != nil {
130
for _, block := range incoming.Blocks() {
131
- go bs.blockstore.Put(block) // FIXME(brian): err ignored
132
- go bs.notifications.Publish(block)
133
- go bs.HasBlock(ctx, block) // FIXME err ignored
131
+ bs.blockstore.Put(block) // FIXME(brian): err ignored
132
+ bs.notifications.Publish(block)
133
+ bs.HasBlock(ctx, block) // FIXME err ignored
134
}
135
}
136
@@ -139,12 +139,11 @@ func (bs *bitswap) ReceiveMessage(
139
if bs.strategy.ShouldSendBlockToPeer(key, p) {
140
block, errBlockNotFound := bs.blockstore.Get(key)
141
if errBlockNotFound != nil {
142
- // TODO(brian): log/return the error
143
- continue
142
+ return nil, nil, errBlockNotFound
143
}
144
message := bsmsg.New()
145
message.AppendBlock(*block)
147
- go bs.send(ctx, p, message)
146
+ bs.send(ctx, p, message)
147
}
148
}
149
}
@@ -168,7 +167,7 @@ func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block)
167
if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
168
message := bsmsg.New()
169
message.AppendBlock(block)
171
- go bs.send(ctx, p, message)
170
+ bs.send(ctx, p, message)
171
}
172
}
173
}