contractset

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SectorSize is used to define the size of data sector, which is 4 MiB
	SectorSize = uint64(1 << 22)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Contract

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

Contract is a data structure that stored the contract information

func (*Contract) CommitDownload

func (c *Contract) CommitDownload(t *writeaheadlog.Transaction, signedRev types.StorageContractRevision, bandwidth common.BigInt) (err error)

CommitDownload will update the contract header information after each file download information will be stored in both db and memory

func (*Contract) CommitRevision

func (c *Contract) CommitRevision(signedRevision types.StorageContractRevision, costs ...common.BigInt) (err error)

CommitRevision unify the CommitUpload and CommitDownload signature and use memory snapshot instead of WAL.Transaction log

func (*Contract) CommitTxns

func (c *Contract) CommitTxns() (err error)

CommitTxns will apply all un-applied transactions

func (*Contract) CommitUpload

func (c *Contract) CommitUpload(t *writeaheadlog.Transaction, signedRev types.StorageContractRevision, storageCost, bandwidthCost common.BigInt) (err error)

CommitUpload will update the contract header and merkle root information after each file upload information will be stored in both db and memory

func (*Contract) Header

func (c *Contract) Header() ContractHeader

Header will return the contract header information of the contract

func (*Contract) LatestRevisionValidation

func (c *Contract) LatestRevisionValidation(rev types.StorageContractRevision) (err error)

LatestRevisionValidation will validate the storage host revision passed in, check if they have the same latest revision

func (*Contract) MerkleRoots

func (c *Contract) MerkleRoots() ([]common.Hash, error)

MerkleRoots will return the merkle roots information of the contract

func (*Contract) Metadata

func (c *Contract) Metadata() (meta storage.ContractMetaData)

Metadata will generate contract meta data based on the contract information

func (*Contract) RollbackUndoMem

func (c *Contract) RollbackUndoMem(undoHeader ContractHeader) (err error)

RollbackUndoMem will execute rollback from memory undo record

func (*Contract) RollbackUndoWal

func (c *Contract) RollbackUndoWal(t *writeaheadlog.Transaction) (err error)

RollbackUndoWal will execute rollback from WAL undo record

func (*Contract) Status

func (c *Contract) Status() (stats storage.ContractStatus)

Status will return the current status of the contract

func (*Contract) UndoRevisionLog

func (c *Contract) UndoRevisionLog(contractHeader ContractHeader) (t *writeaheadlog.Transaction, err error)

UndoRevisionLog will record pre-revision contract revision, which is not stored in the database. once negotiation has completed, CommitUpload/CommitDownload will be called to record the actual contract revision and store it into database

func (*Contract) UpdateStatus

func (c *Contract) UpdateStatus(status storage.ContractStatus) (err error)

UpdateStatus will update the current contract status

type ContractHeader

type ContractHeader struct {
	ID      storage.ContractID
	EnodeID enode.ID

	LatestContractRevision types.StorageContractRevision

	// Convert the PrivateKey from string to ecdsa private key
	// and convert the ecdsa private key to string
	//
	//Encode Private Key to String: hex.EncodeToString(crypto.FromECDSA(k.PrivateKey))
	//Change the string back to private key: privkey, err := crypto.HexToECDSA(keyJSON.PrivateKey)
	PrivateKey string

	StartHeight uint64

	// contract cost
	UploadCost   common.BigInt
	DownloadCost common.BigInt
	StorageCost  common.BigInt
	TotalCost    common.BigInt
	GasFee       common.BigInt
	ContractFee  common.BigInt

	// status specifies if the contract is good for file uploading or renewing.
	// it also specifies if the contract is canceled
	Status storage.ContractStatus
}

ContractHeader specifies contract's general information

type DB

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

DB is the database wrapper that is used to store the contract set information

func OpenDB

func OpenDB(path string) (db *DB, err error)

OpenDB will create a new level db. If the db already existed, it will open the db instead

func (*DB) Close

func (db *DB) Close()

Close will close the level db, therefore, another process can open it again

func (*DB) DeleteContractHeader

func (db *DB) DeleteContractHeader(id storage.ContractID) (err error)

DeleteContractHeader will delete the contract header information from the contractsetdb, based on the contract id provided

func (*DB) DeleteHeaderAndRoots

func (db *DB) DeleteHeaderAndRoots(id storage.ContractID) (err error)

DeleteHeaderAndRoots will delete both contract header and contract roots information from the contract set database

func (*DB) DeleteMerkleRoots

func (db *DB) DeleteMerkleRoots(id storage.ContractID) (err error)

DeleteMerkleRoots will delete the contract roots information from the contractsetdb, based on the contract id provided

func (*DB) EmptyDB

func (db *DB) EmptyDB() (err error)

EmptyDB will clear all db entries

func (*DB) FetchAll

func (db *DB) FetchAll() (chs []ContractHeader, allRoots [][]common.Hash, err error)

FetchAll will fetch all contract header and merkle roots information

func (*DB) FetchAllContractID

func (db *DB) FetchAllContractID() (ids []storage.ContractID)

FetchAllContractID will fetch all contract ID stored in the contract set db

func (*DB) FetchAllHeader

func (db *DB) FetchAllHeader() (chs []ContractHeader, err error)

FetchAllHeader will fetch all contract header information from the database

func (*DB) FetchAllRoots

func (db *DB) FetchAllRoots() (allRoots [][]common.Hash, err error)

FetchAllRoots will fetch all merkle roots information from the database

func (*DB) FetchContractHeader

func (db *DB) FetchContractHeader(id storage.ContractID) (ch ContractHeader, err error)

FetchContractHeader will retrieve the contract header information based on the contract id provided

func (*DB) FetchHeaderAndRoots

func (db *DB) FetchHeaderAndRoots(id storage.ContractID) (ch ContractHeader, roots []common.Hash, err error)

FetchHeaderAndRoots will fetch both contract header and contract roots information from the contract set database

func (*DB) FetchMerkleRoots

func (db *DB) FetchMerkleRoots(id storage.ContractID) (roots []common.Hash, err error)

FetchMerkleRoots will retrieve the contract roots information based on the contract id provided

func (*DB) StoreContractHeader

func (db *DB) StoreContractHeader(ch ContractHeader) (err error)

StoreContractHeader will stored the contract header information into the database

func (*DB) StoreHeaderAndRoots

func (db *DB) StoreHeaderAndRoots(ch ContractHeader, roots []common.Hash) (err error)

StoreHeaderAndRoots will store both contract header and contract roots information into the contract set database

func (*DB) StoreMerkleRoots

func (db *DB) StoreMerkleRoots(id storage.ContractID, roots []common.Hash) (err error)

StoreMerkleRoots will store the contract roots information into the database

func (*DB) StoreSingleRoot

func (db *DB) StoreSingleRoot(id storage.ContractID, root common.Hash) (err error)

StoreSingleRoot will store one root into the database. If the contract id already have merkle roots stored in the database, append the new root into it. Otherwise store the root as a new root

type RateLimit

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

RateLimit is the data structure that defines the read and write speed limit in terms of bytes per second. It also defines the packet size per transfer.

func NewRateLimit

func NewRateLimit(readBPS, writeBPS int64, packetSize uint64) (rt *RateLimit)

NewRateLimit will initialize the RateLimit object, where readBPS specifies the read bytes per second, writeBPS specify the write bytes per second, and the packet size specifies the size of data can be uploaded each time. readBPS -> 0: unlimited read writeBPS -> 0: unlimited write packetSize -> 0: 4 MiB by default

func (*RateLimit) RetrieveRateLimit

func (rl *RateLimit) RetrieveRateLimit() (readBPS, writeBPS int64, packetSize uint64)

RetrieveRateLimit will return the current rate limit settings

func (*RateLimit) SetRateLimit

func (rl *RateLimit) SetRateLimit(readBPS, writeBPS int64, packetSize uint64)

SetRateLimit will set the rate limit based on the value user provided

type StorageContractSet

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

StorageContractSet is used to record all contract signed by the storage client

func New

func New(persistDir string) (scs *StorageContractSet, err error)

New will initialize the StorageContractSet object, as well as loading the data that already stored in the database

func (*StorageContractSet) Acquire

func (scs *StorageContractSet) Acquire(id storage.ContractID) (c *Contract, exists bool)

Acquire will acquire the contract from the contractSet, the contract acquired from the contract set will be locked. Once acquired, the contract must be returned to unlock it.

func (*StorageContractSet) Close

func (scs *StorageContractSet) Close() (err error)

Close will close the database and closing the writeaheadlog

func (*StorageContractSet) Contracts

func (scs *StorageContractSet) Contracts() map[storage.ContractID]*Contract

Contracts is used to get all active contracts signed by the storage client

func (*StorageContractSet) Delete

func (scs *StorageContractSet) Delete(c *Contract) (err error)

Delete will delete a storage contract from the contract set the contract must be acquired using the Acquire function

func (*StorageContractSet) EmptyDB

func (scs *StorageContractSet) EmptyDB() (err error)

EmptyDB will clear all data stored in the contractset database

func (*StorageContractSet) GetContractIDByHostID

func (scs *StorageContractSet) GetContractIDByHostID(hostID enode.ID) storage.ContractID

GetContractIDByHostID will retrieve the contractID based on the hostID provided

func (*StorageContractSet) IDs

func (scs *StorageContractSet) IDs() (ids []storage.ContractID)

IDs return a list of storage contract id stored in the contract set

func (*StorageContractSet) InsertContract

func (scs *StorageContractSet) InsertContract(ch ContractHeader, roots []common.Hash) (cm storage.ContractMetaData, err error)

InsertContract will insert the formed or renewed contract into the storage contract set allow contract manager further to maintain them

func (*StorageContractSet) RetrieveAllContractsMetaData

func (scs *StorageContractSet) RetrieveAllContractsMetaData() (cms []storage.ContractMetaData)

RetrieveAllContractsMetaData will return all ContractMetaData stored in the contract set in the form of list

func (*StorageContractSet) RetrieveContractMetaData

func (scs *StorageContractSet) RetrieveContractMetaData(id storage.ContractID) (cm storage.ContractMetaData, exist bool)

RetrieveContractMetaData will return ContractMetaData based on the contract id provided

func (*StorageContractSet) RetrieveRateLimit

func (scs *StorageContractSet) RetrieveRateLimit() (readBPS, writeBPS int64, packetSize uint64)

RetrieveRateLimit will retrieve the current rate limit settings

func (*StorageContractSet) Return

func (scs *StorageContractSet) Return(c *Contract) (err error)

Return will unlock the contract acquired from the contractSet using the acquire function the contract must be acquired using the Acquire function first before using this function

func (*StorageContractSet) SetRateLimit

func (scs *StorageContractSet) SetRateLimit(readBPS, writeBPS int64, packetSize uint64)

SetRateLimit will set the rate limit based on the value user provided

Jump to

Keyboard shortcuts

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