Documentation ¶
Index ¶
- type ClientStreamWriter
- func (csw *ClientStreamWriter) PostRun(ctx context.Context) (err error)
- func (csw *ClientStreamWriter) PreRun(ctx context.Context) (err error)
- func (csw *ClientStreamWriter) Read(p []byte) (n int, err error)
- func (csw *ClientStreamWriter) Run(ctx context.Context)
- func (csw *ClientStreamWriter) Wait()
- type ClientWriter
- type P2PDownloader
- type Piece
- type PieceWriter
- type PowerClient
- type TargetWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientStreamWriter ¶ added in v1.0.1
type ClientStreamWriter struct {
// contains filtered or unexported fields
}
ClientWriter writes a file for uploading and a target file.
func NewClientStreamWriter ¶ added in v1.0.1
func NewClientStreamWriter(clientQueue, notifyQueue queue.Queue, api api.SupernodeAPI, cfg *config.Config) *ClientStreamWriter
NewClientStreamWriter creates and initialize a ClientStreamWriter instance.
func (*ClientStreamWriter) PostRun ¶ added in v1.0.1
func (csw *ClientStreamWriter) PostRun(ctx context.Context) (err error)
func (*ClientStreamWriter) PreRun ¶ added in v1.0.1
func (csw *ClientStreamWriter) PreRun(ctx context.Context) (err error)
func (*ClientStreamWriter) Read ¶ added in v1.0.1
func (csw *ClientStreamWriter) Read(p []byte) (n int, err error)
func (*ClientStreamWriter) Run ¶ added in v1.0.1
func (csw *ClientStreamWriter) Run(ctx context.Context)
Run starts writing pipe.
func (*ClientStreamWriter) Wait ¶ added in v1.0.1
func (csw *ClientStreamWriter) Wait()
Wait for Run whether is finished.
type ClientWriter ¶
type ClientWriter struct {
// contains filtered or unexported fields
}
ClientWriter writes a file for uploading and a target file.
func (*ClientWriter) PostRun ¶ added in v1.0.1
func (cw *ClientWriter) PostRun(ctx context.Context) (err error)
func (*ClientWriter) PreRun ¶ added in v1.0.1
func (cw *ClientWriter) PreRun(ctx context.Context) (err error)
func (*ClientWriter) Run ¶
func (cw *ClientWriter) Run(ctx context.Context)
Run starts writing downloading file.
type P2PDownloader ¶
type P2PDownloader struct { // API holds the instance of SupernodeAPI to interact with supernode. API api.SupernodeAPI // Register holds the instance of SupernodeRegister. Register regist.SupernodeRegister // RegisterResult indicates the result set of registering to supernode. RegisterResult *regist.RegisterResult // contains filtered or unexported fields }
P2PDownloader is one implementation of Downloader that uses p2p pattern to download files.
func NewP2PDownloader ¶
func NewP2PDownloader(cfg *config.Config, api api.SupernodeAPI, register regist.SupernodeRegister, result *regist.RegisterResult) *P2PDownloader
NewP2PDownloader creates a P2PDownloader.
func (*P2PDownloader) Cleanup ¶
func (p2p *P2PDownloader) Cleanup()
Cleanup cleans all temporary resources generated by executing Run.
func (*P2PDownloader) GetNode ¶
func (p2p *P2PDownloader) GetNode() string
GetNode returns supernode ip.
func (*P2PDownloader) GetTaskID ¶
func (p2p *P2PDownloader) GetTaskID() string
GetTaskID returns downloading taskID.
type Piece ¶
type Piece struct { // TaskID a string which represents a unique task. TaskID string `json:"taskID"` // SuperNode indicates the IP address of the currently registered supernode. SuperNode string `json:"superNode"` // DstCid means the clientID of the target peer node for downloading the piece. DstCid string `json:"dstCid"` // Range indicates the range of specific piece in the task, example "0-45565". Range string `json:"range"` // Result of the piece downloaded. Result int `json:"result"` // Status of the downloading task. Status int `json:"status"` // PieceSize the length of the piece. PieceSize int32 `json:"pieceSize"` // PieceNum represents the position of the piece in the pieces list by cutting files. PieceNum int `json:"pieceNum"` // Content uses a buffer to temporarily store the piece content. Content *pool.Buffer `json:"-"` // contains filtered or unexported fields }
Piece contains all information of a piece.
func NewPiece ¶
func NewPiece(taskID, node, dstCid, pieceRange string, result, status int, cdnSource apiTypes.CdnSource) *Piece
NewPiece creates a Piece.
func NewPieceContent ¶
func NewPieceContent(taskID, node, dstCid, pieceRange string, result, status int, contents *pool.Buffer, cdnSource apiTypes.CdnSource) *Piece
NewPieceContent creates a Piece with specified content.
func NewPieceSimple ¶
NewPieceSimple creates a Piece with default value.
func (*Piece) ContentLength ¶ added in v1.0.3
ContentLength returns the content length.
func (*Piece) IncWriter ¶ added in v1.0.4
func (p *Piece) IncWriter()
IncWriter increase a writer for the piece.
func (*Piece) RawContent ¶
RawContent returns raw contents, If the piece has wrapper, and the piece content will remove the head and tail.
func (*Piece) TryResetContent ¶ added in v1.0.4
func (p *Piece) TryResetContent()
ResetContent reset contents and returns it back to buffer pool.
type PieceWriter ¶ added in v1.0.1
type PieceWriter interface { // PreRun initializes PieceWriter PreRun(ctx context.Context) error // Run starts to process piece data in background Run(ctx context.Context) // PostRun will run when finish a task PostRun(ctx context.Context) error // Wait will block util all piece are processed Wait() }
PieceWriter will be used in p2p downloader we provide 2 implementations, one for downloading file, one for streaming
func NewClientWriter ¶
func NewClientWriter(clientFilePath, serviceFilePath string, clientQueue, notifyQueue queue.Queue, api api.SupernodeAPI, cfg *config.Config, cdnSource apiTypes.CdnSource) PieceWriter
NewClientWriter creates and initialize a ClientWriter instance.
type PowerClient ¶
type PowerClient struct {
// contains filtered or unexported fields
}
PowerClient downloads file from dragonfly.
func (*PowerClient) ClientError ¶ added in v0.3.1
func (pc *PowerClient) ClientError() *types.ClientErrorRequest
ClientError returns the client error if occurred
type TargetWriter ¶
type TargetWriter struct {
// contains filtered or unexported fields
}
TargetWriter writes downloading file to disk.
func NewTargetWriter ¶
func NewTargetWriter(dst string, q queue.Queue, cfg *config.Config, cdnSource apiTypes.CdnSource) (*TargetWriter, error)
NewTargetWriter creates and initialize a TargetWriter instance.
func (*TargetWriter) Run ¶
func (tw *TargetWriter) Run(ctx context.Context)
Run starts writing downloading file.