Documentation ¶
Overview ¶
Package tor implements behaviour of torrents in storrent.
Index ¶
- Constants
- Variables
- func Announce(h hash.Hash, ipv6 bool) error
- func Client(conn net.Conn, t *Torrent, addr netip.AddrPort, proxy string, ...) error
- func DialClient(ctx context.Context, t *Torrent, addr netip.AddrPort, ...) error
- func Expire() int
- func NewWriter(t *Torrent, index, offset, length uint32) *writer
- func Range(f func(hash.Hash, *Torrent) bool)
- func Server(conn net.Conn, cryptoOptions *crypto.Options) error
- func WriteTorrent(w io.Writer, t *Torrent) error
- type Available
- type BFile
- type BInfo
- type BTorrent
- type ParseURLError
- type Reader
- type Requested
- func (rs *Requested) Add(index uint32, prio int8, want bool) (<-chan struct{}, bool)
- func (rs *Requested) Count(f func(uint32) bool) int
- func (rs *Requested) Del(index uint32, prio int8) bool
- func (rs *Requested) DelIdle()
- func (rs *Requested) DelIdlePiece(index uint32)
- func (rs *Requested) Done(index uint32)
- type RequestedPiece
- type Torfile
- type Torrent
- func AddTorrent(ctx context.Context, t *Torrent) (*Torrent, error)
- func Get(hash hash.Hash) *Torrent
- func GetByName(name string) *Torrent
- func GetTorrent(ctx context.Context, proxy string, url string) (*Torrent, error)
- func New(proxy string, hsh hash.Hash, dn string, info []byte, cdate int64, ...) (*Torrent, error)
- func ReadMagnet(proxy string, m string) (*Torrent, error)
- func ReadTorrent(proxy string, r io.Reader) (*Torrent, error)
- func (t *Torrent) AddKnown(addr netip.AddrPort, id hash.Hash, version string, kind known.Kind) error
- func (t *Torrent) BadPeer(p uint32, bad bool) error
- func (t *Torrent) BadPeers(peers []uint32, bad bool)
- func (t *Torrent) DropPeer() (bool, error)
- func (t *Torrent) GetAvailable() (Available, error)
- func (t *Torrent) GetConf() (peer.TorConf, error)
- func (t *Torrent) GetKnown(id hash.Hash, addr netip.AddrPort) (*known.Peer, error)
- func (t *Torrent) GetKnowns() ([]known.Peer, error)
- func (t *Torrent) GetPeer(id hash.Hash) (*peer.Peer, error)
- func (t *Torrent) GetPeers() ([]*peer.Peer, error)
- func (t *Torrent) GetStats() (*peer.TorStats, error)
- func (t *Torrent) Have(index uint32, have bool) error
- func (t *Torrent) InfoComplete() bool
- func (t *Torrent) Kill(ctx context.Context) error
- func (torrent *Torrent) MetadataComplete() error
- func (t *Torrent) NewPeer(proxy string, conn net.Conn, addr netip.AddrPort, incoming bool, ...) error
- func (t *Torrent) NewReader(ctx context.Context, offset int64, length int64) *Reader
- func (t *Torrent) Request(index uint32, prio int8, request bool, want bool) (bool, <-chan struct{}, error)
- func (t *Torrent) SetConf(conf peer.TorConf) error
- func (t *Torrent) Trackers() [][]tracker.Tracker
- func (t *Torrent) Webseeds() []webseed.Webseed
- type UnknownSchemeError
Constants ¶
const IdlePriority = int8(math.MinInt8)
IdlePriority is returned for pieces that have been requested for reasons other than a client requiring them.
Variables ¶
var ErrConnectionSelf = errors.New("connection to self")
var ErrDuplicateConnection = errors.New("duplicate connection")
var ErrMartianAddress = errors.New("martian address")
var ErrMetadataIncomplete = errors.New("metadata incomplete")
var ErrShortWrite = errors.New("short write")
var ErrTorrentDead = errors.New("torrent is dead")
Functions ¶
func Client ¶
func Client(conn net.Conn, t *Torrent, addr netip.AddrPort, proxy string, cryptoHandshake bool, cryptoOptions *crypto.Options) error
Client establishes a connection with a client.
func DialClient ¶
func DialClient(ctx context.Context, t *Torrent, addr netip.AddrPort, cryptoOptions *crypto.Options) error
DialClient connects to a peer.
func NewWriter ¶
NewWriter creates a writer. The chunks covered by length have already been marked as in-flight by the caller.
Types ¶
type Available ¶
type Available []uint16
Available is an array indicating the number of locally available copies of each piece in a torrent.
type BFile ¶
type BFile struct { Path path.Path `bencode:"path"` Path8 path.Path `bencode:"path.utf-8,omitempty"` Length int64 `bencode:"length"` Attr string `bencode:"attr,omitempty"` }
BFile is a file entry in a torrent file.
type BInfo ¶
type BInfo struct { Name string `bencode:"name"` Name8 string `bencode:"name.utf-8,omitempty"` PieceLength uint32 `bencode:"piece length"` Pieces []byte `bencode:"pieces"` Length int64 `bencode:"length"` Files []BFile `bencode:"files,omitempty"` }
BInfo is the info dictionary of a torrent file.
type BTorrent ¶
type BTorrent struct { Info bencode.RawMessage `bencode:"info"` CreationDate int64 `bencode:"creation date,omitempty"` Announce string `bencode:"announce,omitempty"` AnnounceList [][]string `bencode:"announce-list,omitempty"` URLList listOrString `bencode:"url-list,omitempty"` HTTPSeeds listOrString `bencode:"httpseeds,omitempty"` }
BTorrent stores the contents of a torrent file.
type ParseURLError ¶
type ParseURLError struct {
Err error
}
func (ParseURLError) Error ¶
func (e ParseURLError) Error() string
func (ParseURLError) Unwrap ¶
func (e ParseURLError) Unwrap() error
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader reads data from a torrent. It can span piece boundaries.
func (*Reader) SetContext ¶
SetContext changes the context that will abort any requests sent by the reader.
type Requested ¶
type Requested struct {
// contains filtered or unexported fields
}
Requested is a set of pieces that are requested for a torrent.
func (*Requested) Add ¶
Add adds a piece to a set of requested pieces. It returns a channel that will be closed when the piece is complete, as well as a boolean that indicates if the priority of the piece has been increased.
func (*Requested) Del ¶
Del deletes a request for a piece. It returns true if the piece has been cancelled (no other clients are requesting this piece).
func (*Requested) DelIdle ¶
func (rs *Requested) DelIdle()
DelIdle cancels all pieces that are not currently requested by any client.
func (*Requested) DelIdlePiece ¶
DelIdlePiece deletes a given piece only if it is not currently requested by a client.
type RequestedPiece ¶
type RequestedPiece struct {
// contains filtered or unexported fields
}
type Torfile ¶
type Torfile struct { Path path.Path Offset int64 // offset within the torrent Length int64 // length of the file Padding bool // true if a padding file }
Torfile represents a file within a torrent.
type Torrent ¶
type Torrent struct { Hash hash.Hash MyId hash.Hash Info []byte // raw info dictionary CreationDate int64 PieceHashes []hash.Hash Name string Files []Torfile // nil if single-file torrent Pieces piece.Pieces Event chan peer.TorEvent Done chan struct{} Deleted chan struct{} Log *log.Logger // contains filtered or unexported fields }
Torrent represents an active torrent.
func AddTorrent ¶
AddTorrent starts a new torrent.
func GetByName ¶
GetByName gets a torrent by name. If behaves deterministically if multiple torrents have the same name.
func GetTorrent ¶
GetTorrent fetches a torrent file from a web server.
func ReadMagnet ¶
ReadMagnet parses a magnet link.
func ReadTorrent ¶
ReadTorrent reads a torrent from an io.Reader. The given proxy will be used when accessing trackers for this torrent.
func (*Torrent) GetAvailable ¶
GetAvailable returns information about piece availability.
func (*Torrent) InfoComplete ¶
InfoComplete returns true if the metadata of a torrent is complete.
func (*Torrent) MetadataComplete ¶
MetadataComplete must be called when a torrent's metadata is complete.
func (*Torrent) Request ¶
func (t *Torrent) Request(index uint32, prio int8, request bool, want bool) (bool, <-chan struct{}, error)
Request requests a piece from a torrent with given priority and updates the piece's access time. It returns a boolean indicating whether the piece was requested and a channel that will be closed when the piece is complete (nil if already complete).
type UnknownSchemeError ¶
type UnknownSchemeError struct {
Scheme string
}
func (UnknownSchemeError) Error ¶
func (e UnknownSchemeError) Error() string