tracker

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDomainForTrackerURL

func GetDomainForTrackerURL(urlString string) (string, error)

Types

type CacheOpts

type CacheOpts struct {
	// MaxAge is the maximum age of a cached item before it is considered stale.
	MaxAge time.Duration
	// MinAge is the minimum age of a cached item before it is considered fresh.
	MinAge time.Duration
	// MaxParallelRequests is the maximum number of parallel requests that can be made to the fetcher.
	MaxParallelRequests int
	// TrackerNameSubstitutions is a list of tracker name substitutions that can be used to convert tracker names to a different name.
	TrackerNameSubstitutions []config.TrackerNameSubstitutions
}

CacheOpts is a struct that contains the options for a Cacher.

type Cacher

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

Cacher is a construct that caches the results of a Tracker Fetcher for a specified min / max time and according to a set number of maximum parallel requests.

func NewCacher

func NewCacher(f Source, opts CacheOpts) *Cacher

NewCacher creates a new Cacher with the specified Fetcher and CacheOpts.

func (*Cacher) GetTrackerFromCacheBlocking

func (c *Cacher) GetTrackerFromCacheBlocking(ctx context.Context, ti *rtorrent.TrackerIndex) (*ModifiedTracker, error)

GetTrackerFromCacheBlocking retrieves a tracker from the cache, if it doesn't exist, it will send a fetch request and block until the tracker is available, and then return the tracker. In the case of stale cached data, it will return stale data and send a fetch request

func (*Cacher) GetTrackerFromCacheNonBlocking

func (c *Cacher) GetTrackerFromCacheNonBlocking(ti *rtorrent.TrackerIndex) *ModifiedTracker

GetTrackerFromCacheNonBlocking retrieves a tracker from the cache, if it doesn't exist, it will send a fetch request and return nil. In the case of stale cached data, it will return stale data and send a fetch request.

func (*Cacher) Run

func (c *Cacher) Run(ctx context.Context, wg *sync.WaitGroup)

Run starts the cacher and runs the main loop for the cacher.

type FetchRequest

type FetchRequest struct {
	// TrackerIndex contains the hash and optionally an index as well to identify the tracker.
	*rtorrent.TrackerIndex
	// Fields is a slice of fields that should be fetched. If this is empty, then all fields will be fetched.
	Fields []rtorrent.TrackerField
}

FetchRequest is a construct that contains the request to fetch tracker information.

type Fetcher

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

Fetcher is a construct that retrieves tracker information from a Source.

func NewFetcher

func NewFetcher(ts Source) *Fetcher

NewFethcer creates a new Fetcher with the specified Source.

func (*Fetcher) GetTrackersAllFields

func (f *Fetcher) GetTrackersAllFields(ctx context.Context, ti *rtorrent.TrackerIndex) ([]*rtorrent.Tracker, error)

GetTrackersAllFields retrieves all available fields for a tracker (identified by hash and index).

func (*Fetcher) GetTrackersByHashAllFields

func (f *Fetcher) GetTrackersByHashAllFields(ctx context.Context, hash string) ([]*rtorrent.Tracker, error)

GetTrackersByHashAllFields retrieves all available fields for a tracker (identified by hash). This is implemented as a helper function to avoid having to create a TrackerIndex object.

func (*Fetcher) GetTrackersByHashIndexAllFields

func (f *Fetcher) GetTrackersByHashIndexAllFields(ctx context.Context, hash string, index int) ([]*rtorrent.Tracker, error)

GetTrackersByHashIndexAllFields retrieves all available fields for a tracker (identified by hash and index). This is implemented as a helper function to avoid having to create a TrackerIndex object.

func (*Fetcher) GetTrackersByHashIndexSelectedFields

func (f *Fetcher) GetTrackersByHashIndexSelectedFields(ctx context.Context, hash string, index int,
	fields []rtorrent.TrackerField) ([]*rtorrent.Tracker, error)

GetTrackersByHashIndexSelectedFields retrieves the specified fields for a tracker (identified by hash and index). This is implemented as a helper function to avoid having to create a TrackerIndex object.

func (*Fetcher) GetTrackersByHashSelectedFields

func (f *Fetcher) GetTrackersByHashSelectedFields(ctx context.Context, hash string,
	fields []rtorrent.TrackerField) ([]*rtorrent.Tracker, error)

GetTrackersByHashSelectedFields retrieves the specified fields for a tracker (identified by hash). This is implemented as a helper function to avoid having to create a TrackerIndex object.

func (*Fetcher) GetTrackersSelectedFields

func (f *Fetcher) GetTrackersSelectedFields(ctx context.Context, ti *rtorrent.TrackerIndex,
	fields []rtorrent.TrackerField) ([]*rtorrent.Tracker, error)

GetTrackersSelectedFields retrieves the specified fields for a tracker (identified by hash and index).

func (*Fetcher) Run

func (f *Fetcher) Run(ctx context.Context, wg *sync.WaitGroup, inCH <-chan *FetchRequest, outCH chan<- *TrackerResponse)

type ModifiedTracker added in v1.4.0

type ModifiedTracker struct {
	Tracker           *rtorrent.Tracker
	SubstitutedDomain string
}

type Source

type Source interface {
	TrackerWithDetails(ctx context.Context, ti *rtorrent.TrackerIndex, fields []rtorrent.TrackerField) ([]*rtorrent.Tracker, error)
}

Source is an interface that provides tracker information.

type TimedTrackerCacheInstance

type TimedTrackerCacheInstance struct {
	// Tracker is a single tracker that was fetched.
	Tracker *ModifiedTracker
	// FetchedAt is the time that the tracker was fetched.
	FetchedAt time.Time
}

TimedTrackerCacheInstance is a struct that holds a single tracker and the time that it was fetched. This is what is stored in the internal trackerCache. This is distinct from the TrackerResponse as it only holds a single tracker and the time that it was fetched and does not hold any errors that may have been encountered during the tracker request.

func (*TimedTrackerCacheInstance) IsStale

func (ttci *TimedTrackerCacheInstance) IsStale(minAge time.Duration, maxAge time.Duration) bool

func (*TimedTrackerCacheInstance) String

func (ttci *TimedTrackerCacheInstance) String() string

type TrackerResponse

type TrackerResponse struct {
	// Trackers is a slice of trackers that were fetched. If an index was passed in the TrackerIndex object, then it should only ever
	// contain a single Tracker. However, if only a hash was passed, then it may contain multiple trackers.
	Trackers []*rtorrent.Tracker
	// Error is any errors that were encountered while fetching the trackers.
	Error error
	// FetchedAt is the time that the trackers were fetched.
	FetchedAt time.Time
}

TrackerResponse is a construct that contains the response from a tracker FetchRequest

func (*TrackerResponse) Len

func (tr *TrackerResponse) Len() int

Implement methods to make TrackerResponse sortable Len is the number of elements in the collection.

func (*TrackerResponse) Less

func (tr *TrackerResponse) Less(i, j int) bool

Less uses the string representation of TrackerIndex (which includes the info hash and an index if it exists) to compare two TrackerResponse objects.

func (*TrackerResponse) String

func (tr *TrackerResponse) String() string

func (*TrackerResponse) Swap

func (tr *TrackerResponse) Swap(i, j int)

Swap swaps the elements with indexes i and j.

Jump to

Keyboard shortcuts

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