tokenstorage

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInsufficientDownloadBytes is an error indicating lack of DownloadBytes resource on the token.
	ErrInsufficientDownloadBytes = errors.New("insufficient DownloadBytes for this operation")

	// ErrInsufficientSectorAccesses is an error indicating lack of SectorAccesses resource on the token.
	ErrInsufficientSectorAccesses = errors.New("insufficient SectorAccesses for this operation")

	// ErrInsufficientDownloadBytesAndSectorAccesses is an error indicating lack of DownloadBytes and SectorAccesses resources on the token.
	ErrInsufficientDownloadBytesAndSectorAccesses = errors.New("insufficient DownloadBytes and SectorAccesses for this operation")

	// ErrInsufficientUploadBytes is an error indicating lack of UploadBytes resource on the token.
	ErrInsufficientUploadBytes = errors.New("insufficient UploadBytes for this operation")

	// ErrInsufficientStorage is an error indicating lack of Storage resource on the token.
	ErrInsufficientStorage = errors.New("insufficient Storage for this operation")
)

Functions

This section is empty.

Types

type TokenRecord

type TokenRecord struct {
	DownloadBytes    int64
	UploadBytes      int64
	SectorAccesses   int64
	TokenStorageInfo TokenStorageInfo
}

TokenRecord include information about token record.

type TokenStorage

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

TokenStorage - storage of tokens for prepaid downloads.

func NewTokenStorage

func NewTokenStorage(stManager modules.StorageManager, dir string) (*TokenStorage, error)

NewTokenStorage - create new storage of tokens for prepaid downloads.

func (*TokenStorage) AddResources

func (t *TokenStorage) AddResources(id types.TokenID, resourceType types.Specifier, amount int64) error

AddResources - add resource to token.

func (*TokenStorage) AddSectors

func (t *TokenStorage) AddSectors(id types.TokenID, sectorsIDs []crypto.Hash, time time.Time) (TokenRecord, error)

AddSectors add sectors to token.

func (*TokenStorage) AttachSectors

func (t *TokenStorage) AttachSectors(sectorIDs map[types.TokenID][]crypto.Hash, callTime time.Time) error

AttachSectors attach sector to contract.

func (*TokenStorage) CheckExpiration

func (t *TokenStorage) CheckExpiration(frequency time.Duration, done chan bool)

CheckExpiration remove sectors from token when token storage resource ends.

func (*TokenStorage) Close

func (t *TokenStorage) Close(ctx context.Context) error

Close - drain event queue and close storage.

func (*TokenStorage) EnoughStorageResource

func (t *TokenStorage) EnoughStorageResource(id types.TokenID, sectorsNum int64, now time.Time) (bool, error)

EnoughStorageResource checks if there is enough storage resource on token to store existing sectors and new ones, return false if not enough.

func (*TokenStorage) ListSectorIDs

func (t *TokenStorage) ListSectorIDs(id types.TokenID, pageID string, limit int) (sectorIDs []crypto.Hash, nextPageID string, err error)

ListSectorIDs returns list of sector ids.

func (*TokenStorage) RecordDownload

func (t *TokenStorage) RecordDownload(id types.TokenID, downloadBytes, sectorAccesses int64, callTime time.Time) (TokenRecord, error)

RecordDownload set token record fields.

func (*TokenStorage) RemoveSpecificSectors

func (t *TokenStorage) RemoveSpecificSectors(id types.TokenID, sectorIDs []crypto.Hash, time time.Time) error

RemoveSpecificSectors removes only passed sectors ids.

func (*TokenStorage) TokenRecord

func (t *TokenStorage) TokenRecord(id types.TokenID) (TokenRecord, error)

TokenRecord return token record by id.

type TokenStorageInfo

type TokenStorageInfo struct {
	Storage        int64 // sectors * second
	LastChangeTime time.Time
	SectorsNum     uint64
}

TokenStorageInfo represent data about storage resource.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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