peer

package
v2.1.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Overview

Code generated by MockGen. DO NOT EDIT. Source: peertask_manager.go

Generated by this command:

mockgen -destination peertask_manager_mock.go -source peertask_manager.go -package peer

Package peer is a generated GoMock package.

Code generated by MockGen. DO NOT EDIT. Source: piece_downloader.go

Generated by this command:

mockgen -destination piece_downloader_mock.go -source piece_downloader.go -package peer

Package peer is a generated GoMock package.

Code generated by MockGen. DO NOT EDIT. Source: piece_manager.go

Generated by this command:

mockgen -destination piece_manager_mock.go -source piece_manager.go -package peer

Package peer is a generated GoMock package.

Index

Constants

View Source
const (
	TypePlainTrafficShaper    = "plain"
	TypeSamplingTrafficShaper = "sampling"
)

Variables

View Source
var ErrNoValidPieceTemporarily = errors.New("no valid piece temporarily")

Functions

func WithCalculateDigest

func WithCalculateDigest(enable bool) func(*pieceManager)

func WithConcurrentOption added in v2.0.5

func WithConcurrentOption(opt *config.ConcurrentOption) func(*pieceManager)

func WithLimiter

func WithLimiter(limiter *rate.Limiter) func(*pieceManager)

WithLimiter sets upload rate limiter, the burst size must be bigger than piece size

func WithSyncPieceViaHTTPS added in v2.0.6

func WithSyncPieceViaHTTPS(caCertPEM string) func(*pieceManager)

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 NewBitmap

func NewBitmap() *Bitmap

func NewBitmapWithCap

func NewBitmapWithCap(c int32) *Bitmap

func (*Bitmap) Clean added in v2.0.2

func (b *Bitmap) Clean(i int32)

func (*Bitmap) IsSet

func (b *Bitmap) IsSet(i int32) bool

func (*Bitmap) Set

func (b *Bitmap) Set(i int32)

func (*Bitmap) Sets

func (b *Bitmap) Sets(xs ...int32)

func (*Bitmap) Settled

func (b *Bitmap) Settled() int32

type DownloadPieceRequest

type DownloadPieceRequest struct {
	TaskID     string
	PeerID     string
	DstPid     string
	DstAddr    string
	CalcDigest bool
	// contains filtered or unexported fields
}

type DownloadPieceResult added in v2.0.2

type DownloadPieceResult struct {
	// Size of piece
	Size int64
	// BeginTime nanosecond
	BeginTime int64
	// FinishTime nanosecond
	FinishTime int64
	DstPeerID  string
	Fail       bool
	// contains filtered or unexported fields
}

type FileTask added in v2.0.2

type FileTask interface {
	Start(ctx context.Context) (chan *FileTaskProgress, error)
}

FileTask represents a peer task to download a file

type FileTaskProgress added in v2.0.2

type FileTaskProgress struct {
	State           *ProgressState
	TaskID          string
	PeerID          string
	ContentLength   int64
	CompletedLength int64
	PeerTaskDone    bool
	DoneCallback    func()
}

type FileTaskRequest added in v2.0.2

type FileTaskRequest struct {
	schedulerv1.PeerTaskRequest
	Output             string
	Limit              float64
	DisableBackSource  bool
	Range              *http.Range
	KeepOriginalOffset bool
}

type IDGenerator added in v2.0.2

type IDGenerator interface {
	PeerID() string
}

func NewPeerIDGenerator added in v2.0.2

func NewPeerIDGenerator(ip string) IDGenerator

type Logger added in v2.0.2

type Logger interface {
	Log() *logger.SugaredLoggerOnWith
}

type MockLogger added in v2.0.4

type MockLogger struct {
	// contains filtered or unexported fields
}

MockLogger is a mock of Logger interface.

func NewMockLogger added in v2.0.4

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) EXPECT added in v2.0.4

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Log added in v2.0.4

Log mocks base method.

type MockLoggerMockRecorder added in v2.0.4

type MockLoggerMockRecorder struct {
	// contains filtered or unexported fields
}

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Log added in v2.0.4

func (mr *MockLoggerMockRecorder) Log() *gomock.Call

Log indicates an expected call of Log.

type MockPieceDownloader added in v2.0.4

type MockPieceDownloader struct {
	// contains filtered or unexported fields
}

MockPieceDownloader is a mock of PieceDownloader interface.

func NewMockPieceDownloader added in v2.0.4

func NewMockPieceDownloader(ctrl *gomock.Controller) *MockPieceDownloader

NewMockPieceDownloader creates a new mock instance.

func (*MockPieceDownloader) DownloadPiece added in v2.0.4

func (m *MockPieceDownloader) DownloadPiece(arg0 context.Context, arg1 *DownloadPieceRequest) (io.Reader, io.Closer, error)

DownloadPiece mocks base method.

func (*MockPieceDownloader) EXPECT added in v2.0.4

EXPECT returns an object that allows the caller to indicate expected use.

type MockPieceDownloaderMockRecorder added in v2.0.4

type MockPieceDownloaderMockRecorder struct {
	// contains filtered or unexported fields
}

MockPieceDownloaderMockRecorder is the mock recorder for MockPieceDownloader.

func (*MockPieceDownloaderMockRecorder) DownloadPiece added in v2.0.4

func (mr *MockPieceDownloaderMockRecorder) DownloadPiece(arg0, arg1 any) *gomock.Call

DownloadPiece indicates an expected call of DownloadPiece.

type MockPieceManager added in v2.0.7

type MockPieceManager struct {
	// contains filtered or unexported fields
}

MockPieceManager is a mock of PieceManager interface.

func NewMockPieceManager added in v2.0.7

func NewMockPieceManager(ctrl *gomock.Controller) *MockPieceManager

NewMockPieceManager creates a new mock instance.

func (*MockPieceManager) DownloadPiece added in v2.0.7

func (m *MockPieceManager) DownloadPiece(ctx context.Context, request *DownloadPieceRequest) (*DownloadPieceResult, error)

DownloadPiece mocks base method.

func (*MockPieceManager) DownloadSource added in v2.0.7

func (m *MockPieceManager) DownloadSource(ctx context.Context, pt Task, request *scheduler.PeerTaskRequest, parsedRange *http.Range) error

DownloadSource mocks base method.

func (*MockPieceManager) EXPECT added in v2.0.7

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPieceManager) Import added in v2.0.7

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 added in v2.0.7

ImportFile mocks base method.

type MockPieceManagerMockRecorder added in v2.0.7

type MockPieceManagerMockRecorder struct {
	// contains filtered or unexported fields
}

MockPieceManagerMockRecorder is the mock recorder for MockPieceManager.

func (*MockPieceManagerMockRecorder) DownloadPiece added in v2.0.7

func (mr *MockPieceManagerMockRecorder) DownloadPiece(ctx, request any) *gomock.Call

DownloadPiece indicates an expected call of DownloadPiece.

func (*MockPieceManagerMockRecorder) DownloadSource added in v2.0.7

func (mr *MockPieceManagerMockRecorder) DownloadSource(ctx, pt, request, parsedRange any) *gomock.Call

DownloadSource indicates an expected call of DownloadSource.

func (*MockPieceManagerMockRecorder) Import added in v2.0.7

func (mr *MockPieceManagerMockRecorder) Import(ctx, ptm, tsd, contentLength, reader any) *gomock.Call

Import indicates an expected call of Import.

func (*MockPieceManagerMockRecorder) ImportFile added in v2.0.7

func (mr *MockPieceManagerMockRecorder) ImportFile(ctx, ptm, tsd, req any) *gomock.Call

ImportFile indicates an expected call of ImportFile.

type MockTask added in v2.0.4

type MockTask struct {
	// contains filtered or unexported fields
}

MockTask is a mock of Task interface.

func NewMockTask added in v2.0.4

func NewMockTask(ctrl *gomock.Controller) *MockTask

NewMockTask creates a new mock instance.

func (*MockTask) AddTraffic added in v2.0.4

func (m *MockTask) AddTraffic(arg0 uint64)

AddTraffic mocks base method.

func (*MockTask) Context added in v2.0.4

func (m *MockTask) Context() context.Context

Context mocks base method.

func (*MockTask) EXPECT added in v2.0.4

func (m *MockTask) EXPECT() *MockTaskMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTask) GetContentLength added in v2.0.4

func (m *MockTask) GetContentLength() int64

GetContentLength mocks base method.

func (*MockTask) GetPeerID added in v2.0.4

func (m *MockTask) GetPeerID() string

GetPeerID mocks base method.

func (*MockTask) GetPieceMd5Sign added in v2.0.4

func (m *MockTask) GetPieceMd5Sign() string

GetPieceMd5Sign mocks base method.

func (*MockTask) GetStorage added in v2.0.4

func (m *MockTask) GetStorage() storage.TaskStorageDriver

GetStorage mocks base method.

func (*MockTask) GetTaskID added in v2.0.4

func (m *MockTask) GetTaskID() string

GetTaskID mocks base method.

func (*MockTask) GetTotalPieces added in v2.0.4

func (m *MockTask) GetTotalPieces() int32

GetTotalPieces mocks base method.

func (*MockTask) GetTraffic added in v2.0.4

func (m *MockTask) GetTraffic() uint64

GetTraffic mocks base method.

func (*MockTask) Log added in v2.0.4

Log mocks base method.

func (*MockTask) PublishPieceInfo added in v2.0.4

func (m *MockTask) PublishPieceInfo(pieceNum int32, size uint32)

PublishPieceInfo mocks base method.

func (*MockTask) ReportPieceResult added in v2.0.4

func (m *MockTask) ReportPieceResult(request *DownloadPieceRequest, result *DownloadPieceResult, err error)

ReportPieceResult mocks base method.

func (*MockTask) SetContentLength added in v2.0.4

func (m *MockTask) SetContentLength(arg0 int64)

SetContentLength mocks base method.

func (*MockTask) SetPieceMd5Sign added in v2.0.4

func (m *MockTask) SetPieceMd5Sign(arg0 string)

SetPieceMd5Sign mocks base method.

func (*MockTask) SetTotalPieces added in v2.0.4

func (m *MockTask) SetTotalPieces(arg0 int32)

SetTotalPieces mocks base method.

func (*MockTask) UpdateSourceErrorStatus added in v2.0.5

func (m *MockTask) UpdateSourceErrorStatus(st *status.Status)

UpdateSourceErrorStatus mocks base method.

type MockTaskManager added in v2.0.4

type MockTaskManager struct {
	// contains filtered or unexported fields
}

MockTaskManager is a mock of TaskManager interface.

func NewMockTaskManager added in v2.0.4

func NewMockTaskManager(ctrl *gomock.Controller) *MockTaskManager

NewMockTaskManager creates a new mock instance.

func (*MockTaskManager) AnnouncePeerTask added in v2.0.4

func (m *MockTaskManager) AnnouncePeerTask(ctx context.Context, meta storage.PeerTaskMetadata, url string, taskType common.TaskType, urlMeta *common.UrlMeta) error

AnnouncePeerTask mocks base method.

func (*MockTaskManager) EXPECT added in v2.0.4

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTaskManager) GetPieceManager added in v2.0.4

func (m *MockTaskManager) GetPieceManager() PieceManager

GetPieceManager mocks base method.

func (*MockTaskManager) IsPeerTaskRunning added in v2.0.4

func (m *MockTaskManager) IsPeerTaskRunning(taskID, peerID string) (Task, bool)

IsPeerTaskRunning mocks base method.

func (*MockTaskManager) StartFileTask added in v2.0.4

func (m *MockTaskManager) StartFileTask(ctx context.Context, req *FileTaskRequest) (chan *FileTaskProgress, error)

StartFileTask mocks base method.

func (*MockTaskManager) StartSeedTask added in v2.0.4

func (m *MockTaskManager) StartSeedTask(ctx context.Context, req *SeedTaskRequest) (*SeedTaskResponse, bool, error)

StartSeedTask mocks base method.

func (*MockTaskManager) StartStreamTask added in v2.0.4

func (m *MockTaskManager) StartStreamTask(ctx context.Context, req *StreamTaskRequest) (io.ReadCloser, map[string]string, error)

StartStreamTask mocks base method.

func (*MockTaskManager) StatTask added in v2.0.4

func (m *MockTaskManager) StatTask(ctx context.Context, taskID string) (*scheduler.Task, error)

StatTask mocks base method.

func (*MockTaskManager) Stop added in v2.0.4

func (m *MockTaskManager) Stop(ctx context.Context) error

Stop mocks base method.

func (*MockTaskManager) Subscribe added in v2.0.4

func (m *MockTaskManager) Subscribe(request *common.PieceTaskRequest) (*SubscribeResponse, bool)

Subscribe mocks base method.

type MockTaskManagerMockRecorder added in v2.0.4

type MockTaskManagerMockRecorder struct {
	// contains filtered or unexported fields
}

MockTaskManagerMockRecorder is the mock recorder for MockTaskManager.

func (*MockTaskManagerMockRecorder) AnnouncePeerTask added in v2.0.4

func (mr *MockTaskManagerMockRecorder) AnnouncePeerTask(ctx, meta, url, taskType, urlMeta any) *gomock.Call

AnnouncePeerTask indicates an expected call of AnnouncePeerTask.

func (*MockTaskManagerMockRecorder) GetPieceManager added in v2.0.4

func (mr *MockTaskManagerMockRecorder) GetPieceManager() *gomock.Call

GetPieceManager indicates an expected call of GetPieceManager.

func (*MockTaskManagerMockRecorder) IsPeerTaskRunning added in v2.0.4

func (mr *MockTaskManagerMockRecorder) IsPeerTaskRunning(taskID, peerID any) *gomock.Call

IsPeerTaskRunning indicates an expected call of IsPeerTaskRunning.

func (*MockTaskManagerMockRecorder) StartFileTask added in v2.0.4

func (mr *MockTaskManagerMockRecorder) StartFileTask(ctx, req any) *gomock.Call

StartFileTask indicates an expected call of StartFileTask.

func (*MockTaskManagerMockRecorder) StartSeedTask added in v2.0.4

func (mr *MockTaskManagerMockRecorder) StartSeedTask(ctx, req any) *gomock.Call

StartSeedTask indicates an expected call of StartSeedTask.

func (*MockTaskManagerMockRecorder) StartStreamTask added in v2.0.4

func (mr *MockTaskManagerMockRecorder) StartStreamTask(ctx, req any) *gomock.Call

StartStreamTask indicates an expected call of StartStreamTask.

func (*MockTaskManagerMockRecorder) StatTask added in v2.0.4

func (mr *MockTaskManagerMockRecorder) StatTask(ctx, taskID any) *gomock.Call

StatTask indicates an expected call of StatTask.

func (*MockTaskManagerMockRecorder) Stop added in v2.0.4

func (mr *MockTaskManagerMockRecorder) Stop(ctx any) *gomock.Call

Stop indicates an expected call of Stop.

func (*MockTaskManagerMockRecorder) Subscribe added in v2.0.4

func (mr *MockTaskManagerMockRecorder) Subscribe(request any) *gomock.Call

Subscribe indicates an expected call of Subscribe.

type MockTaskMockRecorder added in v2.0.4

type MockTaskMockRecorder struct {
	// contains filtered or unexported fields
}

MockTaskMockRecorder is the mock recorder for MockTask.

func (*MockTaskMockRecorder) AddTraffic added in v2.0.4

func (mr *MockTaskMockRecorder) AddTraffic(arg0 any) *gomock.Call

AddTraffic indicates an expected call of AddTraffic.

func (*MockTaskMockRecorder) Context added in v2.0.4

func (mr *MockTaskMockRecorder) Context() *gomock.Call

Context indicates an expected call of Context.

func (*MockTaskMockRecorder) GetContentLength added in v2.0.4

func (mr *MockTaskMockRecorder) GetContentLength() *gomock.Call

GetContentLength indicates an expected call of GetContentLength.

func (*MockTaskMockRecorder) GetPeerID added in v2.0.4

func (mr *MockTaskMockRecorder) GetPeerID() *gomock.Call

GetPeerID indicates an expected call of GetPeerID.

func (*MockTaskMockRecorder) GetPieceMd5Sign added in v2.0.4

func (mr *MockTaskMockRecorder) GetPieceMd5Sign() *gomock.Call

GetPieceMd5Sign indicates an expected call of GetPieceMd5Sign.

func (*MockTaskMockRecorder) GetStorage added in v2.0.4

func (mr *MockTaskMockRecorder) GetStorage() *gomock.Call

GetStorage indicates an expected call of GetStorage.

func (*MockTaskMockRecorder) GetTaskID added in v2.0.4

func (mr *MockTaskMockRecorder) GetTaskID() *gomock.Call

GetTaskID indicates an expected call of GetTaskID.

func (*MockTaskMockRecorder) GetTotalPieces added in v2.0.4

func (mr *MockTaskMockRecorder) GetTotalPieces() *gomock.Call

GetTotalPieces indicates an expected call of GetTotalPieces.

func (*MockTaskMockRecorder) GetTraffic added in v2.0.4

func (mr *MockTaskMockRecorder) GetTraffic() *gomock.Call

GetTraffic indicates an expected call of GetTraffic.

func (*MockTaskMockRecorder) Log added in v2.0.4

func (mr *MockTaskMockRecorder) Log() *gomock.Call

Log indicates an expected call of Log.

func (*MockTaskMockRecorder) PublishPieceInfo added in v2.0.4

func (mr *MockTaskMockRecorder) PublishPieceInfo(pieceNum, size any) *gomock.Call

PublishPieceInfo indicates an expected call of PublishPieceInfo.

func (*MockTaskMockRecorder) ReportPieceResult added in v2.0.4

func (mr *MockTaskMockRecorder) ReportPieceResult(request, result, err any) *gomock.Call

ReportPieceResult indicates an expected call of ReportPieceResult.

func (*MockTaskMockRecorder) SetContentLength added in v2.0.4

func (mr *MockTaskMockRecorder) SetContentLength(arg0 any) *gomock.Call

SetContentLength indicates an expected call of SetContentLength.

func (*MockTaskMockRecorder) SetPieceMd5Sign added in v2.0.4

func (mr *MockTaskMockRecorder) SetPieceMd5Sign(arg0 any) *gomock.Call

SetPieceMd5Sign indicates an expected call of SetPieceMd5Sign.

func (*MockTaskMockRecorder) SetTotalPieces added in v2.0.4

func (mr *MockTaskMockRecorder) SetTotalPieces(arg0 any) *gomock.Call

SetTotalPieces indicates an expected call of SetTotalPieces.

func (*MockTaskMockRecorder) UpdateSourceErrorStatus added in v2.0.5

func (mr *MockTaskMockRecorder) UpdateSourceErrorStatus(st any) *gomock.Call

UpdateSourceErrorStatus indicates an expected call of UpdateSourceErrorStatus.

type PieceDispatcher added in v2.0.9

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 added in v2.0.9

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 added in v2.0.6

type PieceDownloaderOption func(*pieceDownloader) error

type PieceInfo added in v2.0.2

type PieceInfo struct {
	// Num is the current piece num
	Num int32
	// OrderedNum is the max pieces num with ordered, eg: 0 1 2 3 5 7 8, the OrderedNum is 3
	OrderedNum int32
	Finished   bool
}

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 added in v2.0.6

type PieceManagerOption func(*pieceManager)

type ProgressState

type ProgressState struct {
	Success bool
	Code    commonv1.Code
	Msg     string
}

type SeedTask added in v2.0.3

type SeedTask interface {
	Start(ctx context.Context) (chan *SeedTaskProgress, error)
}

SeedTask represents a seed peer task

type SeedTaskProgress added in v2.0.3

type SeedTaskProgress struct {
	State           *ProgressState
	TaskID          string
	PeerID          string
	ContentLength   int64
	CompletedLength int64
	PeerTaskDone    bool
}

type SeedTaskRequest added in v2.0.3

type SeedTaskRequest struct {
	schedulerv1.PeerTaskRequest
	Limit float64
	Range *http.Range
}

type SeedTaskResponse added in v2.0.3

type SeedTaskResponse struct {
	SubscribeResponse
	Context context.Context
	Span    trace.Span
	TaskID  string
	PeerID  string
}

type StreamTask added in v2.0.2

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 added in v2.0.2

type StreamTaskRequest struct {
	// universal resource locator for different kind of storage
	URL string
	// url meta info
	URLMeta *commonv1.UrlMeta
	// http range
	Range *http.Range
	// peer's id and must be global uniqueness
	PeerID string
	// contains filtered or unexported fields
}

func (*StreamTaskRequest) TaskID added in v2.1.40

func (req *StreamTaskRequest) TaskID() string

type SubscribeResponse added in v2.0.3

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 added in v2.0.6

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

	PeerSearchBroadcaster pex.PeerSearchBroadcaster
}

type TaskOption added in v2.0.6

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 TinyData

type TinyData struct {
	TaskID  string
	PeerID  string
	Content []byte
}

type TrafficShaper added in v2.0.7

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 added in v2.0.7

func NewPlainTrafficShaper() TrafficShaper

func NewSamplingTrafficShaper added in v2.0.7

func NewSamplingTrafficShaper(totalRateLimit rate.Limit, computePieceSize func(int64) uint32) TrafficShaper

func NewTrafficShaper added in v2.0.7

func NewTrafficShaper(trafficShaperType string, totalRateLimit rate.Limit, computePieceSize func(int64) uint32) TrafficShaper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL