Documentation
¶
Index ¶
- func ConcurrentDownloads(concurrent int) func(*Client) error
- func DownloadCap(bytesPerSecond int) func(*Client) error
- func NotifyWhenDownloadComplete(notifier chan *Client) func(*Client) error
- func NotifyWhenStopped(notifier chan *Client) func(*Client) error
- func PeersWanted(wanted int) func(*Client) error
- func SeedDuration(duration time.Duration) func(*Client) error
- func SetTrackerUserAgent(agent string)
- func TrackerUserAgent() string
- func UploadCap(bytesPerSecond int) func(*Client) error
- type Client
- func (c *Client) ExternalIP() net.IP
- func (c *Client) HandleConnection(conn net.Conn, logger *slog.Logger, _ dispatcher.ProtocolExtensions, ...)
- func (c *Client) Logger() *slog.Logger
- func (c *Client) Status() *Status
- func (c *Client) Stop(timeout time.Duration)
- func (c *Client) TorrentFile() *tfs.File
- type State
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConcurrentDownloads ¶
ConcurrentDownloads sets the number of peers to actively download from at the same time. Peers beyond this many are still connected to, and still uploaded to, but are not asked for pieces until one of the peers downloading finishes or gives up its piece. Default is 4.
What the cap governs is how many peers hold a fresh claim on a piece. In the endgame, once every piece still missing has already been claimed, further peers may take a duplicate of a claim regardless of the cap — the peers holding it are the ones being backed up — with at most maxPieceOwners peers fetching any one piece.
func DownloadCap ¶
DownloadCap sets the maximum download speed of the client, subject to the dispatcher's overall limit. Must be at least dispatcher.MinimumRateCap. Default is no limit.
func NotifyWhenDownloadComplete ¶
NotifyWhenDownloadComplete sets a channel to notify when the download is verified and completes.
func NotifyWhenStopped ¶
NotifyWhenStopped sets a channel to notify when the client is stopped.
func PeersWanted ¶
PeersWanted sets the number of peers to ask the tracker for. Default is 32.
func SeedDuration ¶
SeedDuration sets the maximum amount of time to seed. Default is 4 days.
func SetTrackerUserAgent ¶ added in v1.7.0
func SetTrackerUserAgent(agent string)
SetTrackerUserAgent sets the user agent header sent with tracker announces. An empty string, which is the default, sends none. It is safe to call at any time, including while clients are announcing.
func TrackerUserAgent ¶
func TrackerUserAgent() string
TrackerUserAgent returns the user agent header sent with tracker announces. An empty string means none is sent.
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
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, handshakeDone func(), )
HandleConnection is called by the dispatcher for new connections. handshakeDone, when it isn't nil, is the dispatcher's notification that the pending handshake slot it took for this connection may be released, and is called as soon as the handshake this finishes is over.
func (*Client) Stop ¶
Stop the torrent. Does not return until the torrent has stopped or the timeout has been hit.
func (*Client) TorrentFile ¶
TorrentFile returns the client's torrent file.
type Status ¶
type Status struct {
SeedingStopsAt time.Time
State State
PercentComplete float64
TotalBytes int64
RemainingBytes int64
UploadBytesPerSecond int
DownloadBytesPerSecond int
// PeersDownloading counts the distinct peers we are currently downloading a piece from, not the pieces being
// downloaded: a peer answers for itself once however many pieces it has been asked for.
PeersDownloading int
PeersConnected int
Leechers int
Seeders int
}
Status holds the status information for a torrent.