bittorrent

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DontDownloadPriority = uint(0)
	LowPriority          = uint(1)
	DefaultPriority      = uint(4)
	HighPriority         = uint(6)
	TopPriority          = uint(7)
)

noinspection GoUnusedConst

Variables

View Source
var (
	DuplicateTorrentError  = errors.New("torrent was previously added")
	LoadTorrentError       = errors.New("failed loading torrent")
	InvalidInfoHashError   = errors.New("no such info hash")
	InvalidFileIdError     = errors.New("no such file id")
	ServiceClosedError     = errors.New("service was closed")
	TorrentClosedError     = errors.New("torrent was closed")
	TorrentPausedError     = errors.New("torrent paused")
	ReaderClosedError      = errors.New("reader was closed")
	ReaderCloseNotifyError = errors.New("reader close notify received")
	InvalidWhenceError     = errors.New("invalid whence")
	TimeoutError           = errors.New("timeout reached")
	NoMetadataError        = errors.New("no metadata")
)
View Source
var DefaultDhtBootstrapNodes = []string{
	"router.utorrent.com:6881",
	"router.bittorrent.com:6881",
	"dht.transmissionbt.com:6881",
	"dht.aelitis.com:6881",
	"router.silotis.us:6881",
	"dht.libtorrent.org:25401",
}

Functions

This section is empty.

Types

type File

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

func NewFile

func NewFile(torrent *Torrent, storage libtorrent.FileStorage, index int) *File

func (*File) Buffer

func (f *File) Buffer(startBufferSize, endBufferSize int64)

func (*File) BufferBytesCompleted added in v0.0.3

func (f *File) BufferBytesCompleted() int64

func (*File) BufferBytesMissing added in v0.0.3

func (f *File) BufferBytesMissing() int64

func (*File) BufferLength added in v0.0.3

func (f *File) BufferLength() int64

func (*File) BytesCompleted

func (f *File) BytesCompleted() int64

func (*File) GetBufferingProgress

func (f *File) GetBufferingProgress() float64

func (*File) GetDownloadPath

func (f *File) GetDownloadPath() string

func (*File) GetProgress

func (f *File) GetProgress() float64

func (*File) GetState

func (f *File) GetState() LTStatus

func (*File) Id

func (f *File) Id() int

func (*File) Info

func (f *File) Info() *FileInfo

func (*File) IsDownloading

func (f *File) IsDownloading() bool

func (*File) Length

func (f *File) Length() int64

func (*File) Name

func (f *File) Name() string

func (*File) NewReader

func (f *File) NewReader() *reader

func (*File) Path

func (f *File) Path() string

func (*File) SetPriority

func (f *File) SetPriority(priority uint)

func (*File) Status

func (f *File) Status() *FileStatus

type FileInfo

type FileInfo struct {
	Id     int    `json:"id"`
	Length int64  `json:"length"`
	Path   string `json:"path"`
	Name   string `json:"name"`
}

type FileStatus

type FileStatus struct {
	Total             int64    `json:"total"`
	TotalDone         int64    `json:"total_done"`
	Progress          float64  `json:"progress"`
	Priority          uint     `json:"priority"`
	BufferingTotal    int64    `json:"buffering_total"`
	BufferingProgress float64  `json:"buffering_progress"`
	State             LTStatus `json:"state"`
}

type LTStatus

type LTStatus int
const (
	QueuedStatus             LTStatus = iota // libtorrent.TorrentStatusUnusedEnumForBackwardsCompatibility
	CheckingStatus                           // libtorrent.TorrentStatusCheckingFiles
	FindingStatus                            // libtorrent.TorrentStatusDownloadingMetadata
	DownloadingStatus                        // libtorrent.TorrentStatusDownloading
	FinishedStatus                           // libtorrent.TorrentStatusFinished
	SeedingStatus                            // libtorrent.TorrentStatusSeeding
	AllocatingStatus                         // libtorrent.TorrentStatusAllocating
	CheckingResumeDataStatus                 // libtorrent.TorrentStatusCheckingResumeData
	// Custom status
	PausedStatus
	BufferingStatus
)

noinspection GoUnusedConst

type Magnet added in v0.0.7

type Magnet struct {
	Uri      string
	Download bool
}

type Service

type Service struct {
	UserAgent string
	// contains filtered or unexported fields
}

Service represents the torrent service

func NewService

func NewService(config *settings.Settings) *Service

NewService creates a service given the provided configs

func (*Service) AddMagnet

func (s *Service) AddMagnet(magnet string, download bool) (infoHash string, err error)

func (*Service) AddTorrentData

func (s *Service) AddTorrentData(data []byte, download bool) (infoHash string, err error)

func (*Service) AddTorrentFile

func (s *Service) AddTorrentFile(torrentFile string, download bool) (infoHash string, err error)

func (*Service) Close

func (s *Service) Close()

func (*Service) GetStatus

func (s *Service) GetStatus() *ServiceStatus

func (*Service) GetTorrent

func (s *Service) GetTorrent(infoHash string) (*Torrent, error)

func (*Service) Pause

func (s *Service) Pause()

func (*Service) Reconfigure

func (s *Service) Reconfigure(config *settings.Settings, reset bool)

func (*Service) RemoveTorrent

func (s *Service) RemoveTorrent(infoHash string, removeFiles bool) error

func (*Service) Resume

func (s *Service) Resume()

func (*Service) Torrents

func (s *Service) Torrents() []*Torrent

type ServiceStatus

type ServiceStatus struct {
	Progress     float64 `json:"progress"`
	DownloadRate int64   `json:"download_rate"`
	UploadRate   int64   `json:"upload_rate"`
	NumTorrents  int     `json:"num_torrents"`
	IsPaused     bool    `json:"is_paused"`
}

type Torrent

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

func NewTorrent

func NewTorrent(service *Service, handle libtorrent.TorrentHandle, infoHash string) *Torrent

func (*Torrent) Files

func (t *Torrent) Files() ([]*File, error)

func (*Torrent) GetFile

func (t *Torrent) GetFile(id int) (*File, error)

func (*Torrent) GetInfo

func (t *Torrent) GetInfo() *TorrentInfo

func (*Torrent) GetState

func (t *Torrent) GetState() LTStatus

func (*Torrent) GetStatus

func (t *Torrent) GetStatus() *TorrentStatus

func (*Torrent) HasMetadata

func (t *Torrent) HasMetadata() bool

func (*Torrent) InfoHash

func (t *Torrent) InfoHash() string

func (*Torrent) Pause

func (t *Torrent) Pause()

func (*Torrent) Resume

func (t *Torrent) Resume()

func (*Torrent) SetPriority

func (t *Torrent) SetPriority(priority uint) error

type TorrentFileRaw

type TorrentFileRaw struct {
	Announce     string                 `bencode:"announce"`
	AnnounceList [][]string             `bencode:"announce-list"`
	Info         map[string]interface{} `bencode:"info"`
}

func DecodeTorrentData

func DecodeTorrentData(data []byte) (*TorrentFileRaw, error)

type TorrentInfo

type TorrentInfo struct {
	InfoHash string `json:"info_hash"`
	Name     string `json:"name"`
	Size     int64  `json:"size"`
}

type TorrentStatus

type TorrentStatus struct {
	Total           int64    `json:"total"`
	TotalDone       int64    `json:"total_done"`
	TotalWanted     int64    `json:"total_wanted"`
	TotalWantedDone int64    `json:"total_wanted_done"`
	Progress        float64  `json:"progress"`
	DownloadRate    int      `json:"download_rate"`
	UploadRate      int      `json:"upload_rate"`
	Paused          bool     `json:"paused"`
	HasMetadata     bool     `json:"has_metadata"`
	State           LTStatus `json:"state"`
	Seeders         int      `json:"seeders"`
	SeedersTotal    int      `json:"seeders_total"`
	Peers           int      `json:"peers"`
	PeersTotal      int      `json:"peers_total"`
	SeedingTime     int64    `json:"seeding_time"`
	FinishedTime    int64    `json:"finished_time"`
	ActiveTime      int64    `json:"active_time"`
	AllTimeDownload int64    `json:"all_time_download"`
	AllTimeUpload   int64    `json:"all_time_upload"`
}

Jump to

Keyboard shortcuts

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