summaryrefslogtreecommitdiff
path: root/replay_filter.go
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2014-05-23 04:04:31 +0000
committerYawning Angel <yawning@schwanenlied.me>2014-05-23 04:04:31 +0000
commit272fb852e72ac282144fe8608fea62ab74b9549c (patch)
treeed5afd35f72cc3739caf75395674b612f812ce76 /replay_filter.go
parentfd4e3c7c74ad4d1acb37c43fde8d18786616846a (diff)
Change the maximm handshake length to 8192 bytes.
* handhake_ntor_test now is considerably more comprehensive. * The padding related constants in the spec were clarified. This breaks wireprotocol compatibility.
Diffstat (limited to 'replay_filter.go')
-rw-r--r--replay_filter.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/replay_filter.go b/replay_filter.go
index f5c64f8..5e98b89 100644
--- a/replay_filter.go
+++ b/replay_filter.go
@@ -78,7 +78,7 @@ func newReplayFilter() (filter *replayFilter, err error) {
}
// testAndSet queries the filter for buf, adds it if it was not present and
-// returns if it has added the entry or not.
+// returns if it has added the entry or not. This method is threadsafe.
func (f *replayFilter) testAndSet(now int64, buf []byte) bool {
hash := siphash.Hash(f.key[0], f.key[1], buf)
@@ -102,7 +102,8 @@ func (f *replayFilter) testAndSet(now int64, buf []byte) bool {
}
// compactFilter purges entries that are too old to be relevant. If the filter
-// is filled to maxFilterCapacity, it will force purge a single entry.
+// is filled to maxFilterCapacity, it will force purge a single entry. This
+// method is NOT threadsafe.
func (f *replayFilter) compactFilter(now int64) {
e := f.fifo.Front()
for e != nil {
@@ -116,8 +117,7 @@ func (f *replayFilter) compactFilter(now int64) {
// a lot. This will eventually self-correct, but "eventually"
// could be a long time. As much as this sucks, jettison the
// entire filter.
- f.filter = make(map[uint64]*filterEntry)
- f.fifo = list.New()
+ f.reset()
return
}
if deltaT < 3600*2 {
@@ -135,4 +135,10 @@ func (f *replayFilter) compactFilter(now int64) {
}
}
+// reset purges the entire filter. This methoid is NOT threadsafe.
+func (f *replayFilter) reset() {
+ f.filter = make(map[uint64]*filterEntry)
+ f.fifo = list.New()
+}
+
/* vim :set ts=4 sw=4 sts=4 noet : */