bittorrent

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2016 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (

	// QueuedForChecking means that the torrent is in the queue for being checked. But there currently
	// is another torrent that are being checked. This torrent will wait for its turn.
	QueuedForChecking TorrentState = "Queued for checking"

	// CheckingFiles means that the torrent has not started its download yet, and is currently
	// checking existing files.
	CheckingFiles = "Checking files"

	// DownloadingMetadata means that the torrent is trying to download metadata from peers.
	DownloadingMetadata = "Downloading metadata"

	// Downloading means that the torrent is being downloaded. This is the state most torrents will be
	// in most of the time.
	Downloading = "Downloading"

	// Finished means that the torrent has finished downloading but still doesn't have the entire torrent.
	// i.e. some pieces are filtered and won't get downloaded.
	// As this library doesn't allow filtering, the state is transient.
	Finished = "Finished"

	// Seeding means that torrent has finished downloading and is a pure seeder.
	Seeding = "Seeding"

	// Allocating means that if the torrent was started in full allocation mode, this indicates
	// that the (disk) storage for the torrent is allocated.
	// As this library only uses the default allocation mode (sparse allocation), this state should
	// never appear.
	Allocating = "Allocating"

	// CheckingResumeData means that the torrent is currently checking the fastresume data and
	// comparing it to the files on disk. This is typically completed in a fraction of a second,
	// but if you add a large number of torrents at once, they will queue up.
	CheckingResumeData = "Checking resume data"

	// Unknown probably means that we couldn't get the current state information or that libtorrent
	// introduced a new state that we don't recognize yet.
	Unknown = "Unknown"
)
View Source
const (
	// FORCED allows only encrypted connections. Incoming connections that are not encrypted are
	// closed and if the encrypted outgoing connection fails, a non-encrypted retry will not be made.
	FORCED EncryptionMode = 0

	// ENABLED allows both encrypted and non-encryption connections.
	// An incoming non-encrypted connection will be accepted, and if an outgoing encrypted
	// connection fails, a non- encrypted connection will be tried.
	ENABLED = 1

	// DISABLED only allows only non-encrypted connections.
	DISABLED = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Running reports the status of the underlying libtorrent session.
	// It is set to true after a successfull Start() and set to false when Stop() is called.
	// Using Download() only makes sense when Running equals true.
	Running bool
	// contains filtered or unexported fields
}

Client wraps libtorrent and allows us to download torrents easily.

func NewClient

func NewClient(config ClientConfig) *Client

NewClient initializes a new Bittorrent client using the specified configuration.

func (*Client) Download

func (bt *Client) Download(sourcePath, downloadPath string, seedDuration *time.Duration, config DownloadConfig) (string, chan struct{}, error)

Download submits a new torrent to be downloaded.

The provided torrent must either be a magnet link, a local file path or an HTTP URL to a .torrent file.

The function blocks until the torrent is fully downloaded and then returns the path where the downloaded content sits.

Once the torrent has been downloaded, it will keep being seeded for the specified amount of time, the returned channel will be closed at the end of the seeding period. There are three cases: - seedDuration == nil, no seeding: the torrent is removed right away and keepSeedingChan is closed. - seedDuration > 0, seed for the specified duration: the torrent will be removed and keepSeedingChan closed after that duration. - seedDuration == 0, seed forever: the torrent will not be removed and keepSeedingChan will not be closed until Stop() is called.

func (*Client) GetStatus

func (bt *Client) GetStatus(sourcePath string) (Status, error)

GetStatus queries and returns several informations about the specified torrent. The torrent must be currently downloading or seed, an error will be thrown otherwise.

func (*Client) Start

func (bt *Client) Start() error

Start launches the configured Client and makes it ready to accept torrents.

func (*Client) Stop

func (bt *Client) Stop()

Stop interrupts every active torrents and destroy the libtorrent session.

type ClientConfig

type ClientConfig struct {
	// Fingerprint represents information about a client and its version.
	// It is used to encode this information into the client's peer id.
	Fingerprint ClientFingerprint

	// LowerListenPort defines the lowest port on which libtorrent will try to listen.
	LowerListenPort int

	// UpperListenPort defines the highest port on which libtorrent will try to listen.
	UpperListenPort int

	// ConnectionsPerSecond specifies the maximum number of outgoing connections per second
	// libtorrent allows.
	ConnectionsPerSecond int

	// MaxDownloadRate defines the maximun bandwidth (in bytes/s) that libtorrent will use to download
	// torrents. A zero value mean unlimited.
	// Note that it does not apply for peers on the local network, which are not rate limited.
	MaxDownloadRate int

	// MaxUploadRate defines the maximun bandwidth (in bytes/s) that libtorrent will use to upload
	// torrents. A zero value mean unlimited.
	// Note that it does not apply for peers on the local network, which are not rate limited.
	MaxUploadRate int

	// Encryption controls the peer protocol encryption policies.
	Encryption EncryptionMode

	// Debug, when set to true, makes libtorrent output every available alert.
	Debug bool
}

ClientConfig represents the configuration that can be passed to NewClient to configure libtorrent.

type ClientFingerprint

type ClientFingerprint struct {
	// ID represents uniquely a client. It must contains exactly two characters.
	// Unofficial list: https://wiki.theory.org/BitTorrentSpecification#peer_id
	ID string

	// Major represents the major version of the client. It must be within the range [0, 9].
	Major int

	// Minor represents the minor version of the client. It must be within the range [0, 9].
	Minor int

	// Revision represents the revision of the client. It must be within the range [0, 9].
	Revision int

	// Tag represents the version tag of the client. It must be within the range [0, 9].
	Tag int
}

ClientFingerprint represents information about a client and its version. It is encoded into the client's peer id.

type DownloadConfig

type DownloadConfig struct {
	// SkipWebseed, if set to true, skips the webseed when downloading the torrent.
	SkipWebseed bool

	// CustomTrackers hold the domain names of the custom tracker(s) to use for downloading the
	// torrent.
	// If specified, the default tracker is not used.
	CustomTrackers []string
}

DownloadConfig represents extra configuration for downloading a specific torrent.

type EncryptionMode

type EncryptionMode int

EncryptionMode is the type that control the settings related to peer protocol encryption in libtorrent.

type Status

type Status struct {
	// Name is the torrent's name.
	Name string

	// Status represents the current torrent's state.
	Status TorrentState

	// Progress is download completion percentage.
	Progress float32

	// DownloadRate is the total download rates for all peers for this torrent, expressed in kB/s.
	DownloadRate float32

	// UploadRate is the total upload rates for all peers for this torrent, expressed in kB/s.
	UploadRate float32

	// NumConnectCandidates is the number of peers in this torrent's peer list that is a candidate
	// to be connected to. i.e. It has fewer connect attempts than the max fail count, it is not a
	// seed if we are a seed, it is not banned etc.
	// If this is 0, it means we don't know of any more peers that we can try.
	NumConnectCandidates int

	// NumPeeers is the total number of peer connections this session has. This includes incoming
	// connections that still hasn't sent their handshake or outgoing connections that still hasn't
	// completed the TCP connection.
	NumPeers int

	// NumSeeds is the number of peers that are seeding that this client is currently connected to.
	NumSeeds int
}

Status contains several pieces of information about the status of a torrent.

type TorrentState

type TorrentState string

TorrentState represents a torrent's current task.

Jump to

Keyboard shortcuts

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