tracker

package
v0.0.0-...-c57407d Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package tracker provides a generic interface for manipulating a BitTorrent tracker's fast-moving data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

func NewStorage

func NewStorage(cfg *config.Config) *Storage

func (*Storage) ClientApproved

func (s *Storage) ClientApproved(peerID string) error

func (*Storage) DeleteClient

func (s *Storage) DeleteClient(peerID string)

func (*Storage) DeleteLeecher

func (s *Storage) DeleteLeecher(infohash string, p *models.Peer) error

func (*Storage) DeleteSeeder

func (s *Storage) DeleteSeeder(infohash string, p *models.Peer) error

func (*Storage) DeleteTorrent

func (s *Storage) DeleteTorrent(infohash string)

func (*Storage) DeleteUser

func (s *Storage) DeleteUser(passkey string)

func (*Storage) DumpTorrents

func (s *Storage) DumpTorrents() (t []*models.Torrent)

func (*Storage) FindTorrent

func (s *Storage) FindTorrent(infohash string) (*models.Torrent, error)

func (*Storage) FindUser

func (s *Storage) FindUser(passkey string) (*models.User, error)

func (*Storage) IncrementTorrentSnatches

func (s *Storage) IncrementTorrentSnatches(infohash string) error

func (*Storage) Len

func (s *Storage) Len() int

func (*Storage) PurgeInactivePeers

func (s *Storage) PurgeInactivePeers(purgeEmptyTorrents bool, before time.Time) error

func (*Storage) PurgeInactiveTorrent

func (s *Storage) PurgeInactiveTorrent(infohash string) error

func (*Storage) PutClient

func (s *Storage) PutClient(peerID string)

func (*Storage) PutLeecher

func (s *Storage) PutLeecher(infohash string, p *models.Peer) error

func (*Storage) PutSeeder

func (s *Storage) PutSeeder(infohash string, p *models.Peer) error

func (*Storage) PutTorrent

func (s *Storage) PutTorrent(torrent *models.Torrent)

func (*Storage) PutUser

func (s *Storage) PutUser(user *models.User)

func (*Storage) TopTorrents

func (s *Storage) TopTorrents(n int) (t []*models.Torrent)

func (*Storage) TouchTorrent

func (s *Storage) TouchTorrent(infohash string) error

type Torrents

type Torrents struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type Tracker

type Tracker struct {
	Config  *config.Config
	Backend backend.Conn
	Cache   *Storage
}

Tracker represents the logic necessary to service BitTorrent announces, independently of the underlying data transports used.

func New

func New(cfg *config.Config) (*Tracker, error)

New creates a new Tracker, and opens any necessary connections. Maintenance routines are automatically spawned in the background.

func (*Tracker) ClientApproved

func (tkr *Tracker) ClientApproved(peerID string) (err error)

check if a peerID is approved

func (*Tracker) Close

func (tkr *Tracker) Close() error

Close gracefully shutdowns a Tracker by closing any database connections.

func (*Tracker) DeleteLeecher

func (tkr *Tracker) DeleteLeecher(infohash string, p *models.Peer) (err error)

delete leecher from cache

func (*Tracker) DeleteSeeder

func (tkr *Tracker) DeleteSeeder(infohash string, p *models.Peer) (err error)

delete seeder from cache

func (*Tracker) DeleteTorrent

func (tkr *Tracker) DeleteTorrent(infohash string) error

delete torrent from database

func (*Tracker) DeleteUser

func (tkr *Tracker) DeleteUser(passkey string) (err error)

func (*Tracker) FindTorrent

func (tkr *Tracker) FindTorrent(infohash string) (t *models.Torrent, err error)

find a torrent, checks cache then looks it up

func (*Tracker) FindUser

func (tkr *Tracker) FindUser(passkey string) (u *models.User, err error)

find user given passkey

func (*Tracker) HandleAnnounce

func (tkr *Tracker) HandleAnnounce(ann *models.Announce, w Writer) (err error)

HandleAnnounce encapsulates all of the logic of handling a BitTorrent client's Announce without being coupled to any transport protocol.

func (*Tracker) HandleScrape

func (tkr *Tracker) HandleScrape(scrape *models.Scrape, w Writer) (err error)

HandleScrape encapsulates all the logic of handling a BitTorrent client's scrape without being coupled to any transport protocol.

func (*Tracker) IncrementTorrentSnatches

func (tkr *Tracker) IncrementTorrentSnatches(infohash string) (err error)

increment snatches for a torrent with an infohash

func (*Tracker) LoadApprovedClients

func (tkr *Tracker) LoadApprovedClients(clients []string)

LoadApprovedClients loads a list of client IDs into the tracker's storage.

func (*Tracker) PurgeInactiveTorrent

func (tkr *Tracker) PurgeInactiveTorrent(infohash string)

purge an inactive torrent from the cache

func (*Tracker) PutLeecher

func (tkr *Tracker) PutLeecher(infohash string, p *models.Peer) (err error)

put a leecher into the cache

func (*Tracker) PutSeeder

func (tkr *Tracker) PutSeeder(infohash string, p *models.Peer) (err error)

put a seeder into the cache

func (*Tracker) PutTorrent

func (tkr *Tracker) PutTorrent(torrent *models.Torrent) (err error)

put a torrent into the database

func (*Tracker) RegisterUser

func (tkr *Tracker) RegisterUser(u *models.User) (user *models.User, err error)

put new user into database populate the user model with info

func (*Tracker) TouchTorrent

func (tkr *Tracker) TouchTorrent(infohash string) (err error)

touch a torrent in cache

type Writer

type Writer interface {
	WriteError(err error) error
	WriteAnnounce(*models.AnnounceResponse) error
	WriteScrape(*models.ScrapeResponse) error
}

Writer serializes a tracker's responses, and is implemented for each response transport used by the tracker. Only one of these may be called per request, and only once.

Note, data passed into any of these functions will not contain sensitive information, so it may be passed back the client freely.

Directories

Path Synopsis
Package models implements the common data types used throughout a BitTorrent tracker.
Package models implements the common data types used throughout a BitTorrent tracker.

Jump to

Keyboard shortcuts

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