Documentation ¶
Index ¶
- Constants
- Variables
- type CDN
- type CDNDynmaicClient
- type Channel
- type Host
- type HostManager
- type HostOption
- type Peer
- func (peer *Peer) BindNewConn(stream scheduler.Scheduler_ReportPieceResultServer) (*Channel, bool)
- func (peer *Peer) CloseChannelWithError(err error) error
- func (peer *Peer) GetChildren() *sync.Map
- func (peer *Peer) GetParent() (*Peer, bool)
- func (peer *Peer) GetPieceCosts() []int
- func (peer *Peer) GetRoot() *Peer
- func (peer *Peer) GetStatus() PeerStatus
- func (peer *Peer) GetTreeDepth() int
- func (peer *Peer) GetTreeNodeCount() int
- func (peer *Peer) IsAncestor(offspring *Peer) bool
- func (peer *Peer) IsBad() bool
- func (peer *Peer) IsConnected() bool
- func (peer *Peer) IsDescendant(ancestor *Peer) bool
- func (peer *Peer) IsDone() bool
- func (peer *Peer) IsFail() bool
- func (peer *Peer) IsLeave() bool
- func (peer *Peer) IsRunning() bool
- func (peer *Peer) IsSuccess() bool
- func (peer *Peer) IsWaiting() bool
- func (peer *Peer) Leave()
- func (peer *Peer) Log() *logger.SugaredLoggerOnWith
- func (peer *Peer) ReplaceParent(parent *Peer)
- func (peer *Peer) SendSchedulePacket(packet *scheduler.PeerPacket) error
- func (peer *Peer) SetParent(parent *Peer)
- func (peer *Peer) SetPieceCosts(costs ...int)
- func (peer *Peer) SetStatus(status PeerStatus)
- func (peer *Peer) SortedValue() int
- func (peer *Peer) Touch()
- func (peer *Peer) UpdateProgress(finishedCount int32, cost int)
- type PeerManager
- type PeerStatus
- type Task
- func (task *Task) AddBackToSourcePeer(peerID string)
- func (task *Task) AddPeer(peer *Peer)
- func (task *Task) CanBackToSource() bool
- func (task *Task) CanSchedule() bool
- func (task *Task) ContainsBackToSourcePeer(peerID string) bool
- func (task *Task) DeletePeer(peer *Peer)
- func (task *Task) GetBackToSourcePeers() []string
- func (task *Task) GetOrAddPiece(p *base.PieceInfo) (*base.PieceInfo, bool)
- func (task *Task) GetPeers() list.SortedUniqueList
- func (task *Task) GetPiece(n int32) (*base.PieceInfo, bool)
- func (task *Task) GetStatus() TaskStatus
- func (task *Task) IsFail() bool
- func (task *Task) IsHealth() bool
- func (task *Task) IsSuccess() bool
- func (task *Task) IsWaiting() bool
- func (task *Task) Log() *logger.SugaredLoggerOnWith
- func (task *Task) Pick(limit int, pickFn func(peer *Peer) bool) []*Peer
- func (task *Task) PickReverse(limit int, pickFn func(peer *Peer) bool) []*Peer
- func (task *Task) SetStatus(status TaskStatus)
- func (task *Task) Touch()
- func (task *Task) UpdatePeer(peer *Peer)
- func (task *Task) UpdateSuccess(pieceCount int32, contentLength int64)
- type TaskManager
- type TaskStatus
Constants ¶
View Source
const ( TaskGCID = "task" TinyFileSize = 128 )
View Source
const (
// When using the manager configuration parameter, limit the maximum load number to 5000
HostMaxLoad = 5 * 1000
)
View Source
const (
PeerGCID = "peer"
)
Variables ¶
View Source
var ( ErrCDNClientUninitialized = errors.New("cdn client is not initialized") ErrCDNRegisterFail = errors.New("cdn task register failed") ErrCDNDownloadFail = errors.New("cdn task download failed") ErrCDNUnknown = errors.New("cdn obtain seed encounter unknown err") ErrCDNInvokeFail = errors.New("invoke cdn interface failed") ErrInitCDNPeerFail = errors.New("init cdn peer failed") )
View Source
var ErrChannelBusy = errors.New("channel busy")
Functions ¶
This section is empty.
Types ¶
type CDN ¶ added in v2.0.1
type CDN interface { // CetClient get cdn grpc client GetClient() CDNDynmaicClient // StartSeedTask start seed cdn task StartSeedTask(context.Context, *Task) (*Peer, error) }
func NewCDN ¶ added in v2.0.1
func NewCDN(client CDNDynmaicClient, peerManager PeerManager, hostManager HostManager) CDN
type CDNDynmaicClient ¶ added in v2.0.1
type CDNDynmaicClient interface { // cdnclient is cdn grpc client cdnclient.CdnClient // Observer is dynconfig observer config.Observer // Get cdn host GetHost(hostID string) (*Host, bool) }
func NewCDNDynmaicClient ¶ added in v2.0.1
func NewCDNDynmaicClient(dynConfig config.DynconfigInterface, opts []grpc.DialOption) (CDNDynmaicClient, error)
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
func (*Channel) Receiver ¶
func (c *Channel) Receiver() <-chan *scheduler.PieceResult
type Host ¶ added in v2.0.1
type Host struct { // uuid each time the daemon starts, it will generate a different uuid UUID string // IP peer host ip IP string // HostName peer host name HostName string // RPCPort rpc service port for peer RPCPort int32 // DownloadPort piece downloading port for peer DownloadPort int32 // IsCDN if host type is cdn IsCDN bool // SecurityDomain security isolation domain for network SecurityDomain string // Location location path: area|country|province|city|... Location string // IDC idc where the peer host is located IDC string // NetTopology network device path // according to the user's own network topology definition, the coverage range from large to small, using the | symbol segmentation, // Example: switch|router|... NetTopology string // TODO TotalUploadLoad currentUploadLoad decided by real time client report host info TotalUploadLoad uint32 // CurrentUploadLoad is current upload load number CurrentUploadLoad atomic.Uint32 // contains filtered or unexported fields }
func NewCDNHost ¶ added in v2.0.1
func NewCDNHost(uuid, ip, hostname string, rpcPort, downloadPort int32, securityDomain, location, idc string, options ...HostOption) *Host
func NewClientHost ¶ added in v2.0.1
func NewClientHost(uuid, ip, hostname string, rpcPort, downloadPort int32, securityDomain, location, idc string, options ...HostOption) *Host
func (*Host) DeletePeer ¶ added in v2.0.1
func (*Host) GetFreeUploadLoad ¶ added in v2.0.1
func (*Host) GetPeersLen ¶ added in v2.0.1
func (*Host) Log ¶ added in v2.0.1
func (h *Host) Log() *logger.SugaredLoggerOnWith
type HostManager ¶ added in v2.0.1
type HostManager interface { // Add host Add(*Host) // Get host Get(string) (*Host, bool) // Delete host Delete(string) }
func NewHostManager ¶ added in v2.0.1
func NewHostManager() HostManager
type HostOption ¶ added in v2.0.1
func WithNetTopology ¶ added in v2.0.1
func WithNetTopology(n string) HostOption
func WithTotalUploadLoad ¶ added in v2.0.1
func WithTotalUploadLoad(load uint32) HostOption
type Peer ¶
type Peer struct { // ID is ID of peer ID string // Task is peer task Task *Task // Host is peer host Host *Host // TotalPieceCount is downloaded finished piece count TotalPieceCount atomic.Int32 // CreateAt is peer create time CreateAt *atomic.Time // contains filtered or unexported fields }
func (*Peer) BindNewConn ¶
func (peer *Peer) BindNewConn(stream scheduler.Scheduler_ReportPieceResultServer) (*Channel, bool)
func (*Peer) CloseChannelWithError ¶ added in v2.0.1
func (*Peer) GetChildren ¶
func (*Peer) GetPieceCosts ¶ added in v2.0.1
func (*Peer) GetStatus ¶
func (peer *Peer) GetStatus() PeerStatus
func (*Peer) GetTreeDepth ¶ added in v2.0.1
func (*Peer) GetTreeNodeCount ¶ added in v2.0.1
func (*Peer) IsAncestor ¶ added in v2.0.1
IsAncestorOf if offspring is offspring of peer
func (*Peer) IsConnected ¶
func (*Peer) IsDescendant ¶ added in v2.0.1
IsDescendant if peer is offspring of ancestor
func (*Peer) Log ¶
func (peer *Peer) Log() *logger.SugaredLoggerOnWith
func (*Peer) ReplaceParent ¶
func (*Peer) SendSchedulePacket ¶
func (peer *Peer) SendSchedulePacket(packet *scheduler.PeerPacket) error
func (*Peer) SetPieceCosts ¶ added in v2.0.1
func (*Peer) SetStatus ¶
func (peer *Peer) SetStatus(status PeerStatus)
func (*Peer) SortedValue ¶ added in v2.0.1
func (*Peer) UpdateProgress ¶
type PeerManager ¶ added in v2.0.1
type PeerManager interface { // Add peer Add(*Peer) // Get peer Get(string) (*Peer, bool) // Delete peer Delete(string) // Get peer by task id GetPeersByTask(string) []*Peer // Get peers GetPeers() *sync.Map }
func NewPeerManager ¶ added in v2.0.1
func NewPeerManager(cfg *config.GCConfig, gcManager gc.GC, hostManager HostManager) (PeerManager, error)
type PeerStatus ¶
type PeerStatus uint8
const ( PeerStatusWaiting PeerStatus = iota PeerStatusRunning // TODO add Seeding status PeerStatusZombie PeerStatusFail PeerStatusSuccess )
func (PeerStatus) String ¶
func (status PeerStatus) String() string
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 // CreateAt is peer create time CreateAt *atomic.Time // LastTriggerAt is peer last trigger time LastTriggerAt *atomic.Time // BackToSourceWeight is back-to-source peer weight BackToSourceWeight atomic.Int32 // TotalPieceCount is total piece count TotalPieceCount atomic.Int32 // contains filtered or unexported fields }
func (*Task) AddBackToSourcePeer ¶ added in v2.0.1
func (*Task) CanBackToSource ¶ added in v2.0.1
func (*Task) CanSchedule ¶
CanSchedule determines whether task can be scheduled only task status is seeding or success can be scheduled
func (*Task) ContainsBackToSourcePeer ¶ added in v2.0.1
func (*Task) DeletePeer ¶
func (*Task) GetBackToSourcePeers ¶ added in v2.0.1
func (*Task) GetOrAddPiece ¶ added in v2.0.1
func (*Task) GetPeers ¶ added in v2.0.1
func (task *Task) GetPeers() list.SortedUniqueList
func (*Task) GetStatus ¶
func (task *Task) GetStatus() TaskStatus
func (*Task) Log ¶
func (task *Task) Log() *logger.SugaredLoggerOnWith
func (*Task) PickReverse ¶
func (*Task) SetStatus ¶
func (task *Task) SetStatus(status TaskStatus)
func (*Task) UpdatePeer ¶
func (*Task) UpdateSuccess ¶ added in v2.0.1
type TaskManager ¶ added in v2.0.1
type TaskManager interface { // Add task Add(*Task) // Get task Get(string) (*Task, bool) // Delete task Delete(string) // Get or add task GetOrAdd(*Task) (*Task, bool) }
func NewTaskManager ¶ added in v2.0.1
func NewTaskManager(cfg *config.GCConfig, gcManager gc.GC, peerManager PeerManager) (TaskManager, error)
type TaskStatus ¶
type TaskStatus uint8
const ( TaskStatusWaiting TaskStatus = iota TaskStatusRunning TaskStatusSeeding TaskStatusSuccess TaskStatusZombie TaskStatusFail )
func (TaskStatus) String ¶
func (status TaskStatus) String() string
Click to show internal directories.
Click to hide internal directories.