From f2d9b5a50aee63b0897de8aa8d43052663c0a316 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Sun, 30 May 2021 11:16:38 +0200 Subject: [PATCH 1/2] fix: Nil dereference while using SetSendDontHaves This option is used by the benchmark to simulate the old bitswap comportement. This follows the same refactoring idea as done in 47b99b1ce34a. It was crashing since it was trying to access the `sendDontHaves` property of `bs.engine` but `bs.engine` is initialized right after the options are applied, not before. --- bitswap.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bitswap.go b/bitswap.go index ac890437..bc87a006 100644 --- a/bitswap.go +++ b/bitswap.go @@ -107,7 +107,7 @@ func EngineBlockstoreWorkerCount(count int) Option { // This option is only used for testing. func SetSendDontHaves(send bool) Option { return func(bs *Bitswap) { - bs.engine.SetSendDontHaves(send) + bs.engineSetSendDontHaves = send } } @@ -210,6 +210,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, provSearchDelay: defaultProvSearchDelay, rebroadcastDelay: delay.Fixed(time.Minute), engineBstoreWorkerCount: defaulEngineBlockstoreWorkerCount, + engineSetSendDontHaves: true, simulateDontHavesOnTimeout: true, } @@ -220,6 +221,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, // Set up decision engine bs.engine = decision.NewEngine(bstore, bs.engineBstoreWorkerCount, network.ConnectionManager(), network.Self(), bs.engineScoreLedger) + bs.engine.SetSendDontHaves(bs.engineSetSendDontHaves) bs.pqm.Startup() network.SetDelegate(bs) @@ -304,6 +306,11 @@ type Bitswap struct { // the score ledger used by the decision engine engineScoreLedger deciface.ScoreLedger + // indicates what to do when the engine receives a want-block for a block that + // is not in the blockstore. Either send DONT_HAVE or do nothing. + // This is used to simulate with old version of bitswap that were quiets. + engineSetSendDontHaves bool + // whether we should actually simulate dont haves on request timeout simulateDontHavesOnTimeout bool } From 3f031b40cd5c2716fce2759986f1893aa03da4a5 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Wed, 16 Jun 2021 09:04:52 +0200 Subject: [PATCH 2/2] docs: better engineSetSendDontHaves description Co-authored-by: Adin Schmahmann --- bitswap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitswap.go b/bitswap.go index bc87a006..6368095b 100644 --- a/bitswap.go +++ b/bitswap.go @@ -308,7 +308,7 @@ type Bitswap struct { // indicates what to do when the engine receives a want-block for a block that // is not in the blockstore. Either send DONT_HAVE or do nothing. - // This is used to simulate with old version of bitswap that were quiets. + // This is used to simulate older versions of bitswap that did nothing instead of sending back a DONT_HAVE. engineSetSendDontHaves bool // whether we should actually simulate dont haves on request timeout