engine

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: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blockchain

type Blockchain interface {
	// The following contract methods are used by storage node,
	// for distributed governance and healthy check of nodes
	AddNode(opt *blockchain.AddNodeOptions) error
	ListNodes() (blockchain.Nodes, error)
	GetNode(id []byte) (blockchain.Node, error)
	NodeOffline(opt *blockchain.NodeOperateOptions) error
	NodeOnline(opt *blockchain.NodeOperateOptions) error
	Heartbeat(opt *blockchain.NodeHeartBeatOptions) error
	GetHeartbeatNum(id []byte, timestamp int64) (int, error)
	GetNodeHealth(id []byte) (string, error)
	ListNodesExpireSlice(opt *blockchain.ListNodeSliceOptions) ([][2]string, error)
	GetSliceMigrateRecords(opt *blockchain.NodeSliceMigrateOptions) (string, error)

	// The following contract methods are used by dataOwner node
	PublishFile(file *blockchain.PublishFileOptions) error
	GetFileByName(owner []byte, ns, name string) (blockchain.File, error)
	GetFileByID(id string) (blockchain.File, error)
	UpdateFileExpireTime(opt *blockchain.UpdateExptimeOptions) (blockchain.File, error)
	AddFileNs(opt *blockchain.AddNsOptions) error
	UpdateNsReplica(opt *blockchain.UpdateNsReplicaOptions) error
	UpdateFilePublicSliceMeta(opt *blockchain.UpdateFilePSMOptions) error
	SliceMigrateRecord(opt *blockchain.SliceMigrateOptions) error
	GetNsByName(owner []byte, name string) (blockchain.Namespace, error)
	ListFileNs(opt *blockchain.ListNsOptions) ([]blockchain.Namespace, error)
	ListFiles(opt *blockchain.ListFileOptions) ([]blockchain.File, error)
	ListExpiredFiles(opt *blockchain.ListFileOptions) ([]blockchain.File, error)
	// The following contract methods used for authorizers to operate the file authorization application
	GetAuthApplicationByID(authID string) (blockchain.FileAuthApplication, error)
	ListFileAuthApplications(opt *blockchain.ListFileAuthOptions) (blockchain.FileAuthApplications, error)
	ConfirmFileAuthApplication(opt *blockchain.ConfirmFileAuthOptions) error
	RejectFileAuthApplication(opt *blockchain.ConfirmFileAuthOptions) error

	ListChallengeRequests(opt *blockchain.ListChallengeOptions) ([]blockchain.Challenge, error)
	ChallengeRequest(opt *blockchain.ChallengeRequestOptions) error
	ChallengeAnswer(opt *blockchain.ChallengeAnswerOptions) ([]byte, error)
	GetChallengeByID(id string) (blockchain.Challenge, error)
}

Blockchain defines some contract methods

For xchain they are contract methods, and for fabric they are chaincode methods
see more from blockchain.xchain and blockchain.fabric

type Challenger

type Challenger interface {
	// pairing based Challenge
	GenerateChallenge(sliceIdxList []int, interval int64) ([][]byte, [][]byte, int64, []byte, error)

	// merkle Challenge
	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)
	Close()
}

Challenger generates challenge requests as dataOwner-node for storage-nodes to answer

Pairing-based and MerkleTree-based are both supported
see more from engine.challenger

type Copier

type Copier interface {
	Select(slice slicer.Slice, nodes blockchain.NodeHs, opt *copier.SelectOptions) (copier.LocatedSlice, error)
	Push(ctx context.Context, id, sourceID string, r io.Reader, node *blockchain.Node) (string, error)
	Pull(ctx context.Context, id, storIndex, fileID string, node *blockchain.Node) (io.ReadCloser, error)
	ReplicaExpansion(ctx context.Context, opt *copier.ReplicaExpOptions, enc common.CommonEncryptor,
		challengeAlgorithm, sourceID, fileID string) ([]blockchain.PublicSliceMeta, []encryptor.EncryptedSlice, error)
}

Copier selects Storage Nodes randomly from healthy candidates.

You can call Push() to push slices onto Storage Node, and Pull() to pull slices from Storage Node.
If you want more Storage Nodes, you can call ReplicaExpansion(),
and it pulls slices from original nodes and decrypts and re-encrypts those slices,
then push them onto new Storage Nodes.

type Encryptor

type Encryptor interface {
	GetKey(fileID, sliceID string, nodeID []byte) aes.AESKey
	Encrypt(r io.Reader, opt *encryptor.EncryptOptions) (encryptor.EncryptedSlice, error)
	Recover(r io.Reader, opt *encryptor.RecoverOptions) ([]byte, error)
}

Encryptor encrypts data and decrypts encoded data

type Engine

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

func NewEngine

func NewEngine(conf *config.MonitorConf, opt *NewEngineOption) (*Engine, error)

NewEngine initiates Engine by the node's configuration file

func (*Engine) AddFileNs

func (e *Engine) AddFileNs(opt types.AddNsOptions) (err error)

AddFileNs adds file namespace, opt.User is dataOwner node client's public key

func (*Engine) Close

func (e *Engine) Close()

func (*Engine) ConfirmAuth

func (e *Engine) ConfirmAuth(opt types.ConfirmAuthOptions) error

ConfirmAuth the dataOwner node confirms or rejects the applier's file authorization application

func (*Engine) GetAuthByID

func (e *Engine) GetAuthByID(id string) (fileAuth blockchain.FileAuthApplication, err error)

GetAuthByID get file authorization application detail by authID

func (*Engine) GetChallengeByID

func (e *Engine) GetChallengeByID(id string) (challenge blockchain.Challenge, err error)

GetChallengeByID gets a challenge by id

func (*Engine) GetChallenges

func (e *Engine) GetChallenges(opt blockchain.ListChallengeOptions) (challenges []blockchain.Challenge, err error)

GetChallenges lists all challenges with given status from blockchain

func (*Engine) GetFileByID

func (e *Engine) GetFileByID(ctx context.Context, id string) (hfile blockchain.FileH, err error)

GetFileByID gets file by id from blockchain

func (*Engine) GetFileByName

func (e *Engine) GetFileByName(ctx context.Context, pubkey, ns, name string) (
	hfile blockchain.FileH, err error)

GetFileByName gets file by name from blockchain

func (*Engine) GetFileSysHealth

func (e *Engine) GetFileSysHealth(ctx context.Context, pubkey string) (fh blockchain.FileSysHealth, err error)

GetFileSysHealth get file owner system health status

func (*Engine) GetHeartbeatNum

func (e *Engine) GetHeartbeatNum(id []byte, ctime int64) (int, int, error)

GetHeartbeatNum gets storage node heartbeats number of given time The total number of heartbeats is obtained from the blockchain and the maximum number of heartbeats is estimated by given time, node's heartbeat healthy rate is calculated from the total number and maximum number

func (*Engine) GetNode

func (e *Engine) GetNode(id []byte) (blockchain.Node, error)

GetNode gets storage node by node id

func (*Engine) GetNodeHealth

func (e *Engine) GetNodeHealth(id []byte) (string, error)

GetNodeHealth gets storage node health status by node id

func (*Engine) GetNsByName

func (e *Engine) GetNsByName(ctx context.Context, pubkey, name string) (nsh blockchain.NamespaceH, err error)

GetNsByName gets namespace by name from blockchain

func (*Engine) GetSliceMigrateRecords

func (e *Engine) GetSliceMigrateRecords(opt *blockchain.NodeSliceMigrateOptions) (string, error)

GetSliceMigrateRecords gets storage node slice migration record

func (*Engine) ListExpiredFiles

func (e *Engine) ListExpiredFiles(opt types.ListFileOptions) ([]blockchain.File, error)

ListExpiredFiles list expired but still valid files

func (*Engine) ListFileAuths

func (e *Engine) ListFileAuths(opt types.ListFileAuthOptions) (fileAuths blockchain.FileAuthApplications, err error)

ListFileAuths query the list of authorization applications

func (*Engine) ListFileNs

func (e *Engine) ListFileNs(opt types.ListNsOptions) (nss []blockchain.Namespace, err error)

ListFileNs lists file namespaces by owner

func (*Engine) ListNodes

func (e *Engine) ListNodes() (blockchain.Nodes, error)

ListNodes lists storage nodes from blockchain

func (*Engine) ListUnExpiredFiles

func (e *Engine) ListUnExpiredFiles(opt types.ListFileOptions) (
	[]blockchain.File, error)

ListFiles lists unExpired files from blockchain

func (*Engine) NodeOffline

func (e *Engine) NodeOffline(opt types.NodeOperateOptions) error

NodeOffline set storage node status to offline

func (*Engine) NodeOnline

func (e *Engine) NodeOnline(opt types.NodeOperateOptions) error

NodeOnline set storage node status to online

func (*Engine) Pull

func (e *Engine) Pull(opt types.PullOptions) (io.ReadCloser, error)

Pull load ciphertext slices locally and return them to the dataOwner node To prevent the request is intercepted and the slice is downloaded maliciously, the request's validity is five minutes

func (*Engine) Push

func (e *Engine) Push(opt types.PushOptions, r io.Reader) (
	types.PushResponse, error)

Push receive slices from dataOwner nodes rewriting a slice is not allowed

func (*Engine) Read

func (e *Engine) Read(ctx context.Context, opt types.ReadOptions) (io.ReadCloser, error)

Read download file by pulling slices from storage nodes The detailed steps are as follows: 1. parameters check 2. read file info from the blockchain 3. decrypt the file's struct to get slice's order 4. download slices from the storage node, if request fails, pull slices from other storage nodes 5. slices decryption and combination 6. decrypt the combined slices to get the original file

func (*Engine) Start

func (e *Engine) Start(ctx context.Context) error

Start starts Engine

func (*Engine) UpdateFileExpireTime

func (e *Engine) UpdateFileExpireTime(ctx context.Context, opt types.UpdateFileEtimeOptions) (err error)

UpdateFileExpireTime updates file expire time

func (*Engine) UpdateNsReplica

func (e *Engine) UpdateNsReplica(ctx context.Context, opt types.UpdateNsOptions) error

UpdateNsReplica updates file namespace replica

func (*Engine) Write

func (e *Engine) Write(ctx context.Context, opt types.WriteOptions,
	r io.Reader) (resp types.WriteResponse, err error)

Write upload a file and push file slices to storage nodes The detailed steps are as follows: 1. check parameters, the file is not allowed upload repeatedly 2. first file encryption 3. divide the file into multiple slices by a fixed size and generate copies 4. second encryption of ciphertext slices 5. push slices into storage nodes, retry five times if push failed 6. store file's digest info into blockchain

type Monitor

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

Monitor includes ChallengingMonitor, NodeMaintainer, and FileMaintainer

ChallengingMonitor's main work is to publish challenge requests if local node is dataOwner-node,
   otherwise is to listen challenge requests and answer them in order to prove specified files are stored
NodeMaintainer runs if local node is storage-node, and its main work is to clean expired encrypted slices
   and to send heartbeats regularly in order to claim it's alive
FileMaintainer runs if local node is dataOwner-node, and its main work is to check storage-nodes health conditions
   and migrate slices from bad nodes to healthy nodes.

func (*Monitor) Close

func (m *Monitor) Close()

Close stops all inner services gracefully

could be called in main()

func (*Monitor) Start

func (m *Monitor) Start(ctx context.Context) error

Start starts Monitor

type NewEngineOption

type NewEngineOption struct {
	LocalNode peer.Local

	Slicer     Slicer
	Encryptor  Encryptor
	Challenger Challenger
	Chain      Blockchain
	Copier     Copier
	ProveStor  ProveStorage
	SliceStor  SliceStorage
}

NewEngineOption contains parameters for initiating Engine

type ProveStorage

type ProveStorage interface {
	Save(key string, value io.Reader) error
	Load(key string) (io.ReadCloser, error)
	Delete(key string) (bool, error)
	Exist(key string) (bool, error)
	LoadStr(key string) (string, error)
	SaveAndUpdate(key string, value io.Reader) error
}

ProveStorage is local storage to keep temporary data during time and space proof process

type SliceStorage

type SliceStorage interface {
	Save(key string, value io.Reader) (string, error)
	Load(key string, index string) (io.ReadCloser, error)
	Exist(key string, index string) (bool, error)
	Delete(key string, index string) error
	LoadStr(key string, index string) (string, error)
}

SliceStorage stores slices

type Slicer

type Slicer interface {
	// Slice Async slicing
	Slice(ctx context.Context, r io.Reader, opt *slicer.SliceOptions, onErr func(err error)) chan slicer.Slice
	GetBlockSize() int
}

Slicer cuts data into blocks

Jump to

Keyboard shortcuts

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