diff --git a/cmd/booster-bitswap/filters/filters.go b/cmd/booster-bitswap/filters/filters.go index f4bfaf7b9..22057ae1b 100644 --- a/cmd/booster-bitswap/filters/filters.go +++ b/cmd/booster-bitswap/filters/filters.go @@ -93,20 +93,20 @@ func (f *filter) update() error { } type MultiFilter struct { - cfgDir string - filters []*filter - clock clock.Clock - onTimerSet func() - ctx context.Context - cancel context.CancelFunc + cfgDir string + filters []*filter + clock clock.Clock + onTick func() + ctx context.Context + cancel context.CancelFunc } -func newMultiFilter(cfgDir string, filters []*filter, clock clock.Clock, onTimerSet func()) *MultiFilter { +func newMultiFilter(cfgDir string, filters []*filter, clock clock.Clock, onTick func()) *MultiFilter { return &MultiFilter{ - cfgDir: cfgDir, - filters: filters, - clock: clock, - onTimerSet: onTimerSet, + cfgDir: cfgDir, + filters: filters, + clock: clock, + onTick: onTick, } } @@ -189,10 +189,10 @@ func (mf *MultiFilter) run(cachedCopies []bool) { } } updater := mf.clock.Ticker(UpdateInterval) - defer updater.Stop() + defer updater.Stop() // call the callback if set - if mf.onTimerSet != nil { - mf.onTimerSet() + if mf.onTick != nil { + mf.onTick() } for { select { @@ -207,8 +207,8 @@ func (mf *MultiFilter) run(cachedCopies []bool) { } } // call the callback if set - if mf.onTimerSet != nil { - mf.onTimerSet() + if mf.onTick != nil { + mf.onTick() } } } diff --git a/cmd/booster-bitswap/filters/filters_test.go b/cmd/booster-bitswap/filters/filters_test.go index 8f0acb04e..04d9f4d6a 100644 --- a/cmd/booster-bitswap/filters/filters_test.go +++ b/cmd/booster-bitswap/filters/filters_test.go @@ -30,9 +30,9 @@ func TestMultiFilter(t *testing.T) { require.NoError(t, err) notBlockedCid, err := cid.Parse("QmajLDwZLH6bKTzd8jkq913ZbxaB2nFGRrkDAuygYNNv39") require.NoError(t, err) - timerSetChan := make(chan struct{}, 1) - onTimerSet := func() { - timerSetChan <- struct{}{} + tickChan := make(chan struct{}, 1) + onTick := func() { + tickChan <- struct{}{} } fbf := &fakeBlockFetcher{} fpf := &fakePeerFetcher{} @@ -52,7 +52,7 @@ func TestMultiFilter(t *testing.T) { fetcher: fpf.fetchList, handler: NewPeerFilter(), }, - }, clock, onTimerSet) + }, clock, onTick) err = mf.Start(ctx) require.NoError(t, err) cache, err := os.ReadFile(filepath.Join(cfgDir, "denylist.json")) @@ -88,13 +88,13 @@ func TestMultiFilter(t *testing.T) { select { case <-ctx.Done(): t.Fatal("should have updated list but didn't") - case <-timerSetChan: + case <-tickChan: } clock.Add(UpdateInterval) select { case <-ctx.Done(): t.Fatal("should have updated list but didn't") - case <-timerSetChan: + case <-tickChan: } // blockedCid1 is blocked, do not fulfill fulfillRequest, err = mf.FulfillRequest(peer1, blockedCid1) @@ -116,7 +116,7 @@ func TestMultiFilter(t *testing.T) { select { case <-ctx.Done(): t.Fatal("should have updated list but didn't") - case <-timerSetChan: + case <-tickChan: } // blockedCid1 is blocked, do not fulfill fulfillRequest, err = mf.FulfillRequest(peer3, blockedCid1) @@ -170,7 +170,7 @@ func TestMultiFilter(t *testing.T) { fetcher: fpf.fetchList, handler: NewPeerFilter(), }, - }, clock, onTimerSet) + }, clock, onTick) err = mf.Start(ctx) require.NoError(t, err) // blockedCid1 is blocked, do not fulfill