Documentation ¶
Index ¶
- func WithCalculateDigest(enable bool) func(*pieceManager)
- func WithLimiter(limiter *rate.Limiter) func(*pieceManager)
- func WithTransport(rt http.RoundTripper) func(*pieceDownloader) error
- func WithTransportOption(opt *config.TransportOption) func(*pieceManager)
- 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 WithCalculateDigest ¶
func WithCalculateDigest(enable bool) func(*pieceManager)
func WithLimiter ¶
WithLimiter sets upload rate limiter, the burst size must be bigger than piece size
func WithTransport ¶
func WithTransport(rt http.RoundTripper) func(*pieceDownloader) error
func WithTransportOption ¶ added in v2.0.1
func WithTransportOption(opt *config.TransportOption) func(*pieceManager)
Types ¶
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
func NewBitmapWithCap ¶
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 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(timeout time.Duration, 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, pieceDownloadTimeout time.Duration, opts ...func(*pieceManager)) (PieceManager, error)
type StreamPeerTask ¶
type StreamPeerTask interface { Task // Start starts the special peer task, return an io.Reader for stream io // when all data transferred, reader return an io.EOF // attribute stands some extra data, like HTTP response Header Start(ctx context.Context) (rc io.ReadCloser, 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(result *pieceTaskResult) error GetPeerID() string GetTaskID() string GetTotalPieces() int32 SetTotalPieces(int32) GetContentLength() int64 // SetContentLength will be called after download completed, when download from source without content length SetContentLength(int64) error SetCallback(TaskCallback) AddTraffic(uint64) GetTraffic() uint64 SetPieceMd5Sign(string) GetPieceMd5Sign() string }
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 ValidateDigest(pt Task) error }
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, calculateDigest bool, getPiecesMaxRetry int) (TaskManager, error)
Click to show internal directories.
Click to hide internal directories.