common

package
v0.0.0-...-ebe581b Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ChallengeFileSuffix = "_sigmas"
)

Functions

func AddFileNewMerkleChallenge

func AddFileNewMerkleChallenge(ctx context.Context, challenger CommonChallenger, chain CommonChain, copier CommonCopier,
	chalEncryptor CommonEncryptor, file blockchain.File, startTime, interval int64, logger *logrus.Entry) error

AddFileNewMerkleChallenge add file merkle challenges when extend file expire time

func AddFilePairingChallenges

func AddFilePairingChallenges(ctx context.Context, pairingConf types.PairingChallengeConf, chain CommonChain, copier CommonCopier,
	file blockchain.File, sourceID string, oldExp, interval int64, logger *logrus.Entry) error

AddFilePairingChallenges add file pairing based challenges when extend file expire time 1. pull slice and sigmas from storage node 2. generate new sigmas and push all sigmas to storage node

func AddSlicesNewMerkleChallenge

func AddSlicesNewMerkleChallenge(challenger CommonChallenger, file blockchain.File, expandSlices []encryptor.EncryptedSlice,
	interval int64, logger *logrus.Entry) error

AddSlicesNewMerkleChallenge add merkle challenges for a storage node when slice migrates to new node

func AddSlicesNewPairingChallenge

func AddSlicesNewPairingChallenge(ctx context.Context, pairingConf types.PairingChallengeConf, copier CommonCopier, slices []encryptor.EncryptedSlice,
	file blockchain.File, chain CommonChain, sourceID string, interval, start, end int64, existSigmas []map[int64][]byte, logger *logrus.Entry) error

AddSlicesNewPairingChallenge generate pairing based challenge material for each slice and push it to storage node 1. get roundStart and roundEnd by start&end time 2. calculate sigmaI for each round 3. pack all sigmas and push to storage node interval, start, end are in nanoseconds

func AnswerPairingChallenge

func AnswerPairingChallenge(content, indices, randVs, sigmas [][]byte, rand []byte) ([]byte, []byte, error)

AnswerPairingChallenge answers pairing based random challenge based on file content

func EncAndPush

func EncAndPush(ctx context.Context, copier CommonCopier, encrypt CommonEncryptor,
	plaintext []byte, sliceID, sourceID, fileID string, node *blockchain.Node) (encryptor.EncryptedSlice, string, error)

EncAndPush encrypt a slice and push to specified storage node returns `EncryptedSlice` for the specified storage node and `Storage Index` returned by the specified storage node

func ExpandFileSlices

func ExpandFileSlices(ctx context.Context, privkey ecdsa.PrivateKey, cp CommonCopier, enc CommonEncryptor, chain CommonChain,
	challenger CommonChallenger, file blockchain.File, nodesMap map[string]blockchain.Node, replica int,
	healthNodes blockchain.NodeHs, interval int64, l *logrus.Entry) error

ExpandFileSlices expand each slice to specific replica 1. find new storage node for the slice 2. pull slice from other node and re-encrypt for new node 3. push slice to new storage node 4. generate challenge material for new storage node

func FindNewNodes

func FindNewNodes(healthNodes blockchain.NodeHs, selected []string) (blockchain.Nodes, error)

FindNewNodes selects a new healthy node for slice

func GetFileHealth

func GetFileHealth(ctx context.Context, chain CommonChain, file blockchain.File, replica int) (health string, err error)

GetFileHealth gets file heath status

func GetFileSysHealth

func GetFileSysHealth(ctx context.Context, nss []blockchain.Namespace, nodes blockchain.Nodes, chain CommonChain) (
	fh blockchain.FileSysHealth, err error)

GetFileSysHealth get system health status of a file owner, include files and nodes health status

func GetHealthNodes

func GetHealthNodes(chain CommonChain) (nodes blockchain.NodeHs, err error)

GetHealthNodes gets online healthy(green, yellow) nodes

func GetHeartBeatStats

func GetHeartBeatStats(now, regTime int64) (int64, int64)

GetHeartBeatStats get heart beat statistics during start and end time

func GetHeartBeatTotalNumByTime

func GetHeartBeatTotalNumByTime(chain CommonChain, id []byte, start, end int64) (int, error)

GetHeartBeatTotalNumByTime get total heart beat number of a storage node during given time period

func GetHeartbeatMaxNum

func GetHeartbeatMaxNum(start, end, regTime int64) int

GetHeartbeatMaxNum calculate the max possible heart beat number given a time period

func GetHeartbeatNum

func GetHeartbeatNum(chain CommonChain, id []byte, ts []int64) (int, error)

GetHeartbeatNum get heart beat number of a storage node from blockchain

func GetMCRange

func GetMCRange(challenger CommonChallenger, fileID string, es encryptor.EncryptedSlice, expireTime,
	startTime, interval int64) (m ctype.Material, err error)

GetMCRange generate and save more merkle challenges

func GetNsFilesHealth

func GetNsFilesHealth(ctx context.Context, ns blockchain.Namespace, chain CommonChain) (nsh blockchain.NamespaceH, err error)

GetNsFilesHealth gets namespace health conditions

func GetPairingChallengeRound

func GetPairingChallengeRound(interval int64) int64

GetPairingChallengeRound get challenge round number for pairing based challenge round = timeNow / challengeInterval (in nanoseconds)

func GetSliceAvgHealth

func GetSliceAvgHealth(nodes []string, fhns map[string]string) (health string, err error)

GetSliceAvgHealth get slice health status

func GetSliceNodes

func GetSliceNodes(ss []blockchain.PublicSliceMeta, nodesMap map[string]blockchain.Node) map[string][]blockchain.Node

GetSliceNodes get storage nodes for each slice

func GetSliceSigmasID

func GetSliceSigmasID(sliceID string) string

GetSliceSigmasID pack file name to pull sigmas from `Storage Node`

func PullAndDec

func PullAndDec(ctx context.Context, copier CommonCopier, encrypt CommonEncryptor,
	slice blockchain.PublicSliceMeta, node *blockchain.Node, fileID string) ([]byte, error)

PullAndDec pull a slice from healthy node and decrypt

func SaveMerkleChallenger

func SaveMerkleChallenger(challenger CommonChallenger, challengingMaterial []ctype.Material) error

SaveMerkleChallenger save challenge material

func SigmasFromBytes

func SigmasFromBytes(sigmasBytes []byte) (map[int64][]byte, error)

SigmasFromBytes convert sigma list from bytes

func SigmasToBytes

func SigmasToBytes(sigmas map[int64][]byte) ([]byte, error)

SigmasToBytes convert a slice's sigma list to bytes

func ToNodeHsMap

func ToNodeHsMap(nodes blockchain.NodeHs) map[string]blockchain.Node

ToNodeHsMap make a map from node id to node with health status

func ToNodesMap

func ToNodesMap(nodes blockchain.Nodes) map[string]blockchain.Node

ToNodesMap make a map from node id to node

func TodayBeginning

func TodayBeginning(timestamp int64) int64

TodayBeginning convert a timestamp to 00:00:00 of this day

Types

type CommonChain

type CommonChain interface {
	ListNodes() (blockchain.Nodes, error)
	GetNode(id []byte) (blockchain.Node, error)
	GetNodeHealth(id []byte) (string, error)
	GetHeartbeatNum(id []byte, timestamp int64) (int, error)

	ListFiles(opt *blockchain.ListFileOptions) ([]blockchain.File, error)
	ListFileNs(opt *blockchain.ListNsOptions) ([]blockchain.Namespace, error)
	UpdateFilePublicSliceMeta(opt *blockchain.UpdateFilePSMOptions) error
}

CommonChain defines several contract/chaincode methods related to file migration and node/file health

type CommonChallenger

type CommonChallenger interface {
	Setup(sliceData []byte, rangeAmount int) ([]ctype.RangeHash, error)
	Save(cms []ctype.Material) error
	Take(fileID string, sliceID string, nodeID []byte) (ctype.RangeHash, error)

	GetChallengeConf() (string, types.PairingChallengeConf)
}

CommonChallenger defines Merkle-Tree based / pairing based challenger

type CommonCopier

type CommonCopier interface {
	// Push pushes slices onto Storage Node, returns storage index of slice
	Push(ctx context.Context, id, sourceID string, r io.Reader, node *blockchain.Node) (string, error)

	// Pull pulls slice from storage node
	Pull(ctx context.Context, id, storIndex, fileID string, node *blockchain.Node) (io.ReadCloser, error)

	// ReplicaExpansion slice performs Replica-Expand, that is to
	//  pull slices from original nodes and decrypt and re-encrypt those slices,
	//  then push them onto new Storage Nodes.
	ReplicaExpansion(ctx context.Context, opt *copier.ReplicaExpOptions, enc CommonEncryptor, ca, sourceID, fileID string) (
		[]blockchain.PublicSliceMeta, []encryptor.EncryptedSlice, error)
}

CommonCopier defines slice copier when migrating a file

type CommonEncryptor

type CommonEncryptor interface {
	Encrypt(r io.Reader, opt *encryptor.EncryptOptions) (encryptor.EncryptedSlice, error)
	Recover(r io.Reader, opt *encryptor.RecoverOptions) ([]byte, error)
}

CommonEncryptor defines encryptor for file encryption and decryption when adding more merkle challenges or migrate files

Jump to

Keyboard shortcuts

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