diff options
author | Guillaume Ballet <gballet@gmail.com> | 2018-02-24 01:02:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-24 01:02:51 +0800 |
commit | 423c8bb1d8210387944e379a5f151c5ff4b8803f (patch) | |
tree | f2b6b44c4ec5dabd68bd481b6057d77b7c34d706 | |
parent | 114738982ef2fa15b4f5c0c2d691dca1e22cc2ee (diff) | |
parent | 6919c36432226a9d86dbe4a65ed9563dd42a4e08 (diff) | |
download | go-tangerine-423c8bb1d8210387944e379a5f151c5ff4b8803f.tar go-tangerine-423c8bb1d8210387944e379a5f151c5ff4b8803f.tar.gz go-tangerine-423c8bb1d8210387944e379a5f151c5ff4b8803f.tar.bz2 go-tangerine-423c8bb1d8210387944e379a5f151c5ff4b8803f.tar.lz go-tangerine-423c8bb1d8210387944e379a5f151c5ff4b8803f.tar.xz go-tangerine-423c8bb1d8210387944e379a5f151c5ff4b8803f.tar.zst go-tangerine-423c8bb1d8210387944e379a5f151c5ff4b8803f.zip |
Merge pull request #16176 from gluk256/255-refactoring
whisper: filters no longer get removed after a while
-rw-r--r-- | whisper/whisperv5/api.go | 23 | ||||
-rw-r--r-- | whisper/whisperv6/api.go | 26 | ||||
-rw-r--r-- | whisper/whisperv6/whisper.go | 5 |
3 files changed, 3 insertions, 51 deletions
diff --git a/whisper/whisperv5/api.go b/whisper/whisperv5/api.go index b4494d0d6..ee566625c 100644 --- a/whisper/whisperv5/api.go +++ b/whisper/whisperv5/api.go @@ -60,32 +60,9 @@ func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI { w: w, lastUsed: make(map[string]time.Time), } - - go api.run() return api } -// run the api event loop. -// this loop deletes filter that have not been used within filterTimeout -func (api *PublicWhisperAPI) run() { - timeout := time.NewTicker(2 * time.Minute) - for { - <-timeout.C - - api.mu.Lock() - for id, lastUsed := range api.lastUsed { - if time.Since(lastUsed).Seconds() >= filterTimeout { - delete(api.lastUsed, id) - if err := api.w.Unsubscribe(id); err != nil { - log.Error("could not unsubscribe whisper filter", "error", err) - } - log.Debug("delete whisper filter (timeout)", "id", id) - } - } - api.mu.Unlock() - } -} - // Version returns the Whisper sub-protocol version. func (api *PublicWhisperAPI) Version(ctx context.Context) string { return ProtocolVersionStr diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go index f3d9977fa..96e2b17e7 100644 --- a/whisper/whisperv6/api.go +++ b/whisper/whisperv6/api.go @@ -61,32 +61,9 @@ func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI { w: w, lastUsed: make(map[string]time.Time), } - - go api.run() return api } -// run the api event loop. -// this loop deletes filter that have not been used within filterTimeout -func (api *PublicWhisperAPI) run() { - timeout := time.NewTicker(2 * time.Minute) - for { - <-timeout.C - - api.mu.Lock() - for id, lastUsed := range api.lastUsed { - if time.Since(lastUsed).Seconds() >= filterTimeout { - delete(api.lastUsed, id) - if err := api.w.Unsubscribe(id); err != nil { - log.Error("could not unsubscribe whisper filter", "error", err) - } - log.Debug("delete whisper filter (timeout)", "id", id) - } - } - api.mu.Unlock() - } -} - // Version returns the Whisper sub-protocol version. func (api *PublicWhisperAPI) Version(ctx context.Context) string { return ProtocolVersionStr @@ -219,7 +196,8 @@ func (api *PublicWhisperAPI) DeleteSymKey(ctx context.Context, id string) bool { return api.w.DeleteSymKey(id) } -// MakeLightClient turns the node into light client, which does not forward any incoming messages. +// MakeLightClient turns the node into light client, which does not forward +// any incoming messages, and sends only messages originated in this node. func (api *PublicWhisperAPI) MakeLightClient(ctx context.Context) bool { api.w.lightClient = true return api.w.lightClient diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go index e0ed00bb5..b0b601f03 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -590,10 +590,7 @@ func (whisper *Whisper) Unsubscribe(id string) error { // network in the coming cycles. func (whisper *Whisper) Send(envelope *Envelope) error { ok, err := whisper.add(envelope, false) - if err != nil { - return err - } - if !ok { + if err == nil && !ok { return fmt.Errorf("failed to add envelope") } return err |