diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-03 23:16:05 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-03 23:16:05 +0800 |
commit | 7bd2fbe2b1445c26190008d21ad52dc5c364765c (patch) | |
tree | 88553917d6be4a51f4a9dd87f35ce31782319ee1 | |
parent | 623469cb6c6cdb6ff84dc2cb7d4409e9d7cf3f65 (diff) | |
download | dexon-7bd2fbe2b1445c26190008d21ad52dc5c364765c.tar dexon-7bd2fbe2b1445c26190008d21ad52dc5c364765c.tar.gz dexon-7bd2fbe2b1445c26190008d21ad52dc5c364765c.tar.bz2 dexon-7bd2fbe2b1445c26190008d21ad52dc5c364765c.tar.lz dexon-7bd2fbe2b1445c26190008d21ad52dc5c364765c.tar.xz dexon-7bd2fbe2b1445c26190008d21ad52dc5c364765c.tar.zst dexon-7bd2fbe2b1445c26190008d21ad52dc5c364765c.zip |
Fixed whisper "to" filtering. Closes #283
-rw-r--r-- | cmd/mist/assets/examples/whisper.html | 10 | ||||
-rw-r--r-- | whisper/message.go | 4 | ||||
-rw-r--r-- | whisper/whisper.go | 2 | ||||
-rw-r--r-- | xeth/whisper.go | 4 |
4 files changed, 16 insertions, 4 deletions
diff --git a/cmd/mist/assets/examples/whisper.html b/cmd/mist/assets/examples/whisper.html index 6a7143eef..ad568f783 100644 --- a/cmd/mist/assets/examples/whisper.html +++ b/cmd/mist/assets/examples/whisper.html @@ -10,6 +10,7 @@ <h1>Whisper test</h1> <button onclick="test()">Send</button> +<button onclick="test2()">Private send</button> <table width="100%" id="table"> <tr> @@ -44,10 +45,19 @@ document.querySelector("#table").innerHTML += "<tr><td colspan='2'>"+JSON.stringify(message)+"</td></tr>"; }); + var selfWatch = shh.watch({to: id, topics: ["test"]}) + selfWatch.arrived(function(message) { + document.querySelector("#table").innerHTML += "<tr><td>To me</td><td>"+JSON.stringify(message)+"</td></tr>"; + }); + function test() { shh.post({topics: ["test"], payload: web3.fromAscii("test it")}); count(); + } + function test2() { + shh.post({to: id, topics: ["test"], payload: web3.fromAscii("Private")}); + count(); } function count() { diff --git a/whisper/message.go b/whisper/message.go index fa631b2ef..23b5cfb0e 100644 --- a/whisper/message.go +++ b/whisper/message.go @@ -11,11 +11,11 @@ type Message struct { Flags byte Signature []byte Payload []byte - Sent uint64 + Sent int64 } func NewMessage(payload []byte) *Message { - return &Message{Flags: 0, Payload: payload} + return &Message{Flags: 0, Payload: payload, Sent: time.Now().Unix()} } func (self *Message) hash() []byte { diff --git a/whisper/whisper.go b/whisper/whisper.go index 8eab0825b..cc0348422 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -269,7 +269,7 @@ func (self *Whisper) Protocol() p2p.Protocol { func createFilter(message *Message, topics [][]byte, key *ecdsa.PrivateKey) filter.Filter { return filter.Generic{ - Str1: string(crypto.FromECDSA(key)), Str2: string(crypto.FromECDSAPub(message.Recover())), + Str1: string(crypto.FromECDSAPub(&key.PublicKey)), Str2: string(crypto.FromECDSAPub(message.Recover())), Data: bytesToMap(topics), } } diff --git a/xeth/whisper.go b/xeth/whisper.go index d537f8c54..42d7c44bc 100644 --- a/xeth/whisper.go +++ b/xeth/whisper.go @@ -2,6 +2,7 @@ package xeth import ( "errors" + "fmt" "time" "github.com/ethereum/go-ethereum/crypto" @@ -31,6 +32,7 @@ func (self *Whisper) Post(payload string, to, from string, topics []string, prio pk := crypto.ToECDSAPub(fromHex(from)) if key := self.Whisper.GetIdentity(pk); key != nil || len(from) == 0 { + fmt.Println("POST:", to) msg := whisper.NewMessage(fromHex(payload)) envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ Ttl: time.Duration(ttl) * time.Second, @@ -101,7 +103,7 @@ type WhisperMessage struct { ref *whisper.Message Payload string `json:"payload"` From string `json:"from"` - Sent uint64 `json:"time"` + Sent int64 `json:"time"` } func NewWhisperMessage(msg *whisper.Message) WhisperMessage { |