Skip to content

Commit b4a9681

Browse files
committed
expose DontHaveTimeoutConfig
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
1 parent 24b6bc3 commit b4a9681

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The following emojis are used to highlight certain changes:
1616

1717
### Added
1818

19+
- `bitswap/client`: Add `DontHaveTimeoutConfig` type alias and `func DontHaveTimeoutConfig()` to expose config defined in internal package.
20+
1921
### Changed
2022

2123
- `provider`: Prevent multiple instances of reprovider.Reprovide() from running at the same time. [#834](https://github.com/ipfs/boxo/pull/834)

bitswap/client/bitswap_with_sessions_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,35 @@ func TestWantlistClearsOnCancel(t *testing.T) {
561561
t.Fatal(err)
562562
}
563563
}
564+
565+
func TestDontHaveTimeoutConfig(t *testing.T) {
566+
cfg := client.DefaultDontHaveTimeoutConfig()
567+
if cfg.DontHaveTimeout <= 0 {
568+
t.Fatal("invalid default dont have timeout")
569+
}
570+
571+
vnet := getVirtualNetwork()
572+
router := mockrouting.NewServer()
573+
ig := testinstance.NewTestInstanceGenerator(vnet, router, nil, nil)
574+
defer ig.Close()
575+
576+
a := ig.Next()
577+
578+
// Replace bitswap in instance a with our customized one.
579+
pqm, err := providerquerymanager.New(a.Adapter, router.Client(a.Identity))
580+
if err != nil {
581+
t.Fatal(err)
582+
}
583+
defer pqm.Close()
584+
585+
ctx, cancel := context.WithCancel(context.Background())
586+
defer cancel()
587+
588+
bs := bitswap.New(ctx, a.Adapter, pqm, a.Blockstore,
589+
bitswap.WithClientOption(client.WithDontHaveTimeoutConfig(cfg)))
590+
a.Exchange.Close()
591+
a.Exchange = bs
592+
593+
a.Exchange.Close()
594+
bs.Close()
595+
}

bitswap/client/client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ import (
4040

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

43+
type DontHaveTimeoutConfig = bsmq.DontHaveTimeoutConfig
44+
45+
func DefaultDontHaveTimeoutConfig() *DontHaveTimeoutConfig {
46+
return bsmq.DefaultDontHaveTimeoutConfig()
47+
}
48+
4349
// Option defines the functional option type that can be used to configure
4450
// bitswap instances
4551
type Option func(*Client)
@@ -71,7 +77,7 @@ func SetSimulateDontHavesOnTimeout(send bool) Option {
7177
}
7278
}
7379

74-
func WithDontHaveTimeoutConfig(cfg *bsmq.DontHaveTimeoutConfig) Option {
80+
func WithDontHaveTimeoutConfig(cfg *DontHaveTimeoutConfig) Option {
7581
return func(bs *Client) {
7682
bs.dontHaveTimeoutConfig = cfg
7783
}
@@ -300,7 +306,7 @@ type Client struct {
300306

301307
// whether we should actually simulate dont haves on request timeout
302308
simulateDontHavesOnTimeout bool
303-
dontHaveTimeoutConfig *bsmq.DontHaveTimeoutConfig
309+
dontHaveTimeoutConfig *DontHaveTimeoutConfig
304310

305311
// dupMetric will stay at 0
306312
skipDuplicatedBlocksStats bool

0 commit comments

Comments
 (0)