Documentation ¶
Index ¶
- Constants
- Variables
- func ChoosePieceLength(totalLength int64) (pieceLength int64)
- func GeneratePieces(r io.Reader, pieceLength int64, b []byte) ([]byte, error)
- type AnnounceList
- type FileInfo
- type Hash
- type Info
- func (info Info) BestName() string
- func (info *Info) BuildFromFilePath(root string) (err error)
- func (info *Info) GeneratePieces(open func(fi FileInfo) (io.ReadCloser, error)) (err error)
- func (info *Info) IsDir() bool
- func (info *Info) NumPieces() int
- func (info *Info) Piece(index int) Piece
- func (info *Info) TotalLength() (ret int64)
- func (info *Info) UpvertedFiles() []FileInfo
- type Magnet
- type MetaInfo
- func (mi MetaInfo) HashInfoBytes() (infoHash Hash)
- func (mi MetaInfo) Magnet(infoHash *Hash, info *Info) (m Magnet)
- func (mi *MetaInfo) SetDefaults()
- func (mi MetaInfo) UnmarshalInfo() (info Info, err error)
- func (mi *MetaInfo) UpvertedAnnounceList() AnnounceList
- func (mi MetaInfo) Write(w io.Writer) error
- type Node
- type Piece
- type PieceKey
- type UrlList
Constants ¶
const HashSize = infohash.Size
const NoName = "-"
The Info.Name field is "advisory". For multi-file torrents it's usually a suggested directory name. There are situations where we don't want a directory (like using the contents of a torrent as the immediate contents of a directory), or the name is invalid. Transmission will inject the name of the torrent file if it doesn't like the name, resulting in a different infohash (https://github.com/transmission/transmission/issues/1775). To work around these situations, we will use a sentinel name for compatibility with Transmission and to signal to our own client that we intended to have no directory name. By exposing it in the API we can check for references to this behaviour within this implementation.
Variables ¶
var ( NewHashFromHex = infohash.FromHexString HashBytes = infohash.HashBytes )
var ParseMagnetURI = ParseMagnetUri
Deprecated: Use ParseMagnetUri.
Functions ¶
func ChoosePieceLength ¶ added in v1.47.0
Choose a good piecelength.
Types ¶
type AnnounceList ¶
type AnnounceList [][]string
func (AnnounceList) Clone ¶ added in v1.16.0
func (al AnnounceList) Clone() (ret AnnounceList)
func (AnnounceList) DistinctValues ¶
func (al AnnounceList) DistinctValues() (ret []string)
func (AnnounceList) OverridesAnnounce ¶
func (al AnnounceList) OverridesAnnounce(announce string) bool
Whether the AnnounceList should be preferred over a single URL announce.
type FileInfo ¶
type FileInfo struct { Length int64 `bencode:"length"` // BEP3 Path []string `bencode:"path"` // BEP3 PathUtf8 []string `bencode:"path.utf-8,omitempty"` }
Information specific to a single file inside the MetaInfo structure.
func (*FileInfo) DisplayPath ¶
type Info ¶
type Info struct { PieceLength int64 `bencode:"piece length"` // BEP3 Pieces []byte `bencode:"pieces"` // BEP3 Name string `bencode:"name"` // BEP3 NameUtf8 string `bencode:"name.utf-8,omitempty"` Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files Private *bool `bencode:"private,omitempty"` // BEP27 // TODO: Document this field. Source string `bencode:"source,omitempty"` Files []FileInfo `bencode:"files,omitempty"` // BEP3, mutually exclusive with Length }
The info dictionary.
func (*Info) BuildFromFilePath ¶
This is a helper that sets Files and Pieces from a root path and its children.
func (*Info) GeneratePieces ¶
Sets Pieces (the block of piece hashes in the Info) by using the passed function to get at the torrent data.
func (*Info) TotalLength ¶
func (*Info) UpvertedFiles ¶
The files field, converted up from the old single-file in the parent info dict if necessary. This is a helper to avoid having to conditionally handle single and multi-file torrent infos.
type Magnet ¶
type Magnet struct { InfoHash Hash // Expected in this implementation Trackers []string // "tr" values DisplayName string // "dn" value, if not empty Params url.Values // All other values, such as "x.pe", "as", "xs" etc. }
Magnet link components.
func ParseMagnetUri ¶ added in v1.19.0
ParseMagnetUri parses Magnet-formatted URIs into a Magnet instance
type MetaInfo ¶
type MetaInfo struct { InfoBytes bencode.Bytes `bencode:"info,omitempty"` // BEP 3 Announce string `bencode:"announce,omitempty"` // BEP 3 AnnounceList AnnounceList `bencode:"announce-list,omitempty"` // BEP 12 Nodes []Node `bencode:"nodes,omitempty,ignore_unmarshal_type_error"` // BEP 5 // Where's this specified? Mentioned at // https://wiki.theory.org/index.php/BitTorrentSpecification: (optional) the creation time of // the torrent, in standard UNIX epoch format (integer, seconds since 1-Jan-1970 00:00:00 UTC) CreationDate int64 `bencode:"creation date,omitempty,ignore_unmarshal_type_error"` Comment string `bencode:"comment,omitempty"` CreatedBy string `bencode:"created by,omitempty"` Encoding string `bencode:"encoding,omitempty"` UrlList UrlList `bencode:"url-list,omitempty"` // BEP 19 WebSeeds }
func LoadFromFile ¶
Convenience function for loading a MetaInfo from a file.
func (MetaInfo) HashInfoBytes ¶
func (MetaInfo) Magnet ¶
Creates a Magnet from a MetaInfo. Optional infohash and parsed info can be provided.
func (*MetaInfo) SetDefaults ¶
func (mi *MetaInfo) SetDefaults()
Set good default values in preparation for creating a new MetaInfo file.
func (MetaInfo) UnmarshalInfo ¶
func (*MetaInfo) UpvertedAnnounceList ¶
func (mi *MetaInfo) UpvertedAnnounceList() AnnounceList
Returns the announce list converted from the old single announce field if necessary.
type Piece ¶
type Piece struct { Info *Info // Can we embed the fields here instead, or is it something to do with saving memory? // contains filtered or unexported fields }