Send event when envelope was received from a peer (#19)

* Send event when envelope was received from a peer

* Update event description
This commit is contained in:
Dmitry Shulyak 2019-02-19 09:08:40 +02:00 committed by GitHub
parent 9cdf6385f8
commit 9e2f8db257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -13,6 +13,10 @@ const (
EventEnvelopeSent EventType = "envelope.sent" EventEnvelopeSent EventType = "envelope.sent"
// EventEnvelopeExpired fires when envelop expired // EventEnvelopeExpired fires when envelop expired
EventEnvelopeExpired EventType = "envelope.expired" EventEnvelopeExpired EventType = "envelope.expired"
// EventEnvelopeReceived is sent once envelope was received from a peer.
// EventEnvelopeReceived must be sent to the feed even if envelope was previously in the cache.
// And event, ideally, should contain information about peer that sent envelope to us.
EventEnvelopeReceived EventType = "envelope.received"
// EventBatchAcknowledged is sent when batch of envelopes was acknowleged by a peer. // EventBatchAcknowledged is sent when batch of envelopes was acknowleged by a peer.
EventBatchAcknowledged EventType = "batch.acknowleged" EventBatchAcknowledged EventType = "batch.acknowleged"
// EventEnvelopeAvailable fires when envelop is available for filters // EventEnvelopeAvailable fires when envelop is available for filters

View File

@ -876,7 +876,6 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
log.Warn("failed to decode envelopes, peer will be disconnected", "peer", p.peer.ID(), "err", err) log.Warn("failed to decode envelopes, peer will be disconnected", "peer", p.peer.ID(), "err", err)
return errors.New("invalid envelopes") return errors.New("invalid envelopes")
} }
trouble := false trouble := false
for _, env := range envelopes { for _, env := range envelopes {
cached, err := whisper.add(env, whisper.LightClientMode()) cached, err := whisper.add(env, whisper.LightClientMode())
@ -884,6 +883,11 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
trouble = true trouble = true
log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err) log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err)
} }
whisper.envelopeFeed.Send(EnvelopeEvent{
Event: EventEnvelopeReceived,
Hash: env.Hash(),
Peer: p.peer.ID(),
})
if cached { if cached {
p.mark(env) p.mark(env)
} }