torrent

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MPL-2.0 Imports: 28 Imported by: 0

README

Implementation of the BitTorrent protocol: http://www.bittorrent.org/beps/bep_0003.html

Implemented:

  • BEP-3 The BitTorrent Protocol Specification
  • BEP-23 Tracker Returns Compact Peer Lists
  • BEP-27 Private Torrents

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TrackerUserAgent will be used as the http client user agent header if
	// not empty.
	TrackerUserAgent = ""
)

Functions

func ConcurrentDownloads

func ConcurrentDownloads(concurrent int) func(*Client) error

ConcurrentDownloads sets the number of peers to actively download from at the same time. Default is 4.

func DownloadCap

func DownloadCap(bytesPerSecond int) func(*Client) error

DownloadCap sets the maximum download speed of the client, subject to the dispatcher's overall limit. Default is no limit.

func NotifyWhenDownloadComplete

func NotifyWhenDownloadComplete(notifier chan *Client) func(*Client) error

NotifyWhenDownloadComplete sets a channel to notify when the download is verified and completes.

func NotifyWhenStopped

func NotifyWhenStopped(notifier chan *Client) func(*Client) error

NotifyWhenStopped sets a channel to notify when the client is stopped.

func PeersWanted

func PeersWanted(wanted int) func(*Client) error

PeersWanted sets the number of peers to ask the tracker for. Default is 32.

func SeedDuration

func SeedDuration(duration time.Duration) func(*Client) error

SeedDuration sets the maximum amount of time to seed. Default is 4 days.

func UploadCap

func UploadCap(bytesPerSecond int) func(*Client) error

UploadCap sets the maximum upload speed of the client, subject to the dispatcher's overall limit. Default is no limit.

Types

type Client

type Client struct {
	InRate  rate.Limiter
	OutRate rate.Limiter
	// contains filtered or unexported fields
}

Client provides the ability to download and/or seed a torrent.

func NewClient

func NewClient(d *dispatcher.Dispatcher, torrentFile *tfs.File, options ...func(*Client) error) (*Client, error)

NewClient creates and starts a new client for a torrent.

func (*Client) ExternalIP added in v1.0.3

func (c *Client) ExternalIP() string

ExternalIP returns our external IP address.

func (*Client) HandleConnection

func (c *Client) HandleConnection(conn net.Conn, logger *slog.Logger, _ dispatcher.ProtocolExtensions, infoHash tfs.InfoHash, sendHandshake bool)

HandleConnection is called by the dispatcher for new connections.

func (*Client) Logger

func (c *Client) Logger() *slog.Logger

Logger returns the client's logger.

func (*Client) Status

func (c *Client) Status() *Status

Status returns the current status of the torrent.

func (*Client) Stop

func (c *Client) Stop(timeout time.Duration)

Stop the torrent. Does not return until the torrent has stopped or the timeout has been hit.

func (*Client) TorrentFile

func (c *Client) TorrentFile() *tfs.File

TorrentFile returns the client's torrent file.

type State

type State int

State holds the enumeration of possible states.

const (
	Initializing State = iota
	Downloading
	Seeding
	Stopping
	Done
	Errored
)

Possible states.

type Status

type Status struct {
	State                  State
	PercentComplete        float64
	UploadBytesPerSecond   int
	DownloadBytesPerSecond int
	PeersDownloading       int
	PeersConnected         int
	Leechers               int
	Seeders                int
	SeedingStopsAt         time.Time
}

Status holds the status information for a torrent.

func (*Status) String

func (s *Status) String() string

Directories

Path Synopsis
container

Jump to

Keyboard shortcuts

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