whisper: expiry refactoring (#3706)

This commit is contained in:
gluk256
2017-02-23 18:46:32 +01:00
committed by Felix Lange
parent 357732a840
commit 11539030cd
5 changed files with 72 additions and 36 deletions

View File

@@ -133,20 +133,14 @@ func (peer *Peer) marked(envelope *Envelope) bool {
// expire iterates over all the known envelopes in the host and removes all
// expired (unknown) ones from the known list.
func (peer *Peer) expire() {
// Assemble the list of available envelopes
available := set.NewNonTS()
for _, envelope := range peer.host.Envelopes() {
available.Add(envelope.Hash())
}
// Cross reference availability with known status
unmark := make(map[common.Hash]struct{})
peer.known.Each(func(v interface{}) bool {
if !available.Has(v.(common.Hash)) {
if !peer.host.isEnvelopeCached(v.(common.Hash)) {
unmark[v.(common.Hash)] = struct{}{}
}
return true
})
// Dump all known but unavailable
// Dump all known but no longer cached
for hash := range unmark {
peer.known.Remove(hash)
}