@@ -88,6 +88,8 @@ type Whisper struct {
88
88
stats Statistics // Statistics of whisper node
89
89
90
90
mailServer MailServer // MailServer interface
91
+
92
+ wg sync.WaitGroup
91
93
}
92
94
93
95
// New creates a Whisper client ready to communicate through the Ethereum P2P network.
@@ -243,8 +245,10 @@ func (whisper *Whisper) SetBloomFilter(bloom []byte) error {
243
245
whisper .settings .Store (bloomFilterIdx , b )
244
246
whisper .notifyPeersAboutBloomFilterChange (b )
245
247
248
+ whisper .wg .Add (1 )
246
249
go func () {
247
250
// allow some time before all the peers have processed the notification
251
+ defer whisper .wg .Done ()
248
252
time .Sleep (time .Duration (whisper .syncAllowance ) * time .Second )
249
253
whisper .settings .Store (bloomFilterToleranceIdx , b )
250
254
}()
@@ -261,7 +265,9 @@ func (whisper *Whisper) SetMinimumPoW(val float64) error {
261
265
whisper .settings .Store (minPowIdx , val )
262
266
whisper .notifyPeersAboutPowRequirementChange (val )
263
267
268
+ whisper .wg .Add (1 )
264
269
go func () {
270
+ defer whisper .wg .Done ()
265
271
// allow some time before all the peers have processed the notification
266
272
time .Sleep (time .Duration (whisper .syncAllowance ) * time .Second )
267
273
whisper .settings .Store (minPowToleranceIdx , val )
@@ -626,10 +632,12 @@ func (whisper *Whisper) Send(envelope *Envelope) error {
626
632
// of the Whisper protocol.
627
633
func (whisper * Whisper ) Start (* p2p.Server ) error {
628
634
log .Info ("started whisper v." + ProtocolVersionStr )
635
+ whisper .wg .Add (1 )
629
636
go whisper .update ()
630
637
631
638
numCPU := runtime .NumCPU ()
632
639
for i := 0 ; i < numCPU ; i ++ {
640
+ whisper .wg .Add (1 )
633
641
go whisper .processQueue ()
634
642
}
635
643
@@ -640,6 +648,7 @@ func (whisper *Whisper) Start(*p2p.Server) error {
640
648
// of the Whisper protocol.
641
649
func (whisper * Whisper ) Stop () error {
642
650
close (whisper .quit )
651
+ whisper .wg .Wait ()
643
652
log .Info ("whisper stopped" )
644
653
return nil
645
654
}
@@ -874,6 +883,7 @@ func (whisper *Whisper) checkOverflow() {
874
883
875
884
// processQueue delivers the messages to the watchers during the lifetime of the whisper node.
876
885
func (whisper * Whisper ) processQueue () {
886
+ defer whisper .wg .Done ()
877
887
var e * Envelope
878
888
for {
879
889
select {
@@ -892,6 +902,7 @@ func (whisper *Whisper) processQueue() {
892
902
// update loops until the lifetime of the whisper node, updating its internal
893
903
// state by expiring stale messages from the pool.
894
904
func (whisper * Whisper ) update () {
905
+ defer whisper .wg .Done ()
895
906
// Start a ticker to check for expirations
896
907
expire := time .NewTicker (expirationCycle )
897
908
0 commit comments