downloader

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientWriter

type ClientWriter struct {
	// contains filtered or unexported fields
}

ClientWriter writes a file for uploading and a target file.

func NewClientWriter

func NewClientWriter(clientFilePath, serviceFilePath string,
	clientQueue util.Queue, api api.SupernodeAPI, cfg *config.Config) (*ClientWriter, error)

NewClientWriter creates and initialize a ClientWriter instance.

func (*ClientWriter) Run

func (cw *ClientWriter) Run()

Run starts writing downloading file.

func (*ClientWriter) Wait

func (cw *ClientWriter) Wait()

Wait for Run whether is finished.

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 create P2PDownloader

func (*P2PDownloader) Cleanup

func (p2p *P2PDownloader) Cleanup()

Cleanup clean 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.

func (*P2PDownloader) Run

func (p2p *P2PDownloader) Run() error

Run starts to download the file.

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 *bytes.Buffer `json:"-"`
}

Piece contains all information of a piece.

func NewPiece

func NewPiece(taskID, node, dstCid, pieceRange string, result, status int) *Piece

NewPiece creates a Piece.

func NewPieceContent

func NewPieceContent(taskID, node, dstCid, pieceRange string,
	result, status int, contents *bytes.Buffer) *Piece

NewPieceContent creates a Piece with specified content.

func NewPieceSimple

func NewPieceSimple(taskID string, node string, status int) *Piece

NewPieceSimple creates a Piece with default value.

func (*Piece) RawContent

func (p *Piece) RawContent() *bytes.Buffer

RawContent return raw contents.

func (*Piece) String

func (p *Piece) String() string

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 return the client error if occurred

func (*PowerClient) Run

func (pc *PowerClient) Run() error

Run starts run the task.

type TargetWriter

type TargetWriter struct {
	// contains filtered or unexported fields
}

TargetWriter writes downloading file to disk.

func NewTargetWriter

func NewTargetWriter(dst string, queue util.Queue, cfg *config.Config) (*TargetWriter, error)

NewTargetWriter creates and initialize a TargetWriter instance.

func (*TargetWriter) Run

func (tw *TargetWriter) Run()

Run starts writing downloading file.

func (*TargetWriter) Wait

func (tw *TargetWriter) Wait()

Wait the Run is finished.

Jump to

Keyboard shortcuts

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