Whisper API fixed (#3687)
* whisper: wnode updated for tests with geth * whisper: updated processing of incoming messages * whisper: symmetric encryption updated * whisper: filter id type changed to enhance security * whisper: allow filter without topic for asymmetric encryption * whisper: POW updated * whisper: logging updated * whisper: spellchecker update * whisper: error handling changed * whisper: JSON field names fixed
This commit is contained in:
@@ -116,12 +116,16 @@ func (e *Envelope) Seal(options *MessageParams) error {
|
||||
}
|
||||
|
||||
if target > 0 && bestBit < target {
|
||||
return errors.New("Failed to reach the PoW target")
|
||||
return errors.New("Failed to reach the PoW target, insufficient work time")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Envelope) size() int {
|
||||
return len(e.Data) + len(e.Version) + len(e.AESNonce) + len(e.Salt) + 20
|
||||
}
|
||||
|
||||
func (e *Envelope) PoW() float64 {
|
||||
if e.pow == 0 {
|
||||
e.calculatePoW(0)
|
||||
@@ -137,14 +141,14 @@ func (e *Envelope) calculatePoW(diff uint32) {
|
||||
h = crypto.Keccak256(buf)
|
||||
firstBit := common.FirstBitSet(common.BigD(h))
|
||||
x := math.Pow(2, float64(firstBit))
|
||||
x /= float64(len(e.Data)) // we only count e.Data, other variable-sized members are checked in Whisper.add()
|
||||
x /= float64(e.size())
|
||||
x /= float64(e.TTL + diff)
|
||||
e.pow = x
|
||||
}
|
||||
|
||||
func (e *Envelope) powToFirstBit(pow float64) int {
|
||||
x := pow
|
||||
x *= float64(len(e.Data))
|
||||
x *= float64(e.size())
|
||||
x *= float64(e.TTL)
|
||||
bits := math.Log2(x)
|
||||
bits = math.Ceil(bits)
|
||||
|
Reference in New Issue
Block a user