Skip to content

Commit

Permalink
expose DontHaveTimeoutConfig
Browse files Browse the repository at this point in the history
This was missed in an earlier PR, and the config needs to be exposed using a type alias as the type is defined in an internal package.

- Add `DontHaveConfigConfig` type alias in bitswap client
- Add `DefaultDontHaveConfigConfig` function to get struct populated with default values.

Closes #842
  • Loading branch information
gammazero committed Feb 15, 2025
1 parent 24b6bc3 commit b4a9681
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The following emojis are used to highlight certain changes:

### Added

- `bitswap/client`: Add `DontHaveTimeoutConfig` type alias and `func DontHaveTimeoutConfig()` to expose config defined in internal package.

### Changed

- `provider`: Prevent multiple instances of reprovider.Reprovide() from running at the same time. [#834](https://github.com/ipfs/boxo/pull/834)
Expand Down
32 changes: 32 additions & 0 deletions bitswap/client/bitswap_with_sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,35 @@ func TestWantlistClearsOnCancel(t *testing.T) {
t.Fatal(err)
}
}

func TestDontHaveTimeoutConfig(t *testing.T) {
cfg := client.DefaultDontHaveTimeoutConfig()
if cfg.DontHaveTimeout <= 0 {
t.Fatal("invalid default dont have timeout")
}

vnet := getVirtualNetwork()
router := mockrouting.NewServer()
ig := testinstance.NewTestInstanceGenerator(vnet, router, nil, nil)
defer ig.Close()

a := ig.Next()

// Replace bitswap in instance a with our customized one.
pqm, err := providerquerymanager.New(a.Adapter, router.Client(a.Identity))
if err != nil {
t.Fatal(err)
}
defer pqm.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

bs := bitswap.New(ctx, a.Adapter, pqm, a.Blockstore,
bitswap.WithClientOption(client.WithDontHaveTimeoutConfig(cfg)))
a.Exchange.Close()
a.Exchange = bs

a.Exchange.Close()
bs.Close()
}
10 changes: 8 additions & 2 deletions bitswap/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ import (

var log = logging.Logger("bitswap/client")

type DontHaveTimeoutConfig = bsmq.DontHaveTimeoutConfig

func DefaultDontHaveTimeoutConfig() *DontHaveTimeoutConfig {
return bsmq.DefaultDontHaveTimeoutConfig()
}

// Option defines the functional option type that can be used to configure
// bitswap instances
type Option func(*Client)
Expand Down Expand Up @@ -71,7 +77,7 @@ func SetSimulateDontHavesOnTimeout(send bool) Option {
}
}

func WithDontHaveTimeoutConfig(cfg *bsmq.DontHaveTimeoutConfig) Option {
func WithDontHaveTimeoutConfig(cfg *DontHaveTimeoutConfig) Option {
return func(bs *Client) {
bs.dontHaveTimeoutConfig = cfg
}
Expand Down Expand Up @@ -300,7 +306,7 @@ type Client struct {

// whether we should actually simulate dont haves on request timeout
simulateDontHavesOnTimeout bool
dontHaveTimeoutConfig *bsmq.DontHaveTimeoutConfig
dontHaveTimeoutConfig *DontHaveTimeoutConfig

// dupMetric will stay at 0
skipDuplicatedBlocksStats bool
Expand Down

0 comments on commit b4a9681

Please sign in to comment.