types

package
v0.1.0-beta-3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostTypePeer = 1
	HostTypeCdn  = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Host

type Host struct {
	scheduler.PeerHost

	Type HostType // peer / cdn

	// ServiceDownTime the down time of the peer service.
	ServiceDownTime int64
	// contains filtered or unexported fields
}

func Init

func Init(h *Host) *Host

func (*Host) AddDownloadLoad

func (h *Host) AddDownloadLoad(delta int32)

func (*Host) AddPeerTask

func (h *Host) AddPeerTask(peerTask *PeerTask)

func (*Host) AddUploadLoad

func (h *Host) AddUploadLoad(delta int32)

func (*Host) DeletePeerTask

func (h *Host) DeletePeerTask(peerTaskID string)

func (*Host) GetDownloadLoad

func (h *Host) GetDownloadLoad() int32

func (*Host) GetDownloadLoadPercent

func (h *Host) GetDownloadLoadPercent() float64

func (*Host) GetFreeDownloadLoad

func (h *Host) GetFreeDownloadLoad() int32

func (*Host) GetFreeUploadLoad

func (h *Host) GetFreeUploadLoad() int32

func (*Host) GetPeerTask

func (h *Host) GetPeerTask(peerTaskID string) (peerTask *PeerTask)

func (*Host) GetPeerTaskNum

func (h *Host) GetPeerTaskNum() int32

func (*Host) GetUploadLoad

func (h *Host) GetUploadLoad() int32

func (*Host) GetUploadLoadPercent

func (h *Host) GetUploadLoadPercent() float64

func (*Host) SetTotalDownloadLoad

func (h *Host) SetTotalDownloadLoad(load int32)

func (*Host) SetTotalUploadLoad

func (h *Host) SetTotalUploadLoad(load int32)

type HostType

type HostType int

type IClient

type IClient interface {
	Send(*scheduler.PeerPacket) error
	Recv() (*scheduler.PieceResult, error)
	Close()
	IsClosed() bool
}

type PeerEdge

type PeerEdge struct {
	SrcPeerTask *PeerTask // child, consumer
	DstPeerTask *PeerTask // parent, provider
	Concurrency int8      // number of thread download from the provider
	CostHistory []int64   // history of downloading one piece cost from the provider
}

func (*PeerEdge) AddCost

func (pe *PeerEdge) AddCost(cost int64)

type PeerTask

type PeerTask struct {
	Pid  string // peer id
	Task *Task  // task info
	Host *Host  // host info

	Traffic int64
	Cost    uint32
	Success bool
	Code    base.Code
	// contains filtered or unexported fields
}

func NewPeerTask

func NewPeerTask(pid string, task *Task, host *Host, touch func(*PeerTask)) *PeerTask

func (*PeerTask) AddConcurrency

func (pt *PeerTask) AddConcurrency(parent *PeerTask, delta int8)

func (*PeerTask) AddParent

func (pt *PeerTask) AddParent(parent *PeerTask, concurrency int8)

func (*PeerTask) AddPieceStatus

func (pt *PeerTask) AddPieceStatus(ps *scheduler.PieceResult)

func (*PeerTask) DeleteParent

func (pt *PeerTask) DeleteParent()

func (*PeerTask) GetChildren

func (pt *PeerTask) GetChildren() (children []*PeerEdge)

func (*PeerTask) GetCost

func (pt *PeerTask) GetCost() int64

func (*PeerTask) GetDeep

func (pt *PeerTask) GetDeep() int32

func (*PeerTask) GetDiffPieceNum

func (pt *PeerTask) GetDiffPieceNum(dst *PeerTask) int32

func (*PeerTask) GetFinishedNum

func (pt *PeerTask) GetFinishedNum() int32

func (*PeerTask) GetFreeLoad

func (pt *PeerTask) GetFreeLoad() int32

func (*PeerTask) GetJobData

func (pt *PeerTask) GetJobData() interface{}

func (*PeerTask) GetLastActiveTime

func (pt *PeerTask) GetLastActiveTime() int64

func (*PeerTask) GetNodeStatus

func (pt *PeerTask) GetNodeStatus() PeerTaskStatus

func (*PeerTask) GetParent

func (pt *PeerTask) GetParent() *PeerEdge

func (*PeerTask) GetRoot

func (pt *PeerTask) GetRoot() *PeerTask

func (*PeerTask) GetSendPkg

func (pt *PeerTask) GetSendPkg() (pkg *scheduler.PeerPacket)

func (*PeerTask) GetSortKeys

func (pt *PeerTask) GetSortKeys() (key1, key2 int)

func (*PeerTask) GetStartTime

func (pt *PeerTask) GetStartTime() int64

func (*PeerTask) GetSubTreeNodesNum

func (pt *PeerTask) GetSubTreeNodesNum() int32

func (*PeerTask) IsAncestor

func (pt *PeerTask) IsAncestor(a *PeerTask) bool

func (*PeerTask) IsDown

func (pt *PeerTask) IsDown() (ok bool)

func (*PeerTask) IsWaiting

func (pt *PeerTask) IsWaiting() bool

func (*PeerTask) Send

func (pt *PeerTask) Send() error

func (*PeerTask) SendError

func (pt *PeerTask) SendError(dfError *dferrors.DfError) error

func (*PeerTask) SetClient

func (pt *PeerTask) SetClient(client IClient)

func (*PeerTask) SetDown

func (pt *PeerTask) SetDown()

func (*PeerTask) SetNodeStatus

func (pt *PeerTask) SetNodeStatus(status PeerTaskStatus, data ...interface{})

func (*PeerTask) SetNodeStatusHealth

func (pt *PeerTask) SetNodeStatusHealth(swapStatus ...PeerTaskStatus)

func (*PeerTask) SetStatus

func (pt *PeerTask) SetStatus(traffic int64, cost uint32, success bool, code base.Code)

func (*PeerTask) SetUp

func (pt *PeerTask) SetUp()

func (*PeerTask) Touch

func (pt *PeerTask) Touch()

type PeerTaskStatus

type PeerTaskStatus int8
const (
	PeerTaskStatusHealth         PeerTaskStatus = 0
	PeerTaskStatusBadNode        PeerTaskStatus = 11
	PeerTaskStatusNodeGone       PeerTaskStatus = 12
	PeerTaskStatusNeedCheckNode  PeerTaskStatus = 13
	PeerTaskStatusNeedAdjustNode PeerTaskStatus = 21
	PeerTaskStatusNeedChildren   PeerTaskStatus = 22
	PeerTaskStatusNeedParent     PeerTaskStatus = 23
	PeerTaskStatusAddParent      PeerTaskStatus = 24
	PeerTaskStatusDone           PeerTaskStatus = 31
	PeerTaskStatusLeaveNode      PeerTaskStatus = 32
)

type Piece

type Piece struct {
	base.PieceInfo

	Task *Task
}

type Task

type Task struct {
	TaskID string `json:"task_id,omitempty"`
	URL    string `json:"url,omitempty"`
	// regex format, used for task id generator, assimilating different urls
	Filter string `json:"filter,omitempty"`
	// biz_id and md5 are used for task id generator to distinguish the same urls
	// md5 is also used to check consistency about file content
	BizID   string        `json:"biz_id,omitempty"`   // caller's biz id that can be any string
	URLMata *base.UrlMeta `json:"url_mata,omitempty"` // downloaded file content md5

	SizeScope   base.SizeScope
	DirectPiece *scheduler.RegisterResult_PieceContent

	CreateTime time.Time
	LastActive time.Time

	PieceList     map[int32]*Piece // Piece list
	PieceTotal    int32            // the total number of Pieces, set > 0 when cdn finished
	ContentLength int64
	Statistic     *metrics.TaskStatistic
	Removed       bool
	CDNError      *dferrors.DfError
	// contains filtered or unexported fields
}

func CopyTask

func CopyTask(t *Task) *Task

func (*Task) AddPiece

func (t *Task) AddPiece(p *Piece)

func (*Task) GetOrCreatePiece

func (t *Task) GetOrCreatePiece(pieceNum int32) *Piece

func (*Task) GetPiece

func (t *Task) GetPiece(pieceNum int32) *Piece

type WaitingType

type WaitingType int

Jump to

Keyboard shortcuts

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