mirror of
https://github.com/status-im/whisper.git
synced 2025-01-22 08:39:01 +00:00
rpc, whisper, xeth: fix RPC message retrieval data race
This commit is contained in:
parent
5381475b40
commit
ea0dc6e1cf
@ -73,6 +73,7 @@ func (self *Envelope) Open(key *ecdsa.PrivateKey) (msg *Message, err error) {
|
|||||||
message := &Message{
|
message := &Message{
|
||||||
Flags: data[0],
|
Flags: data[0],
|
||||||
Sent: int64(self.Expiry - self.TTL),
|
Sent: int64(self.Expiry - self.TTL),
|
||||||
|
Hash: self.Hash(),
|
||||||
}
|
}
|
||||||
data = data[1:]
|
data = data[1:]
|
||||||
|
|
||||||
|
36
envelope_test.go
Normal file
36
envelope_test.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package whisper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEnvelopeOpen(t *testing.T) {
|
||||||
|
payload := []byte("hello world")
|
||||||
|
message := NewMessage(payload)
|
||||||
|
|
||||||
|
envelope, err := message.Wrap(DefaultPoW, Options{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to wrap message: %v", err)
|
||||||
|
}
|
||||||
|
opened, err := envelope.Open(nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to open envelope: %v.", err)
|
||||||
|
}
|
||||||
|
if opened.Flags != message.Flags {
|
||||||
|
t.Fatalf("flags mismatch: have %d, want %d", opened.Flags, message.Flags)
|
||||||
|
}
|
||||||
|
if bytes.Compare(opened.Signature, message.Signature) != 0 {
|
||||||
|
t.Fatalf("signature mismatch: have 0x%x, want 0x%x", opened.Signature, message.Signature)
|
||||||
|
}
|
||||||
|
if bytes.Compare(opened.Payload, message.Payload) != 0 {
|
||||||
|
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, message.Payload)
|
||||||
|
}
|
||||||
|
if opened.Sent != message.Sent {
|
||||||
|
t.Fatalf("send time mismatch: have %d, want %d", opened.Sent, message.Sent)
|
||||||
|
}
|
||||||
|
|
||||||
|
if opened.Hash != envelope.Hash() {
|
||||||
|
t.Fatalf("message hash mismatch: have 0x%x, want 0x%x", opened.Hash, envelope.Hash())
|
||||||
|
}
|
||||||
|
}
|
@ -8,12 +8,13 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"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
|
// protocol. These are wrapped into Envelopes that need not be understood by
|
||||||
// intermediate nodes, just forwarded.
|
// intermediate nodes, just forwarded.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
@ -22,7 +23,8 @@ type Message struct {
|
|||||||
Payload []byte
|
Payload []byte
|
||||||
Sent int64
|
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.
|
// Options specifies the exact way a message should be wrapped into an Envelope.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user