sdk

package
v1.0.45 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 38 Imported by: 10

Documentation

Index

Constants

View Source
const (
	DOWNLOAD_CONTENT_FULL  = "full"
	DOWNLOAD_CONTENT_THUMB = "thumbnail"
)
View Source
const (
	OpUpload   int = 0
	OpDownload int = 1
	OpRepair   int = 2
	OpUpdate   int = 3
)
View Source
const (
	Upload      = "Upload"
	Download    = "Download"
	Update      = "Update"
	Delete      = "Delete"
	Conflict    = "Conflict"
	LocalDelete = "LocalDelete"
)

For sync app

View Source
const STORAGE_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7"

Variables

This section is empty.

Functions

func AddBlockDownloadReq

func AddBlockDownloadReq(req *BlockDownloadRequest)

func AddCommitRequest

func AddCommitRequest(req *CommitRequest)

func CancelAlloctioan added in v1.0.41

func CancelAlloctioan(allocID string) (string, error)

func CommitToFabric

func CommitToFabric(metaTxnData, fabricConfigJSON string) (string, error)

func CreateAllocation

func CreateAllocation(datashards, parityshards int, size, expiry int64,
	readPrice, writePrice PriceRange, lock int64) (
	string, error)

func CreateAllocationForOwner

func CreateAllocationForOwner(owner, ownerpublickey string,
	datashards, parityshards int,
	size, expiry int64, readPrice, writePrice PriceRange, lock int64,
	preferredBlobbers []string) (string, error)

func CreateReadPool

func CreateReadPool() (err error)

func FinalizeAllocation

func FinalizeAllocation(allocID string) (string, error)

func GetClientEncryptedPublicKey

func GetClientEncryptedPublicKey() (string, error)

func GetVersion

func GetVersion() string

GetVersion - returns version string

func InitBlockDownloader

func InitBlockDownloader(blobbers []*blockchain.StorageNode)

func InitCommitWorker

func InitCommitWorker(blobbers []*blockchain.StorageNode)

func InitStorageSDK

func InitStorageSDK(clientJson string, miners []string, sharders []string, chainID string, signatureScheme string, preferredBlobbers []string) error

func ReadPoolLock

func ReadPoolLock(dur time.Duration, tokens, fee int64) (err error)

ReadPoolLock locks given number of tokes for given duration in read pool.

func ReadPoolUnlock

func ReadPoolUnlock(poolID string, fee int64) (err error)

ReadPoolUnlock unlocks tokens in expired read pool

func SetLogFile

func SetLogFile(logFile string, verbose bool)

logFile - Log file verbose - true - console output; false - no console output

func SetMaxTxnQuery

func SetMaxTxnQuery(num int)

func SetNumBlockDownloads

func SetNumBlockDownloads(num int)

func SetQuerySleepTime

func SetQuerySleepTime(time int)

func StakePoolLock

func StakePoolLock(value, fee int64) (err error)

StakePoolLock locks tokens lack in stake pool

func StakePoolUnlock

func StakePoolUnlock(fee int64) (err error)

StakePoolUnlock unlocks a stake pool overfill.

func UpdateAllocation

func UpdateAllocation(size int64, expiry int64, allocationID string) (string, error)

func WritePoolLock

func WritePoolLock(allocID string, tokens, fee int64) (err error)

WritePoolLock unlocks tokens in expired write pool

Types

type Allocation

type Allocation struct {
	ID             string                    `json:"id"`
	Tx             string                    `json:"tx"`
	DataShards     int                       `json:"data_shards"`
	ParityShards   int                       `json:"parity_shards"`
	Size           int64                     `json:"size"`
	Expiration     int64                     `json:"expiration_date"`
	Owner          string                    `json:"owner_id"`
	OwnerPublicKey string                    `json:"owner_public_key"`
	Payer          string                    `json:"payer_id"`
	Blobbers       []*blockchain.StorageNode `json:"blobbers"`
	Stats          *AllocationStats          `json:"stats"`

	// BlobberDetails contains real terms used for the allocation.
	// If the allocation has updated, then terms calculated using
	// weighted average values.
	BlobberDetails []*BlobberAllocation `json:"blobber_details"`

	// ReadPriceRange is requested reading prices range.
	ReadPriceRange PriceRange `json:"read_price_range"`
	// WritePriceRange is requested writing prices range.
	WritePriceRange PriceRange `json:"write_price_range"`
	// ChallengeCompletionTime is max challenge completion time of
	// all blobbers of the allocation.
	ChallengeCompletionTime time.Duration `json:"challenge_completion_time"`
	// Finalized allocation.
	Finalized bool `json:"finalized,omitempty"`
	// Canceled allocation.
	Canceled bool `json:"canceled,omitempty"`
	// contains filtered or unexported fields
}

func GetAllocation

func GetAllocation(allocationID string) (*Allocation, error)

func GetAllocationFromAuthTicket

func GetAllocationFromAuthTicket(authTicket string) (*Allocation, error)

func GetAllocations

func GetAllocations() ([]*Allocation, error)

func GetAllocationsForClient

func GetAllocationsForClient(clientID string) ([]*Allocation, error)

func (*Allocation) CancelDownload

func (a *Allocation) CancelDownload(remotepath string) error

func (*Allocation) CommitMetaTransaction

func (a *Allocation) CommitMetaTransaction(path, crudOperation, authTicket, lookupHash string, fileMeta *ConsolidatedFileMeta, status StatusCallback) (err error)

func (*Allocation) CopyObject

func (a *Allocation) CopyObject(path string, destPath string) error

func (*Allocation) DeleteFile

func (a *Allocation) DeleteFile(path string) error

func (*Allocation) DownloadFile

func (a *Allocation) DownloadFile(localPath string, remotePath string, status StatusCallback) error

func (*Allocation) DownloadFromAuthTicket

func (a *Allocation) DownloadFromAuthTicket(localPath string, authTicket string, remoteLookupHash string, remoteFilename string, status StatusCallback) error

func (*Allocation) DownloadThumbnail

func (a *Allocation) DownloadThumbnail(localPath string, remotePath string, status StatusCallback) error

func (*Allocation) DownloadThumbnailFromAuthTicket

func (a *Allocation) DownloadThumbnailFromAuthTicket(localPath string, authTicket string, remoteLookupHash string, remoteFilename string, status StatusCallback) error

func (*Allocation) EncryptAndUpdateFile

func (a *Allocation) EncryptAndUpdateFile(localpath string, remotepath string, status StatusCallback) error

func (*Allocation) EncryptAndUpdateFileWithThumbnail

func (a *Allocation) EncryptAndUpdateFileWithThumbnail(localpath string, remotepath string, thumbnailpath string, status StatusCallback) error

func (*Allocation) EncryptAndUploadFile

func (a *Allocation) EncryptAndUploadFile(localpath string, remotepath string, status StatusCallback) error

func (*Allocation) EncryptAndUploadFileWithThumbnail

func (a *Allocation) EncryptAndUploadFileWithThumbnail(localpath string, remotepath string, thumbnailpath string, status StatusCallback) error

func (*Allocation) GetAllocationDiff

func (a *Allocation) GetAllocationDiff(lastSyncCachePath string, localRootPath string, localFileFilters []string, remoteExcludePath []string) ([]FileDiff, error)

func (*Allocation) GetAuthTicket

func (a *Allocation) GetAuthTicket(path string, filename string, referenceType string, refereeClientID string, refereeEncryptionPublicKey string) (string, error)

func (*Allocation) GetAuthTicketForShare

func (a *Allocation) GetAuthTicketForShare(path string, filename string, referenceType string, refereeClientID string) (string, error)

func (*Allocation) GetFileMeta

func (a *Allocation) GetFileMeta(path string) (*ConsolidatedFileMeta, error)

func (*Allocation) GetFileMetaFromAuthTicket

func (a *Allocation) GetFileMetaFromAuthTicket(authTicket string, lookupHash string) (*ConsolidatedFileMeta, error)

func (*Allocation) GetFileStats

func (a *Allocation) GetFileStats(path string) (map[string]*FileStats, error)

func (*Allocation) GetStats

func (a *Allocation) GetStats() *AllocationStats

func (*Allocation) InitAllocation

func (a *Allocation) InitAllocation()

func (*Allocation) ListDir

func (a *Allocation) ListDir(path string) (*ListResult, error)

func (*Allocation) ListDirFromAuthTicket

func (a *Allocation) ListDirFromAuthTicket(authTicket string, lookupHash string) (*ListResult, error)

func (*Allocation) MoveObject

func (a *Allocation) MoveObject(path string, destPath string) error

func (*Allocation) RenameObject

func (a *Allocation) RenameObject(path string, destName string) error

func (*Allocation) RepairFile

func (a *Allocation) RepairFile(localpath string, remotepath string, status StatusCallback) error

func (*Allocation) SaveRemoteSnapshot

func (a *Allocation) SaveRemoteSnapshot(pathToSave string, remoteExcludePath []string) error

SaveRemoteSnapShot - Saves the remote current information to the given file This file can be passed to GetAllocationDiff to exactly find the previous sync state to current.

func (*Allocation) UnderRepair added in v1.0.31

func (a *Allocation) UnderRepair() bool

func (*Allocation) UpdateFile

func (a *Allocation) UpdateFile(localpath string, remotepath string, status StatusCallback) error

func (*Allocation) UpdateFileWithThumbnail

func (a *Allocation) UpdateFileWithThumbnail(localpath string, remotepath string, thumbnailpath string, status StatusCallback) error

func (*Allocation) UpdateRepairStatus added in v1.0.31

func (a *Allocation) UpdateRepairStatus(value bool)

func (*Allocation) UploadFile

func (a *Allocation) UploadFile(localpath string, remotepath string, status StatusCallback) error

func (*Allocation) UploadFileWithThumbnail

func (a *Allocation) UploadFileWithThumbnail(localpath string, remotepath string, thumbnailpath string, status StatusCallback) error

type AllocationStats

type AllocationStats struct {
	UsedSize                  int64  `json:"used_size"`
	NumWrites                 int64  `json:"num_of_writes"`
	NumReads                  int64  `json:"num_of_reads"`
	TotalChallenges           int64  `json:"total_challenges"`
	OpenChallenges            int64  `json:"num_open_challenges"`
	SuccessChallenges         int64  `json:"num_success_challenges"`
	FailedChallenges          int64  `json:"num_failed_challenges"`
	LastestClosedChallengeTxn string `json:"latest_closed_challenge"`
}

type AuthTicket

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

func InitAuthTicket

func InitAuthTicket(authTicket string) *AuthTicket

func (*AuthTicket) GetFileName

func (at *AuthTicket) GetFileName() (string, error)

func (*AuthTicket) GetLookupHash

func (at *AuthTicket) GetLookupHash() (string, error)

func (*AuthTicket) IsDir

func (at *AuthTicket) IsDir() (bool, error)

type Blobber

type Blobber struct {
	ID              common.Key       `json:"id"`
	BaseURL         string           `json:"url"`
	Terms           Terms            `json:"terms"`
	Capacity        common.Size      `json:"capacity"`
	Used            common.Size      `json:"used"`
	LastHealthCheck common.Timestamp `json:"last_health_check"`
	PublicKey       string           `json:"-"`
}

func GetBlobbers

func GetBlobbers() (bs []*Blobber, err error)

type BlobberAllocation

type BlobberAllocation struct {
	BlobberID     string         `json:"blobber_id"`
	Size          int64          `json:"size"`
	Terms         Terms          `json:"terms"`
	MinLockDemand common.Balance `json:"min_lock_demand"`
	Spent         common.Balance `json:"spent"`
}

type BlockDownloadRequest

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

type ChallengePoolInfo

type ChallengePoolInfo = WritePoolInfo

ChallengePoolInfo is alias for WritePoolInfo

func GetChallengePoolInfo

func GetChallengePoolInfo(allocID string) (info *ChallengePoolInfo, err error)

GetChallengePoolInfo for given allocation.

type CommitMetaData

type CommitMetaData struct {
	CrudType string
	MetaData *ConsolidatedFileMeta
}

type CommitMetaRequest

type CommitMetaRequest struct {
	CommitMetaData
	// contains filtered or unexported fields
}

type CommitMetaResponse

type CommitMetaResponse struct {
	TxnID    string
	MetaData *ConsolidatedFileMeta
}

type CommitRequest

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

type CommitResult

type CommitResult struct {
	Success      bool   `json:"success"`
	ErrorMessage string `json:"error_msg,omitempty"`
}

func ErrorCommitResult

func ErrorCommitResult(errMsg string) *CommitResult

func SuccessCommitResult

func SuccessCommitResult() *CommitResult

type Consensus

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

type ConsolidatedFileMeta

type ConsolidatedFileMeta struct {
	Name         string
	Type         string
	Path         string
	LookupHash   string
	Hash         string
	MimeType     string
	Size         int64
	EncryptedKey string
}

type CopyRequest

type CopyRequest struct {
	Consensus
	// contains filtered or unexported fields
}

func (*CopyRequest) ProcessCopy

func (req *CopyRequest) ProcessCopy() error

type DeleteRequest

type DeleteRequest struct {
	Consensus
	// contains filtered or unexported fields
}

func (*DeleteRequest) ProcessDelete

func (req *DeleteRequest) ProcessDelete() error

type DownloadRequest

type DownloadRequest struct {
	Consensus
	// contains filtered or unexported fields
}

type FileDiff

type FileDiff struct {
	Op   string `json:"operation"`
	Path string `json:"path"`
	Type string `json:"type"`
}

type FileStats

type FileStats struct {
	Name                     string `json:"name"`
	Size                     int64  `json:"size"`
	PathHash                 string `json:"path_hash"`
	Path                     string `json:"path"`
	NumBlocks                int64  `json:"num_of_blocks"`
	NumUpdates               int64  `json:"num_of_updates"`
	NumBlockDownloads        int64  `json:"num_of_block_downloads"`
	SuccessChallenges        int64  `json:"num_of_challenges"`
	FailedChallenges         int64  `json:"num_of_failed_challenges"`
	LastChallengeResponseTxn string `json:"last_challenge_txn"`
	WriteMarkerRedeemTxn     string `json:"write_marker_txn"`
	BlobberID                string `json:"blobber_id"`
	BlobberURL               string `json:"blobber_url"`
	BlockchainAware          bool   `json:"blockchain_aware"`
}

type ListRequest

type ListRequest struct {
	Consensus
	// contains filtered or unexported fields
}

func (*ListRequest) GetListFromBlobbers

func (req *ListRequest) GetListFromBlobbers() *ListResult

type ListResult

type ListResult struct {
	Name          string        `json:"name"`
	Path          string        `json:"path,omitempty"`
	Type          string        `json:"type"`
	Size          int64         `json:"size"`
	Hash          string        `json:"hash,omitempty"`
	MimeType      string        `json:"mimetype,omitempty"`
	NumBlocks     int64         `json:"num_blocks"`
	LookupHash    string        `json:"lookup_hash"`
	EncryptionKey string        `json:"encryption_key"`
	Children      []*ListResult `json:"list"`
	Consensus     `json:"-"`
}

type PriceRange

type PriceRange struct {
	Min int64 `json:"min"`
	Max int64 `json:"max"`
}

PriceRange represents a price range allowed by user to filter blobbers.

func (*PriceRange) IsValid

func (pr *PriceRange) IsValid() bool

IsValid price range.

type ReadPoolInfo added in v1.0.39

type ReadPoolInfo struct {
	Stats []*ReadPoolStat `json:"stats"`
}

ReadPoolInfo is set of read pool locks statistic.

func GetReadPoolInfo

func GetReadPoolInfo(clientID string) (info *ReadPoolInfo, err error)

GetReadPoolInfo for given client, or, if the given clientID is empty, for current client of the sdk.

type ReadPoolStat added in v1.0.39

type ReadPoolStat struct {
	ID        common.Key       `json:"pool_id"`
	StartTime common.Timestamp `json:"start_time"`
	Duration  time.Duration    `json:"duration"`
	TimeLeft  time.Duration    `json:"time_left"`
	Locked    bool             `json:"locked"`
	Balance   common.Balance   `json:"balance"`
}

ReadPoolStat is number of tokens and locking status for the tokens.

type ReferencePathResult

type ReferencePathResult struct {
	*fileref.ReferencePath
	LatestWM *marker.WriteMarker `json:"latest_write_marker"`
}

type RenameRequest

type RenameRequest struct {
	Consensus
	// contains filtered or unexported fields
}

func (*RenameRequest) ProcessRename

func (req *RenameRequest) ProcessRename() error

type ShareRequest

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

func (*ShareRequest) GetAuthTicket

func (req *ShareRequest) GetAuthTicket(clientID string) (string, error)

func (*ShareRequest) GetAuthTicketForEncryptedFile

func (req *ShareRequest) GetAuthTicketForEncryptedFile(clientID string, encPublicKey string) (string, error)

type StakePoolInfo

type StakePoolInfo struct {
	ID            common.Key     `json:"pool_id"`
	Locked        common.Balance `json:"locked"`
	OffersTotal   common.Balance `json:"offers_total"`
	CapacityStake common.Balance `json:"capacity_stake"`
	Lack          common.Balance `json:"lack"`
	Overfill      common.Balance `json:"overfill"`

	Offers []*StakePoolOfferStat `json:"offers"`
}

func GetStakePoolInfo

func GetStakePoolInfo(blobberID string) (info *StakePoolInfo, err error)

GetStakePoolInfo for given client, or, if the given clientID is empty, for current client of the sdk.

type StakePoolOfferStat added in v1.0.39

type StakePoolOfferStat struct {
	Lock         common.Balance   `json:"lock"`
	Expire       common.Timestamp `json:"expire"`
	AllocationID common.Key       `json:"allocation_id"`
	IsExpired    bool             `json:"is_expired"`
}

type StatusCallback

type StatusCallback interface {
	Started(allocationId, filePath string, op int, totalBytes int)
	InProgress(allocationId, filePath string, op int, completedBytes int)
	Error(allocationID string, filePath string, op int, err error)
	Completed(allocationId, filePath string, filename string, mimetype string, size int, op int)
	CommitMetaCompleted(request, response string, err error)
}

type StorageSCConfig

type StorageSCConfig struct {
	ChallengeEnabled           bool                      `json:"challenge_enabled"`
	ChallengeRatePerMBMin      time.Duration             `json:"challenge_rate_per_mb_min"`
	MinAllocSize               common.Size               `json:"min_alloc_size"` // size, bytes
	MinAllocDuration           time.Duration             `json:"min_alloc_duration"`
	MaxChallengeCompletionTime time.Duration             `json:"max_challenge_completion_time"`
	MinOfferDuration           time.Duration             `json:"min_offer_duration"`
	MinBlobberCapacity         common.Size               `json:"min_blobber_capacity"`
	ReadPool                   *StorageSCReadPoolConfig  `json:"readpool"`
	WritePool                  *StorageSCWritePoolConfig `json:"writepool"`
	ValidatorReward            float64                   `json:"validator_reward"`
	BlobberSlash               float64                   `json:"blobber_slash"`
}

func GetStorageSCConfig

func GetStorageSCConfig() (conf *StorageSCConfig, err error)

type StorageSCReadPoolConfig added in v1.0.39

type StorageSCReadPoolConfig struct {
	MinLock       common.Balance `json:"min_lock"`
	MinLockPeriod time.Duration  `json:"min_lock_period"`
	MaxLockPeriod time.Duration  `json:"max_lock_period"`
}

type StorageSCWritePoolConfig added in v1.0.39

type StorageSCWritePoolConfig struct {
	MinLock common.Balance `json:"min_lock"`
}

type Terms

type Terms struct {
	ReadPrice               common.Balance `json:"read_price"`  // tokens / GB
	WritePrice              common.Balance `json:"write_price"` // tokens / GB
	MinLockDemand           float64        `json:"min_lock_demand"`
	MaxOfferDuration        time.Duration  `json:"max_offer_duration"`
	ChallengeCompletionTime time.Duration  `json:"challenge_completion_time"`
}

Terms represents Blobber terms. A Blobber can update its terms, but any existing offer will use terms of offer signing time.

type UploadFileMeta

type UploadFileMeta struct {
	Name          string
	Path          string
	Hash          string
	MimeType      string
	Size          int64
	ThumbnailSize int64
	ThumbnailHash string
}

type UploadRequest

type UploadRequest struct {
	Consensus
	// contains filtered or unexported fields
}

type WritePoolInfo added in v1.0.39

type WritePoolInfo struct {
	ID         common.Key       `json:"pool_id"`
	Balance    common.Balance   `json:"balance"`
	StartTime  common.Timestamp `json:"start_time"`
	Expiration common.Timestamp `json:"expiration"`
	Finalized  bool             `json:"finalized"`
}

func GetWritePoolInfo

func GetWritePoolInfo(allocID string) (info *WritePoolInfo, err error)

GetWritePoolInfo for given client, or, if the given clientID is empty, for current client of the sdk.

Jump to

Keyboard shortcuts

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