diff --git a/CHANGELOG.md b/CHANGELOG.md index b3a32c852..c68aeccdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,10 +16,11 @@ The following emojis are used to highlight certain changes: ### Added -- `bitswap/client/messagequeue`: Expose `DontHaveTimeoutConfig` to hold configuration values for dontHaveTimeoutMgr - - Provide function DefaultDontHaveTimeoutConfig to return a DontHaveTimeoutConfig populated with default values - - Bitswap client New has new option for caller to supply a DontHaveTimeoutConfig - - If the required onHaveTimeout function is nil, then disable the dontaHaveTimeoutMgr +- `bitswap/client`: Improved timeout configuration for block requests + - Exposed `DontHaveTimeoutConfig` to hold configuration values for `dontHaveTimeoutMgr` which controls how long to wait for requested block, and if timeout should emit a synthetic DontHave response + - Added `DefaultDontHaveTimeoutConfig()` to return a `DontHaveTimeoutConfig` populated with default values + - Added optional `WithDontHaveTimeoutConfig` to allow passing a custom `DontHaveTimeoutConfig` + - If `DontHaveTimeoutConfig.onDontHaveTimeout` is `nil`, then `dontaHaveTimeoutMgr` is disabled and synthetic DontHave won't be emitted on timeout ### Changed diff --git a/bitswap/client/internal/messagequeue/donthavetimeoutmgr.go b/bitswap/client/internal/messagequeue/donthavetimeoutmgr.go index f2e1d2c4c..deeaeb81c 100644 --- a/bitswap/client/internal/messagequeue/donthavetimeoutmgr.go +++ b/bitswap/client/internal/messagequeue/donthavetimeoutmgr.go @@ -12,24 +12,31 @@ import ( ) type DontHaveTimeoutConfig struct { + // OnDontHaveTimeout is the function called when DontHaveTimeout hits. OnDontHaveTimeout func([]cid.Cid) + // DontHaveTimeout is used to simulate a DONT_HAVE when communicating with // a peer whose Bitswap client doesn't support the DONT_HAVE response, // or when the peer takes too long to respond. // If the peer doesn't respond to a want-block within the timeout, the // local node assumes that the peer doesn't have the block. DontHaveTimeout time.Duration + // MaxExpectedWantProcessTime is the maximum amount of time we expect a // peer takes to process a want and initiate sending a response to us MaxExpectedWantProcessTime time.Duration - // maxTimeout is the maximum allowed timeout, regardless of latency + + // MaxTimeout is the maximum allowed timeout, regardless of latency MaxTimeout time.Duration + // PingLatencyMultiplier is multiplied by the average ping time to // get an upper bound on how long we expect to wait for a peer's response // to arrive PingLatencyMultiplier int + // MessageLatencyAlpha is the alpha supplied to the message latency EWMA MessageLatencyAlpha float64 + // MessageLatencyMultiplier gives a margin for error. The timeout is calculated as // MessageLatencyMultiplier * message latency MessageLatencyMultiplier int @@ -37,6 +44,7 @@ type DontHaveTimeoutConfig struct { // timeoutsSignal used for testing -- caller-provided channel to signals // when a dont have timeout was triggered. timeoutsSignal chan<- struct{} + // clock is a mockable time api used for testing. clock clock.Clock }