mirror of
https://github.com/status-im/whisper.git
synced 2025-01-20 07:39:00 +00:00
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:
parent
9cdf6385f8
commit
9e2f8db257
@ -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
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user