peer

package
v2.0.2-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: Apache-2.0 Imports: 38 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 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 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
	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
}

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 {
	scheduler.PeerTaskRequest
	Output            string
	Limit             float64
	DisableBackSource bool
	Pattern           string
	Callsystem        string
}

type Logger added in v2.0.2

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

type PieceDownloader

type PieceDownloader interface {
	DownloadPiece(context.Context, *DownloadPieceRequest) (io.Reader, io.Closer, 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, request *DownloadPieceRequest) (*DownloadPieceResult, error)
}

func NewPieceManager

func NewPieceManager(s storage.TaskStorageDriver, pieceDownloadTimeout time.Duration, opts ...func(*pieceManager)) (PieceManager, error)

type ProgressState

type ProgressState struct {
	Success bool
	Code    base.Code
	Msg     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 *base.UrlMeta
	// peer's id and must be global uniqueness
	PeerID string
}

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)
}

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, tiny *TinyData, err error)
	// StartStreamTask starts a peer task with stream io
	// tiny stands task file is tiny and task is done
	StartStreamTask(ctx context.Context, req *StreamTaskRequest) (
		readCloser io.ReadCloser, attribute map[string]string, err error)

	IsPeerTaskRunning(id 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)

type TinyData

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

Jump to

Keyboard shortcuts

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