|
@ -9,9 +9,10 @@ import ( |
|
|
|
|
|
|
|
|
"golang.org/x/crypto/ripemd160" |
|
|
"golang.org/x/crypto/ripemd160" |
|
|
|
|
|
|
|
|
. "github.com/tendermint/tmlibs/common" |
|
|
|
|
|
"github.com/tendermint/tmlibs/merkle" |
|
|
|
|
|
"github.com/tendermint/go-wire" |
|
|
"github.com/tendermint/go-wire" |
|
|
|
|
|
"github.com/tendermint/go-wire/data" |
|
|
|
|
|
cmn "github.com/tendermint/tmlibs/common" |
|
|
|
|
|
"github.com/tendermint/tmlibs/merkle" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
@ -21,7 +22,7 @@ var ( |
|
|
|
|
|
|
|
|
type Part struct { |
|
|
type Part struct { |
|
|
Index int `json:"index"` |
|
|
Index int `json:"index"` |
|
|
Bytes []byte `json:"bytes"` |
|
|
|
|
|
|
|
|
Bytes data.Bytes `json:"bytes"` |
|
|
Proof merkle.SimpleProof `json:"proof"` |
|
|
Proof merkle.SimpleProof `json:"proof"` |
|
|
|
|
|
|
|
|
// Cache
|
|
|
// Cache
|
|
@ -49,7 +50,7 @@ func (part *Part) StringIndented(indent string) string { |
|
|
%s Proof: %v |
|
|
%s Proof: %v |
|
|
%s}`, |
|
|
%s}`, |
|
|
part.Index, |
|
|
part.Index, |
|
|
indent, Fingerprint(part.Bytes), |
|
|
|
|
|
|
|
|
indent, cmn.Fingerprint(part.Bytes), |
|
|
indent, part.Proof.StringIndented(indent+" "), |
|
|
indent, part.Proof.StringIndented(indent+" "), |
|
|
indent) |
|
|
indent) |
|
|
} |
|
|
} |
|
@ -57,12 +58,12 @@ func (part *Part) StringIndented(indent string) string { |
|
|
//-------------------------------------
|
|
|
//-------------------------------------
|
|
|
|
|
|
|
|
|
type PartSetHeader struct { |
|
|
type PartSetHeader struct { |
|
|
Total int `json:"total"` |
|
|
|
|
|
Hash []byte `json:"hash"` |
|
|
|
|
|
|
|
|
Total int `json:"total"` |
|
|
|
|
|
Hash data.Bytes `json:"hash"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (psh PartSetHeader) String() string { |
|
|
func (psh PartSetHeader) String() string { |
|
|
return fmt.Sprintf("%v:%X", psh.Total, Fingerprint(psh.Hash)) |
|
|
|
|
|
|
|
|
return fmt.Sprintf("%v:%X", psh.Total, cmn.Fingerprint(psh.Hash)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (psh PartSetHeader) IsZero() bool { |
|
|
func (psh PartSetHeader) IsZero() bool { |
|
@ -85,7 +86,7 @@ type PartSet struct { |
|
|
|
|
|
|
|
|
mtx sync.Mutex |
|
|
mtx sync.Mutex |
|
|
parts []*Part |
|
|
parts []*Part |
|
|
partsBitArray *BitArray |
|
|
|
|
|
|
|
|
partsBitArray *cmn.BitArray |
|
|
count int |
|
|
count int |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -96,11 +97,11 @@ func NewPartSetFromData(data []byte, partSize int) *PartSet { |
|
|
total := (len(data) + partSize - 1) / partSize |
|
|
total := (len(data) + partSize - 1) / partSize |
|
|
parts := make([]*Part, total) |
|
|
parts := make([]*Part, total) |
|
|
parts_ := make([]merkle.Hashable, total) |
|
|
parts_ := make([]merkle.Hashable, total) |
|
|
partsBitArray := NewBitArray(total) |
|
|
|
|
|
|
|
|
partsBitArray := cmn.NewBitArray(total) |
|
|
for i := 0; i < total; i++ { |
|
|
for i := 0; i < total; i++ { |
|
|
part := &Part{ |
|
|
part := &Part{ |
|
|
Index: i, |
|
|
Index: i, |
|
|
Bytes: data[i*partSize : MinInt(len(data), (i+1)*partSize)], |
|
|
|
|
|
|
|
|
Bytes: data[i*partSize : cmn.MinInt(len(data), (i+1)*partSize)], |
|
|
} |
|
|
} |
|
|
parts[i] = part |
|
|
parts[i] = part |
|
|
parts_[i] = part |
|
|
parts_[i] = part |
|
@ -126,7 +127,7 @@ func NewPartSetFromHeader(header PartSetHeader) *PartSet { |
|
|
total: header.Total, |
|
|
total: header.Total, |
|
|
hash: header.Hash, |
|
|
hash: header.Hash, |
|
|
parts: make([]*Part, header.Total), |
|
|
parts: make([]*Part, header.Total), |
|
|
partsBitArray: NewBitArray(header.Total), |
|
|
|
|
|
|
|
|
partsBitArray: cmn.NewBitArray(header.Total), |
|
|
count: 0, |
|
|
count: 0, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -150,7 +151,7 @@ func (ps *PartSet) HasHeader(header PartSetHeader) bool { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (ps *PartSet) BitArray() *BitArray { |
|
|
|
|
|
|
|
|
func (ps *PartSet) BitArray() *cmn.BitArray { |
|
|
ps.mtx.Lock() |
|
|
ps.mtx.Lock() |
|
|
defer ps.mtx.Unlock() |
|
|
defer ps.mtx.Unlock() |
|
|
return ps.partsBitArray.Copy() |
|
|
return ps.partsBitArray.Copy() |
|
@ -224,7 +225,7 @@ func (ps *PartSet) IsComplete() bool { |
|
|
|
|
|
|
|
|
func (ps *PartSet) GetReader() io.Reader { |
|
|
func (ps *PartSet) GetReader() io.Reader { |
|
|
if !ps.IsComplete() { |
|
|
if !ps.IsComplete() { |
|
|
PanicSanity("Cannot GetReader() on incomplete PartSet") |
|
|
|
|
|
|
|
|
cmn.PanicSanity("Cannot GetReader() on incomplete PartSet") |
|
|
} |
|
|
} |
|
|
return NewPartSetReader(ps.parts) |
|
|
return NewPartSetReader(ps.parts) |
|
|
} |
|
|
} |
|
|