mirror of
https://github.com/status-im/whisper.git
synced 2025-01-20 07:39:00 +00:00
Apply whisper confirmations patch
This commit is contained in:
parent
536333e998
commit
5e489619d5
23
whisperv6/events.go
Normal file
23
whisperv6/events.go
Normal file
@ -0,0 +1,23 @@
|
||||
package whisperv6
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
)
|
||||
|
||||
// EventType used to define known envelope events.
|
||||
type EventType string
|
||||
|
||||
const (
|
||||
// EventEnvelopeSent fires when envelope was sent to a peer.
|
||||
EventEnvelopeSent EventType = "envelope.sent"
|
||||
// EventEnvelopeExpired fires when envelop expired
|
||||
EventEnvelopeExpired EventType = "envelope.expired"
|
||||
)
|
||||
|
||||
// EnvelopeEvent used for envelopes events.
|
||||
type EnvelopeEvent struct {
|
||||
Event EventType
|
||||
Hash common.Hash
|
||||
Peer discover.NodeID
|
||||
}
|
@ -212,6 +212,11 @@ func (peer *Peer) broadcast() error {
|
||||
// mark envelopes only if they were successfully sent
|
||||
for _, e := range bundle {
|
||||
peer.mark(e)
|
||||
peer.host.envelopeFeed.Send(EnvelopeEvent{
|
||||
Event: EventEnvelopeSent,
|
||||
Hash: e.Hash(),
|
||||
Peer: peer.peer.ID(), // specifically discover.NodeID because it can be pretty printed
|
||||
})
|
||||
}
|
||||
|
||||
log.Trace("broadcast", "num. messages", len(bundle))
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
mapset "github.com/deckarep/golang-set"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
@ -88,6 +89,8 @@ type Whisper struct {
|
||||
stats Statistics // Statistics of whisper node
|
||||
|
||||
mailServer MailServer // MailServer interface
|
||||
|
||||
envelopeFeed event.Feed
|
||||
}
|
||||
|
||||
// New creates a Whisper client ready to communicate through the Ethereum P2P network.
|
||||
@ -133,6 +136,12 @@ func New(cfg *Config) *Whisper {
|
||||
return whisper
|
||||
}
|
||||
|
||||
// SubscribeEnvelopeEvents subscribes to envelopes feed.
|
||||
// In order to prevent blocking whisper producers events must be amply buffered.
|
||||
func (whisper *Whisper) SubscribeEnvelopeEvents(events chan<- EnvelopeEvent) event.Subscription {
|
||||
return whisper.envelopeFeed.Subscribe(events)
|
||||
}
|
||||
|
||||
// MinPow returns the PoW value required by this node.
|
||||
func (whisper *Whisper) MinPow() float64 {
|
||||
val, exist := whisper.settings.Load(minPowIdx)
|
||||
@ -987,6 +996,10 @@ func (whisper *Whisper) expire() {
|
||||
hashSet.Each(func(v interface{}) bool {
|
||||
sz := whisper.envelopes[v.(common.Hash)].size()
|
||||
delete(whisper.envelopes, v.(common.Hash))
|
||||
whisper.envelopeFeed.Send(EnvelopeEvent{
|
||||
Hash: v.(common.Hash),
|
||||
Event: EventEnvelopeExpired,
|
||||
})
|
||||
whisper.stats.messagesCleared++
|
||||
whisper.stats.memoryCleared += sz
|
||||
whisper.stats.memoryUsed -= sz
|
||||
|
Loading…
x
Reference in New Issue
Block a user