peer

package
v2.0.3-beta.6 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 40 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) 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
}

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
	Callsystem         string
	Range              *clientutil.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 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 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 *scheduler.PeerTaskRequest) error
	DownloadPiece(ctx context.Context, request *DownloadPieceRequest) (*DownloadPieceResult, error)
	ImportFile(ctx context.Context, ptm storage.PeerTaskMetadata, tsd storage.TaskStorageDriver, req *dfdaemon.ImportTaskRequest) error
}

func NewPieceManager

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

type ProgressState

type ProgressState struct {
	Success bool
	Code    base.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 {
	scheduler.PeerTaskRequest
	Limit      float64
	Callsystem string
	Range      *clientutil.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 *base.UrlMeta
	// http range
	Range *clientutil.Range
	// peer's id and must be global uniqueness
	PeerID string
	// Pattern to register to scheduler
	Pattern scheduler.Pattern
}

type SubscribeResponse added in v2.0.3

type SubscribeResponse struct {
	Storage          storage.TaskStorageDriver
	PieceInfoChannel chan *PieceInfo
	Success          chan struct{}
	Fail             chan struct{}
}

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
	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, err error)

	Subscribe(request *base.PieceTaskRequest) (*SubscribeResponse, bool)

	IsPeerTaskRunning(taskID string) (Task, bool)

	// StatTask checks whether the given task exists in P2P network
	StatTask(ctx context.Context, taskID string) (*scheduler.Task, error)

	// AnnouncePeerTask announces peer task info to P2P network
	AnnouncePeerTask(ctx context.Context, meta storage.PeerTaskMetadata, cid string, urlMeta *base.UrlMeta) error

	GetPieceManager() PieceManager

	// 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.Client,
	schedulerOption config.SchedulerOption,
	perPeerRateLimit rate.Limit,
	multiplex bool,
	prefetch bool,
	calculateDigest bool,
	getPiecesMaxRetry int,
	watchdog time.Duration) (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