Documentation ¶
Index ¶
- func DefaultPeerComparator(pa, pb *PeerTracker) bool
- type DefaultTaskMerger
- type Option
- type PeerComparator
- type PeerTracker
- func (p *PeerTracker) Freeze()
- func (p *PeerTracker) FullThaw()
- func (p *PeerTracker) Index() int
- func (p *PeerTracker) IsFrozen() bool
- func (p *PeerTracker) IsIdle() bool
- func (p *PeerTracker) PopTasks(targetMinWork int) ([]*peertask.Task, int)
- func (p *PeerTracker) PushTasks(tasks ...peertask.Task)
- func (p *PeerTracker) PushTasksTruncated(n uint, tasks ...peertask.Task)
- func (p *PeerTracker) Remove(topic peertask.Topic) bool
- func (p *PeerTracker) SetIndex(i int)
- func (p *PeerTracker) Stats() *PeerTrackerStats
- func (p *PeerTracker) Target() peer.ID
- func (p *PeerTracker) TaskDone(task *peertask.Task)
- func (p *PeerTracker) Thaw() bool
- func (p *PeerTracker) Topics() *PeerTrackerTopics
- type PeerTrackerStats
- type PeerTrackerTopics
- type TaskMerger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPeerComparator ¶
func DefaultPeerComparator(pa, pb *PeerTracker) bool
DefaultPeerComparator implements the default peer prioritization logic.
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 ¶
type Option ¶
type Option func(*PeerTracker)
Option is a function that configures the peer tracker
func WithQueueTaskComparator ¶
func WithQueueTaskComparator(f peertask.QueueTaskComparator) Option
WithQueueTaskComparator sets a custom QueueTask comparison function for the peer tracker's task queue.
type PeerComparator ¶
type PeerComparator func(a, b *PeerTracker) bool
PeerComparator is used for peer prioritization. It should return true if peer 'a' has higher priority than peer 'b'
func TaskPriorityPeerComparator ¶
func TaskPriorityPeerComparator(comparator peertask.QueueTaskComparator) PeerComparator
TaskPriorityPeerComparator prioritizes peers based on their highest priority 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, maxActiveWorkPerPeer int, opts ...Option) *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) 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) PushTasksTruncated ¶
func (p *PeerTracker) PushTasksTruncated(n uint, tasks ...peertask.Task)
PushTasksTruncated is like PushTasks but it will never grow the queue more than n. When truncation happen we will keep older tasks in the queue to avoid some infinite tasks rotations if we are continously receiving work faster than we process it.
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) Stats ¶
func (p *PeerTracker) Stats() *PeerTrackerStats
Stats returns current statistics for this peer.
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.
func (*PeerTracker) Topics ¶
func (p *PeerTracker) Topics() *PeerTrackerTopics
Topics gives a full list of current and active topics for this peer Stats returns current statistics for this peer.
type PeerTrackerStats ¶
PeerTrackerStats captures number of active and pending tasks for this peer.
type PeerTrackerTopics ¶
PeerTrackerTopics captures the current state of topics in this peers queue
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