mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-07 08:15:49 +08:00
采用更快的Hash算法
This commit is contained in:
@@ -2,6 +2,7 @@ package checkpoints
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// just a sample checkpoint, copy and change it for your new checkpoint
|
||||
@@ -9,11 +10,11 @@ type SampleRequestCheckpoint struct {
|
||||
Checkpoint
|
||||
}
|
||||
|
||||
func (this *SampleRequestCheckpoint) RequestValue(req *requests.Request, param string, options map[string]string) (value interface{}, sysErr error, userErr error) {
|
||||
func (this *SampleRequestCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *SampleRequestCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options map[string]string) (value interface{}, sysErr error, userErr error) {
|
||||
func (this *SampleRequestCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||
if this.IsRequest() {
|
||||
return this.RequestValue(req, param, options)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package waf
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/dchest/siphash"
|
||||
"github.com/cespare/xxhash"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@@ -174,7 +174,9 @@ func BenchmarkRuleSet_MatchRequest_Regexp3(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkHash(b *testing.B) {
|
||||
runtime.GOMAXPROCS(1)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = siphash.Hash(0, 0, bytes.Repeat([]byte("HELLO"), 10240))
|
||||
_ = xxhash.Sum64(bytes.Repeat([]byte("HELLO"), 10240))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ func testTemplate20001(a *assert.Assertion, t *testing.T, template *WAF) {
|
||||
// enable bot rule set
|
||||
for _, g := range template.Inbound {
|
||||
if g.Code == "bot" {
|
||||
g.On = true
|
||||
g.IsOn = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/ttlcache"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"github.com/dchest/siphash"
|
||||
"github.com/cespare/xxhash"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -21,7 +20,7 @@ func MatchStringCache(regex *regexp.Regexp, s string) bool {
|
||||
return regex.MatchString(s)
|
||||
}
|
||||
|
||||
hash := siphash.Hash(0, 0, utils.UnsafeStringToBytes(s))
|
||||
hash := xxhash.Sum64String(s)
|
||||
key := fmt.Sprintf("%p_", regex) + strconv.FormatUint(hash, 10)
|
||||
item := cache.Read(key)
|
||||
if item != nil {
|
||||
@@ -43,7 +42,7 @@ func MatchBytesCache(regex *regexp.Regexp, byteSlice []byte) bool {
|
||||
return regex.Match(byteSlice)
|
||||
}
|
||||
|
||||
hash := siphash.Hash(0, 0, byteSlice)
|
||||
hash := xxhash.Sum64(byteSlice)
|
||||
key := fmt.Sprintf("%p_", regex) + strconv.FormatUint(hash, 10)
|
||||
item := cache.Read(key)
|
||||
if item != nil {
|
||||
|
||||
Reference in New Issue
Block a user