Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CDNMgr ¶
type CDNMgr interface {
// TriggerCDN will trigger CDN to download the file from sourceUrl.
// In common, it will including the following steps:
// 1). download the source file
// 2). update the taskInfo
// 3). write the file to disk
TriggerCDN(ctx context.Context, taskInfo *types.TaskInfo) error
// GetStatus get the status of the file.
GetStatus(ctx context.Context, taskID string) (cdnStatus string, err error)
// Delete delete the file from disk with specified taskID.
Delete(ctx context.Context, taskID string) error
}
CDNMgr as an interface defines all operations against CDN and operates on the underlying files stored on the local disk, etc.
type DfgetTaskMgr ¶
type DfgetTaskMgr interface {
// Add a new dfgetTask, we use clientID to identify a dfgetTask uniquely.
// ClientID should be generated by dfget, supernode will use it directly.
// NOTE: We should create a new dfgetTask for each download process,
// even if the downloads initiated by the same machine.
Add(ctx context.Context, dfgetTask *types.DfGetTask) error
// Get get a dfgetTask info with specified clientID.
Get(ctx context.Context, clientID string) (dfgetTask *types.DfGetTask, err error)
// List return the list of dfgetTask.
List(ctx context.Context, filter map[string]string) (dfgetTaskList []*types.DfGetTask, err error)
// Delete a dfgetTask with clientID.
Delete(ctx context.Context, clientID string) error
// UpdateStatus update the status of dfgetTask with specified clientID.
// Supernode will update the status of dfgetTask in the following situations:
// 1. after init the dfgetTask
// 2. when success/fail to download some pieces
// 3. when the entire download process ends in success or failure
UpdateStatus(ctx context.Context, clientID string, status string) error
}
DfgetTaskMgr as an interface defines all operations against DfgetTask. A DfgetTask represents a download process initiated by dfget or other clients.
type PeerMgr ¶
type PeerMgr interface {
// Register a peer with specified peerInfo.
// Supernode will generate a unique peerID for every Peer with PeerInfo provided.
Register(ctx context.Context, peerInfo *types.PeerInfo) (peerID string, err error)
// DeRegister offline a peer service and
// NOTE: update the info related for scheduler.
DeRegister(ctx context.Context, peerID string) error
// Get the peer Info with specified peerID.
Get(ctx context.Context, peerID string) (*types.PeerInfo, error)
// List return a list of peers info with filter.
List(ctx context.Context, filter map[string]string) (peerList []*types.PeerInfo, err error)
// Update the status of specified peer.
//
// Supernode will update the status of peer in the following situations:
// 1) When an exception occurs to the peer server.
// 2) When peer sends a request take the server offline.
//
// NOTE: update the info related for scheduler.
Update(ctx context.Context, peerID string, peerInfo *types.PeerInfo) error
}
PeerMgr as an interface defines all operations against Peer. A Peer represents a web server that provides file downloads for others.
type ProgressMgr ¶
type ProgressMgr interface {
// InitProgress init the correlation information between peers and pieces, etc.
InitProgress(ctx context.Context, taskID, clientID string) error
// UpdateProgress update the correlation information between peers and pieces.
// 1. update the info about srcCid to tell the scheduler that corresponding peer has the piece now.
// 2. update the info about dstCid to tell the scheduler that someone has downloaded the piece form here.
// Scheduler will calculate the load and times of error/success for every peer to make better decisions.
UpdateProgress(ctx context.Context, taskID, srcCid, dstCid string, pieceRange string, pieceStatus string) error
// GetPieceByCid get all pieces with specified clientID.
GetPiecesByCid(ctx context.Context, clientID string) (pieceRanges []string, err error)
// GetPeersByPieceRange get all peers info with specified taskID and pieceRange.
GetPeersByPieceRange(ctx context.Context, taskID, pieceRange string) (peersInfo []*types.PeerInfo, err error)
// GetPeersBytaskID get all peers info with specified taskID.
GetPeersBytaskID(ctx context.Context, taskID string) (peersInfo []*types.PeerInfo, err error)
}
ProgressMgr is responsible for maintaining the correspondence between peer and pieces.
type SchedulerMgr ¶
type SchedulerMgr interface {
// Schedule get scheduler result with specified taskID, clientID through some rules.
Schedule(ctx context.Context, taskID, clientID string) ([]*types.PieceInfo, error)
}
SchedulerMgr is responsible for calculating scheduling results according to certain rules.
type TaskMgr ¶
type TaskMgr interface {
// Register a task represents that someone wants to download a file.
// Supernode will get the task file meta and return taskID.
// NOTE: If supernode cannot find the task file, the CDN download will be triggered.
Register(ctx context.Context, task *types.TaskInfo) (taskID string, err error)
// Get the task Info with specified taskID.
Get(ctx context.Context, taskID string) (*types.TaskInfo, error)
// List returns the list tasks with filter.
List(ctx context.Context, filter map[string]string) ([]*types.TaskInfo, error)
// CheckTaskStatus check whether the taskID corresponding file exists.
CheckTaskStatus(ctx context.Context, taskID string) (bool, error)
// DeleteTask delete a task
// NOTE: delete the related peers and dfgetTask info is necessary.
DeleteTask(ctx context.Context, taskID string) error
// update the task info with specified info.
// In common, there are several situations that we will use this method:
// 1. when finished to download, update task status.
// 2. for operation usage.
UpdateTaskInfo(ctx context.Context, taskID string, taskInfo *types.TaskInfo) error
// GetPieces get the pieces to be downloaded based on the scheduling result,
// just like this: which pieces can be downloaded from which peers.
GetPieces(ctx context.Context, taskID, clientID string) ([]*types.PieceInfo, error)
// UpdatePieceStatus update the piece status with specified parameters.
// A task file is divided into several pieces logically.
// We use a sting called pieceRange to identify a piece.
// A pieceRange separated by a dash, like this: 0-45565, etc.
UpdatePieceStatus(ctx context.Context, taskID, pieceRange, clientID string) error
}
TaskMgr as an interface defines all operations against Task. A Task will store some meta info about the taskFile, pieces and something else. A Task has a one-to-one correspondence with a file on the disk which is identified by taskID.