piecestore

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2019 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInternal is an error class for internal errors.
	ErrInternal = errs.Class("internal")
	// ErrProtocol is an error class for unexpected protocol sequence.
	ErrProtocol = errs.Class("protocol")
	// ErrVerifyUntrusted is an error in case there is a trust issue.
	ErrVerifyUntrusted = errs.Class("untrusted")
)
View Source
var DefaultConfig = Config{
	UploadBufferSize:   256 * memory.KiB.Int64(),
	DownloadBufferSize: 256 * memory.KiB.Int64(),

	InitialStep: 64 * memory.KiB.Int64(),
	MaximumStep: 1 * memory.MiB.Int64(),
}

DefaultConfig are the default params used for upload and download.

View Source
var Error = errs.Class("piecestore")

Error is the default error class for piecestore client.

Functions

This section is empty.

Types

type BufferedDownload

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

BufferedDownload implements buffering for download.

func (*BufferedDownload) Close

func (download *BufferedDownload) Close() error

Close closes the buffered download.

func (*BufferedDownload) Read

func (download *BufferedDownload) Read(p []byte) (int, error)

Read reads from the buffer and downloading in batches once it's empty.

type BufferedUpload

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

BufferedUpload implements buffering for an Upload.

func (*BufferedUpload) Cancel

func (upload *BufferedUpload) Cancel() error

Cancel aborts the upload.

func (*BufferedUpload) Commit

func (upload *BufferedUpload) Commit() (*pb.PieceHash, error)

Commit flushes any remaining content from buffer and commits the upload.

func (*BufferedUpload) Write

func (upload *BufferedUpload) Write(data []byte) (int, error)

Write writes content to the buffer and flushes it to the upload once enough data has been gathered.

type Client

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

Client implements uploading, downloading and deleting content from a piecestore.

func NewClient

func NewClient(log *zap.Logger, signer signing.Signer, conn *grpc.ClientConn, config Config) *Client

NewClient creates a new piecestore client from a grpc client connection.

func (*Client) Close

func (client *Client) Close() error

Close closes the underlying connection.

func (*Client) Delete

func (client *Client) Delete(ctx context.Context, limit *pb.OrderLimit2) error

Delete uses delete order limit to delete a piece on piece store.

func (*Client) Download

func (client *Client) Download(ctx context.Context, limit *pb.OrderLimit2, offset, size int64) (Downloader, error)

Download starts a new download using the specified order limit at the specified offset and size.

func (*Client) Upload

func (client *Client) Upload(ctx context.Context, limit *pb.OrderLimit2) (Uploader, error)

Upload initiates an upload to the storage node.

func (*Client) VerifyPieceHash

func (client *Client) VerifyPieceHash(ctx context.Context, peer *identity.PeerIdentity, limit *pb.OrderLimit2, hash *pb.PieceHash, expectedHash []byte) error

VerifyPieceHash verifies piece hash which is sent by peer.

type Config

type Config struct {
	UploadBufferSize   int64
	DownloadBufferSize int64

	InitialStep int64
	MaximumStep int64
}

Config defines piecestore client parameters fro upload and download.

type Download

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

Download implements downloading from a piecestore.

func (*Download) Close

func (client *Download) Close() error

Close closes the downloading.

func (*Download) Read

func (client *Download) Read(data []byte) (read int, _ error)

Read downloads data from the storage node allocating as necessary.

type Downloader

type Downloader interface {
	Read([]byte) (int, error)
	Close() error
}

Downloader is interface that can be used for downloading content. It matches signature of `io.ReadCloser`.

func NewBufferedDownload

func NewBufferedDownload(download *Download, size int) Downloader

NewBufferedDownload creates a buffered download with the specified size.

type LockingDownload

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

LockingDownload adds a lock around download making it safe to use concurrently. TODO: this shouldn't be needed.

func (*LockingDownload) Close

func (download *LockingDownload) Close() error

Close closes the deownload.

func (*LockingDownload) Read

func (download *LockingDownload) Read(p []byte) (int, error)

Read downloads content.

type LockingUpload

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

LockingUpload adds a lock around upload making it safe to use concurrently. TODO: this shouldn't be needed.

func (*LockingUpload) Cancel

func (upload *LockingUpload) Cancel() error

Cancel aborts the upload.

func (*LockingUpload) Commit

func (upload *LockingUpload) Commit() (*pb.PieceHash, error)

Commit finishes the upload.

func (*LockingUpload) Write

func (upload *LockingUpload) Write(p []byte) (int, error)

Write uploads data.

type ReadBuffer

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

ReadBuffer implements buffered reading with an error.

func (*ReadBuffer) Empty

func (buffer *ReadBuffer) Empty() bool

Empty checks whether buffer needs to be filled.

func (*ReadBuffer) Error

func (buffer *ReadBuffer) Error() error

Error returns an error if it was encountered.

func (*ReadBuffer) Errored

func (buffer *ReadBuffer) Errored() bool

Errored returns whether the buffer contains an error.

func (*ReadBuffer) Fill

func (buffer *ReadBuffer) Fill(data []byte)

Fill fills the buffer with the specified bytes.

func (*ReadBuffer) IncludeError

func (buffer *ReadBuffer) IncludeError(err error)

IncludeError adds error at the end of the buffer.

func (*ReadBuffer) Read

func (buffer *ReadBuffer) Read(data []byte) (n int, err error)

Read reads from the buffer.

type Upload

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

Upload implements uploading to the storage node.

func (*Upload) Cancel

func (client *Upload) Cancel() error

Cancel cancels the uploading.

func (*Upload) Commit

func (client *Upload) Commit() (*pb.PieceHash, error)

Commit finishes uploading by sending the piece-hash and retrieving the piece-hash.

func (*Upload) Write

func (client *Upload) Write(data []byte) (written int, _ error)

Write sends data to the storagenode allocating as necessary.

type Uploader

type Uploader interface {
	// Write uploads data to the storage node.
	Write([]byte) (int, error)
	// Cancel cancels the upload.
	Cancel() error
	// Commit finalizes the upload.
	Commit() (*pb.PieceHash, error)
}

Uploader defines the interface for uploading a piece.

func NewBufferedUpload

func NewBufferedUpload(upload *Upload, size int) Uploader

NewBufferedUpload creates buffered upload with the specified size.

Jump to

Keyboard shortcuts

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