Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Add type aliases for TaskInfo and TaskComparator
Browse files Browse the repository at this point in the history
  • Loading branch information
synzhu committed Oct 27, 2021
1 parent 1a344b1 commit b124653
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ func SetSimulateDontHavesOnTimeout(send bool) Option {
}
}

type TaskInfo = decision.TaskInfo
type TaskComparator = decision.TaskComparator

// WithTaskComparator configures custom task prioritization logic.
func WithTaskComparator(comparator decision.TaskComparator) Option {
func WithTaskComparator(comparator TaskComparator) Option {
return func(bs *Bitswap) {
bs.taskComparator = comparator
}
Expand Down Expand Up @@ -384,7 +387,7 @@ type Bitswap struct {
// whether we should actually simulate dont haves on request timeout
simulateDontHavesOnTimeout bool

taskComparator decision.TaskComparator
taskComparator TaskComparator
}

type counters struct {
Expand Down
1 change: 1 addition & 0 deletions internal/decision/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ func TestTaskComparator(t *testing.T) {
// use a single task worker so that the order of outgoing messages is deterministic
engineTaskWorkerCount := 1
e := newEngineForTesting(ctx, bs, 4, engineTaskWorkerCount, defaults.BitswapMaxOutstandingBytesPerPeer, fpt, "localhost", 0, sl,
// if this Option is omitted, the test fails
WithTaskComparator(func(ta, tb *TaskInfo) bool {
// prioritize based on lexicographic ordering of block content
return cids[ta.Cid] < cids[tb.Cid]
Expand Down

0 comments on commit b124653

Please sign in to comment.