resource

package
v2.0.8-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package resource is a generated GoMock package.

Package resource is a generated GoMock package.

Package resource is a generated GoMock package.

Package resource is a generated GoMock package.

Package resource is a generated GoMock package.

Package resource is a generated GoMock package.

Index

Constants

View Source
const (
	// Default value of tag.
	DefaultTag = "unknow"

	//DefaultApplication default value of application
	DefaultApplication = "unknown"
)
View Source
const (
	// Peer has been created but did not start running.
	PeerStatePending = "Pending"

	// Peer successfully registered as empty scope size.
	PeerStateReceivedEmpty = "ReceivedEmpty"

	// Peer successfully registered as tiny scope size.
	PeerStateReceivedTiny = "ReceivedTiny"

	// Peer successfully registered as small scope size.
	PeerStateReceivedSmall = "ReceivedSmall"

	// Peer successfully registered as normal scope size.
	PeerStateReceivedNormal = "ReceivedNormal"

	// Peer is downloading resources from peer.
	PeerStateRunning = "Running"

	// Peer is downloading resources from back-to-source.
	PeerStateBackToSource = "BackToSource"

	// Peer has been downloaded successfully.
	PeerStateSucceeded = "Succeeded"

	// Peer has been downloaded failed.
	PeerStateFailed = "Failed"

	// Peer has been left.
	PeerStateLeave = "Leave"
)
View Source
const (
	// Peer is registered as empty scope size.
	PeerEventRegisterEmpty = "RegisterEmpty"

	// Peer is registered as tiny scope size.
	PeerEventRegisterTiny = "RegisterTiny"

	// Peer is registered as small scope size.
	PeerEventRegisterSmall = "RegisterSmall"

	// Peer is registered as normal scope size.
	PeerEventRegisterNormal = "RegisterNormal"

	// Peer is downloading.
	PeerEventDownload = "Download"

	// Peer is downloading back-to-source.
	PeerEventDownloadBackToSource = "DownloadBackToSource"

	// Peer downloaded successfully.
	PeerEventDownloadSucceeded = "DownloadSucceeded"

	// Peer downloaded failed.
	PeerEventDownloadFailed = "DownloadFailed"

	// Peer leaves.
	PeerEventLeave = "Leave"
)
View Source
const (
	// SeedTag Default value of tag label for seed peer.
	SeedTag = "d7y/seed"

	// SeedApplication Default value of application label for seed peer.
	SeedApplication = "d7y/seed"
)
View Source
const (
	// Tiny file size is 128 bytes.
	TinyFileSize = 128

	// Empty file size is 0 bytes.
	EmptyFileSize = 0
)
View Source
const (
	// Peer failure limit in task.
	FailedPeerCountLimit = 200

	// Peer count limit for task.
	PeerCountLimitForTask = 10 * 1000
)
View Source
const (
	// Task has been created but did not start running.
	TaskStatePending = "Pending"

	// Task is downloading resources from seed peer or back-to-source.
	TaskStateRunning = "Running"

	// Task has been downloaded successfully.
	TaskStateSucceeded = "Succeeded"

	// Task has been downloaded failed.
	TaskStateFailed = "Failed"

	// Task has no peers.
	TaskStateLeave = "Leave"
)
View Source
const (
	// Task is downloading.
	TaskEventDownload = "Download"

	// Task downloaded successfully.
	TaskEventDownloadSucceeded = "DownloadSucceeded"

	// Task downloaded failed.
	TaskEventDownloadFailed = "DownloadFailed"

	// Task leaves.
	TaskEventLeave = "Leave"
)
View Source
const (
	// GC host id.
	GCHostID = "host"
)
View Source
const (
	// GC peer id.
	GCPeerID = "peer"
)
View Source
const (
	// GC task id.
	GCTaskID = "task"
)
View Source
const (
	// Default value of seed peer failed timeout.
	SeedPeerFailedTimeout = 30 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Host

type Host struct {
	// ID is host id.
	ID string

	// Type is host type.
	Type HostType

	// IP is host ip.
	IP string

	// Hostname is host name.
	Hostname string

	// Port is grpc service port.
	Port int32

	// DownloadPort is piece downloading port.
	DownloadPort int32

	// SecurityDomain is security domain of host.
	SecurityDomain string

	// IDC is internet data center of host.
	IDC string

	// NetTopology is network topology of host.
	// Example: switch|router|...
	NetTopology string

	// Location is location of host.
	// Example: country|province|...
	Location string

	// ConcurrentUploadLimit is concurrent upload limit count.
	ConcurrentUploadLimit *atomic.Int32

	// ConcurrentUploadCount is concurrent upload count.
	ConcurrentUploadCount *atomic.Int32

	// UploadCount is total upload count.
	UploadCount *atomic.Int64

	// UploadFailedCount is upload failed count.
	UploadFailedCount *atomic.Int64

	// Peer sync map.
	Peers *sync.Map

	// PeerCount is peer count.
	PeerCount *atomic.Int32

	// CreateAt is host create time.
	CreateAt *atomic.Time

	// UpdateAt is host update time.
	UpdateAt *atomic.Time

	// Host log.
	Log *logger.SugaredLoggerOnWith
}

func NewHost

func NewHost(rawHost *schedulerv1.PeerHost, options ...HostOption) *Host

New host instance.

func (*Host) DeletePeer

func (h *Host) DeletePeer(key string)

DeletePeer deletes peer for a key.

func (*Host) FreeUploadCount added in v2.0.8

func (h *Host) FreeUploadCount() int32

FreeUploadCount return free upload count of host.

func (*Host) LeavePeers

func (h *Host) LeavePeers()

LeavePeers set peer state to PeerStateLeave.

func (*Host) LoadPeer

func (h *Host) LoadPeer(key string) (*Peer, bool)

LoadPeer return peer for a key.

func (*Host) StorePeer

func (h *Host) StorePeer(peer *Peer)

StorePeer set peer.

type HostManager

type HostManager interface {
	// Load returns host for a key.
	Load(string) (*Host, bool)

	// Store sets host.
	Store(*Host)

	// LoadOrStore returns host the key if present.
	// Otherwise, it stores and returns the given host.
	// The loaded result is true if the host was loaded, false if stored.
	LoadOrStore(*Host) (*Host, bool)

	// Delete deletes host for a key.
	Delete(string)

	// Try to reclaim host.
	RunGC() error
}

type HostOption

type HostOption func(h *Host) *Host

HostOption is a functional option for configuring the host.

func WithConcurrentUploadLimit added in v2.0.8

func WithConcurrentUploadLimit(limit int32) HostOption

WithConcurrentUploadLimit sets host's ConcurrentUploadLimit.

func WithHostType added in v2.0.3

func WithHostType(hostType HostType) HostOption

WithHostType sets host's type.

type HostType added in v2.0.3

type HostType int
const (
	// HostTypeNormal is the normal type of host.
	HostTypeNormal HostType = iota

	// HostTypeSuperSeed is the super seed type of host.
	HostTypeSuperSeed

	// HostTypeStrongSeed is the strong seed type of host.
	HostTypeStrongSeed

	// HostTypeWeakSeed is the weak seed type of host.
	HostTypeWeakSeed
)

type MockHostManager

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

MockHostManager is a mock of HostManager interface.

func NewMockHostManager

func NewMockHostManager(ctrl *gomock.Controller) *MockHostManager

NewMockHostManager creates a new mock instance.

func (*MockHostManager) Delete

func (m *MockHostManager) Delete(arg0 string)

Delete mocks base method.

func (*MockHostManager) EXPECT

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

func (*MockHostManager) Load

func (m *MockHostManager) Load(arg0 string) (*Host, bool)

Load mocks base method.

func (*MockHostManager) LoadOrStore

func (m *MockHostManager) LoadOrStore(arg0 *Host) (*Host, bool)

LoadOrStore mocks base method.

func (*MockHostManager) RunGC

func (m *MockHostManager) RunGC() error

RunGC mocks base method.

func (*MockHostManager) Store

func (m *MockHostManager) Store(arg0 *Host)

Store mocks base method.

type MockHostManagerMockRecorder

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

MockHostManagerMockRecorder is the mock recorder for MockHostManager.

func (*MockHostManagerMockRecorder) Delete

func (mr *MockHostManagerMockRecorder) Delete(arg0 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockHostManagerMockRecorder) Load

func (mr *MockHostManagerMockRecorder) Load(arg0 interface{}) *gomock.Call

Load indicates an expected call of Load.

func (*MockHostManagerMockRecorder) LoadOrStore

func (mr *MockHostManagerMockRecorder) LoadOrStore(arg0 interface{}) *gomock.Call

LoadOrStore indicates an expected call of LoadOrStore.

func (*MockHostManagerMockRecorder) RunGC

RunGC indicates an expected call of RunGC.

func (*MockHostManagerMockRecorder) Store

func (mr *MockHostManagerMockRecorder) Store(arg0 interface{}) *gomock.Call

Store indicates an expected call of Store.

type MockPeerManager

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

MockPeerManager is a mock of PeerManager interface.

func NewMockPeerManager

func NewMockPeerManager(ctrl *gomock.Controller) *MockPeerManager

NewMockPeerManager creates a new mock instance.

func (*MockPeerManager) Delete

func (m *MockPeerManager) Delete(arg0 string)

Delete mocks base method.

func (*MockPeerManager) EXPECT

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

func (*MockPeerManager) Load

func (m *MockPeerManager) Load(arg0 string) (*Peer, bool)

Load mocks base method.

func (*MockPeerManager) LoadOrStore

func (m *MockPeerManager) LoadOrStore(arg0 *Peer) (*Peer, bool)

LoadOrStore mocks base method.

func (*MockPeerManager) RunGC

func (m *MockPeerManager) RunGC() error

RunGC mocks base method.

func (*MockPeerManager) Store

func (m *MockPeerManager) Store(arg0 *Peer)

Store mocks base method.

type MockPeerManagerMockRecorder

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

MockPeerManagerMockRecorder is the mock recorder for MockPeerManager.

func (*MockPeerManagerMockRecorder) Delete

func (mr *MockPeerManagerMockRecorder) Delete(arg0 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockPeerManagerMockRecorder) Load

func (mr *MockPeerManagerMockRecorder) Load(arg0 interface{}) *gomock.Call

Load indicates an expected call of Load.

func (*MockPeerManagerMockRecorder) LoadOrStore

func (mr *MockPeerManagerMockRecorder) LoadOrStore(arg0 interface{}) *gomock.Call

LoadOrStore indicates an expected call of LoadOrStore.

func (*MockPeerManagerMockRecorder) RunGC

RunGC indicates an expected call of RunGC.

func (*MockPeerManagerMockRecorder) Store

func (mr *MockPeerManagerMockRecorder) Store(arg0 interface{}) *gomock.Call

Store indicates an expected call of Store.

type MockResource

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

MockResource is a mock of Resource interface.

func NewMockResource

func NewMockResource(ctrl *gomock.Controller) *MockResource

NewMockResource creates a new mock instance.

func (*MockResource) EXPECT

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

func (*MockResource) HostManager

func (m *MockResource) HostManager() HostManager

HostManager mocks base method.

func (*MockResource) PeerManager

func (m *MockResource) PeerManager() PeerManager

PeerManager mocks base method.

func (*MockResource) SeedPeer added in v2.0.3

func (m *MockResource) SeedPeer() SeedPeer

SeedPeer mocks base method.

func (*MockResource) Stop added in v2.0.7

func (m *MockResource) Stop() error

Stop mocks base method.

func (*MockResource) TaskManager

func (m *MockResource) TaskManager() TaskManager

TaskManager mocks base method.

type MockResourceMockRecorder

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

MockResourceMockRecorder is the mock recorder for MockResource.

func (*MockResourceMockRecorder) HostManager

func (mr *MockResourceMockRecorder) HostManager() *gomock.Call

HostManager indicates an expected call of HostManager.

func (*MockResourceMockRecorder) PeerManager

func (mr *MockResourceMockRecorder) PeerManager() *gomock.Call

PeerManager indicates an expected call of PeerManager.

func (*MockResourceMockRecorder) SeedPeer added in v2.0.3

func (mr *MockResourceMockRecorder) SeedPeer() *gomock.Call

SeedPeer indicates an expected call of SeedPeer.

func (*MockResourceMockRecorder) Stop added in v2.0.7

func (mr *MockResourceMockRecorder) Stop() *gomock.Call

Stop indicates an expected call of Stop.

func (*MockResourceMockRecorder) TaskManager

func (mr *MockResourceMockRecorder) TaskManager() *gomock.Call

TaskManager indicates an expected call of TaskManager.

type MockSeedPeer added in v2.0.3

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

MockSeedPeer is a mock of SeedPeer interface.

func NewMockSeedPeer added in v2.0.3

func NewMockSeedPeer(ctrl *gomock.Controller) *MockSeedPeer

NewMockSeedPeer creates a new mock instance.

func (*MockSeedPeer) Client added in v2.0.3

func (m *MockSeedPeer) Client() SeedPeerClient

Client mocks base method.

func (*MockSeedPeer) EXPECT added in v2.0.3

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

func (*MockSeedPeer) TriggerTask added in v2.0.3

func (m *MockSeedPeer) TriggerTask(arg0 context.Context, arg1 *Task) (*Peer, *v1.PeerResult, error)

TriggerTask mocks base method.

type MockSeedPeerClient added in v2.0.3

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

MockSeedPeerClient is a mock of SeedPeerClient interface.

func NewMockSeedPeerClient added in v2.0.3

func NewMockSeedPeerClient(ctrl *gomock.Controller) *MockSeedPeerClient

NewMockSeedPeerClient creates a new mock instance.

func (*MockSeedPeerClient) Close added in v2.0.3

func (m *MockSeedPeerClient) Close() error

Close mocks base method.

func (*MockSeedPeerClient) EXPECT added in v2.0.3

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

func (*MockSeedPeerClient) GetPieceTasks added in v2.0.3

func (m *MockSeedPeerClient) GetPieceTasks(arg0 context.Context, arg1 *v10.PieceTaskRequest, arg2 ...grpc.CallOption) (*v10.PiecePacket, error)

GetPieceTasks mocks base method.

func (*MockSeedPeerClient) ObtainSeeds added in v2.0.3

ObtainSeeds mocks base method.

func (*MockSeedPeerClient) OnNotify added in v2.0.3

func (m *MockSeedPeerClient) OnNotify(arg0 *config.DynconfigData)

OnNotify mocks base method.

func (*MockSeedPeerClient) SyncPieceTasks added in v2.0.3

SyncPieceTasks mocks base method.

type MockSeedPeerClientMockRecorder added in v2.0.3

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

MockSeedPeerClientMockRecorder is the mock recorder for MockSeedPeerClient.

func (*MockSeedPeerClientMockRecorder) Close added in v2.0.3

Close indicates an expected call of Close.

func (*MockSeedPeerClientMockRecorder) GetPieceTasks added in v2.0.3

func (mr *MockSeedPeerClientMockRecorder) GetPieceTasks(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

GetPieceTasks indicates an expected call of GetPieceTasks.

func (*MockSeedPeerClientMockRecorder) ObtainSeeds added in v2.0.3

func (mr *MockSeedPeerClientMockRecorder) ObtainSeeds(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

ObtainSeeds indicates an expected call of ObtainSeeds.

func (*MockSeedPeerClientMockRecorder) OnNotify added in v2.0.3

func (mr *MockSeedPeerClientMockRecorder) OnNotify(arg0 interface{}) *gomock.Call

OnNotify indicates an expected call of OnNotify.

func (*MockSeedPeerClientMockRecorder) SyncPieceTasks added in v2.0.3

func (mr *MockSeedPeerClientMockRecorder) SyncPieceTasks(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

SyncPieceTasks indicates an expected call of SyncPieceTasks.

type MockSeedPeerMockRecorder added in v2.0.3

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

MockSeedPeerMockRecorder is the mock recorder for MockSeedPeer.

func (*MockSeedPeerMockRecorder) Client added in v2.0.3

func (mr *MockSeedPeerMockRecorder) Client() *gomock.Call

Client indicates an expected call of Client.

func (*MockSeedPeerMockRecorder) TriggerTask added in v2.0.3

func (mr *MockSeedPeerMockRecorder) TriggerTask(arg0, arg1 interface{}) *gomock.Call

TriggerTask indicates an expected call of TriggerTask.

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

func (m *MockTaskManager) Delete(arg0 string)

Delete mocks base method.

func (*MockTaskManager) EXPECT

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

func (*MockTaskManager) Load

func (m *MockTaskManager) Load(arg0 string) (*Task, bool)

Load mocks base method.

func (*MockTaskManager) LoadOrStore

func (m *MockTaskManager) LoadOrStore(arg0 *Task) (*Task, bool)

LoadOrStore mocks base method.

func (*MockTaskManager) RunGC

func (m *MockTaskManager) RunGC() error

RunGC mocks base method.

func (*MockTaskManager) Store

func (m *MockTaskManager) Store(arg0 *Task)

Store mocks base method.

type MockTaskManagerMockRecorder

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

MockTaskManagerMockRecorder is the mock recorder for MockTaskManager.

func (*MockTaskManagerMockRecorder) Delete

func (mr *MockTaskManagerMockRecorder) Delete(arg0 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockTaskManagerMockRecorder) Load

func (mr *MockTaskManagerMockRecorder) Load(arg0 interface{}) *gomock.Call

Load indicates an expected call of Load.

func (*MockTaskManagerMockRecorder) LoadOrStore

func (mr *MockTaskManagerMockRecorder) LoadOrStore(arg0 interface{}) *gomock.Call

LoadOrStore indicates an expected call of LoadOrStore.

func (*MockTaskManagerMockRecorder) RunGC

RunGC indicates an expected call of RunGC.

func (*MockTaskManagerMockRecorder) Store

func (mr *MockTaskManagerMockRecorder) Store(arg0 interface{}) *gomock.Call

Store indicates an expected call of Store.

type Option added in v2.0.3

type Option func(task *Task)

Option is a functional option for task.

func WithBackToSourceLimit added in v2.0.3

func WithBackToSourceLimit(limit int32) Option

WithBackToSourceLimit set BackToSourceLimit for task.

type Peer

type Peer struct {
	// ID is peer id.
	ID string

	// Tag is peer tag.
	Tag string

	// Application is peer application.
	Application string

	// Pieces is finished piece set.
	Pieces set.SafeSet[*schedulerv1.PieceResult]

	// Pieces is finished pieces bitset.
	FinishedPieces *bitset.BitSet

	// Stream is grpc stream instance.
	Stream *atomic.Value

	// Task state machine.
	FSM *fsm.FSM

	// Task is peer task.
	Task *Task

	// Host is peer host.
	Host *Host

	// BlockParents is bad parents ids.
	BlockParents set.SafeSet[string]

	// NeedBackToSource needs downloaded from source.
	//
	// When peer is registering, at the same time,
	// scheduler needs to create the new corresponding task and the seed peer is disabled,
	// NeedBackToSource is set to true.
	NeedBackToSource *atomic.Bool

	// IsBackToSource is downloaded from source.
	//
	// When peer is scheduling and NeedBackToSource is true,
	// scheduler needs to return Code_SchedNeedBackSource and
	// IsBackToSource is set to true.
	IsBackToSource *atomic.Bool

	// CreateAt is peer create time.
	CreateAt *atomic.Time

	// UpdateAt is peer update time.
	UpdateAt *atomic.Time

	// Peer log.
	Log *logger.SugaredLoggerOnWith
	// contains filtered or unexported fields
}

func NewPeer

func NewPeer(id string, task *Task, host *Host, options ...PeerOption) *Peer

New Peer instance.

func (*Peer) AppendPieceCost

func (p *Peer) AppendPieceCost(cost int64)

AppendPieceCost append piece cost to costs slice.

func (*Peer) Children

func (p *Peer) Children() []*Peer

Children returns children of peer.

func (*Peer) DeleteStream

func (p *Peer) DeleteStream()

DeleteStream deletes grpc stream.

func (*Peer) DownloadTinyFile

func (p *Peer) DownloadTinyFile() ([]byte, error)

DownloadTinyFile downloads tiny file from peer.

func (*Peer) LoadStream

LoadStream return grpc stream.

func (*Peer) MainParent added in v2.0.6

func (p *Peer) MainParent() (*Peer, error)

MainParent returns the parent whose peer has downloaded the most pieces.

func (*Peer) Parents added in v2.0.5

func (p *Peer) Parents() []*Peer

Parents returns parents of peer.

func (*Peer) PieceCosts

func (p *Peer) PieceCosts() []int64

PieceCosts return piece costs slice.

func (*Peer) StoreStream

func (p *Peer) StoreStream(stream schedulerv1.Scheduler_ReportPieceResultServer)

StoreStream set grpc stream.

type PeerManager

type PeerManager interface {
	// Load returns peer for a key.
	Load(string) (*Peer, bool)

	// Store sets peer.
	Store(*Peer)

	// LoadOrStore returns peer the key if present.
	// Otherwise, it stores and returns the given peer.
	// The loaded result is true if the peer was loaded, false if stored.
	LoadOrStore(*Peer) (*Peer, bool)

	// Delete deletes peer for a key.
	Delete(string)

	// Try to reclaim peer.
	RunGC() error
}

type PeerOption

type PeerOption func(p *Peer) *Peer

PeerOption is a functional option for configuring the peer.

func WithApplication added in v2.0.6

func WithApplication(application string) PeerOption

WithApplication sets peer's Application.

func WithTag added in v2.0.5

func WithTag(tag string) PeerOption

WithTag sets peer's Tag.

type Resource

type Resource interface {
	// SeedPeer interface.
	SeedPeer() SeedPeer

	// Host manager interface.
	HostManager() HostManager

	// Peer manager interface.
	PeerManager() PeerManager

	// Task manager interface.
	TaskManager() TaskManager

	// Stop resource serivce.
	Stop() error
}

func New

func New(cfg *config.Config, gc gc.GC, dynconfig config.DynconfigInterface, opts ...grpc.DialOption) (Resource, error)

type SeedPeer added in v2.0.3

type SeedPeer interface {
	// TriggerTask triggers the seed peer to download the task.
	TriggerTask(context.Context, *Task) (*Peer, *schedulerv1.PeerResult, error)

	// Client returns grpc client of seed peer.
	Client() SeedPeerClient
}

type SeedPeerClient added in v2.0.3

type SeedPeerClient interface {
	// client is seed peer grpc client interface.
	client.Client

	// Observer is dynconfig observer interface.
	config.Observer
}

type Task

type Task struct {
	// ID is task id.
	ID string

	// URL is task download url.
	URL string

	// Type is task type.
	Type commonv1.TaskType

	// URLMeta is task download url meta.
	URLMeta *commonv1.UrlMeta

	// DirectPiece is tiny piece data.
	DirectPiece []byte

	// ContentLength is task total content length.
	ContentLength *atomic.Int64

	// TotalPieceCount is total piece count.
	TotalPieceCount *atomic.Int32

	// BackToSourceLimit is back-to-source limit.
	BackToSourceLimit *atomic.Int32

	// BackToSourcePeers is back-to-source sync map.
	BackToSourcePeers set.SafeSet[string]

	// Task state machine.
	FSM *fsm.FSM

	// Piece sync map.
	Pieces *sync.Map

	// DAG is directed acyclic graph of peers.
	DAG dag.DAG[*Peer]

	// PeerFailedCount is peer failed count,
	// if one peer succeeds, the value is reset to zero.
	PeerFailedCount *atomic.Int32

	// CreateAt is task create time.
	CreateAt *atomic.Time

	// UpdateAt is task update time.
	UpdateAt *atomic.Time

	// Task log.
	Log *logger.SugaredLoggerOnWith
}

func NewTask

func NewTask(id, url string, taskType commonv1.TaskType, meta *commonv1.UrlMeta, options ...Option) *Task

New task instance.

func (*Task) AddPeerEdge added in v2.0.5

func (t *Task) AddPeerEdge(fromPeer *Peer, toPeer *Peer) error

AddPeerEdge adds inedges between two peers.

func (*Task) CanAddPeerEdge added in v2.0.5

func (t *Task) CanAddPeerEdge(fromPeerKey, toPeerKey string) bool

CanAddPeerEdge finds whether there are peer circles through depth-first search.

func (*Task) CanBackToSource

func (t *Task) CanBackToSource() bool

CanBackToSource represents whether task can back-to-source.

func (*Task) CanReuseDirectPiece added in v2.0.7

func (t *Task) CanReuseDirectPiece() bool

CanReuseDirectPiece represents whether task can reuse data of direct piece.

func (*Task) DeletePeer

func (t *Task) DeletePeer(key string)

DeletePeer deletes peer for a key.

func (*Task) DeletePeerInEdges added in v2.0.5

func (t *Task) DeletePeerInEdges(key string) error

DeletePeerInEdges deletes inedges of peer.

func (*Task) DeletePeerOutEdges added in v2.0.5

func (t *Task) DeletePeerOutEdges(key string) error

DeletePeerOutEdges deletes outedges of peer.

func (*Task) DeletePiece

func (t *Task) DeletePiece(key int32)

DeletePiece deletes piece for a key.

func (*Task) HasAvailablePeer

func (t *Task) HasAvailablePeer() bool

HasAvailablePeer returns whether there is an available peer.

func (*Task) IsSeedPeerFailed added in v2.0.3

func (t *Task) IsSeedPeerFailed() bool

IsSeedPeerFailed returns whether the seed peer in the task failed.

func (*Task) LoadPeer

func (t *Task) LoadPeer(key string) (*Peer, bool)

LoadPeer return peer for a key.

func (*Task) LoadPiece

func (t *Task) LoadPiece(key int32) (*commonv1.PieceInfo, bool)

LoadPiece return piece for a key.

func (*Task) LoadRandomPeers added in v2.0.5

func (t *Task) LoadRandomPeers(n uint) []*Peer

LoadRandomPeers return random peers.

func (*Task) LoadSeedPeer added in v2.0.3

func (t *Task) LoadSeedPeer() (*Peer, bool)

LoadSeedPeer return latest seed peer in peers sync map.

func (*Task) NotifyPeers

func (t *Task) NotifyPeers(peerPacket *schedulerv1.PeerPacket, event string)

NotifyPeers notify all peers in the task with the state code.

func (*Task) PeerCount

func (t *Task) PeerCount() int

PeerCount returns count of peer.

func (*Task) PeerDegree added in v2.0.5

func (t *Task) PeerDegree(key string) (int, error)

PeerDegree returns the degree of peer.

func (*Task) PeerInDegree added in v2.0.5

func (t *Task) PeerInDegree(key string) (int, error)

PeerInDegree returns the indegree of peer.

func (*Task) PeerOutDegree added in v2.0.5

func (t *Task) PeerOutDegree(key string) (int, error)

PeerOutDegree returns the outdegree of peer.

func (*Task) SizeScope

func (t *Task) SizeScope() (commonv1.SizeScope, error)

SizeScope return task size scope type.

func (*Task) StorePeer

func (t *Task) StorePeer(peer *Peer)

StorePeer set peer.

func (*Task) StorePiece

func (t *Task) StorePiece(piece *commonv1.PieceInfo)

StorePiece set piece.

type TaskManager

type TaskManager interface {
	// Load returns task for a key.
	Load(string) (*Task, bool)

	// Store sets task.
	Store(*Task)

	// LoadOrStore returns task the key if present.
	// Otherwise, it stores and returns the given task.
	// The loaded result is true if the task was loaded, false if stored.
	LoadOrStore(*Task) (*Task, bool)

	// Delete deletes task for a key.
	Delete(string)

	// Try to reclaim task.
	RunGC() error
}

Jump to

Keyboard shortcuts

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