mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
privatize Task
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
This commit is contained in:

committed by
Juan Batiz-Benet

parent
181ff4eab1
commit
e11f099c42
@ -9,17 +9,17 @@ import (
|
|||||||
// to help decide how to sort tasks (on add) and how to select
|
// to help decide how to sort tasks (on add) and how to select
|
||||||
// tasks (on getnext). For now, we are assuming a dumb/nice strategy.
|
// tasks (on getnext). For now, we are assuming a dumb/nice strategy.
|
||||||
type taskQueue struct {
|
type taskQueue struct {
|
||||||
tasks []*Task
|
tasks []*task
|
||||||
taskmap map[string]*Task
|
taskmap map[string]*task
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTaskQueue() *taskQueue {
|
func newTaskQueue() *taskQueue {
|
||||||
return &taskQueue{
|
return &taskQueue{
|
||||||
taskmap: make(map[string]*Task),
|
taskmap: make(map[string]*task),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Task struct {
|
type task struct {
|
||||||
Key u.Key
|
Key u.Key
|
||||||
Target peer.Peer
|
Target peer.Peer
|
||||||
theirPriority int
|
theirPriority int
|
||||||
@ -30,11 +30,11 @@ type Task struct {
|
|||||||
func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) {
|
func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) {
|
||||||
if task, ok := tl.taskmap[taskKey(to, block)]; ok {
|
if task, ok := tl.taskmap[taskKey(to, block)]; ok {
|
||||||
// TODO: when priority queue is implemented,
|
// TODO: when priority queue is implemented,
|
||||||
// rearrange this Task
|
// rearrange this task
|
||||||
task.theirPriority = priority
|
task.theirPriority = priority
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
task := &Task{
|
task := &task{
|
||||||
Key: block,
|
Key: block,
|
||||||
Target: to,
|
Target: to,
|
||||||
theirPriority: priority,
|
theirPriority: priority,
|
||||||
@ -44,8 +44,8 @@ func (tl *taskQueue) Push(block u.Key, priority int, to peer.Peer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pop 'pops' the next task to be performed. Returns nil no task exists.
|
// Pop 'pops' the next task to be performed. Returns nil no task exists.
|
||||||
func (tl *taskQueue) Pop() *Task {
|
func (tl *taskQueue) Pop() *task {
|
||||||
var out *Task
|
var out *task
|
||||||
for len(tl.tasks) > 0 {
|
for len(tl.tasks) > 0 {
|
||||||
// TODO: instead of zero, use exponential distribution
|
// TODO: instead of zero, use exponential distribution
|
||||||
// it will help reduce the chance of receiving
|
// it will help reduce the chance of receiving
|
||||||
|
Reference in New Issue
Block a user