Documentation ¶
Index ¶
- func WithCalculateDigest(enable bool) func(*pieceManager)
- func WithLimiter(limiter *rate.Limiter) func(*pieceManager)
- func WithPieceDownloader(d PieceDownloader) func(*pieceManager)
- func WithTransport(rt http.RoundTripper) func(*pieceDownloader) error
- type Bitmap
- type DownloadPieceRequest
- type FilePeerTask
- type FilePeerTaskProgress
- type FilePeerTaskRequest
- type PieceDownloader
- type PieceManager
- type ProgressState
- type StreamPeerTask
- type Task
- type TaskCallback
- type TaskManager
- type TinyData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithLimiter ¶
WithLimiter sets upload rate limiter, the burst size must big than piece size
func WithPieceDownloader ¶
func WithPieceDownloader(d PieceDownloader) func(*pieceManager)
func WithTransport ¶
func WithTransport(rt http.RoundTripper) func(*pieceDownloader) error
Types ¶
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
type DownloadPieceRequest ¶
type FilePeerTask ¶
type FilePeerTask interface { Task // Start start the special peer task, return a *FilePeerTaskProgress channel for updating download progress Start(ctx context.Context) (chan *FilePeerTaskProgress, error) }
FilePeerTask represents a peer task to download a file
type FilePeerTaskProgress ¶
type FilePeerTaskRequest ¶
type FilePeerTaskRequest struct { scheduler.PeerTaskRequest Output string }
type PieceDownloader ¶
type PieceDownloader interface {
DownloadPiece(context.Context, *DownloadPieceRequest) (io.Reader, io.Closer, error)
}
func NewOptimizedPieceDownloader ¶
func NewOptimizedPieceDownloader(opts ...func(*optimizedPieceDownloader) error) (PieceDownloader, error)
func NewPieceDownloader ¶
func NewPieceDownloader(opts ...func(*pieceDownloader) error) (PieceDownloader, error)
type PieceManager ¶
type PieceManager interface { DownloadSource(ctx context.Context, pt Task, request *scheduler.PeerTaskRequest) error DownloadPiece(ctx context.Context, peerTask Task, request *DownloadPieceRequest) bool ReadPiece(ctx context.Context, req *storage.ReadPieceRequest) (io.Reader, io.Closer, error) }
func NewPieceManager ¶
func NewPieceManager(s storage.TaskStorageDriver, opts ...func(*pieceManager)) (PieceManager, error)
type StreamPeerTask ¶
type StreamPeerTask interface { Task // Start start the special peer task, return a io.Reader for stream io // when all data transferred, reader return a io.EOF // attribute stands some extra data, like HTTP response Header Start(ctx context.Context) (reader io.Reader, attribute map[string]string, err error) }
StreamPeerTask represents a peer task with stream io for reading directly without once more disk io
type Task ¶
type Task interface { Context() context.Context Log() *logger.SugaredLoggerOnWith ReportPieceResult(pieceTask *base.PieceInfo, pieceResult *scheduler.PieceResult) error GetPeerID() string GetTaskID() string GetTotalPieces() int32 GetContentLength() int64 // SetContentLength will called after download completed, when download from source without content length SetContentLength(int64) error SetCallback(TaskCallback) AddTraffic(int64) GetTraffic() int64 }
Task represents common interface to operate a peer task
type TaskCallback ¶
type TaskCallback interface { Init(pt Task) error Done(pt Task) error Update(pt Task) error Fail(pt Task, code base.Code, reason string) error GetStartTime() time.Time }
TaskCallback inserts some operations for peer task download lifecycle
type TaskManager ¶
type TaskManager interface { // StartFilePeerTask starts a peer task to download a file // return a progress channel for request download progress // tiny stands task file is tiny and task is done StartFilePeerTask(ctx context.Context, req *FilePeerTaskRequest) ( progress chan *FilePeerTaskProgress, tiny *TinyData, err error) // StartStreamPeerTask starts a peer task with stream io // tiny stands task file is tiny and task is done StartStreamPeerTask(ctx context.Context, req *scheduler.PeerTaskRequest) ( readCloser io.ReadCloser, attribute map[string]string, err error) IsPeerTaskRunning(pid string) bool // Stop stops the PeerTaskManager Stop(ctx context.Context) error }
TaskManager processes all peer tasks request
func NewPeerTaskManager ¶
func NewPeerTaskManager( host *scheduler.PeerHost, pieceManager PieceManager, storageManager storage.Manager, schedulerClient schedulerclient.SchedulerClient, schedulerOption config.SchedulerOption, perPeerRateLimit rate.Limit, multiplex bool) (TaskManager, error)
Click to show internal directories.
Click to hide internal directories.