Documentation ¶
Index ¶
- Constants
- Variables
- func AddMagnet(path string, magnet string) int
- func AddTorrent(file string) int
- func AddTorrentFromBytes(path string, buf []byte) int
- func AddTorrentFromURL(path string, url string) int
- func CheckTorrent(i int)
- func Close()
- func CloseMetaInfo()
- func Count() int
- func Create() bool
- func CreateMetainfo(root string) int
- func CreateMetainfoBuilder(b MetainfoBuilder) int
- func CreateTorrentFile(root string) []byte
- func CreateTorrentFileFromMetaInfo() []byte
- func CreateTorrentFromMetaInfo() int
- func DownloadMetadata(i int) bool
- func Error() string
- func GetTorrent(i int) []byte
- func HashMetaInfo(piece int) bool
- func ListenAddr() string
- func LoadTorrent(path string, buf []byte) int
- func MetaTorrent(i int) bool
- func Pause()
- func Paused() bool
- func PendingCompleted(i int) bool
- func Port(i int) string
- func PortCheck() (bool, error)
- func PortCount() int
- func RemoveTorrent(i int)
- func Resume()
- func SaveTorrent(i int) []byte
- func SetDefaultAnnouncesList(str string)
- func SetDownloadRate(i int)
- func SetUploadRate(i int)
- func StartTorrent(i int) bool
- func StopTorrent(i int)
- func TorrentActive(i int) bool
- func TorrentBytesCompleted(i int) int64
- func TorrentBytesLength(i int) int64
- func TorrentFileDeleteUnselected(i int)
- func TorrentFileRename(i int, f int, n string) bool
- func TorrentFilesCheck(i int, p int, b bool)
- func TorrentFilesCheckAll(i int, b bool)
- func TorrentFilesCheckFilter(i int, filter string, b bool)
- func TorrentFilesCount(i int) int
- func TorrentHash(i int) string
- func TorrentInfoComment(i int, s string)
- func TorrentInfoCreator(i int, s string)
- func TorrentInfoName(i int, s string)
- func TorrentMagnet(i int) string
- func TorrentMetainfo(i int) *metainfo.MetaInfo
- func TorrentName(i int) string
- func TorrentPeersCount(i int) int
- func TorrentPendingBytesCompleted(i int) int64
- func TorrentPendingBytesLength(i int) int64
- func TorrentPieceLength(i int) int64
- func TorrentPiecesCompact(i int, p int) int32
- func TorrentPiecesCompactCount(i int, size int) int
- func TorrentPiecesCount(i int) int
- func TorrentRename(i int, n string) bool
- func TorrentSetName(i int, n string)
- func TorrentStatus(i int) int32
- func TorrentStorageSet(p FileStorageTorrent)
- func TorrentTrackerAdd(i int, addr string)
- func TorrentTrackerRemove(i int, url string)
- func TorrentTrackersCount(i int) int
- func TorrentWebSeedsCount(i int) int
- func WaitAll() bool
- func WebSeedStart(t *torrent.Torrent)
- type BodyReader
- type Buffer
- type BytesInfo
- type File
- type FileStorageTorrent
- type InfoTorrent
- type Int64Slice
- type LPDConn
- type LPDServer
- type MetainfoBuilder
- type MultipartReader
- type Peer
- type StatsTorrent
- type TorrentState
- type Tracker
- type WebSeedUrl
Constants ¶
const ( StatusPaused int32 = 0 StatusDownloading int32 = 1 StatusSeeding int32 = 2 StatusChecking int32 = 3 StatusQueued int32 = 4 )
const ( PieceEmpty int32 = 0 // gray PieceComplete int32 = 1 // blue PieceChecking int32 = 2 // yellow PiecePartial int32 = 3 // green, when booth empty and completed PieceWriting int32 = 4 // red, when have partial pieces PieceUnpended int32 = 5 // ltgray, empy pieces can be unpended )
const WEBSEED_BUF = 64 * 1024 // read buffer size
const WEBSEED_CONCURENT = 4 // how many concurent downloading total
const WEBSEED_SPLIT = 10 * 1024 * 1024 // how large split for single sizes
const WEBSEED_TIMEOUT = time.Duration(5 * time.Second) // dial up and socket read timeouts
const WEBSEED_URL_CONCURENT = 2 // how many concurent downloading per one Url
Variables ¶
var ( Version = "" Bep20 = "" SocketsPerTorrent int = 40 BindAddr string = ":53007" )
var ActiveCount = 3
var CONTENT_RANGE = regexp.MustCompile("bytes (\\d+)-(\\d+)/(\\d+)")
var QueueTimeout = (30 * time.Minute).Nanoseconds()
var (
RefreshPort = (1 * time.Minute).Nanoseconds()
)
Functions ¶
func AddTorrentFromBytes ¶
func CheckTorrent ¶
func CheckTorrent(i int)
CheckTorrent
Check torrent file consisteny (pices hases) on a disk. Pause torrent if downloading, resume after.
func CloseMetaInfo ¶
func CloseMetaInfo()
func CreateMetainfo ¶
func CreateMetainfoBuilder ¶
func CreateMetainfoBuilder(b MetainfoBuilder) int
func CreateTorrentFile ¶
func CreateTorrentFileFromMetaInfo ¶
func CreateTorrentFileFromMetaInfo() []byte
func CreateTorrentFromMetaInfo ¶
func CreateTorrentFromMetaInfo() int
func DownloadMetadata ¶
Download only metadata from magnet link and stop torrent
func HashMetaInfo ¶
func ListenAddr ¶
func ListenAddr() string
func MetaTorrent ¶
func PendingCompleted ¶
func SaveTorrent ¶
SaveTorrent
Every torrent application restarts it require to check files consistency. To avoid this, and save machine time we need to store torrents runtime states completed pieces and other information externaly.
Save runtime torrent data to state file
func SetDefaultAnnouncesList ¶
func SetDefaultAnnouncesList(str string)
func SetDownloadRate ¶
func SetDownloadRate(i int)
func SetUploadRate ¶
func SetUploadRate(i int)
func StartTorrent ¶
Separate load / create torrent from network activity.
Start announce torrent, seed/download
func TorrentActive ¶
func TorrentBytesCompleted ¶
func TorrentBytesLength ¶
func TorrentFileDeleteUnselected ¶
func TorrentFileDeleteUnselected(i int)
func TorrentFileRename ¶
TorrentFileRename
To implement this we need to keep two Metainfo one for network operations, and second for local file storage.
func TorrentFilesCheck ¶
func TorrentFilesCheckAll ¶
func TorrentFilesCheckFilter ¶
func TorrentFilesCount ¶
func TorrentHash ¶
func TorrentInfoComment ¶
func TorrentInfoCreator ¶
func TorrentInfoName ¶
func TorrentMetainfo ¶
func TorrentName ¶
func TorrentPeersCount ¶
func TorrentPendingBytesCompleted ¶
Get total bytes downloaded by pending pieces list
func TorrentPendingBytesLength ¶
Get total bytes for pending pieces list
func TorrentPieceLength ¶
func TorrentPiecesCompact ¶
func TorrentPiecesCount ¶
func TorrentRename ¶
func TorrentSetName ¶
func TorrentStatus ¶
func TorrentStorageSet ¶
func TorrentStorageSet(p FileStorageTorrent)
func TorrentTrackerAdd ¶
func TorrentTrackerRemove ¶
func TorrentTrackersCount ¶
func TorrentWebSeedsCount ¶
func WebSeedStart ¶
Types ¶
type BodyReader ¶
type BodyReader struct {
// contains filtered or unexported fields
}
type FileStorageTorrent ¶
type FileStorageTorrent interface { ReadFileAt(hash string, path string, buf *Buffer, off int64) (n int, err error) // java unable to change []byte buf if it passed as a parameter WriteFileAt(hash string, path string, b []byte, off int64) (n int, err error) Remove(hash string, path string) error Rename(hash string, old string, path string) error }
type InfoTorrent ¶
type InfoTorrent struct { Creator string CreateOn int64 Comment string DateAdded int64 DateCompleted int64 }
func TorrentInfo ¶
func TorrentInfo(i int) *InfoTorrent
type Int64Slice ¶
type Int64Slice []int64
func (Int64Slice) Len ¶
func (p Int64Slice) Len() int
func (Int64Slice) Less ¶
func (p Int64Slice) Less(i, j int) bool
func (Int64Slice) Sort ¶
func (p Int64Slice) Sort()
func (Int64Slice) Swap ¶
func (p Int64Slice) Swap(i, j int)
type MetainfoBuilder ¶
type MetainfoBuilder interface { Name() string Root() string // root directory / url for torrent register FilesCount() (int, error) FilesName(i int) string FilesLength(i int) int64 ReadFileAt(path string, buf *Buffer, off int64) (n int, err error) // java unable to change buf if it passed as a parameter }
type MultipartReader ¶
type MultipartReader struct {
// contains filtered or unexported fields
}
type Peer ¶
type Peer struct { Id [20]byte Name string Addr string Source string // Peer is known to support encryption. SupportsEncryption bool PiecesCompleted int64 // how many data we downloaded/uploaded from peer Downloaded int64 Uploaded int64 }
func TorrentPeers ¶
type StatsTorrent ¶
type StatsTorrent struct { Downloaded int64 // bytes Uploaded int64 // bytes Downloading int64 // time Seeding int64 // time }
func TorrentStats ¶
func TorrentStats(i int) *StatsTorrent
type TorrentState ¶
type TorrentState struct { Version int `json:"version"` // metainfo or these InfoHash *metainfo.Hash `json:"hash,omitempty"` Name string `json:"name,omitempty"` Trackers [][]string `json:"trackers,omitempty"` MetaInfo *metainfo.MetaInfo `json:"metainfo,omitempty"` Pieces []bool `json:"pieces,omitempty"` Root string `json:root,omitempty` Checks []bool `json:"checks,omitempty"` // Stats bytes Downloaded int64 `json:"downloaded,omitempty"` Uploaded int64 `json:"uploaded,omitempty"` // dates AddedDate int64 `json:"added_date,omitempty"` CompletedDate int64 `json:"completed_date,omitempty"` // time DownloadingTime int64 `json:"downloading_time,omitempty"` SeedingTime int64 `json:"seeding_time,omitempty"` // .torrent Comment string `json:"comment,omitempty"` Creator string `json:"creator,omitempty"` CreatedOn int64 `json:"created_on,omitempty"` UrlList metainfo.UrlList `bencode:"url-list,omitempty"` }
type Tracker ¶
type Tracker struct { // Tracker URI or DHT, LSD, PE Addr string Error string LastAnnounce int64 NextAnnounce int64 Peers int // scrape info LastScrape int64 Seeders int Leechers int Downloaded int }
func TorrentTrackers ¶
type WebSeedUrl ¶
type WebSeedUrl struct { Url string Downloaded int64 // total bytes / speed test Error string // error if url were removed }
func TorrentWebSeeds ¶
func TorrentWebSeeds(i int, p int) *WebSeedUrl