remove some redundant blockputs to avoid false duplicate block receives
Jeromy committed
Apr 29, 2015 at 19:59 UTC
f998339acb8a5a74eac708576d66fcd062804a0d
2 files changed
+10
-5
exchange/bitswap/bitswap.go
+9
@@ -219,6 +219,15 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
219
return errors.New("bitswap is closed")
220
default:
221
}
222
+ has, err := bs.blockstore.Has(blk.Key())
223
+ if err != nil {
224
+ return err
225
+ }
226
+
227
+ if has {
228
+ log.Error(bs.self, "Dup Block! ", blk.Key())
229
+ }
230
+
231
if err := bs.blockstore.Put(blk); err != nil {
232
return err
233
}
exchange/bitswap/bitswap_test.go
+1
-5
@@ -69,9 +69,6 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
69
hasBlock := g.Next()
70
defer hasBlock.Exchange.Close()
71
72
- if err := hasBlock.Blockstore().Put(block); err != nil {
73
- t.Fatal(err)
74
- }
72
if err := hasBlock.Exchange.HasBlock(context.Background(), block); err != nil {
73
t.Fatal(err)
74
}
@@ -136,7 +133,6 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
133
var blkeys []u.Key
134
first := instances[0]
135
for _, b := range blocks {
139
- first.Blockstore().Put(b) // TODO remove. don't need to do this. bitswap owns block
136
blkeys = append(blkeys, b.Key())
137
first.Exchange.HasBlock(context.Background(), b)
138
}
@@ -144,7 +140,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
140
t.Log("Distribute!")
141
142
wg := sync.WaitGroup{}
147
- for _, inst := range instances {
143
+ for _, inst := range instances[1:] {
144
wg.Add(1)
145
go func(inst Instance) {
146
defer wg.Done()