diff options
author | gluk256 <gluk256@users.noreply.github.com> | 2017-02-23 16:41:47 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-02-23 16:41:47 +0800 |
commit | 29fac7de448c85049a97cbec3dc0819122bd2cb0 (patch) | |
tree | eaa56d55f2ff5c15fca84a6d408d6aaff7d78404 /whisper/whisperv5/envelope.go | |
parent | 555273495b413069e9422b04aa46251146c752b2 (diff) | |
download | dexon-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar dexon-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.gz dexon-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.bz2 dexon-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.lz dexon-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.xz dexon-29fac7de448c85049a97cbec3dc0819122bd2cb0.tar.zst dexon-29fac7de448c85049a97cbec3dc0819122bd2cb0.zip |
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
Diffstat (limited to 'whisper/whisperv5/envelope.go')
-rw-r--r-- | whisper/whisperv5/envelope.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/whisper/whisperv5/envelope.go b/whisper/whisperv5/envelope.go index 1b976705d..8812ae207 100644 --- a/whisper/whisperv5/envelope.go +++ b/whisper/whisperv5/envelope.go @@ -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) |