peer

package
v0.1.0-beta-3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCalculateDigest

func WithCalculateDigest(enable bool) func(*pieceManager)

func WithLimiter

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

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
}

func NewBitmap

func NewBitmap() *Bitmap

func NewBitmapWithCap

func NewBitmapWithCap(c int32) *Bitmap

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
	DstPid     string
	DstAddr    string
	CalcDigest bool
	// contains filtered or unexported fields
}

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 FilePeerTaskProgress struct {
	State           *ProgressState
	TaskID          string
	PeerID          string
	ContentLength   int64
	CompletedLength int64
	PeerTaskDone    bool
	DoneCallback    func()
}

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 ProgressState

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

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)

type TinyData

type TinyData struct {
	TaskID  string
	PeerID  string
	Content []byte
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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