itemsfetcher

package
v0.0.1-dev Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	// FilterInterested returns only item which may be requested.
	OnlyInterested func(ids []interface{}) []interface{}
	Suspend        func() bool
}

type Config

type Config struct {
	ForgetTimeout time.Duration // Time before an announced event is forgotten
	ArriveTimeout time.Duration // Time allowance before an announced event is explicitly requested
	GatherSlack   time.Duration // Interval used to collate almost-expired announces with fetches
	HashLimit     int           // Maximum number of unique events a peer may have announced

	MaxBatch int // Maximum number of hashes in an announce batch (batch is divided if exceeded)

	MaxParallelRequests int // Maximum number of parallel requests

	// MaxQueuedHashesBatches is the maximum number of announce batches to queue up before
	// dropping incoming hashes.
	MaxQueuedBatches int
}

func DefaultConfig

func DefaultConfig(scale cachescale.Func) Config

type Fetcher

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

Fetcher is responsible for accumulating item announcements from various peers and scheduling them for retrieval.

func New

func New(cfg Config, callback Callback) *Fetcher

New creates a item fetcher to retrieve items based on hash announcements.

func (*Fetcher) NotifyAnnounces

func (f *Fetcher) NotifyAnnounces(peer string, ids []interface{}, time time.Time, fetchItems ItemsRequesterFn) error

NotifyAnnounces announces the fetcher of the potential availability of a new item in the network.

func (*Fetcher) NotifyReceived

func (f *Fetcher) NotifyReceived(ids []interface{}) error

func (*Fetcher) Overloaded

func (f *Fetcher) Overloaded() bool

Overloaded returns true if too much items are being requested

func (*Fetcher) Start

func (f *Fetcher) Start()

Start boots up the items fetcher.

func (*Fetcher) Stop

func (f *Fetcher) Stop()

Stop interrupts the fetcher, canceling all the pending operations. Stop waits until all the internal goroutines have finished.

type ItemsRequesterFn

type ItemsRequesterFn func([]interface{}) error

ItemsRequesterFn is a callback type for sending a item retrieval request.

Jump to

Keyboard shortcuts

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