Documentation ¶
Index ¶
- Constants
- func CalculateFileHosterTotalContractFees(downloadContract *messages.DownloadContractProto, ...) (*big.Int, error)
- func ChunkString(s string, chunkSize int) []string
- func ConcatenateFiles(outputFile string, inputFiles []string) error
- func CreateDirectory(path string) error
- func DecryptFileSegments(fileSize, totalSegments, percentageToEncryptData int, ...) error
- func DefaultDataDir() string
- func DirExists(filename string) bool
- func EncryptWriteOutput(fileSize, from, to, totalSegments, percentageToEncryptData int, ...) error
- func FileExists(filename string) bool
- func FileSegmentsInfo(fileSize int, howManySegments int, percentageToEncrypt int) (int, int, int, int, error)
- func FileSize(fullPath string) (int64, error)
- func FormatBigWithSeperator(s string, sep string, index int) string
- func GenerateRandomIntSlice(totalPerm int) []int
- func GetDirectoryFreeSpace(directoryPath string) (uint64, error)
- func GetFileMerkleRootHash(filePath string, totalSegments int, segmentsOrder []int) ([]byte, error)
- func GetFileMerkleRootHashFromNodes(fileBlockHashes []FileBlockHash) ([]byte, error)
- func HomeDir() string
- func IsValidPath(s string) bool
- func LeftPad2Len(s string, padStr string, overallLen int) string
- func Reverse(s string) string
- func WriteToFile(data []byte, filePath string) (string, error)
- func WriteUnencryptedSegments(fileSize, totalSegments, percentageToEncryptData int, ...) error
- type DataEncryptor
- type EncryptionType
- type Encryptor
- type FileBlockHash
- func EncryptAndHashSegments(fileSize, totalSegments int, randomizedFileSegments []int, ...) ([]FileBlockHash, error)
- func HashFileBlockSegments(filePath string, totalSegments int, randomSegments []int) ([]FileBlockHash, error)
- func RetrieveMerkleTreeNodesFromFileWithRawData(encryptEverySegment int, randomizedFileSegments []int, ...) ([]FileBlockHash, error)
- type FileBlockRange
- type ReadWriteSeekerSyncer
Constants ¶
const ( // FFGNetPubSubBlocksTXQuery is a pub sub topic name to receive transactions, data queries and blocks. FFGNetPubSubBlocksTXQuery = "ffgnet_pubsub" // FFGNetPubSubStorageQuery is a pub sub topic name to receive storage queryies. FFGNetPubSubStorageQuery = "ffgnet_pubsub_storage" )
const ( // EncryptionTypeAES key and iv are both 32 bytes for aes EncryptionTypeAES256 EncryptionType = 1 // EncryptionTypeChacha20 key 32 bytes, iv(nounce) 32 bytes EncryptionTypeChacha20 EncryptionType = 2 // KB represents 1024 bytes KB = 1024 // MB represents 1024 KBytes MB = 1024 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func CalculateFileHosterTotalContractFees ¶ added in v1.3.1
func CalculateFileHosterTotalContractFees(downloadContract *messages.DownloadContractProto, fileHosterFeesPerByte *big.Int) (*big.Int, error)
CalculateFileHosterTotalContractFees given a download contract calculates the amount required by the file hoster
func ChunkString ¶
ChunkString chunks a string based on the chunk size.
func ConcatenateFiles ¶
ConcatenateFiles concatenates multiple files into one output file.
func DecryptFileSegments ¶
func DecryptFileSegments(fileSize, totalSegments, percentageToEncryptData int, randomizedFileSegments []int, input ReadWriteSeekerSyncer, output io.WriteCloser, encryptor DataEncryptor, onlyFileReArrangement bool) error
DecryptFileSegments decrypts the segments and replaces them in the original file and then performs a file block/segment re-arrangement and writes to the output.
func EncryptWriteOutput ¶
func EncryptWriteOutput(fileSize, from, to, totalSegments, percentageToEncryptData int, randomizedFileSegments []int, input io.ReadSeekCloser, output io.WriteCloser, encryptor DataEncryptor) error
EncryptWriteOutput uses the stream cipher to encrypt the input reader and write to the output.
func FileExists ¶
FileExists checks if destination file exists
func FileSegmentsInfo ¶
func FileSegmentsInfo(fileSize int, howManySegments int, percentageToEncrypt int) (int, int, int, int, error)
FileSegmentsInfo returns the info about the segments of a file and number of encrypted segment given the file size.
func FormatBigWithSeperator ¶
FormatBigWithSeperator formats a big number with separator.
func GenerateRandomIntSlice ¶
GenerateRandomIntSlice generates a random slice we always keep the last item same as original index
func GetDirectoryFreeSpace ¶ added in v1.1.20
GetDirectoryFreeSpace returns the available space of a directory.
func GetFileMerkleRootHash ¶
GetFileMerkleRootHash get a merkle root.
func GetFileMerkleRootHashFromNodes ¶
func GetFileMerkleRootHashFromNodes(fileBlockHashes []FileBlockHash) ([]byte, error)
GetFileMerkleRootHashFromNodes get a merkle root from the content.
func IsValidPath ¶ added in v1.2.1
IsValidPath checks if path contains more than one "." character.
func LeftPad2Len ¶
LeftPad2Len add padding deparator.
func WriteToFile ¶
WriteToFile writes data to a file.
func WriteUnencryptedSegments ¶
func WriteUnencryptedSegments(fileSize, totalSegments, percentageToEncryptData int, randomizedFileSegments []int, input io.ReadSeekCloser, output io.WriteCloser) error
WriteUnencryptedSegments takes the file segments that need to be encrypted and copies them to output before encryption is performed.
Types ¶
type DataEncryptor ¶
type DataEncryptor interface { StreamEncryptor() (cipher.Stream, error) EncryptionType() EncryptionType }
DataEncryptor is an interface to define the functionality of a data encryptor.
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
Encryptor represents an encryptor.
func NewEncryptor ¶
func NewEncryptor(encryptionType EncryptionType, key, iv []byte) (*Encryptor, error)
NewEncryptor is a new encryptor.
func (*Encryptor) EncryptionType ¶
func (e *Encryptor) EncryptionType() EncryptionType
EncryptionType returns the type of the encryptor.
type FileBlockHash ¶
type FileBlockHash struct {
X []byte
}
FileBlockHash represents a hash of a block (range of bytes) of a file.
func EncryptAndHashSegments ¶
func EncryptAndHashSegments(fileSize, totalSegments int, randomizedFileSegments []int, input io.ReadSeekCloser, encryptor DataEncryptor) ([]FileBlockHash, error)
EncryptAndHashSegments encrypts a file's raw segment given a key and hashes the segment.
func HashFileBlockSegments ¶
func HashFileBlockSegments(filePath string, totalSegments int, randomSegments []int) ([]FileBlockHash, error)
HashFileBlockSegments hashes all the file block segments and returns the merkle tree nodes. default totalSegments is 1024
func RetrieveMerkleTreeNodesFromFileWithRawData ¶
func RetrieveMerkleTreeNodesFromFileWithRawData(encryptEverySegment int, randomizedFileSegments []int, merkleTreeItems, merkleTreeOfRawSegments []FileBlockHash) ([]FileBlockHash, error)
RetrieveMerkleTreeNodes retrives the original order of merkle tree given the random list.
func (FileBlockHash) CalculateHash ¶
func (f FileBlockHash) CalculateHash() ([]byte, error)
CalculateHash hashes the content of FileBlockHash.x.
func (FileBlockHash) Equals ¶
func (f FileBlockHash) Equals(other merkletree.Content) (bool, error)
Equals tests for equality of two FileBlockHash.
type FileBlockRange ¶
type FileBlockRange struct {
// contains filtered or unexported fields
}
FileBlockRange represents range of bytes to be encrypted.
func PrepareFileBlockRanges ¶
func PrepareFileBlockRanges(from, to, fileSize, totalSegments, segmentSizeBytes, totalSegmentsToEncrypt, encryptEverySegment int, randomSlice []int) ([]FileBlockRange, bool)
PrepareFileBlockRanges returns a list of file block/segments and the order for each block. random slice is used to shuffle the byte blocks/segments.
type ReadWriteSeekerSyncer ¶
type ReadWriteSeekerSyncer interface { io.ReadWriteSeeker Sync() error }
ReadWriteSeekerSyncer is used to add Sync to ReadWriteSeeker interface.