Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
fix: Nil dereference while using SetSendDontHaves
Browse files Browse the repository at this point in the history
This option is used by the benchmark to simulate the old bitswap
comportement.

This follows the same refactoring idea as done in 47b99b1.

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.
  • Loading branch information
Jorropo committed May 30, 2021
1 parent 0e81f7c commit 2e5e6a8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -201,6 +201,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork,
provSearchDelay: defaultProvSearchDelay,
rebroadcastDelay: delay.Fixed(time.Minute),
engineBstoreWorkerCount: defaulEngineBlockstoreWorkerCount,
engineSetSendDontHaves: true,
}

// apply functional options before starting and running bitswap
Expand All @@ -210,6 +211,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)
Expand Down Expand Up @@ -293,6 +295,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
}

type counters struct {
Expand Down

0 comments on commit 2e5e6a8

Please sign in to comment.