Documentation
¶
Index ¶
- Constants
- Variables
- func ToSpeed(speed uint64) string
- func ToSz(sz uint64) string
- type AddUpdate
- type Connector
- func (c *Connector) CreateDownloader(ctx context.Context, t *Torrent) (_ TorrentDownloader, err error)
- func (c *Connector) GetADNLPrivateKey() ed25519.PrivateKey
- func (c *Connector) GetDownloadLimit() uint64
- func (c *Connector) GetUploadLimit() uint64
- func (c *Connector) SetDownloadLimit(bytesPerSec uint64)
- func (c *Connector) SetUploadLimit(bytesPerSec uint64)
- func (c *Connector) ThrottleDownload(ctx context.Context, sz uint64) error
- func (c *Connector) ThrottleUpload(ctx context.Context, sz uint64) error
- type DHT
- type DownloadResult
- type Event
- type FECInfoNone
- type FS
- type FSController
- type FSFile
- type FileIndex
- type FileInfo
- type FileRef
- type GetPiece
- type GetTorrentInfo
- type KnownNode
- type NetConnector
- type Ok
- type OpenMode
- type PeerConnection
- func (c *PeerConnection) AcquireQueueSlot() error
- func (c *PeerConnection) AcquireQueueSlotWait(ctx context.Context) error
- func (c *PeerConnection) CloseFor(peer *storagePeer)
- func (c *PeerConnection) FreeQueueSlot()
- func (c *PeerConnection) GetFor(id []byte) *storagePeer
- func (c *PeerConnection) UseFor(peer *storagePeer)
- type PeerInfo
- type Piece
- type PieceInfo
- type PiecesInfo
- type Ping
- type Pong
- type PreFetcher
- type Progress
- type Server
- func (s *Server) ConnectToNode(ctx context.Context, t *Torrent, node *overlay.Node, addrs *address.List) error
- func (s *Server) GetADNLPrivateKey() ed25519.PrivateKey
- func (s *Server) GetID() []byte
- func (s *Server) GetPeerIfActive(id []byte) *PeerConnection
- func (s *Server) SetStorage(store Storage)
- func (s *Server) Stop()
- type SpeedLimit
- type State
- type Storage
- type Torrent
- func CreateTorrent(ctx context.Context, filesRootPath, dirName, description string, db Storage, ...) (*Torrent, error)
- func CreateTorrentWithInitialHeader(ctx context.Context, filesRootPath, description string, header *TorrentHeader, ...) (*Torrent, error)
- func NewTorrent(path string, db Storage, connector NetConnector) *Torrent
- func (t *Torrent) DownloadedPiecesNum() int
- func (t *Torrent) GetActiveFilesIDs() []uint32
- func (t *Torrent) GetConnector() NetConnector
- func (t *Torrent) GetFileOffsets(name string) (*FileInfo, error)
- func (t *Torrent) GetFileOffsetsByID(i uint32) (*FileInfo, error)
- func (t *Torrent) GetFilesInPiece(piece uint32) ([]*FileInfo, error)
- func (t *Torrent) GetLastVerifiedAt() (bool, time.Time)
- func (t *Torrent) GetPeer(id []byte) *PeerInfo
- func (t *Torrent) GetPeers() map[string]PeerInfo
- func (t *Torrent) GetPiece(id uint32) (*Piece, error)
- func (t *Torrent) GetPieceProof(id uint32) ([]byte, error)
- func (t *Torrent) GetUploadStats() uint64
- func (t *Torrent) InitMask()
- func (t *Torrent) IsActive() (activeDownload, activeUpload bool)
- func (t *Torrent) IsActiveRaw() (activeDownload, activeUpload bool)
- func (t *Torrent) IsCompleted() bool
- func (t *Torrent) IsDownloadAll() bool
- func (t *Torrent) IsDownloadOrdered() bool
- func (t *Torrent) ListFiles() ([]string, error)
- func (t *Torrent) LoadActiveFilesIDs() error
- func (t *Torrent) PiecesMask() []byte
- func (t *Torrent) RemovePeer(id []byte)
- func (t *Torrent) ResetDownloadPeer(id []byte)
- func (t *Torrent) SetActiveFiles(names []string) error
- func (t *Torrent) SetActiveFilesIDs(ids []uint32) error
- func (t *Torrent) SetInfoStats(pieceSize uint32, headerData, rootHash []byte, fileSize, headerSize uint64, ...)
- func (t *Torrent) SetUploadStats(val uint64)
- func (t *Torrent) Start(withUpload, downloadAll, downloadOrdered bool) (err error)
- func (t *Torrent) Stop()
- func (t *Torrent) TouchPeer(peer *storagePeer) *PeerInfo
- func (t *Torrent) UpdateDownloadedPeer(peer *storagePeer, bytes uint64)
- func (t *Torrent) UpdateUploadedPeer(peer *storagePeer, bytes uint64)
- func (t *Torrent) Verify(ctx context.Context, deep bool) (intact bool, err error)
- func (t *Torrent) Wait()
- type TorrentDownloader
- type TorrentHeader
- type TorrentInfo
- type TorrentInfoContainer
- type TorrentServer
- type TorrentStats
- type UpdateHavePieces
- type UpdateInit
- type UpdateState
Constants ¶
View Source
const ( EventErr = "ERR" EventBagResolved = "BAG_RESOLVED" EventFileDownloaded = "FILE_DOWNLOADED" EventDone = "DONE" EventPieceDownloaded = "PIECE_DOWNLOADED" EventProgress = "PROGRESS" )
Variables ¶
View Source
var DownloadPrefetch = uint32(runtime.NumCPU() * 2 * 16)
View Source
var ErrFileNotExist = errors.New("file is not exists in torrent")
View Source
var ErrQueueIsBusy = errors.New("queue is busy")
View Source
var Logger = func(...any) {}
Functions ¶
Types ¶
type Connector ¶
type Connector struct { TorrentServer // contains filtered or unexported fields }
func NewConnector ¶
func NewConnector(srv TorrentServer) *Connector
func (*Connector) CreateDownloader ¶
func (*Connector) GetADNLPrivateKey ¶ added in v0.5.0
func (c *Connector) GetADNLPrivateKey() ed25519.PrivateKey
func (*Connector) GetDownloadLimit ¶
func (*Connector) GetUploadLimit ¶
func (*Connector) SetDownloadLimit ¶
func (*Connector) SetUploadLimit ¶
func (*Connector) ThrottleDownload ¶
type DHT ¶
type DHT interface { StoreAddress(ctx context.Context, addresses address.List, ttl time.Duration, ownerKey ed25519.PrivateKey, copies int) (int, []byte, error) FindAddresses(ctx context.Context, key []byte) (*address.List, ed25519.PublicKey, error) FindOverlayNodes(ctx context.Context, overlayId []byte, continuation ...*dht.Continuation) (*overlay.NodesList, *dht.Continuation, error) Close() }
type DownloadResult ¶
type FECInfoNone ¶
type FECInfoNone struct{}
type FSController ¶
type GetTorrentInfo ¶
type GetTorrentInfo struct{}
type NetConnector ¶
type NetConnector interface { GetID() []byte GetADNLPrivateKey() ed25519.PrivateKey SetDownloadLimit(bytesPerSec uint64) SetUploadLimit(bytesPerSec uint64) GetUploadLimit() uint64 GetDownloadLimit() uint64 ThrottleDownload(ctx context.Context, sz uint64) error ThrottleUpload(ctx context.Context, sz uint64) error CreateDownloader(ctx context.Context, t *Torrent) (_ TorrentDownloader, err error) ConnectToNode(ctx context.Context, t *Torrent, node *overlay.Node, addrList *address.List) error TorrentServer }
type PeerConnection ¶
type PeerConnection struct { InflightPieces atomic.Int32 MaxInflightPieces atomic.Int32 StableCount atomic.Int64 UnstableCount atomic.Int64 IsLastSuccess atomic.Bool LastChange atomic.Int64 UpStreak atomic.Int64 DownStreak atomic.Int64 // contains filtered or unexported fields }
func (*PeerConnection) AcquireQueueSlot ¶ added in v1.1.0
func (c *PeerConnection) AcquireQueueSlot() error
func (*PeerConnection) AcquireQueueSlotWait ¶ added in v1.1.0
func (c *PeerConnection) AcquireQueueSlotWait(ctx context.Context) error
func (*PeerConnection) CloseFor ¶
func (c *PeerConnection) CloseFor(peer *storagePeer)
func (*PeerConnection) FreeQueueSlot ¶ added in v1.1.0
func (c *PeerConnection) FreeQueueSlot()
func (*PeerConnection) GetFor ¶
func (c *PeerConnection) GetFor(id []byte) *storagePeer
func (*PeerConnection) UseFor ¶
func (c *PeerConnection) UseFor(peer *storagePeer)
type PeerInfo ¶
type PeerInfo struct { Addr string Uploaded uint64 Downloaded uint64 // contains filtered or unexported fields }
func (*PeerInfo) GetDownloadSpeed ¶
func (*PeerInfo) GetUploadSpeed ¶
type PiecesInfo ¶
type PreFetcher ¶
type PreFetcher struct {
// contains filtered or unexported fields
}
func NewPreFetcher ¶
func (*PreFetcher) Free ¶
func (f *PreFetcher) Free(piece uint32)
func (*PreFetcher) Stop ¶
func (f *PreFetcher) Stop()
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ConnectToNode ¶ added in v0.7.1
func (*Server) GetADNLPrivateKey ¶ added in v0.5.0
func (s *Server) GetADNLPrivateKey() ed25519.PrivateKey
func (*Server) GetPeerIfActive ¶
func (s *Server) GetPeerIfActive(id []byte) *PeerConnection
func (*Server) SetStorage ¶
type SpeedLimit ¶ added in v1.3.0
type SpeedLimit struct {
// contains filtered or unexported fields
}
func (*SpeedLimit) GetLimit ¶ added in v1.3.0
func (s *SpeedLimit) GetLimit() uint64
func (*SpeedLimit) SetLimit ¶ added in v1.3.0
func (s *SpeedLimit) SetLimit(bytesPerSec uint64)
type Storage ¶
type Storage interface { GetFS() FS GetAll() []*Torrent GetTorrentByOverlay(overlay []byte) *Torrent SetTorrent(torrent *Torrent) error SetActiveFiles(bagId []byte, ids []uint32) error GetActiveFiles(bagId []byte) ([]uint32, error) GetPiece(bagId []byte, id uint32) (*PieceInfo, error) RemovePiece(bagId []byte, id uint32) error SetPiece(bagId []byte, id uint32, p *PieceInfo) error PiecesMask(bagId []byte, num uint32) []byte UpdateUploadStats(bagId []byte, val uint64) error VerifyOnStartup() bool GetForcedPieceSize() uint32 }
type Torrent ¶
type Torrent struct { BagID []byte Path string Info *TorrentInfo Header *TorrentHeader CreatedAt time.Time CreatedLocally bool // contains filtered or unexported fields }
func CreateTorrent ¶
func CreateTorrentWithInitialHeader ¶ added in v0.8.1
func NewTorrent ¶
func NewTorrent(path string, db Storage, connector NetConnector) *Torrent
func (*Torrent) DownloadedPiecesNum ¶ added in v0.3.0
func (*Torrent) GetActiveFilesIDs ¶
func (*Torrent) GetConnector ¶
func (t *Torrent) GetConnector() NetConnector
func (*Torrent) GetFileOffsetsByID ¶
func (*Torrent) GetFilesInPiece ¶
func (*Torrent) GetLastVerifiedAt ¶ added in v0.6.0
func (*Torrent) GetPieceProof ¶ added in v0.2.0
func (*Torrent) GetUploadStats ¶ added in v0.3.0
func (*Torrent) IsActiveRaw ¶ added in v0.4.0
func (*Torrent) IsCompleted ¶ added in v0.3.0
func (*Torrent) IsDownloadAll ¶
func (*Torrent) IsDownloadOrdered ¶ added in v0.2.0
func (*Torrent) LoadActiveFilesIDs ¶
func (*Torrent) PiecesMask ¶
func (*Torrent) RemovePeer ¶
func (*Torrent) ResetDownloadPeer ¶
func (*Torrent) SetActiveFiles ¶
func (*Torrent) SetActiveFilesIDs ¶
func (*Torrent) SetInfoStats ¶ added in v0.7.0
func (*Torrent) SetUploadStats ¶ added in v0.3.0
func (*Torrent) UpdateDownloadedPeer ¶
func (*Torrent) UpdateUploadedPeer ¶
type TorrentDownloader ¶
type TorrentDownloader interface { Close() IsActive() bool }
type TorrentHeader ¶
type TorrentInfo ¶
type TorrentInfo struct { PieceSize uint32 `tlb:"## 32"` FileSize uint64 `tlb:"## 64"` RootHash []byte `tlb:"bits 256"` HeaderSize uint64 `tlb:"## 64"` HeaderHash []byte `tlb:"bits 256"` Description tlb.Text `tlb:"."` }
func (*TorrentInfo) PiecesNum ¶ added in v0.8.1
func (t *TorrentInfo) PiecesNum() uint32
type TorrentInfoContainer ¶
type TorrentInfoContainer struct {
Data []byte `tl:"bytes"`
}
type TorrentServer ¶
type TorrentStats ¶ added in v0.3.0
type TorrentStats struct {
Uploaded uint64
}
type UpdateHavePieces ¶
type UpdateHavePieces struct {
PieceIDs []int32 `tl:"vector int"`
}
type UpdateInit ¶
type UpdateState ¶
type UpdateState struct {
State State `tl:"struct boxed"`
}
Click to show internal directories.
Click to hide internal directories.