whisper: POW updated

This commit is contained in:
Vlad 2016-11-26 12:56:37 +01:00
parent 74a900ac41
commit 2b549db080
3 changed files with 7 additions and 6 deletions

View file

@ -55,6 +55,7 @@ const (
signatureLength = 65 signatureLength = 65
aesKeyLength = 32 aesKeyLength = 32
saltLength = 12 saltLength = 12
AESNonceMaxLength = 12
MaxMessageLength = 0xFFFF // todo: remove this restriction after testing in morden and analizing stats. this should be regulated by MinimumPoW. MaxMessageLength = 0xFFFF // todo: remove this restriction after testing in morden and analizing stats. this should be regulated by MinimumPoW.
MinimumPoW = 10.0 // todo: review MinimumPoW = 10.0 // todo: review

View file

@ -131,7 +131,7 @@ func (e *Envelope) calculatePoW(diff uint32) {
h = crypto.Keccak256(buf) h = crypto.Keccak256(buf)
firstBit := common.FirstBitSet(common.BigD(h)) firstBit := common.FirstBitSet(common.BigD(h))
x := math.Pow(2, float64(firstBit)) x := math.Pow(2, float64(firstBit))
x /= float64(len(e.Data) + len(e.Salt) + len(e.AESNonce)) x /= float64(len(e.Data)) // we only count e.Data, other variable-sized members are checked in Whisper.add()
x /= float64(e.TTL + diff) x /= float64(e.TTL + diff)
e.pow = x e.pow = x
} }

View file

@ -419,7 +419,7 @@ func (wh *Whisper) add(envelope *Envelope) error {
return fmt.Errorf("oversized Version") return fmt.Errorf("oversized Version")
} }
if len(envelope.AESNonce) > 12 { if len(envelope.AESNonce) > AESNonceMaxLength {
// the standard AES GSM nonce size is 12, // the standard AES GSM nonce size is 12,
// but const gcmStandardNonceSize cannot be accessed directly // but const gcmStandardNonceSize cannot be accessed directly
return fmt.Errorf("oversized AESNonce") return fmt.Errorf("oversized AESNonce")