contract

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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, transfered bool) error
	DeleteContract(contractHash string) error
	GetContractFiles(contractHash string) ([]FileInfo, error)
	ReleaseContractFees(contractHash string)
	GetReleaseContractFeesStatus(contractHash string) bool
	LoadFromDB() error
	IncrementTransferedBytes(contractHash string, fileHash []byte, fileNamePart, destinationFilePath string, filePartFromRange int64, count uint64)
	SetFilePartDownloadError(contractHash string, fileHash []byte, fileNamePart, errorMessage string)
	GetTransferedBytes(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)
	GetDownoadedFilePartNames(contractHash string, fileHash []byte) []string
}

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) 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) GetDownoadedFilePartNames

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

GetDownoadedFilePartNames gets the downloaded file parts names in order.

func (*Store) GetReleaseContractFeesStatus

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

GetReleaseContractFeesStatus returns true if contract fees were released.

func (*Store) GetTransferedBytes

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

GetTransferedBytes gets the transfered bytes for a file.

func (*Store) IncrementTransferedBytes

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

IncrementTransferedBytes increments the number of bytes transfered for a file.

func (*Store) LoadFromDB

func (c *Store) LoadFromDB() error

LoadFromDB loads the persisted data into memory.

func (*Store) ReleaseContractFees

func (c *Store) ReleaseContractFees(contractHash string)

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

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 successfull.

func (*Store) SetReceivedUnencryptedDataFromFileHoster

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

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

Jump to

Keyboard shortcuts

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