zboxutil

package
v1.17.11 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 40 Imported by: 6

Documentation

Overview

Utility functions to support the functionality of the SDK.

Index

Constants

View Source
const (
	ALLOCATION_ENDPOINT          = "/allocation"
	UPLOAD_ENDPOINT              = "/v1/file/upload/"
	RENAME_ENDPOINT              = "/v1/file/rename/"
	COPY_ENDPOINT                = "/v1/file/copy/"
	MOVE_ENDPOINT                = "/v1/file/move/"
	LIST_ENDPOINT                = "/v1/file/list/"
	REFERENCE_ENDPOINT           = "/v1/file/referencepath/"
	CONNECTION_ENDPOINT          = "/v1/connection/details/"
	COMMIT_ENDPOINT              = "/v1/connection/commit/"
	DOWNLOAD_ENDPOINT            = "/v1/file/download/"
	LATEST_READ_MARKER           = "/v1/readmarker/latest"
	FILE_META_ENDPOINT           = "/v1/file/meta/"
	FILE_STATS_ENDPOINT          = "/v1/file/stats/"
	OBJECT_TREE_ENDPOINT         = "/v1/file/objecttree/"
	REFS_ENDPOINT                = "/v1/file/refs/"
	RECENT_REFS_ENDPOINT         = "/v1/file/refs/recent/"
	COLLABORATOR_ENDPOINT        = "/v1/file/collaborator/"
	CALCULATE_HASH_ENDPOINT      = "/v1/file/calculatehash/"
	SHARE_ENDPOINT               = "/v1/marketplace/shareinfo/"
	DIR_ENDPOINT                 = "/v1/dir/"
	PLAYLIST_LATEST_ENDPOINT     = "/v1/playlist/latest/"
	PLAYLIST_FILE_ENDPOINT       = "/v1/playlist/file/"
	WM_LOCK_ENDPOINT             = "/v1/writemarker/lock/"
	CREATE_CONNECTION_ENDPOINT   = "/v1/connection/create/"
	LATEST_WRITE_MARKER_ENDPOINT = "/v1/file/latestwritemarker/"
	ROLLBACK_ENDPOINT            = "/v1/connection/rollback/"
	REDEEM_ENDPOINT              = "/v1/connection/redeem/"

	// CLIENT_SIGNATURE_HEADER represents http request header contains signature.
	CLIENT_SIGNATURE_HEADER    = "X-App-Client-Signature"
	CLIENT_SIGNATURE_HEADER_V2 = "X-App-Client-Signature-V2"
	ALLOCATION_ID_HEADER       = "ALLOCATION-ID"
)
View Source
const EncryptedFolderName = "encrypted"
View Source
const MAX_RETRIES = 5
View Source
const SC_REST_API_URL = "v1/screst/"
View Source
const SLEEP_BETWEEN_RETRIES = 5

Variables

View Source
var (
	Client         HttpClient
	FastHttpClient FastClient

	SignCache simplelru.LRUCache[string, string]
)
View Source
var DefaultTransport = &http.Transport{
	Proxy: envProxy.Proxy,
	DialContext: (&net.Dialer{
		Timeout:   3 * time.Minute,
		KeepAlive: 45 * time.Second,
		DualStack: true,
	}).DialContext,
	MaxIdleConns:          100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   45 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
	MaxIdleConnsPerHost:   25,
}

Functions

func Decrypt

func Decrypt(key, text []byte) ([]byte, error)

func DeleteCollaboratorRequest

func DeleteCollaboratorRequest(baseUrl, allocationID, allocationTx, sig string, query *url.Values) (*http.Request, error)

func Encrypt

func Encrypt(key, text []byte) ([]byte, error)

func GetActiveBlobbers added in v1.8.6

func GetActiveBlobbers(dirMask uint32, blobbers []*blockchain.StorageNode) []*blockchain.StorageNode

func GetCollaboratorsRequest

func GetCollaboratorsRequest(baseUrl, allocationID, allocationTx, sig string, query *url.Values) (*http.Request, error)

func GetErrorMessageCode added in v1.8.16

func GetErrorMessageCode(errorMsg string) (string, error)

Returns the error message code, message should be strictly of the format: ".... err: {"code" : <return_this>, ...}, ..."

func GetFastHTTPClient added in v1.15.9

func GetFastHTTPClient() *fasthttp.Client

func GetFastRateLimitValue added in v1.13.0

func GetFastRateLimitValue(r *fasthttp.Response) (int, error)

func GetFileContentType

func GetFileContentType(ext string, out io.ReadSeeker) (string, error)

GetFileContentType returns the content type of the file based on reading the first 10KB of the file

  • ext is the extension of the file, shouldn't be empty
  • out is the file content

func GetFullRemotePath

func GetFullRemotePath(localPath, remotePath string) string

GetFullRemotePath returns the full remote path by combining the local path and remote path

  • localPath is the local path of the file
  • remotePath is the remote path of the file

func GetLogger added in v1.10.0

func GetLogger() *logger.Logger

func GetRateLimitValue added in v1.8.9

func GetRateLimitValue(r *http.Response) (int, error)

func GetRefsHash added in v1.3.0

func GetRefsHash(r []byte) string

func HttpDo

func HttpDo(ctx context.Context, cncl context.CancelFunc, req *http.Request, f func(*http.Response, error) error) error

func IsRemoteAbs

func IsRemoteAbs(path string) bool

IsRemoteAbs returns true if the path is remote absolute path

  • path is the path to check

func MajorError added in v1.8.16

func MajorError(errors []error) error

func MakeSCRestAPICall

func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, handler SCRestAPIHandler) ([]byte, error)

MakeSCRestAPICall makes a rest api call to the sharders.

  • scAddress is the address of the smart contract
  • relativePath is the relative path of the api
  • params is the query parameters
  • handler is the handler function to handle the response

func NewAllocationRequest

func NewAllocationRequest(baseUrl, allocationID, allocationTx string) (*http.Request, error)

func NewCalculateHashRequest

func NewCalculateHashRequest(baseUrl, allocationID string, allocationTx string, paths []string) (*http.Request, error)

func NewCollaboratorRequest

func NewCollaboratorRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewCommitRequest

func NewCommitRequest(baseUrl, allocationID string, allocationTx string, body io.Reader) (*http.Request, error)

func NewConnectionId

func NewConnectionId() string

NewConnectionId generate new connection id. Connection is used to track the upload/download progress and redeem the cost of the operation from the network. It's in the short uuid format. Check here for more on this format: https://pkg.go.dev/github.com/lithammer/shortuuid/v3@v3.0.7

func NewConnectionRequest added in v1.8.17

func NewConnectionRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewCopyRequest

func NewCopyRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewCreateDirRequest

func NewCreateDirRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewDeleteRequest

func NewDeleteRequest(baseUrl, allocationID, allocationTx, sig string, query *url.Values) (*http.Request, error)

func NewDownloadRequest

func NewDownloadRequest(baseUrl, allocationID, allocationTx string) (*http.Request, error)

func NewFastDownloadRequest added in v1.13.0

func NewFastDownloadRequest(baseUrl, allocationID, allocationTx string) (*fasthttp.Request, error)

func NewFastUploadRequest added in v1.13.0

func NewFastUploadRequest(baseURL, allocationID string, allocationTx string, body []byte, method string) (*fasthttp.Request, error)

func NewFileMetaRequest

func NewFileMetaRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewFileStatsRequest

func NewFileStatsRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewHTTPRequest

func NewHTTPRequest(method string, url string, data []byte) (*http.Request, context.Context, context.CancelFunc, error)

func NewListRequest

func NewListRequest(baseUrl, allocationID, allocationTx, path, pathHash, auth_token string, list bool, offset, pageLimit int) (*http.Request, error)

func NewMoveRequest added in v1.8.10

func NewMoveRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewObjectTreeRequest

func NewObjectTreeRequest(baseUrl, allocationID string, allocationTx string, sig string, path string) (*http.Request, error)

func NewRecentlyAddedRefsRequest added in v1.8.7

func NewRecentlyAddedRefsRequest(bUrl, allocID, allocTx, sig string, fromDate, offset int64, pageLimit int) (*http.Request, error)

func NewRedeemRequest added in v1.8.17

func NewRedeemRequest(baseUrl, allocationID, allocationTx string) (*http.Request, error)

func NewReferencePathRequest

func NewReferencePathRequest(baseUrl, allocationID string, allocationTx string, sig string, paths []string) (*http.Request, error)

func NewRefsRequest added in v1.3.0

func NewRefsRequest(baseUrl, allocationID, sig, allocationTx, path, pathHash, authToken, offsetPath, updatedDate, offsetDate, fileType, refType string, level, pageLimit int) (*http.Request, error)

func NewRenameRequest

func NewRenameRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewRevokeShareRequest

func NewRevokeShareRequest(baseUrl, allocationID, allocationTx, sig string, query *url.Values) (*http.Request, error)

func NewRollbackRequest added in v1.8.17

func NewRollbackRequest(baseUrl, allocationID string, allocationTx string, body io.Reader) (*http.Request, error)

func NewShareRequest

func NewShareRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader) (*http.Request, error)

func NewUploadRequest

func NewUploadRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader, update bool) (*http.Request, error)

func NewUploadRequestWithMethod added in v1.2.88

func NewUploadRequestWithMethod(baseURL, allocationID, allocationTx, sig string, body io.Reader, method string) (*http.Request, error)

NewUploadRequestWithMethod create a http request of upload

func NewWriteMarkerLockRequest added in v1.8.9

func NewWriteMarkerLockRequest(
	baseURL, allocationID, allocationTx, sig, connID string) (*http.Request, error)

func NewWriteMarkerUnLockRequest added in v1.8.9

func NewWriteMarkerUnLockRequest(
	baseURL, allocationID, allocationTx, sig, connID, requestTime string) (*http.Request, error)

func NewWritemarkerRequest added in v1.8.17

func NewWritemarkerRequest(baseUrl, allocationID, allocationTx, sig string) (*http.Request, error)

func RemoteClean

func RemoteClean(path string) string

RemoteClean returns the cleaned remote path

  • path is the path to clean

func ScryptDecrypt added in v1.8.15

func ScryptDecrypt(key, ciphertext []byte) ([]byte, error)

func ScryptEncrypt added in v1.8.15

func ScryptEncrypt(key, text []byte) ([]byte, error)

func Transpose added in v1.8.17

Returns transpose of 2-D slice Example: Given matrix [[a, b], [c, d], [e, f]] returns [[a, c, e], [b, d, f]]

Types

type DownloadBuffer added in v1.12.1

type DownloadBuffer interface {
	RequestChunk(ctx context.Context, num int) []byte
	ReleaseChunk(num int)
	ClearBuffer()
}

type DownloadBufferWithChan added in v1.13.0

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

func NewDownloadBufferWithChan added in v1.13.0

func NewDownloadBufferWithChan(size, numBlocks, effectiveBlockSize int) *DownloadBufferWithChan

func (*DownloadBufferWithChan) ClearBuffer added in v1.13.7

func (r *DownloadBufferWithChan) ClearBuffer()

func (*DownloadBufferWithChan) ReleaseChunk added in v1.13.0

func (r *DownloadBufferWithChan) ReleaseChunk(num int)

func (*DownloadBufferWithChan) RequestChunk added in v1.13.0

func (r *DownloadBufferWithChan) RequestChunk(ctx context.Context, num int) []byte

type DownloadBufferWithMask added in v1.13.0

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

func NewDownloadBufferWithMask added in v1.13.0

func NewDownloadBufferWithMask(size, numBlocks, effectiveBlockSize int) *DownloadBufferWithMask

func (*DownloadBufferWithMask) ClearBuffer added in v1.13.7

func (r *DownloadBufferWithMask) ClearBuffer()

func (*DownloadBufferWithMask) ReleaseChunk added in v1.13.0

func (r *DownloadBufferWithMask) ReleaseChunk(num int)

func (*DownloadBufferWithMask) RequestChunk added in v1.13.0

func (r *DownloadBufferWithMask) RequestChunk(ctx context.Context, num int) []byte

func (*DownloadBufferWithMask) SetNumBlocks added in v1.13.14

func (r *DownloadBufferWithMask) SetNumBlocks(numBlocks int)

type FastClient added in v1.13.0

type FastClient interface {
	DoTimeout(req *fasthttp.Request, resp *fasthttp.Response, timeout time.Duration) error
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type SCRestAPIHandler

type SCRestAPIHandler func(response map[string][]byte, numSharders int, err error)

SCRestAPIHandler is a function type to handle the response from the SC Rest API

`response` - the response from the SC Rest API
`numSharders` - the number of sharders that responded
`err` - the error if any

type Uint128

type Uint128 struct {
	High uint64
	Low  uint64
}

func NewUint128

func NewUint128(x uint64) Uint128

func (Uint128) Add

func (x Uint128) Add(y Uint128) Uint128

Add returns x+y.

func (Uint128) Add64

func (x Uint128) Add64(y uint64) Uint128

Add64 returns x+y.

func (Uint128) And

func (x Uint128) And(v Uint128) Uint128

And returns x&y.

func (Uint128) And64

func (x Uint128) And64(y uint64) Uint128

And64 returns x&y.

func (Uint128) CountOnes

func (x Uint128) CountOnes() int

CountOnes return num of 1 bits in x.

func (Uint128) Equals

func (x Uint128) Equals(y Uint128) bool

Equals returns true if x == y.

func (Uint128) Equals64

func (x Uint128) Equals64(y uint64) bool

Equals64 returns true if x == y.

func (Uint128) Lsh

func (x Uint128) Lsh(y uint64) Uint128

Lsh returns x<<y.

func (Uint128) Not

func (x Uint128) Not() Uint128

Not returns ^x.

func (Uint128) Or

func (x Uint128) Or(v Uint128) Uint128

Or returns x|y.

func (Uint128) Sub

func (x Uint128) Sub(y Uint128) Uint128

Sub returns x-y.

func (Uint128) Sub64

func (x Uint128) Sub64(y uint64) Uint128

Sub64 returns x-y.

func (Uint128) TrailingZeros

func (x Uint128) TrailingZeros() int

TrailingZeros returns the number of trailing zero bits in x; the result is 128 for x == 0.

func (Uint128) Xor

func (x Uint128) Xor(v Uint128) Uint128

Xor returns x^y.

Jump to

Keyboard shortcuts

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