peertracker

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: Apache-2.0, MIT Imports: 7 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPeerComparator added in v0.6.0

func DefaultPeerComparator(pa, pb *PeerTracker) bool

DefaultPeerComparator implements the default peer prioritization logic.

Types

type DefaultTaskMerger added in v0.2.0

type DefaultTaskMerger struct{}

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

func (*DefaultTaskMerger) HasNewInfo added in v0.2.0

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

func (*DefaultTaskMerger) Merge added in v0.2.0

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

type Option added in v0.6.0

type Option func(*PeerTracker)

Option is a function that configures the peer tracker

func WithQueueTaskComparator added in v0.6.0

func WithQueueTaskComparator(f peertask.QueueTaskComparator) Option

WithQueueTaskComparator sets a custom QueueTask comparison function for the peer tracker's task queue.

type PeerComparator added in v0.6.0

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 added in v0.6.0

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) 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 added in v0.2.0

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 added in v0.2.0

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

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

func (*PeerTracker) PushTasksTruncated added in v0.8.1

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) SetIndex

func (p *PeerTracker) SetIndex(i int)

SetIndex implements pq.Elem.

func (*PeerTracker) Stats added in v0.4.0

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 added in v0.7.1

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 added in v0.4.0

type PeerTrackerStats struct {
	NumPending int
	NumActive  int
}

PeerTrackerStats captures number of active and pending tasks for this peer.

type PeerTrackerTopics added in v0.7.1

type PeerTrackerTopics struct {
	Pending []peertask.Topic
	Active  []peertask.Topic
}

PeerTrackerTopics captures the current state of topics in this peers queue

type TaskMerger added in v0.2.0

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