|
|
|
@ -126,6 +126,20 @@ func (self *Whisper) Watch(opts Filter) int { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (self *Whisper) Trigger(id int) { |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Main handler for passing whisper messages to whisper peer objects
|
|
|
|
|
func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error { |
|
|
|
|
wpeer := NewPeer(self, peer, ws) |
|
|
|
@ -227,19 +241,28 @@ func (self *Whisper) envelopes() (envelopes []*Envelope) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (self *Whisper) postEvent(envelope *Envelope) { |
|
|
|
|
if message, key := self.open(envelope); message != nil { |
|
|
|
|
self.filters.Notify(createFilter(message, envelope.Topics, key), message) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (self *Whisper) open(envelope *Envelope) (*Message, *ecdsa.PrivateKey) { |
|
|
|
|
for _, key := range self.keys { |
|
|
|
|
if message, err := envelope.Open(key); err == nil || (err != nil && err == ecies.ErrInvalidPublicKey) { |
|
|
|
|
self.filters.Notify(filter.Generic{ |
|
|
|
|
Str1: string(crypto.FromECDSA(key)), Str2: string(crypto.FromECDSAPub(message.Recover())), |
|
|
|
|
Data: bytesToMap(envelope.Topics), |
|
|
|
|
}, message) |
|
|
|
|
break |
|
|
|
|
} else { |
|
|
|
|
wlogger.Infoln(err) |
|
|
|
|
return message, key |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (self *Whisper) Protocol() p2p.Protocol { |
|
|
|
|
return self.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())), |
|
|
|
|
Data: bytesToMap(topics), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|