Skip to content

Commit

Permalink
whisper: change the whisper message format so as to add the payload s…
Browse files Browse the repository at this point in the history
…ize (#15870)

* whisper: message format changed

* whisper: tests fixed

* whisper: style fixes

* whisper: fixed names, fixed failing tests

* whisper: fix merge issue in #15870

Occured while using the github online merge tool. Lesson learned.

* whisper: fix a gofmt error for #15870
  • Loading branch information
gluk256 authored and karalabe committed Jan 30, 2018
1 parent 59a852e commit a9e4a90
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 183 deletions.
6 changes: 3 additions & 3 deletions whisper/whisperv6/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
if params.KeySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
return false, err
}
if !validateSymmetricKey(params.KeySym) {
if !validateDataIntegrity(params.KeySym, aesKeyLength) {
return false, ErrInvalidSymmetricKey
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.
if err != nil {
return nil, err
}
if !validateSymmetricKey(key) {
if !validateDataIntegrity(key, aesKeyLength) {
return nil, ErrInvalidSymmetricKey
}
filter.KeySym = key
Expand Down Expand Up @@ -556,7 +556,7 @@ func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) {
if keySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
return "", err
}
if !validateSymmetricKey(keySym) {
if !validateDataIntegrity(keySym, aesKeyLength) {
return "", ErrInvalidSymmetricKey
}
}
Expand Down
7 changes: 4 additions & 3 deletions whisper/whisperv6/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,24 @@ const (
p2pMessageCode = 127 // peer-to-peer message (to be consumed by the peer, but not forwarded any further)
NumberOfMessageCodes = 128

paddingMask = byte(3)
SizeMask = byte(3) // mask used to extract the size of payload size field from the flags
signatureFlag = byte(4)

TopicLength = 4 // in bytes
signatureLength = 65 // in bytes
aesKeyLength = 32 // in bytes
AESNonceLength = 12 // in bytes
aesNonceLength = 12 // in bytes; for more info please see cipher.gcmStandardNonceSize & aesgcm.NonceSize()
keyIDSize = 32 // in bytes
bloomFilterSize = 64 // in bytes
flagsLength = 1

EnvelopeHeaderLength = 20

MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message.
DefaultMaxMessageSize = uint32(1024 * 1024)
DefaultMinimumPoW = 0.2

padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol (must not exceed 2^24)
padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol
messageQueueLimit = 1024

expirationCycle = time.Second
Expand Down
5 changes: 2 additions & 3 deletions whisper/whisperv6/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error) {

// Open tries to decrypt an envelope, and populates the message fields in case of success.
func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage) {
// The API interface forbids filters doing both symmetric and
// asymmetric encryption.
// The API interface forbids filters doing both symmetric and asymmetric encryption.
if watcher.expectsAsymmetricEncryption() && watcher.expectsSymmetricEncryption() {
return nil
}
Expand All @@ -219,7 +218,7 @@ func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage) {
}

if msg != nil {
ok := msg.Validate()
ok := msg.ValidateAndParse()
if !ok {
return nil
}
Expand Down
Loading

0 comments on commit a9e4a90

Please sign in to comment.