diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-13 20:36:44 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-13 20:36:44 +0800 |
commit | e3cad04decbbc83a0c956850717cb0ae0b2b3eec (patch) | |
tree | 81e0f1a57344a7c0d6a2ae2f1481c2e26880d1c2 /whisper/whisper.go | |
parent | 1e5353824a7859d5cfa98565b5a879d5ca7e582a (diff) | |
download | dexon-e3cad04decbbc83a0c956850717cb0ae0b2b3eec.tar dexon-e3cad04decbbc83a0c956850717cb0ae0b2b3eec.tar.gz dexon-e3cad04decbbc83a0c956850717cb0ae0b2b3eec.tar.bz2 dexon-e3cad04decbbc83a0c956850717cb0ae0b2b3eec.tar.lz dexon-e3cad04decbbc83a0c956850717cb0ae0b2b3eec.tar.xz dexon-e3cad04decbbc83a0c956850717cb0ae0b2b3eec.tar.zst dexon-e3cad04decbbc83a0c956850717cb0ae0b2b3eec.zip |
Fixed whisper messages
* Whisper protocol wasn't properly suppling envelope slices
* Message history wasn't properly propagated
* Added 'Messages' method, filtering any current envelope with the
supplied filter.
Diffstat (limited to 'whisper/whisper.go')
-rw-r--r-- | whisper/whisper.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/whisper/whisper.go b/whisper/whisper.go index bdc69f199..ece2dd6d4 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -126,18 +126,20 @@ func (self *Whisper) Watch(opts Filter) int { }) } -func (self *Whisper) Trigger(id int) { +func (self *Whisper) Messages(id int) (messages []*Message) { filter := self.filters.Get(id) if filter != nil { for _, e := range self.messages { if msg, key := self.open(e); msg != nil { f := createFilter(msg, e.Topics, key) if self.filters.Match(filter, f) { - self.filters.Notify(f, msg) + messages = append(messages, msg) } } } } + + return } // Main handler for passing whisper messages to whisper peer objects @@ -158,17 +160,19 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error { return err } - envelope, err := NewEnvelopeFromReader(msg.Payload) - if err != nil { + var envelopes []*Envelope + if err := msg.Decode(&envelopes); err != nil { peer.Infoln(err) continue } - if err := self.add(envelope); err != nil { - // TODO Punish peer here. Invalid envelope. - peer.Infoln(err) + for _, envelope := range envelopes { + if err := self.add(envelope); err != nil { + // TODO Punish peer here. Invalid envelope. + peer.Infoln(err) + } + wpeer.addKnown(envelope) } - wpeer.addKnown(envelope) } } @@ -192,6 +196,8 @@ func (self *Whisper) add(envelope *Envelope) error { go self.postEvent(envelope) } + wlogger.DebugDetailln("added whisper message") + return nil } |