This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake.
commit 35e9ab8c0b3168b5eaa4f6538b8e9208eb38c508 Author: Shelikhoo xiaokangwang@outlook.com AuthorDate: Wed Jun 15 15:32:58 2022 +0100
Use truncated hash instead crc64 for counted hash --- common/ipsetsink/sink.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/common/ipsetsink/sink.go b/common/ipsetsink/sink.go index b62f786..168d061 100644 --- a/common/ipsetsink/sink.go +++ b/common/ipsetsink/sink.go @@ -1,9 +1,10 @@ package ipsetsink
import ( + "bytes" "crypto/hmac" + "encoding/binary" "hash" - "hash/crc64"
"github.com/clarkduvall/hyperloglog" "golang.org/x/crypto/sha3" @@ -31,7 +32,7 @@ func (s *IPSetSink) maskIPAddress(ipAddress string) []byte { }
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) { @@ -43,10 +44,12 @@ func (s *IPSetSink) Reset() { }
type hashValue []byte -type crc64FromBytes struct { +type truncatedHash64FromBytes struct { hashValue }
-func (c crc64FromBytes) Sum64() uint64 { - return crc64.Checksum(c.hashValue, crc64.MakeTable(crc64.ECMA)) +func (c truncatedHash64FromBytes) Sum64() uint64 { + var value uint64 + binary.Read(bytes.NewReader(c.hashValue), binary.BigEndian, &value) + return value }