Skip to content

Commit

Permalink
docs: add checksum and integrity hash func instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhaoyu committed Mar 10, 2023
1 parent 5ead084 commit fb00e65
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Support common libs for different repos of greenfield

### 1. Erasure encode/decode algorithm

(1) erasure package support RSEncoder which contain basic Encode and Decode reedSolomon APIs
```
- erasure package support RSEncoder which contain basic Encode and Decode ReedSolomon APIs

```go
// first step, create a new rs encoder, the blockSize indicate the data size to be encoded
func NewRSEncoder(dataShards, parityShards int, blockSize int64) (r RSEncoder, err error) {
// encode data and return the encoded shard number
Expand All @@ -16,8 +17,10 @@ func (r *RSEncoder) DecodeDataShards(content [][]byte) error
// decode the input data and reconstruct the data shards and parity Shards
func (r *RSEncoder) DecodeShards(data [][]byte) error
```
(2) redundancy package support methods to encode/decode segments data using RSEncoder
```
- redundancy package support methods to encode/decode segments data using RSEncoder
```go
// encode one segment
func EncodeRawSegment(content []byte, dataShards, parityShards int) ([][]byte, error)

Expand All @@ -30,7 +33,7 @@ func DecodeRawSegment(pieceData [][]byte, segmentSize int64, dataShards, parityS
hash package support methods to compute hash roots of greenfield objects , the computed methods is based on
redundancy strategy of greenfield
```
```go
// compute hash roots fromm io reader, the parameters should fetch from chain besides reader
func ComputeIntegrityHash(reader io.Reader, segmentSize int64, dataShards, parityShards int) ([]string, int64, error)

Expand All @@ -40,3 +43,26 @@ func ComputerHashFromFile(filePath string, segmentSize int64, dataShards, parity
### 3. Generate checksum and integrity hash
common library supports generating checksum and integrity hash. `GenerateChecksum` uses sha256 algorithm to compute hash. `GenerateIntegrityHash` is used to compute all checksum to get a integrity hash.
Function as follows:
```go
// GenerateChecksum generates the checksum of one piece data
func GenerateIntegrityHash(checksumList [][]byte) []byte

// GenerateIntegrityHash generates integrity hash of all piece data checksum
func GenerateIntegrityHash(checksumList [][]byte) []byte

// ChallengePieceHash challenge integrity hash and checksum list
// integrityHash represents the integrity hash of one piece list, this piece list may be ec piece data list or
// segment piece data list; if piece data list is ec, this list is all ec1 piece data; if piece list is segment, all
// piece data is all segments of an object
// checksumList is composed of one piece list's individual checksum
// index represents which piece is used to challenge
// pieceData represents piece physical data that user want to challenge
func ChallengePieceHash(integrityHash []byte, checksumList [][]byte, index int, pieceData []byte) error

// VerifyIntegrityHash verify integrity hash if right
func VerifyIntegrityHash(integrityHash []byte, checksumList [][]byte) error
```

0 comments on commit fb00e65

Please sign in to comment.