-
Notifications
You must be signed in to change notification settings - Fork 244
/
hash_filter.go
56 lines (48 loc) · 958 Bytes
/
hash_filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package rpcfilters
import (
"errors"
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
)
type hashFilter struct {
hashes []common.Hash
mu sync.Mutex
done chan struct{}
timer *time.Timer
}
// add adds a hash to the hashFilter
func (f *hashFilter) add(data interface{}) error {
hash, ok := data.(common.Hash)
if !ok {
return errors.New("provided data is not a common.Hash")
}
f.mu.Lock()
defer f.mu.Unlock()
f.hashes = append(f.hashes, hash)
return nil
}
// pop returns all the hashes stored in the hashFilter and clears the hashFilter contents
func (f *hashFilter) pop() interface{} {
f.mu.Lock()
defer f.mu.Unlock()
hashes := f.hashes
f.hashes = nil
return hashes
}
func (f *hashFilter) stop() {
select {
case <-f.done:
return
default:
close(f.done)
}
}
func (f *hashFilter) deadline() *time.Timer {
return f.timer
}
func newHashFilter() *hashFilter {
return &hashFilter{
done: make(chan struct{}),
}
}