diff options
Diffstat (limited to 'whisper')
-rw-r--r-- | whisper/whisper.go | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/whisper/whisper.go b/whisper/whisper.go index e56c45786..2634a23a4 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -144,6 +144,21 @@ func (self *Whisper) Stop() { glog.V(logger.Info).Infoln("Whisper stopped") } +// Messages retrieves the currently pooled messages matching a filter id. +func (self *Whisper) Messages(id int) []*Message { + messages := make([]*Message, 0) + if filter := self.filters.Get(id); filter != nil { + for _, envelope := range self.messages { + if message := self.open(envelope); message != nil { + if self.filters.Match(filter, createFilter(message, envelope.Topics)) { + messages = append(messages, message) + } + } + } + } + return messages +} + // func (self *Whisper) RemoveIdentity(key *ecdsa.PublicKey) bool { // k := string(crypto.FromECDSAPub(key)) // if _, ok := self.keys[k]; ok { @@ -153,22 +168,6 @@ func (self *Whisper) Stop() { // return false // } -/*func (self *Whisper) Messages(id int) (messages []*Message) { - filter := self.filters.Get(id) - if filter != nil { - for _, e := range self.messages { - if msg := self.open(e); msg != nil { - f := createFilter(msg, e.Topics) - if self.filters.Match(filter, f) { - messages = append(messages, msg) - } - } - } - } - - return -}*/ - // handlePeer is called by the underlying P2P layer when the whisper sub-protocol // connection is negotiated. func (self *Whisper) handlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error { |