|
|
@ -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) |
|
|
|
filter := self.filters.Get(id) |
|
|
|
if filter != nil { |
|
|
|
if filter != nil { |
|
|
|
for _, e := range self.messages { |
|
|
|
for _, e := range self.messages { |
|
|
|
if msg, key := self.open(e); msg != nil { |
|
|
|
if msg, key := self.open(e); msg != nil { |
|
|
|
f := createFilter(msg, e.Topics, key) |
|
|
|
f := createFilter(msg, e.Topics, key) |
|
|
|
if self.filters.Match(filter, f) { |
|
|
|
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
|
|
|
|
// Main handler for passing whisper messages to whisper peer objects
|
|
|
@ -158,12 +160,13 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
envelope, err := NewEnvelopeFromReader(msg.Payload) |
|
|
|
var envelopes []*Envelope |
|
|
|
if err != nil { |
|
|
|
if err := msg.Decode(&envelopes); err != nil { |
|
|
|
peer.Infoln(err) |
|
|
|
peer.Infoln(err) |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, envelope := range envelopes { |
|
|
|
if err := self.add(envelope); err != nil { |
|
|
|
if err := self.add(envelope); err != nil { |
|
|
|
// TODO Punish peer here. Invalid envelope.
|
|
|
|
// TODO Punish peer here. Invalid envelope.
|
|
|
|
peer.Infoln(err) |
|
|
|
peer.Infoln(err) |
|
|
@ -171,6 +174,7 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error { |
|
|
|
wpeer.addKnown(envelope) |
|
|
|
wpeer.addKnown(envelope) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// takes care of adding envelopes to the messages pool. At this moment no sanity checks are being performed.
|
|
|
|
// takes care of adding envelopes to the messages pool. At this moment no sanity checks are being performed.
|
|
|
|
func (self *Whisper) add(envelope *Envelope) error { |
|
|
|
func (self *Whisper) add(envelope *Envelope) error { |
|
|
@ -192,6 +196,8 @@ func (self *Whisper) add(envelope *Envelope) error { |
|
|
|
go self.postEvent(envelope) |
|
|
|
go self.postEvent(envelope) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlogger.DebugDetailln("added whisper message") |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|