Skip to content

Commit

Permalink
refactor(filters): rename onTimerSet -> onTick
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed Dec 2, 2022
1 parent 3ab025d commit 044ddd7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
32 changes: 16 additions & 16 deletions cmd/booster-bitswap/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/booster-bitswap/filters/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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"))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 044ddd7

Please sign in to comment.