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.
Index ¶
- Constants
- type CDN
- type CDNClient
- type Host
- type HostManager
- type HostOption
- type MockCDN
- type MockCDNClient
- func (m *MockCDNClient) Close() error
- func (m *MockCDNClient) EXPECT() *MockCDNClientMockRecorder
- func (m *MockCDNClient) GetPieceTasks(ctx context.Context, addr dfnet.NetAddr, req *base.PieceTaskRequest, ...) (*base.PiecePacket, error)
- func (m *MockCDNClient) ObtainSeeds(ctx context.Context, sr *cdnsystem.SeedRequest, opts ...grpc.CallOption) (*client.PieceSeedStream, error)
- func (m *MockCDNClient) OnNotify(arg0 *config.DynconfigData)
- func (m *MockCDNClient) UpdateState(addrs []dfnet.NetAddr)
- type MockCDNClientMockRecorder
- func (mr *MockCDNClientMockRecorder) Close() *gomock.Call
- func (mr *MockCDNClientMockRecorder) GetPieceTasks(ctx, addr, req interface{}, opts ...interface{}) *gomock.Call
- func (mr *MockCDNClientMockRecorder) ObtainSeeds(ctx, sr interface{}, opts ...interface{}) *gomock.Call
- func (mr *MockCDNClientMockRecorder) OnNotify(arg0 interface{}) *gomock.Call
- func (mr *MockCDNClientMockRecorder) UpdateState(addrs interface{}) *gomock.Call
- type MockCDNMockRecorder
- type MockHostManager
- func (m *MockHostManager) Delete(arg0 string)
- func (m *MockHostManager) EXPECT() *MockHostManagerMockRecorder
- func (m *MockHostManager) Load(arg0 string) (*Host, bool)
- func (m *MockHostManager) LoadOrStore(arg0 *Host) (*Host, bool)
- func (m *MockHostManager) RunGC() error
- func (m *MockHostManager) Store(arg0 *Host)
- type MockHostManagerMockRecorder
- func (mr *MockHostManagerMockRecorder) Delete(arg0 interface{}) *gomock.Call
- func (mr *MockHostManagerMockRecorder) Load(arg0 interface{}) *gomock.Call
- func (mr *MockHostManagerMockRecorder) LoadOrStore(arg0 interface{}) *gomock.Call
- func (mr *MockHostManagerMockRecorder) RunGC() *gomock.Call
- func (mr *MockHostManagerMockRecorder) Store(arg0 interface{}) *gomock.Call
- type MockPeerManager
- func (m *MockPeerManager) Delete(arg0 string)
- func (m *MockPeerManager) EXPECT() *MockPeerManagerMockRecorder
- func (m *MockPeerManager) Load(arg0 string) (*Peer, bool)
- func (m *MockPeerManager) LoadOrStore(arg0 *Peer) (*Peer, bool)
- func (m *MockPeerManager) RunGC() error
- func (m *MockPeerManager) Store(arg0 *Peer)
- type MockPeerManagerMockRecorder
- func (mr *MockPeerManagerMockRecorder) Delete(arg0 interface{}) *gomock.Call
- func (mr *MockPeerManagerMockRecorder) Load(arg0 interface{}) *gomock.Call
- func (mr *MockPeerManagerMockRecorder) LoadOrStore(arg0 interface{}) *gomock.Call
- func (mr *MockPeerManagerMockRecorder) RunGC() *gomock.Call
- func (mr *MockPeerManagerMockRecorder) Store(arg0 interface{}) *gomock.Call
- type MockResource
- type MockResourceMockRecorder
- type MockTaskManager
- func (m *MockTaskManager) Delete(arg0 string)
- func (m *MockTaskManager) EXPECT() *MockTaskManagerMockRecorder
- func (m *MockTaskManager) Load(arg0 string) (*Task, bool)
- func (m *MockTaskManager) LoadOrStore(arg0 *Task) (*Task, bool)
- func (m *MockTaskManager) RunGC() error
- func (m *MockTaskManager) Store(arg0 *Task)
- type MockTaskManagerMockRecorder
- func (mr *MockTaskManagerMockRecorder) Delete(arg0 interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) Load(arg0 interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) LoadOrStore(arg0 interface{}) *gomock.Call
- func (mr *MockTaskManagerMockRecorder) RunGC() *gomock.Call
- func (mr *MockTaskManagerMockRecorder) Store(arg0 interface{}) *gomock.Call
- type Peer
- func (p *Peer) AppendPieceCost(cost int64)
- func (p *Peer) DeleteChild(key string)
- func (p *Peer) DeleteParent()
- func (p *Peer) DeleteStream()
- func (p *Peer) DownloadTinyFile() ([]byte, error)
- func (p *Peer) IsAncestor(descendant *Peer) bool
- func (p *Peer) IsDescendant(ancestor *Peer) bool
- func (p *Peer) LenChildren() int
- func (p *Peer) LoadChild(key string) (*Peer, bool)
- func (p *Peer) LoadParent() (*Peer, bool)
- func (p *Peer) LoadStream() (scheduler.Scheduler_ReportPieceResultServer, bool)
- func (p *Peer) PieceCosts() []int64
- func (p *Peer) ReplaceParent(parent *Peer)
- func (p *Peer) StoreChild(child *Peer)
- func (p *Peer) StoreParent(parent *Peer)
- func (p *Peer) StoreStream(stream scheduler.Scheduler_ReportPieceResultServer)
- func (p *Peer) TreeTotalNodeCount() int
- type PeerManager
- type Resource
- type Task
- func (t *Task) CanBackToSource() bool
- func (t *Task) DeletePeer(key string)
- func (t *Task) DeletePiece(key int32)
- func (t *Task) LenAvailablePeers() int
- func (t *Task) LenPeers() int
- func (t *Task) LoadCDNPeer() (*Peer, bool)
- func (t *Task) LoadOrStorePeer(peer *Peer) (*Peer, bool)
- func (t *Task) LoadOrStorePiece(piece *base.PieceInfo) (*base.PieceInfo, bool)
- func (t *Task) LoadPeer(key string) (*Peer, bool)
- func (t *Task) LoadPiece(key int32) (*base.PieceInfo, bool)
- func (t *Task) SizeScope() base.SizeScope
- func (t *Task) StorePeer(peer *Peer)
- func (t *Task) StorePiece(piece *base.PieceInfo)
- type TaskManager
Constants ¶
const ( // Peer has been created but did not start running PeerStatePending = "Pending" // 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" )
const ( // 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 from back-to-source PeerEventDownloadFromBackToSource = "DownloadFromBackToSource" // Peer downloaded successfully PeerEventDownloadSucceeded = "DownloadSucceeded" // Peer downloaded failed PeerEventDownloadFailed = "DownloadFailed" // Peer back to initial pending state PeerEventRestart = "Restart" // Peer leaves PeerEventLeave = "Leave" )
const ( // Task has been created but did not start running TaskStatePending = "Pending" // Task is downloading resources from CDN or back-to-source TaskStateRunning = "Running" // Task has been downloaded successfully TaskStateSucceeded = "Succeeded" // Task has been downloaded failed TaskStateFailed = "Failed" )
const ( // Task is downloading TaskEventDownload = "Download" // Task downloaded successfully TaskEventDownloadSucceeded = "DownloadSucceeded" // Task downloaded failed TaskEventDownloadFailed = "DownloadFailed" )
const (
// GC host id
GCHostID = "host"
)
const (
// GC peer id
GCPeerID = "peer"
)
const (
// GC task id
GCTaskID = "task"
)
const (
// Tiny file size is 128 bytes
TinyFileSize = 128
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CDN ¶
type CDN interface { // TriggerTask start to trigger cdn task TriggerTask(context.Context, *Task) (*Peer, *rpcscheduler.PeerResult, error) // Client is cdn grpc client Client() CDNClient }
type Host ¶
type Host struct { // ID is host id ID string // 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 // UploadLoadLimit is upload load limit count UploadLoadLimit *atomic.Int32 // Peer sync map Peers *sync.Map // IsCDN is used as tag cdn IsCDN bool // 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 *scheduler.PeerHost, options ...HostOption) *Host
New host instance
func (*Host) FreeUploadLoad ¶
FreeUploadLoad return free upload load of host
func (*Host) LoadOrStorePeer ¶
LoadOrStorePeer 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.
type HostManager ¶
type HostManager interface { // Load return host for a key Load(string) (*Host, bool) // Store set 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 ¶
HostOption is a functional option for configuring the host
func WithUploadLoadLimit ¶
func WithUploadLoadLimit(limit int32) HostOption
WithUploadLoadLimit sets host's UploadLoadLimit
type MockCDN ¶
type MockCDN struct {
// contains filtered or unexported fields
}
MockCDN is a mock of CDN interface.
func NewMockCDN ¶
func NewMockCDN(ctrl *gomock.Controller) *MockCDN
NewMockCDN creates a new mock instance.
func (*MockCDN) EXPECT ¶
func (m *MockCDN) EXPECT() *MockCDNMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockCDN) TriggerTask ¶
func (m *MockCDN) TriggerTask(arg0 context.Context, arg1 *Task) (*Peer, *scheduler.PeerResult, error)
TriggerTask mocks base method.
type MockCDNClient ¶
type MockCDNClient struct {
// contains filtered or unexported fields
}
MockCDNClient is a mock of CDNClient interface.
func NewMockCDNClient ¶
func NewMockCDNClient(ctrl *gomock.Controller) *MockCDNClient
NewMockCDNClient creates a new mock instance.
func (*MockCDNClient) EXPECT ¶
func (m *MockCDNClient) EXPECT() *MockCDNClientMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockCDNClient) GetPieceTasks ¶
func (m *MockCDNClient) GetPieceTasks(ctx context.Context, addr dfnet.NetAddr, req *base.PieceTaskRequest, opts ...grpc.CallOption) (*base.PiecePacket, error)
GetPieceTasks mocks base method.
func (*MockCDNClient) ObtainSeeds ¶
func (m *MockCDNClient) ObtainSeeds(ctx context.Context, sr *cdnsystem.SeedRequest, opts ...grpc.CallOption) (*client.PieceSeedStream, error)
ObtainSeeds mocks base method.
func (*MockCDNClient) OnNotify ¶
func (m *MockCDNClient) OnNotify(arg0 *config.DynconfigData)
OnNotify mocks base method.
func (*MockCDNClient) UpdateState ¶
func (m *MockCDNClient) UpdateState(addrs []dfnet.NetAddr)
UpdateState mocks base method.
type MockCDNClientMockRecorder ¶
type MockCDNClientMockRecorder struct {
// contains filtered or unexported fields
}
MockCDNClientMockRecorder is the mock recorder for MockCDNClient.
func (*MockCDNClientMockRecorder) Close ¶
func (mr *MockCDNClientMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close.
func (*MockCDNClientMockRecorder) GetPieceTasks ¶
func (mr *MockCDNClientMockRecorder) GetPieceTasks(ctx, addr, req interface{}, opts ...interface{}) *gomock.Call
GetPieceTasks indicates an expected call of GetPieceTasks.
func (*MockCDNClientMockRecorder) ObtainSeeds ¶
func (mr *MockCDNClientMockRecorder) ObtainSeeds(ctx, sr interface{}, opts ...interface{}) *gomock.Call
ObtainSeeds indicates an expected call of ObtainSeeds.
func (*MockCDNClientMockRecorder) OnNotify ¶
func (mr *MockCDNClientMockRecorder) OnNotify(arg0 interface{}) *gomock.Call
OnNotify indicates an expected call of OnNotify.
func (*MockCDNClientMockRecorder) UpdateState ¶
func (mr *MockCDNClientMockRecorder) UpdateState(addrs interface{}) *gomock.Call
UpdateState indicates an expected call of UpdateState.
type MockCDNMockRecorder ¶
type MockCDNMockRecorder struct {
// contains filtered or unexported fields
}
MockCDNMockRecorder is the mock recorder for MockCDN.
func (*MockCDNMockRecorder) Client ¶
func (mr *MockCDNMockRecorder) Client() *gomock.Call
Client indicates an expected call of Client.
func (*MockCDNMockRecorder) TriggerTask ¶
func (mr *MockCDNMockRecorder) TriggerTask(arg0, arg1 interface{}) *gomock.Call
TriggerTask indicates an expected call of TriggerTask.
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 ¶
func (m *MockHostManager) EXPECT() *MockHostManagerMockRecorder
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) 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 ¶
func (mr *MockHostManagerMockRecorder) RunGC() *gomock.Call
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 ¶
func (m *MockPeerManager) EXPECT() *MockPeerManagerMockRecorder
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) 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 ¶
func (mr *MockPeerManagerMockRecorder) RunGC() *gomock.Call
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 ¶
func (m *MockResource) EXPECT() *MockResourceMockRecorder
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) 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) CDN ¶
func (mr *MockResourceMockRecorder) CDN() *gomock.Call
CDN indicates an expected call of CDN.
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) TaskManager ¶
func (mr *MockResourceMockRecorder) TaskManager() *gomock.Call
TaskManager indicates an expected call of TaskManager.
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 ¶
func (m *MockTaskManager) EXPECT() *MockTaskManagerMockRecorder
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) 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 ¶
func (mr *MockTaskManagerMockRecorder) RunGC() *gomock.Call
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 Peer ¶
type Peer struct { // ID is peer id ID string // Pieces is piece bitset Pieces *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 // Parent is peer parent Parent *atomic.Value // Children is peer children Children *sync.Map // 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 (*Peer) AppendPieceCost ¶
AppendPieceCost append piece cost to costs slice
func (*Peer) DeleteChild ¶
DeleteChild deletes peer child for a key
func (*Peer) DownloadTinyFile ¶
DownloadTinyFile downloads tiny file from peer
func (*Peer) IsAncestor ¶
IsAncestor determines whether it is descendant of peer
func (*Peer) IsDescendant ¶
IsDescendant determines whether it is ancestor of peer
func (*Peer) LenChildren ¶
LenChildren return length of children sync map
func (*Peer) LoadStream ¶
func (p *Peer) LoadStream() (scheduler.Scheduler_ReportPieceResultServer, bool)
LoadStream return grpc stream
func (*Peer) ReplaceParent ¶
ReplaceParent replaces peer parent
func (*Peer) StoreStream ¶
func (p *Peer) StoreStream(stream scheduler.Scheduler_ReportPieceResultServer)
StoreStream set grpc stream
func (*Peer) TreeTotalNodeCount ¶
TreeTotalNodeCount represents tree's total node count
type PeerManager ¶
type PeerManager interface { // Load return peer for a key Load(string) (*Peer, bool) // Store set 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 Resource ¶
type Resource interface { // CDN interface CDN() CDN // Host manager interface HostManager() HostManager // Peer manager interface PeerManager() PeerManager // Task manager interface TaskManager() TaskManager }
type Task ¶
type Task struct { // ID is task id ID string // URL is task download url URL string // URLMeta is task download url meta URLMeta *base.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 // Task state machine FSM *fsm.FSM // Piece sync map Pieces *sync.Map // Peer sync map Peers *sync.Map // CreateAt is task create time CreateAt *atomic.Time // UpdateAt is task update time UpdateAt *atomic.Time // Task log Log *logger.SugaredLoggerOnWith }
func (*Task) CanBackToSource ¶
CanBackToSource represents whether peer can back-to-source
func (*Task) DeletePiece ¶
DeletePiece deletes piece for a key
func (*Task) LenAvailablePeers ¶
LenAvailablePeers return length of peers without state is PeerStateLeave
func (*Task) LoadCDNPeer ¶
LoadCDNPeer return latest cdn peer in peers sync map
func (*Task) LoadOrStorePeer ¶
LoadOrStorePeer 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.
func (*Task) LoadOrStorePiece ¶
LoadOrStorePiece returns piece the key if present. Otherwise, it stores and returns the given piece. The loaded result is true if the piece was loaded, false if stored.
type TaskManager ¶
type TaskManager interface { // Load return task for a key Load(string) (*Task, bool) // Store set 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 }