Documentation ¶
Overview ¶
Package peer is a generated GoMock package.
Package peer is a generated GoMock package.
Package peer is a generated GoMock package.
Index ¶
- Constants
- Variables
- func WithCalculateDigest(enable bool) func(*pieceManager)
- func WithConcurrentOption(opt *config.ConcurrentOption) func(*pieceManager)
- func WithLimiter(limiter *rate.Limiter) func(*pieceManager)
- func WithSyncPieceViaHTTPS(caCertPEM string) func(*pieceManager)
- func WithTransportOption(opt *config.TransportOption) func(*pieceManager)
- type Bitmap
- type DownloadPieceRequest
- type DownloadPieceResult
- type FileTask
- type FileTaskProgress
- type FileTaskRequest
- type IDGenerator
- type Logger
- type MockLogger
- type MockLoggerMockRecorder
- type MockPieceDownloader
- type MockPieceDownloaderMockRecorder
- type MockPieceManager
- func (m *MockPieceManager) DownloadPiece(ctx context.Context, request *DownloadPieceRequest) (*DownloadPieceResult, error)
- func (m *MockPieceManager) DownloadSource(ctx context.Context, pt Task, request *v10.PeerTaskRequest, ...) error
- func (m *MockPieceManager) EXPECT() *MockPieceManagerMockRecorder
- func (m *MockPieceManager) Import(ctx context.Context, ptm storage.PeerTaskMetadata, ...) error
- func (m *MockPieceManager) ImportFile(ctx context.Context, ptm storage.PeerTaskMetadata, ...) error
- type MockPieceManagerMockRecorder
- func (mr *MockPieceManagerMockRecorder) DownloadPiece(ctx, request interface{}) *gomock.Call
- func (mr *MockPieceManagerMockRecorder) DownloadSource(ctx, pt, request, parsedRange interface{}) *gomock.Call
- func (mr *MockPieceManagerMockRecorder) Import(ctx, ptm, tsd, contentLength, reader interface{}) *gomock.Call
- func (mr *MockPieceManagerMockRecorder) ImportFile(ctx, ptm, tsd, req interface{}) *gomock.Call
- type MockTask
- func (m *MockTask) AddTraffic(arg0 uint64)
- func (m *MockTask) Context() context.Context
- func (m *MockTask) EXPECT() *MockTaskMockRecorder
- func (m *MockTask) GetContentLength() int64
- func (m *MockTask) GetPeerID() string
- func (m *MockTask) GetPieceMd5Sign() string
- func (m *MockTask) GetStorage() storage.TaskStorageDriver
- func (m *MockTask) GetTaskID() string
- func (m *MockTask) GetTotalPieces() int32
- func (m *MockTask) GetTraffic() uint64
- func (m *MockTask) Log() *dflog.SugaredLoggerOnWith
- func (m *MockTask) PublishPieceInfo(pieceNum int32, size uint32)
- func (m *MockTask) ReportPieceResult(request *DownloadPieceRequest, result *DownloadPieceResult, err error)
- func (m *MockTask) SetContentLength(arg0 int64)
- func (m *MockTask) SetPieceMd5Sign(arg0 string)
- func (m *MockTask) SetTotalPieces(arg0 int32)
- func (m *MockTask) UpdateSourceErrorStatus(st *status.Status)
- type MockTaskManager
- func (m *MockTaskManager) AnnouncePeerTask(ctx context.Context, meta storage.PeerTaskMetadata, url string, ...) error
- func (m *MockTaskManager) EXPECT() *MockTaskManagerMockRecorder
- func (m *MockTaskManager) GetPieceManager() PieceManager
- func (m *MockTaskManager) IsPeerTaskRunning(taskID, peerID string) (Task, bool)
- func (m *MockTaskManager) StartFileTask(ctx context.Context, req *FileTaskRequest) (chan *FileTaskProgress, error)
- func (m *MockTaskManager) StartSeedTask(ctx context.Context, req *SeedTaskRequest) (*SeedTaskResponse, bool, error)
- func (m *MockTaskManager) StartStreamTask(ctx context.Context, req *StreamTaskRequest) (io.ReadCloser, map[string]string, error)
- func (m *MockTaskManager) StatTask(ctx context.Context, taskID string) (*v10.Task, error)
- func (m *MockTaskManager) Stop(ctx context.Context) error
- func (m *MockTaskManager) Subscribe(request *v1.PieceTaskRequest) (*SubscribeResponse, bool)
- type MockTaskManagerMockRecorder
- func (mr *MockTaskManagerMockRecorder) AnnouncePeerTask(ctx, meta, url, taskType, urlMeta interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) GetPieceManager() *gomock.Call
- func (mr *MockTaskManagerMockRecorder) IsPeerTaskRunning(taskID, peerID interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) StartFileTask(ctx, req interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) StartSeedTask(ctx, req interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) StartStreamTask(ctx, req interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) StatTask(ctx, taskID interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) Stop(ctx interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) Subscribe(request interface{}) *gomock.Call
- type MockTaskMockRecorder
- func (mr *MockTaskMockRecorder) AddTraffic(arg0 interface{}) *gomock.Call
- func (mr *MockTaskMockRecorder) Context() *gomock.Call
- func (mr *MockTaskMockRecorder) GetContentLength() *gomock.Call
- func (mr *MockTaskMockRecorder) GetPeerID() *gomock.Call
- func (mr *MockTaskMockRecorder) GetPieceMd5Sign() *gomock.Call
- func (mr *MockTaskMockRecorder) GetStorage() *gomock.Call
- func (mr *MockTaskMockRecorder) GetTaskID() *gomock.Call
- func (mr *MockTaskMockRecorder) GetTotalPieces() *gomock.Call
- func (mr *MockTaskMockRecorder) GetTraffic() *gomock.Call
- func (mr *MockTaskMockRecorder) Log() *gomock.Call
- func (mr *MockTaskMockRecorder) PublishPieceInfo(pieceNum, size interface{}) *gomock.Call
- func (mr *MockTaskMockRecorder) ReportPieceResult(request, result, err interface{}) *gomock.Call
- func (mr *MockTaskMockRecorder) SetContentLength(arg0 interface{}) *gomock.Call
- func (mr *MockTaskMockRecorder) SetPieceMd5Sign(arg0 interface{}) *gomock.Call
- func (mr *MockTaskMockRecorder) SetTotalPieces(arg0 interface{}) *gomock.Call
- func (mr *MockTaskMockRecorder) UpdateSourceErrorStatus(st interface{}) *gomock.Call
- type PieceDispatcher
- type PieceDownloader
- type PieceDownloaderOption
- type PieceInfo
- type PieceManager
- type PieceManagerOption
- type ProgressState
- type SeedTask
- type SeedTaskProgress
- type SeedTaskRequest
- type SeedTaskResponse
- type StreamTask
- type StreamTaskRequest
- type SubscribeResponse
- type Task
- type TaskManager
- type TaskManagerOption
- type TaskOption
- type TinyData
- type TrafficShaper
Constants ¶
const ( TypePlainTrafficShaper = "plain" TypeSamplingTrafficShaper = "sampling" )
Variables ¶
var ErrNoValidPieceTemporarily = errors.New("no valid piece temporarily")
Functions ¶
func WithCalculateDigest ¶
func WithCalculateDigest(enable bool) func(*pieceManager)
func WithConcurrentOption ¶
func WithConcurrentOption(opt *config.ConcurrentOption) func(*pieceManager)
func WithLimiter ¶
WithLimiter sets upload rate limiter, the burst size must be bigger than piece size
func WithSyncPieceViaHTTPS ¶
func WithSyncPieceViaHTTPS(caCertPEM string) func(*pieceManager)
func WithTransportOption ¶
func WithTransportOption(opt *config.TransportOption) func(*pieceManager)
Types ¶
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
func NewBitmapWithCap ¶
type DownloadPieceRequest ¶
type DownloadPieceResult ¶
type FileTask ¶
type FileTask interface {
Start(ctx context.Context) (chan *FileTaskProgress, error)
}
FileTask represents a peer task to download a file
type FileTaskProgress ¶
type FileTaskRequest ¶
type FileTaskRequest struct { schedulerv1.PeerTaskRequest Output string Limit float64 DisableBackSource bool Range *http.Range KeepOriginalOffset bool }
type IDGenerator ¶
type IDGenerator interface {
PeerID() string
}
func NewPeerIDGenerator ¶
func NewPeerIDGenerator(ip string) IDGenerator
type Logger ¶
type Logger interface {
Log() *logger.SugaredLoggerOnWith
}
type MockLogger ¶
type MockLogger struct {
// contains filtered or unexported fields
}
MockLogger is a mock of Logger interface.
func NewMockLogger ¶
func NewMockLogger(ctrl *gomock.Controller) *MockLogger
NewMockLogger creates a new mock instance.
func (*MockLogger) EXPECT ¶
func (m *MockLogger) EXPECT() *MockLoggerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockLogger) Log ¶
func (m *MockLogger) Log() *dflog.SugaredLoggerOnWith
Log mocks base method.
type MockLoggerMockRecorder ¶
type MockLoggerMockRecorder struct {
// contains filtered or unexported fields
}
MockLoggerMockRecorder is the mock recorder for MockLogger.
func (*MockLoggerMockRecorder) Log ¶
func (mr *MockLoggerMockRecorder) Log() *gomock.Call
Log indicates an expected call of Log.
type MockPieceDownloader ¶
type MockPieceDownloader struct {
// contains filtered or unexported fields
}
MockPieceDownloader is a mock of PieceDownloader interface.
func NewMockPieceDownloader ¶
func NewMockPieceDownloader(ctrl *gomock.Controller) *MockPieceDownloader
NewMockPieceDownloader creates a new mock instance.
func (*MockPieceDownloader) DownloadPiece ¶
func (m *MockPieceDownloader) DownloadPiece(arg0 context.Context, arg1 *DownloadPieceRequest) (io.Reader, io.Closer, error)
DownloadPiece mocks base method.
func (*MockPieceDownloader) EXPECT ¶
func (m *MockPieceDownloader) EXPECT() *MockPieceDownloaderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockPieceDownloaderMockRecorder ¶
type MockPieceDownloaderMockRecorder struct {
// contains filtered or unexported fields
}
MockPieceDownloaderMockRecorder is the mock recorder for MockPieceDownloader.
func (*MockPieceDownloaderMockRecorder) DownloadPiece ¶
func (mr *MockPieceDownloaderMockRecorder) DownloadPiece(arg0, arg1 interface{}) *gomock.Call
DownloadPiece indicates an expected call of DownloadPiece.
type MockPieceManager ¶
type MockPieceManager struct {
// contains filtered or unexported fields
}
MockPieceManager is a mock of PieceManager interface.
func NewMockPieceManager ¶
func NewMockPieceManager(ctrl *gomock.Controller) *MockPieceManager
NewMockPieceManager creates a new mock instance.
func (*MockPieceManager) DownloadPiece ¶
func (m *MockPieceManager) DownloadPiece(ctx context.Context, request *DownloadPieceRequest) (*DownloadPieceResult, error)
DownloadPiece mocks base method.
func (*MockPieceManager) DownloadSource ¶
func (m *MockPieceManager) DownloadSource(ctx context.Context, pt Task, request *v10.PeerTaskRequest, parsedRange *http.Range) error
DownloadSource mocks base method.
func (*MockPieceManager) EXPECT ¶
func (m *MockPieceManager) EXPECT() *MockPieceManagerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockPieceManager) Import ¶
func (m *MockPieceManager) Import(ctx context.Context, ptm storage.PeerTaskMetadata, tsd storage.TaskStorageDriver, contentLength int64, reader io.Reader) error
Import mocks base method.
func (*MockPieceManager) ImportFile ¶
func (m *MockPieceManager) ImportFile(ctx context.Context, ptm storage.PeerTaskMetadata, tsd storage.TaskStorageDriver, req *v1.ImportTaskRequest) error
ImportFile mocks base method.
type MockPieceManagerMockRecorder ¶
type MockPieceManagerMockRecorder struct {
// contains filtered or unexported fields
}
MockPieceManagerMockRecorder is the mock recorder for MockPieceManager.
func (*MockPieceManagerMockRecorder) DownloadPiece ¶
func (mr *MockPieceManagerMockRecorder) DownloadPiece(ctx, request interface{}) *gomock.Call
DownloadPiece indicates an expected call of DownloadPiece.
func (*MockPieceManagerMockRecorder) DownloadSource ¶
func (mr *MockPieceManagerMockRecorder) DownloadSource(ctx, pt, request, parsedRange interface{}) *gomock.Call
DownloadSource indicates an expected call of DownloadSource.
func (*MockPieceManagerMockRecorder) Import ¶
func (mr *MockPieceManagerMockRecorder) Import(ctx, ptm, tsd, contentLength, reader interface{}) *gomock.Call
Import indicates an expected call of Import.
func (*MockPieceManagerMockRecorder) ImportFile ¶
func (mr *MockPieceManagerMockRecorder) ImportFile(ctx, ptm, tsd, req interface{}) *gomock.Call
ImportFile indicates an expected call of ImportFile.
type MockTask ¶
type MockTask struct {
// contains filtered or unexported fields
}
MockTask is a mock of Task interface.
func NewMockTask ¶
func NewMockTask(ctrl *gomock.Controller) *MockTask
NewMockTask creates a new mock instance.
func (*MockTask) AddTraffic ¶
AddTraffic mocks base method.
func (*MockTask) EXPECT ¶
func (m *MockTask) EXPECT() *MockTaskMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockTask) GetContentLength ¶
GetContentLength mocks base method.
func (*MockTask) GetPieceMd5Sign ¶
GetPieceMd5Sign mocks base method.
func (*MockTask) GetStorage ¶
func (m *MockTask) GetStorage() storage.TaskStorageDriver
GetStorage mocks base method.
func (*MockTask) GetTotalPieces ¶
GetTotalPieces mocks base method.
func (*MockTask) PublishPieceInfo ¶
PublishPieceInfo mocks base method.
func (*MockTask) ReportPieceResult ¶
func (m *MockTask) ReportPieceResult(request *DownloadPieceRequest, result *DownloadPieceResult, err error)
ReportPieceResult mocks base method.
func (*MockTask) SetContentLength ¶
SetContentLength mocks base method.
func (*MockTask) SetPieceMd5Sign ¶
SetPieceMd5Sign mocks base method.
func (*MockTask) SetTotalPieces ¶
SetTotalPieces mocks base method.
func (*MockTask) UpdateSourceErrorStatus ¶
UpdateSourceErrorStatus mocks base method.
type MockTaskManager ¶
type MockTaskManager struct {
// contains filtered or unexported fields
}
MockTaskManager is a mock of TaskManager interface.
func NewMockTaskManager ¶
func NewMockTaskManager(ctrl *gomock.Controller) *MockTaskManager
NewMockTaskManager creates a new mock instance.
func (*MockTaskManager) AnnouncePeerTask ¶
func (m *MockTaskManager) AnnouncePeerTask(ctx context.Context, meta storage.PeerTaskMetadata, url string, taskType v1.TaskType, urlMeta *v1.UrlMeta) error
AnnouncePeerTask mocks base method.
func (*MockTaskManager) EXPECT ¶
func (m *MockTaskManager) EXPECT() *MockTaskManagerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockTaskManager) GetPieceManager ¶
func (m *MockTaskManager) GetPieceManager() PieceManager
GetPieceManager mocks base method.
func (*MockTaskManager) IsPeerTaskRunning ¶
func (m *MockTaskManager) IsPeerTaskRunning(taskID, peerID string) (Task, bool)
IsPeerTaskRunning mocks base method.
func (*MockTaskManager) StartFileTask ¶
func (m *MockTaskManager) StartFileTask(ctx context.Context, req *FileTaskRequest) (chan *FileTaskProgress, error)
StartFileTask mocks base method.
func (*MockTaskManager) StartSeedTask ¶
func (m *MockTaskManager) StartSeedTask(ctx context.Context, req *SeedTaskRequest) (*SeedTaskResponse, bool, error)
StartSeedTask mocks base method.
func (*MockTaskManager) StartStreamTask ¶
func (m *MockTaskManager) StartStreamTask(ctx context.Context, req *StreamTaskRequest) (io.ReadCloser, map[string]string, error)
StartStreamTask mocks base method.
func (*MockTaskManager) Stop ¶
func (m *MockTaskManager) Stop(ctx context.Context) error
Stop mocks base method.
func (*MockTaskManager) Subscribe ¶
func (m *MockTaskManager) Subscribe(request *v1.PieceTaskRequest) (*SubscribeResponse, bool)
Subscribe mocks base method.
type MockTaskManagerMockRecorder ¶
type MockTaskManagerMockRecorder struct {
// contains filtered or unexported fields
}
MockTaskManagerMockRecorder is the mock recorder for MockTaskManager.
func (*MockTaskManagerMockRecorder) AnnouncePeerTask ¶
func (mr *MockTaskManagerMockRecorder) AnnouncePeerTask(ctx, meta, url, taskType, urlMeta interface{}) *gomock.Call
AnnouncePeerTask indicates an expected call of AnnouncePeerTask.
func (*MockTaskManagerMockRecorder) GetPieceManager ¶
func (mr *MockTaskManagerMockRecorder) GetPieceManager() *gomock.Call
GetPieceManager indicates an expected call of GetPieceManager.
func (*MockTaskManagerMockRecorder) IsPeerTaskRunning ¶
func (mr *MockTaskManagerMockRecorder) IsPeerTaskRunning(taskID, peerID interface{}) *gomock.Call
IsPeerTaskRunning indicates an expected call of IsPeerTaskRunning.
func (*MockTaskManagerMockRecorder) StartFileTask ¶
func (mr *MockTaskManagerMockRecorder) StartFileTask(ctx, req interface{}) *gomock.Call
StartFileTask indicates an expected call of StartFileTask.
func (*MockTaskManagerMockRecorder) StartSeedTask ¶
func (mr *MockTaskManagerMockRecorder) StartSeedTask(ctx, req interface{}) *gomock.Call
StartSeedTask indicates an expected call of StartSeedTask.
func (*MockTaskManagerMockRecorder) StartStreamTask ¶
func (mr *MockTaskManagerMockRecorder) StartStreamTask(ctx, req interface{}) *gomock.Call
StartStreamTask indicates an expected call of StartStreamTask.
func (*MockTaskManagerMockRecorder) StatTask ¶
func (mr *MockTaskManagerMockRecorder) StatTask(ctx, taskID interface{}) *gomock.Call
StatTask indicates an expected call of StatTask.
func (*MockTaskManagerMockRecorder) Stop ¶
func (mr *MockTaskManagerMockRecorder) Stop(ctx interface{}) *gomock.Call
Stop indicates an expected call of Stop.
func (*MockTaskManagerMockRecorder) Subscribe ¶
func (mr *MockTaskManagerMockRecorder) Subscribe(request interface{}) *gomock.Call
Subscribe indicates an expected call of Subscribe.
type MockTaskMockRecorder ¶
type MockTaskMockRecorder struct {
// contains filtered or unexported fields
}
MockTaskMockRecorder is the mock recorder for MockTask.
func (*MockTaskMockRecorder) AddTraffic ¶
func (mr *MockTaskMockRecorder) AddTraffic(arg0 interface{}) *gomock.Call
AddTraffic indicates an expected call of AddTraffic.
func (*MockTaskMockRecorder) Context ¶
func (mr *MockTaskMockRecorder) Context() *gomock.Call
Context indicates an expected call of Context.
func (*MockTaskMockRecorder) GetContentLength ¶
func (mr *MockTaskMockRecorder) GetContentLength() *gomock.Call
GetContentLength indicates an expected call of GetContentLength.
func (*MockTaskMockRecorder) GetPeerID ¶
func (mr *MockTaskMockRecorder) GetPeerID() *gomock.Call
GetPeerID indicates an expected call of GetPeerID.
func (*MockTaskMockRecorder) GetPieceMd5Sign ¶
func (mr *MockTaskMockRecorder) GetPieceMd5Sign() *gomock.Call
GetPieceMd5Sign indicates an expected call of GetPieceMd5Sign.
func (*MockTaskMockRecorder) GetStorage ¶
func (mr *MockTaskMockRecorder) GetStorage() *gomock.Call
GetStorage indicates an expected call of GetStorage.
func (*MockTaskMockRecorder) GetTaskID ¶
func (mr *MockTaskMockRecorder) GetTaskID() *gomock.Call
GetTaskID indicates an expected call of GetTaskID.
func (*MockTaskMockRecorder) GetTotalPieces ¶
func (mr *MockTaskMockRecorder) GetTotalPieces() *gomock.Call
GetTotalPieces indicates an expected call of GetTotalPieces.
func (*MockTaskMockRecorder) GetTraffic ¶
func (mr *MockTaskMockRecorder) GetTraffic() *gomock.Call
GetTraffic indicates an expected call of GetTraffic.
func (*MockTaskMockRecorder) Log ¶
func (mr *MockTaskMockRecorder) Log() *gomock.Call
Log indicates an expected call of Log.
func (*MockTaskMockRecorder) PublishPieceInfo ¶
func (mr *MockTaskMockRecorder) PublishPieceInfo(pieceNum, size interface{}) *gomock.Call
PublishPieceInfo indicates an expected call of PublishPieceInfo.
func (*MockTaskMockRecorder) ReportPieceResult ¶
func (mr *MockTaskMockRecorder) ReportPieceResult(request, result, err interface{}) *gomock.Call
ReportPieceResult indicates an expected call of ReportPieceResult.
func (*MockTaskMockRecorder) SetContentLength ¶
func (mr *MockTaskMockRecorder) SetContentLength(arg0 interface{}) *gomock.Call
SetContentLength indicates an expected call of SetContentLength.
func (*MockTaskMockRecorder) SetPieceMd5Sign ¶
func (mr *MockTaskMockRecorder) SetPieceMd5Sign(arg0 interface{}) *gomock.Call
SetPieceMd5Sign indicates an expected call of SetPieceMd5Sign.
func (*MockTaskMockRecorder) SetTotalPieces ¶
func (mr *MockTaskMockRecorder) SetTotalPieces(arg0 interface{}) *gomock.Call
SetTotalPieces indicates an expected call of SetTotalPieces.
func (*MockTaskMockRecorder) UpdateSourceErrorStatus ¶
func (mr *MockTaskMockRecorder) UpdateSourceErrorStatus(st interface{}) *gomock.Call
UpdateSourceErrorStatus indicates an expected call of UpdateSourceErrorStatus.
type PieceDispatcher ¶
type PieceDispatcher interface { // Put pieceSynchronizer put piece request into PieceDispatcher Put(req *DownloadPieceRequest) // Get downloader will get piece request from PieceDispatcher Get() (req *DownloadPieceRequest, err error) // Report downloader will report piece download result to PieceDispatcher, so PieceDispatcher can score peers Report(result *DownloadPieceResult) // Close related resources, and not accept Put and Get anymore Close() }
func NewPieceDispatcher ¶
func NewPieceDispatcher(randomRatio float64, log *logger.SugaredLoggerOnWith) PieceDispatcher
type PieceDownloader ¶
type PieceDownloader interface {
DownloadPiece(context.Context, *DownloadPieceRequest) (io.Reader, io.Closer, error)
}
func NewPieceDownloader ¶
func NewPieceDownloader(timeout time.Duration, caCertPool *x509.CertPool) PieceDownloader
type PieceDownloaderOption ¶
type PieceDownloaderOption func(*pieceDownloader) error
type PieceManager ¶
type PieceManager interface { DownloadSource(ctx context.Context, pt Task, request *schedulerv1.PeerTaskRequest, parsedRange *nethttp.Range) error DownloadPiece(ctx context.Context, request *DownloadPieceRequest) (*DownloadPieceResult, error) ImportFile(ctx context.Context, ptm storage.PeerTaskMetadata, tsd storage.TaskStorageDriver, req *dfdaemonv1.ImportTaskRequest) error Import(ctx context.Context, ptm storage.PeerTaskMetadata, tsd storage.TaskStorageDriver, contentLength int64, reader io.Reader) error }
func NewPieceManager ¶
func NewPieceManager(pieceDownloadTimeout time.Duration, opts ...PieceManagerOption) (PieceManager, error)
type PieceManagerOption ¶
type PieceManagerOption func(*pieceManager)
type SeedTask ¶
type SeedTask interface {
Start(ctx context.Context) (chan *SeedTaskProgress, error)
}
SeedTask represents a seed peer task
type SeedTaskProgress ¶
type SeedTaskRequest ¶
type SeedTaskRequest struct { schedulerv1.PeerTaskRequest Limit float64 Range *http.Range }
type SeedTaskResponse ¶
type StreamTask ¶
type StreamTask interface { // 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) }
StreamTask represents a peer task with stream io for reading directly without once more disk io
type StreamTaskRequest ¶
type SubscribeResponse ¶
type SubscribeResponse struct { Storage storage.TaskStorageDriver PieceInfoChannel chan *PieceInfo Success chan struct{} Fail chan struct{} FailReason func() error }
type Task ¶
type Task interface { Logger Context() context.Context Log() *logger.SugaredLoggerOnWith GetStorage() storage.TaskStorageDriver GetPeerID() string GetTaskID() string GetTotalPieces() int32 SetTotalPieces(int32) GetContentLength() int64 SetContentLength(int64) AddTraffic(uint64) GetTraffic() uint64 SetPieceMd5Sign(string) GetPieceMd5Sign() string PublishPieceInfo(pieceNum int32, size uint32) ReportPieceResult(request *DownloadPieceRequest, result *DownloadPieceResult, err error) UpdateSourceErrorStatus(st *status.Status) }
Task represents common interface to operate a peer task
type TaskManager ¶
type TaskManager interface { // StartFileTask 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 StartFileTask(ctx context.Context, req *FileTaskRequest) ( progress chan *FileTaskProgress, err error) // StartStreamTask starts a peer task with stream io StartStreamTask(ctx context.Context, req *StreamTaskRequest) ( readCloser io.ReadCloser, attribute map[string]string, err error) // StartSeedTask starts a seed peer task StartSeedTask(ctx context.Context, req *SeedTaskRequest) ( seedTaskResult *SeedTaskResponse, reuse bool, err error) Subscribe(request *commonv1.PieceTaskRequest) (*SubscribeResponse, bool) IsPeerTaskRunning(taskID string, peerID string) (Task, bool) // StatTask checks whether the given task exists in P2P network StatTask(ctx context.Context, taskID string) (*schedulerv1.Task, error) // AnnouncePeerTask announces peer task info to P2P network AnnouncePeerTask(ctx context.Context, meta storage.PeerTaskMetadata, url string, taskType commonv1.TaskType, urlMeta *commonv1.UrlMeta) error GetPieceManager() PieceManager // Stop stops the PeerTaskManager Stop(ctx context.Context) error }
TaskManager processes all peer tasks request
func NewPeerTaskManager ¶
func NewPeerTaskManager(opt *TaskManagerOption) (TaskManager, error)
type TaskManagerOption ¶
type TaskManagerOption struct { TaskOption SchedulerClient schedulerclient.V1 PerPeerRateLimit rate.Limit TotalRateLimit rate.Limit TrafficShaperType string // Multiplex indicates to reuse the data of completed peer tasks Multiplex bool // Prefetch indicates to prefetch the whole files of ranged requests Prefetch bool GetPiecesMaxRetry int SplitRunningTasks bool }
type TaskOption ¶
type TaskOption struct { // PeerHost info about current PeerHost PeerHost *schedulerv1.PeerHost // PieceManager will be used for downloading piece PieceManager PieceManager StorageManager storage.Manager // schedule options SchedulerOption config.SchedulerOption CalculateDigest bool GRPCCredentials credentials.TransportCredentials GRPCDialTimeout time.Duration // WatchdogTimeout > 0 indicates to start watch dog for every single peer task WatchdogTimeout time.Duration }
type TrafficShaper ¶
type TrafficShaper interface { // Start starts the TrafficShaper Start() // Stop stops the TrafficShaper Stop() // AddTask starts managing the new task AddTask(taskID string, ptc *peerTaskConductor) // RemoveTask removes completed task RemoveTask(taskID string) // Record records task's used bandwidth Record(taskID string, n int) // GetBandwidth gets the total download bandwidth in the past second GetBandwidth() int64 }
TrafficShaper allocates bandwidth for running tasks dynamically
func NewPlainTrafficShaper ¶
func NewPlainTrafficShaper() TrafficShaper
func NewSamplingTrafficShaper ¶
func NewSamplingTrafficShaper(totalRateLimit rate.Limit, computePieceSize func(int64) uint32) TrafficShaper
func NewTrafficShaper ¶
Source Files ¶
- peerid_generator.go
- peertask_bitmap.go
- peertask_conductor.go
- peertask_dummy.go
- peertask_file.go
- peertask_manager.go
- peertask_manager_mock.go
- peertask_piecetask_synchronizer.go
- peertask_reuse.go
- peertask_seed.go
- peertask_stream.go
- piece_broker.go
- piece_dispatcher.go
- piece_downloader.go
- piece_downloader_mock.go
- piece_manager.go
- piece_manager_mock.go
- traffic_shaper.go