diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-17 02:55:57 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-17 02:55:57 +0800 |
commit | 52b54631a47dfa46742635be178f2f8d33dd9f41 (patch) | |
tree | 5d99624cd5df30c9747039dd874559a974af9bdd /whisper | |
parent | 93edae280d60d217084430a0c6c16f648c82732e (diff) | |
download | go-tangerine-52b54631a47dfa46742635be178f2f8d33dd9f41.tar.gz go-tangerine-52b54631a47dfa46742635be178f2f8d33dd9f41.tar.zst go-tangerine-52b54631a47dfa46742635be178f2f8d33dd9f41.zip |
Whisper watches fixes
Diffstat (limited to 'whisper')
-rw-r--r-- | whisper/envelope.go | 6 | ||||
-rw-r--r-- | whisper/util.go | 11 | ||||
-rw-r--r-- | whisper/whisper.go | 4 |
3 files changed, 16 insertions, 5 deletions
diff --git a/whisper/envelope.go b/whisper/envelope.go index dc8d3cda4..066e20f6a 100644 --- a/whisper/envelope.go +++ b/whisper/envelope.go @@ -74,11 +74,13 @@ func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) { message.Flags = data[0] message.Signature = data[1:66] } - message.Payload = data[dataStart:] + + payload := data[dataStart:] if prv != nil { - message.Payload, err = crypto.Decrypt(prv, message.Payload) + message.Payload, err = crypto.Decrypt(prv, payload) switch err { case ecies.ErrInvalidPublicKey: // Payload isn't encrypted + message.Payload = payload return &message, err default: return nil, fmt.Errorf("unable to open envelope. Decrypt failed: %v", err) diff --git a/whisper/util.go b/whisper/util.go index abef1d667..7a222395f 100644 --- a/whisper/util.go +++ b/whisper/util.go @@ -18,10 +18,19 @@ func Topics(data [][]byte) [][]byte { return d } -func TopicsFromString(data []string) [][]byte { +func TopicsFromString(data ...string) [][]byte { d := make([][]byte, len(data)) for i, str := range data { d[i] = hashTopic([]byte(str)) } return d } + +func bytesToMap(s [][]byte) map[string]struct{} { + m := make(map[string]struct{}) + for _, topic := range s { + m[string(topic)] = struct{}{} + } + + return m +} diff --git a/whisper/whisper.go b/whisper/whisper.go index 32e951385..9721ca9f9 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/ecdsa" "errors" - "fmt" "sync" "time" @@ -120,6 +119,7 @@ func (self *Whisper) Watch(opts Filter) int { return self.filters.Install(filter.Generic{ Str1: string(crypto.FromECDSA(opts.To)), Str2: string(crypto.FromECDSAPub(opts.From)), + Data: bytesToMap(opts.Topics), Fn: func(data interface{}) { opts.Fn(data.(*Message)) }, @@ -150,7 +150,6 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error { continue } - fmt.Println("recv") if err := self.add(envelope); err != nil { // TODO Punish peer here. Invalid envelope. peer.Infoln(err) @@ -233,6 +232,7 @@ func (self *Whisper) postEvent(envelope *Envelope) { // Create a custom filter? self.filters.Notify(filter.Generic{ Str1: string(crypto.FromECDSA(key)), Str2: string(crypto.FromECDSAPub(message.Recover())), + Data: bytesToMap(envelope.Topics), }, message) } else { wlogger.Infoln(err) |