mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Use truncated hash instead crc64 for counted hash
This commit is contained in:
parent
b18e6fcfe4
commit
35e9ab8c0b
1 changed files with 8 additions and 5 deletions
|
@ -1,9 +1,10 @@
|
||||||
package ipsetsink
|
package ipsetsink
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
|
"encoding/binary"
|
||||||
"hash"
|
"hash"
|
||||||
"hash/crc64"
|
|
||||||
|
|
||||||
"github.com/clarkduvall/hyperloglog"
|
"github.com/clarkduvall/hyperloglog"
|
||||||
"golang.org/x/crypto/sha3"
|
"golang.org/x/crypto/sha3"
|
||||||
|
@ -31,7 +32,7 @@ func (s *IPSetSink) maskIPAddress(ipAddress string) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IPSetSink) AddIPToSet(ipAddress string) {
|
func (s *IPSetSink) AddIPToSet(ipAddress string) {
|
||||||
s.countDistinct.Add(crc64FromBytes{hashValue(s.maskIPAddress(ipAddress))})
|
s.countDistinct.Add(truncatedHash64FromBytes{hashValue(s.maskIPAddress(ipAddress))})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IPSetSink) Dump() ([]byte, error) {
|
func (s *IPSetSink) Dump() ([]byte, error) {
|
||||||
|
@ -43,10 +44,12 @@ func (s *IPSetSink) Reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type hashValue []byte
|
type hashValue []byte
|
||||||
type crc64FromBytes struct {
|
type truncatedHash64FromBytes struct {
|
||||||
hashValue
|
hashValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c crc64FromBytes) Sum64() uint64 {
|
func (c truncatedHash64FromBytes) Sum64() uint64 {
|
||||||
return crc64.Checksum(c.hashValue, crc64.MakeTable(crc64.ECMA))
|
var value uint64
|
||||||
|
binary.Read(bytes.NewReader(c.hashValue), binary.BigEndian, &value)
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue