Versions in this module Expand all Collapse all v0 v0.33.9 Nov 13, 2024 Changes in this version + const HashSize + const PieceSize1MB + const PieceSize256KB + const PieceSize2MB + const PieceSize4MB + const PieceSize512KB + var ErrInvalidAddr = fmt.Errorf("invalid compact information of ip and port") + func LookupNetAddr(shost string) ([]net.Addr, error) + type Address struct + IP net.Addr + Port uint16 + func ConvertAddress(addr net.Addr) (a Address, err error) + func Lookup(shost string, port int) ([]Address, error) + func NewAddress(ip interface{}, port uint16) Address + func NewAddressFromString(s string) (addr Address, err error) + func NewAddressesFromString(s string) (addrs []Address, err error) + func (a *Address) FromString(addr string) (err error) + func (a *Address) FromUDPAddr(ua net.Addr) + func (a *Address) UnmarshalBencode(b []byte) (err error) + func (a *Address) UnmarshalBinary(b []byte) (err error) + func (a Address) Addr() net.Addr + func (a Address) Equal(o Address) bool + func (a Address) HasIPAndPort(ip net.Addr, port uint16) bool + func (a Address) IsIPv6() bool + func (a Address) MarshalBencode() (b []byte, err error) + func (a Address) MarshalBinary() (data []byte, err error) + func (a Address) String() string + func (a Address) To16() *net.IPAddr + func (a Address) To4() *net.IPAddr + func (a Address) WriteBinary(w io.Writer) (m int, err error) + type AnnounceList [][]string + func (al AnnounceList) Unique() (announces []string) + type Bytes = bencode.RawMessage + type File struct + Length int64 + Paths []string + func (f File) FilePieces(info Info) (fps FilePieces) + func (f File) Offset(info Info) (ret int64) + func (f File) Path(info Info) string + func (f File) PathWithPrefix(prefix string, info Info) string + func (f File) String() string + type FilePiece struct + Index uint32 + Length uint32 + Offset uint32 + func (fp FilePiece) Blocks() PieceBlocks + func (fp FilePiece) TotalOffset(pieceLength int64) int64 + type FilePieces []FilePiece + func (fps FilePieces) Len() int + func (fps FilePieces) Less(i, j int) bool + func (fps FilePieces) Merge() FilePieces + func (fps FilePieces) Swap(i, j int) + type Hash [HashSize]byte + func NewHash(b []byte) (h Hash) + func NewHashFromBytes(b []byte) (ret Hash) + func NewHashFromHexString(s string) (h Hash) + func NewHashFromString(s string) (h Hash) + func NewRandomHash() (h Hash) + func (h *Hash) FromHexString(s string) (err error) + func (h *Hash) FromString(s string) (err error) + func (h *Hash) UnmarshalBencode(b []byte) (err error) + func (h *Hash) UnmarshalBinary(b []byte) (err error) + func (h Hash) Bytes() []byte + func (h Hash) BytesString() string + func (h Hash) Compare(o Hash) int + func (h Hash) HexString() string + func (h Hash) IsZero() bool + func (h Hash) MarshalBencode() (b []byte, err error) + func (h Hash) MarshalBinary() (data []byte, err error) + func (h Hash) String() string + func (h Hash) WriteBinary(w io.Writer) (m int, err error) + func (h Hash) Xor(o Hash) (ret Hash) + type Hashes []Hash + func GeneratePieces(r io.Reader, pieceLength int64) (hs Hashes, err error) + func GeneratePiecesFromFiles(files []File, pieceLength int64, open func(File) (io.ReadCloser, error)) (Hashes, error) + func (hs *Hashes) UnmarshalBencode(b []byte) (err error) + func (hs Hashes) Contains(h Hash) bool + func (hs Hashes) MarshalBencode() ([]byte, error) + type HostAddress struct + Host string + Port uint16 + func NewHostAddress(host string, port uint16) HostAddress + func NewHostAddressFromString(s string) (addr HostAddress, err error) + func (a *HostAddress) FromString(addr string) (err error) + func (a *HostAddress) UnmarshalBencode(b []byte) (err error) + func (a HostAddress) Addresses() (addrs []Address, err error) + func (a HostAddress) Equal(o HostAddress) bool + func (a HostAddress) MarshalBencode() (b []byte, err error) + func (a HostAddress) String() string + type Info struct + Files []File + Length int64 + Name string + PieceLength int64 + Pieces Hashes + func NewInfoFromFilePath(root string, pieceLength int64) (info Info, err error) + func (info Info) AllFiles() []File + func (info Info) CountPieces() int + func (info Info) GetFileByOffset(offset int64) (file File, fileOffset int64) + func (info Info) IsDir() bool + func (info Info) Piece(index int) Piece + func (info Info) PieceOffset(index, offset uint32) int64 + func (info Info) TotalLength() (ret int64) + type Magnet struct + DisplayName string + InfoHash Hash + Params url.Values + Trackers []string + func ParseMagnetURI(uri string) (m Magnet, err error) + func (m Magnet) Peers() (peers []HostAddress, err error) + func (m Magnet) String() string + type MetaInfo struct + Announce string + AnnounceList AnnounceList + Comment string + CreatedBy string + CreationDate int64 + Encoding string + InfoBytes Bytes + Nodes []HostAddress + URLList URLList + func Load(r io.Reader) (mi MetaInfo, err error) + func LoadFromFile(filename string) (mi MetaInfo, err error) + func (mi MetaInfo) Announces() AnnounceList + func (mi MetaInfo) Info() (info Info, err error) + func (mi MetaInfo) InfoHash() Hash + func (mi MetaInfo) Magnet(displayName string, infoHash Hash) (m Magnet) + func (mi MetaInfo) Write(w io.Writer) error + type Piece struct + func (p Piece) Hash() (h Hash) + func (p Piece) Index() int + func (p Piece) Length() int64 + func (p Piece) Offset() int64 + type PieceBlock struct + Index uint32 + Length uint32 + Offset uint32 + type PieceBlocks []PieceBlock + func (pbs PieceBlocks) Len() int + func (pbs PieceBlocks) Less(i, j int) bool + func (pbs PieceBlocks) Swap(i, j int) + type Reader interface + Info func() Info + ReadBlock func(pieceIndex, pieceOffset uint32, p []byte) (int, error) + func NewReader(rootDir string, info Info) Reader + type URLList []string + func (us *URLList) UnmarshalBencode(b []byte) (err error) + func (us URLList) FullURL(index int, name string) (url string) + func (us URLList) MarshalBencode() (b []byte, err error) + type Writer interface + Info func() Info + WriteBlock func(pieceIndex, pieceOffset uint32, p []byte) (int, error) + func NewWriter(rootDir string, info Info, fileMode os.FileMode) Writer