From 7948cc0029db76557d6540341bdfeb818ce32c65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= <peterke@gmail.com>
Date: Mon, 20 Apr 2015 14:56:38 +0300
Subject: rpc, whisper, xeth: fix RPC message retrieval data race

---
 whisper/message.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'whisper/message.go')

diff --git a/whisper/message.go b/whisper/message.go
index 07c673567..69d85b894 100644
--- a/whisper/message.go
+++ b/whisper/message.go
@@ -8,12 +8,13 @@ import (
 	"math/rand"
 	"time"
 
+	"github.com/ethereum/go-ethereum/common"
 	"github.com/ethereum/go-ethereum/crypto"
 	"github.com/ethereum/go-ethereum/logger"
 	"github.com/ethereum/go-ethereum/logger/glog"
 )
 
-// Message represents an end-user data packet to trasmit through the Whisper
+// Message represents an end-user data packet to transmit through the Whisper
 // protocol. These are wrapped into Envelopes that need not be understood by
 // intermediate nodes, just forwarded.
 type Message struct {
@@ -22,7 +23,8 @@ type Message struct {
 	Payload   []byte
 	Sent      int64
 
-	To *ecdsa.PublicKey
+	To   *ecdsa.PublicKey // Message recipient (identity used to decode the message)
+	Hash common.Hash      // Message envelope hash to act as a unique id in de-duplication
 }
 
 // Options specifies the exact way a message should be wrapped into an Envelope.
-- 
cgit v1.2.3


From 7f48eb8737878e352a65475382532db26f9fbc52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= <peterke@gmail.com>
Date: Tue, 21 Apr 2015 11:43:11 +0300
Subject: whisper, xeth/whisper: surface TTL and hash to the API

---
 whisper/message.go | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

(limited to 'whisper/message.go')

diff --git a/whisper/message.go b/whisper/message.go
index 69d85b894..2b92d515c 100644
--- a/whisper/message.go
+++ b/whisper/message.go
@@ -21,10 +21,12 @@ type Message struct {
 	Flags     byte // First bit is signature presence, rest reserved and should be random
 	Signature []byte
 	Payload   []byte
-	Sent      int64
+
+	Sent time.Time     // Time when the message was posted into the network
+	TTL  time.Duration // Maximum time to live allowed for the message
 
 	To   *ecdsa.PublicKey // Message recipient (identity used to decode the message)
-	Hash common.Hash      // Message envelope hash to act as a unique id in de-duplication
+	Hash common.Hash      // Message envelope hash to act as a unique id
 }
 
 // Options specifies the exact way a message should be wrapped into an Envelope.
@@ -45,7 +47,7 @@ func NewMessage(payload []byte) *Message {
 	return &Message{
 		Flags:   flags,
 		Payload: payload,
-		Sent:    time.Now().Unix(),
+		Sent:    time.Now(),
 	}
 }
 
@@ -66,6 +68,8 @@ func (self *Message) Wrap(pow time.Duration, options Options) (*Envelope, error)
 	if options.TTL == 0 {
 		options.TTL = DefaultTTL
 	}
+	self.TTL = options.TTL
+
 	// Sign and encrypt the message if requested
 	if options.From != nil {
 		if err := self.sign(options.From); err != nil {
-- 
cgit v1.2.3


From 87447f9f3f99cc59d58b029fff39fc39142f1281 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= <peterke@gmail.com>
Date: Tue, 21 Apr 2015 12:13:57 +0300
Subject: whisper: fix payload loss in case of plaintext decrypt

---
 whisper/message.go | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'whisper/message.go')

diff --git a/whisper/message.go b/whisper/message.go
index 2b92d515c..a80380a92 100644
--- a/whisper/message.go
+++ b/whisper/message.go
@@ -120,9 +120,12 @@ func (self *Message) encrypt(key *ecdsa.PublicKey) (err error) {
 }
 
 // decrypt decrypts an encrypted payload with a private key.
-func (self *Message) decrypt(key *ecdsa.PrivateKey) (err error) {
-	self.Payload, err = crypto.Decrypt(key, self.Payload)
-	return
+func (self *Message) decrypt(key *ecdsa.PrivateKey) error {
+	cleartext, err := crypto.Decrypt(key, self.Payload)
+	if err == nil {
+		self.Payload = cleartext
+	}
+	return err
 }
 
 // hash calculates the SHA3 checksum of the message flags and payload.
-- 
cgit v1.2.3