peertracker

package
v1.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2021 License: MIT, Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PeerCompare

func PeerCompare(a, b pq.Elem) bool

PeerCompare implements pq.ElemComparator returns true if peer 'a' has higher priority than peer 'b'

Types

type DefaultTaskMerger

type DefaultTaskMerger struct{}

DefaultTaskMerger is the TaskMerger used by default. It never overwrites an existing task (with the same Topic).

func (*DefaultTaskMerger) HasNewInfo

func (*DefaultTaskMerger) HasNewInfo(task peertask.Task, existing []peertask.Task) bool

func (*DefaultTaskMerger) Merge

func (*DefaultTaskMerger) Merge(task peertask.Task, existing *peertask.Task)

type PeerTracker

type PeerTracker struct {
	// contains filtered or unexported fields
}

PeerTracker tracks task blocks for a single peer, as well as active tasks for that peer

func New

func New(target peer.ID, taskMerger TaskMerger) *PeerTracker

New creates a new PeerTracker

func (*PeerTracker) Freeze

func (p *PeerTracker) Freeze()

Freeze increments the freeze value for this peer. While a peer is frozen (freeze value > 0) it will not execute tasks.

func (*PeerTracker) FullThaw

func (p *PeerTracker) FullThaw()

FullThaw completely unfreezes this peer so it can execute tasks.

func (*PeerTracker) Index

func (p *PeerTracker) Index() int

Index implements pq.Elem.

func (*PeerTracker) IsFrozen

func (p *PeerTracker) IsFrozen() bool

IsFrozen returns whether this peer is frozen and unable to execute tasks.

func (*PeerTracker) IsIdle

func (p *PeerTracker) IsIdle() bool

IsIdle returns true if the peer has no active tasks or queued tasks

func (*PeerTracker) PopTasks

func (p *PeerTracker) PopTasks(targetMinWork int) ([]*peertask.Task, int)

PopTasks pops as many tasks off the queue as necessary to cover targetMinWork, in priority order. If there are not enough tasks to cover targetMinWork it just returns whatever is in the queue. The second response argument is pending work: the amount of work in the queue for this peer.

func (*PeerTracker) PushTasks

func (p *PeerTracker) PushTasks(tasks ...peertask.Task)

PushTasks adds a group of tasks onto a peer's queue

func (*PeerTracker) Remove

func (p *PeerTracker) Remove(topic peertask.Topic) bool

Remove removes the task with the given topic from this peer's queue

func (*PeerTracker) SetIndex

func (p *PeerTracker) SetIndex(i int)

SetIndex implements pq.Elem.

func (*PeerTracker) Target

func (p *PeerTracker) Target() peer.ID

Target returns the peer that this peer tracker tracks tasks for

func (*PeerTracker) TaskDone

func (p *PeerTracker) TaskDone(task *peertask.Task)

TaskDone signals that a task was completed for this peer.

func (*PeerTracker) Thaw

func (p *PeerTracker) Thaw() bool

Thaw decrements the freeze value for this peer. While a peer is frozen (freeze value > 0) it will not execute tasks.

type TaskMerger

type TaskMerger interface {
	// HasNewInfo indicates whether the given task has more information than
	// the existing group of tasks (which have the same Topic), and thus should
	// be merged.
	HasNewInfo(task peertask.Task, existing []peertask.Task) bool
	// Merge copies relevant fields from a new task to an existing task.
	Merge(task peertask.Task, existing *peertask.Task)
}

TaskMerger is an interface that is used to merge new tasks into the active and pending queues

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL