contract

package
v1.1.26 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytesTransferStats added in v1.1.9

type BytesTransferStats struct {
	FromByteRange       int64
	ToByteRange         int64
	DestinationFilePath string
	FilePartName        string
	BytesTransfer       uint64
	ErrorMessage        string
}

BytesTransferStats represents the metadata of a transferred data file part.

type ContextFileDownloadData added in v1.1.8

type ContextFileDownloadData struct {
	From   int64
	To     int64
	Ctx    context.Context
	Cancel context.CancelFunc
}

ContextFileDownloadData

type FileDecryptionStatus

type FileDecryptionStatus string

FileDecryptionStatus represents the file decryption status.

const (
	FileNotDecrypted    FileDecryptionStatus = ""
	FileDecrypted       FileDecryptionStatus = "decrypted"
	FileDecrypting      FileDecryptionStatus = "decrypting"
	FileDecryptionError FileDecryptionStatus = "decryption_error"
)

type FileInfo

type FileInfo struct {
	FileSize                              uint64
	Key                                   []byte
	IV                                    []byte
	MerkleRootHash                        []byte
	FileHash                              []byte
	RandomSegments                        []int
	MerkleTreeNodes                       [][]byte
	EncryptionType                        common.EncryptionType
	ProofOfTransferVerified               bool
	ReceivedUnencryptedDataFromFileHoster bool
	Error                                 string
	FileDecryptionStatus                  FileDecryptionStatus
}

FileInfo represents a contract with the file information.

type Interface

type Interface interface {
	CreateContract(contract *messages.DownloadContractProto) error
	GetContract(contractHash string) (*messages.DownloadContractProto, error)
	GetContractFileInfo(contractHash string, fileHash []byte) (FileInfo, error)
	SetMerkleTreeNodes(contractHash string, fileHash []byte, merkleTreeNodes [][]byte) error
	SetKeyIVEncryptionTypeRandomizedFileSegments(contractHash string, fileHash []byte, key, iv, merkleRootHash []byte, encryptionType common.EncryptionType, randomizedSegments []int, fileSize uint64) error
	SetProofOfTransferVerified(contractHash string, fileHash []byte, verified bool) error
	SetReceivedUnencryptedDataFromFileHoster(contractHash string, fileHash []byte, transferred bool) error
	DeleteContract(contractHash string) error
	GetContractFiles(contractHash string) ([]FileInfo, error)
	ReleaseContractFees(contractHash string)
	GetReleaseContractFeesStatus(contractHash string) bool
	LoadFromDB() error
	IncrementTransferredBytes(contractHash string, fileHash []byte, fileNamePart, destinationFilePath string, filePartFromRange, filePartToRange int64, count uint64)
	SetFilePartDownloadError(contractHash string, fileHash []byte, fileNamePart, errorMessage string)
	GetTransferredBytes(contractHash string, fileHash []byte) uint64
	SetError(contractHash string, fileHash []byte, errorMessage string)
	SetFileSize(contractHash string, fileHash []byte, fileSize uint64)
	SetFileDecryptionStatus(contractHash string, fileHash []byte, decryptionStatus FileDecryptionStatus)
	GetDownoadedFilePartInfos(contractHash string, fileHash []byte) []BytesTransferStats
	PurgeInactiveContracts(int64) error
	SetContractFileDownloadContexts(key string, ctxData ContextFileDownloadData)
	CancelContractFileDownloadContexts(key string) error
	ResetTransferredBytes(contractHash string, fileHash []byte) error
}

Interface defines the functionalities of contract store.

type Store

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

Store represents the contract stores.

func New

func New(db database.Database) (*Store, error)

New constructs a contract store.

func (*Store) CancelContractFileDownloadContexts added in v1.1.8

func (c *Store) CancelContractFileDownloadContexts(key string) error

CancelContractFileDownloadContexts cancels all the contexts file part downloads. key is ContractHash + FileHash

func (*Store) CreateContract

func (c *Store) CreateContract(contract *messages.DownloadContractProto) error

CreateContract creates a contract with the zero values for file information

func (*Store) Debug

func (c *Store) Debug(w http.ResponseWriter, r *http.Request)

Debug serves the internal state

func (*Store) DeleteContract

func (c *Store) DeleteContract(contractHash string) error

DeleteContract removes a contract.

func (*Store) GetContract

func (c *Store) GetContract(contractHash string) (*messages.DownloadContractProto, error)

GetContract get a contract.

func (*Store) GetContractFileInfo

func (c *Store) GetContractFileInfo(contractHash string, fileHash []byte) (FileInfo, error)

GetContractFileInfo returns the file info given a contract hash and file hash

func (*Store) GetContractFiles

func (c *Store) GetContractFiles(contractHash string) ([]FileInfo, error)

GetContractFiles returns the files info given a contract hash

func (*Store) GetDownoadedFilePartInfos added in v1.1.9

func (c *Store) GetDownoadedFilePartInfos(contractHash string, fileHash []byte) []BytesTransferStats

GetDownoadedFilePartInfos gets the downloaded file part infos.

func (*Store) GetReleaseContractFeesStatus

func (c *Store) GetReleaseContractFeesStatus(contractHash string) bool

GetReleaseContractFeesStatus returns true if contract fees were released.

func (*Store) GetTransferredBytes added in v1.1.17

func (c *Store) GetTransferredBytes(contractHash string, fileHash []byte) uint64

GetTransferredBytes gets the transferred bytes for a file.

func (*Store) IncrementTransferredBytes added in v1.1.17

func (c *Store) IncrementTransferredBytes(contractHash string, fileHash []byte, fileNamePart, destinationFilePath string, filePartFromRange, filePartToRange int64, count uint64)

IncrementTransferredBytes increments the number of bytes transferred for a file.

func (*Store) LoadFromDB

func (c *Store) LoadFromDB() error

LoadFromDB loads the persisted data into memory.

func (*Store) PurgeInactiveContracts added in v1.1.7

func (c *Store) PurgeInactiveContracts(purgeAfterSeconds int64) error

PurgeInactiveContracts removes inactive contracts Purge after 5 days (60 * 60 * 24 * 5)

func (*Store) ReleaseContractFees

func (c *Store) ReleaseContractFees(contractHash string)

ReleaseContractFees stores an inmem indication that contract fees were released to file hoster.

func (*Store) ResetTransferredBytes added in v1.1.17

func (c *Store) ResetTransferredBytes(contractHash string, fileHash []byte) error

ResetTransferredBytes resets file transfer bytes to zero.

func (*Store) SetContractFileDownloadContexts added in v1.1.8

func (c *Store) SetContractFileDownloadContexts(key string, ctxData ContextFileDownloadData)

SetContractFileDownloadContexts stores the contexts for downloading file parts. these contexts can be canceled in future.

func (*Store) SetError

func (c *Store) SetError(contractHash string, fileHash []byte, errorMessage string)

SetError sets an error indication for a filehash

func (*Store) SetFileDecryptionStatus

func (c *Store) SetFileDecryptionStatus(contractHash string, fileHash []byte, decryptionStatus FileDecryptionStatus)

SetFileDecryptionStatus sets a file encryption status.

func (*Store) SetFilePartDownloadError

func (c *Store) SetFilePartDownloadError(contractHash string, fileHash []byte, fileNamePart, errorMessage string)

SetFilePartDownloadError sets an error for a file part download.

func (*Store) SetFileSize

func (c *Store) SetFileSize(contractHash string, fileHash []byte, fileSize uint64)

SetFileSize sets a file size

func (*Store) SetKeyIVEncryptionTypeRandomizedFileSegments

func (c *Store) SetKeyIVEncryptionTypeRandomizedFileSegments(contractHash string, fileHash []byte, key, iv, merkleRootHash []byte, encryptionType common.EncryptionType, randomizedSegments []int, fileSize uint64) error

SetKeyIVEncryptionTypeRandomizedFileSegments sets the key and iv, encryption type and randomized segments of the of file.

func (*Store) SetMerkleTreeNodes

func (c *Store) SetMerkleTreeNodes(contractHash string, fileHash []byte, merkleTreeNodes [][]byte) error

SetMerkleTreeNodes sets a merkle tree nodes of the file.

func (*Store) SetProofOfTransferVerified

func (c *Store) SetProofOfTransferVerified(contractHash string, fileHash []byte, verified bool) error

SetProofOfTransferVerified sets if a proof of transfer was successful.

func (*Store) SetReceivedUnencryptedDataFromFileHoster

func (c *Store) SetReceivedUnencryptedDataFromFileHoster(contractHash string, fileHash []byte, transferred bool) error

SetReceivedUnencryptedDataFromFileHoster if all unencrypted data were transferred from file hoster to verifier node.

Jump to

Keyboard shortcuts

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