mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 17:14:02 +03:00
Add possibility to disable antireplay cache
This commit is contained in:
+4
-4
@@ -11,19 +11,19 @@ type cache struct {
|
|||||||
data *fastcache.Cache
|
data *fastcache.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cache) AddObfuscated2(data []byte) {
|
func (c cache) AddObfuscated2(data []byte) {
|
||||||
c.data.Set(keyObfuscated2(data), nil)
|
c.data.Set(keyObfuscated2(data), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cache) AddTLS(data []byte) {
|
func (c cache) AddTLS(data []byte) {
|
||||||
c.data.Set(keyTLS(data), nil)
|
c.data.Set(keyTLS(data), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cache) HasObfuscated2(data []byte) bool {
|
func (c cache) HasObfuscated2(data []byte) bool {
|
||||||
return c.data.Has(keyObfuscated2(data))
|
return c.data.Has(keyObfuscated2(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cache) HasTLS(data []byte) bool {
|
func (c cache) HasTLS(data []byte) bool {
|
||||||
return c.data.Has(keyTLS(data))
|
return c.data.Has(keyTLS(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-2
@@ -8,13 +8,24 @@ import (
|
|||||||
"github.com/9seconds/mtg/config"
|
"github.com/9seconds/mtg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CacheInterface interface {
|
||||||
|
AddObfuscated2([]byte)
|
||||||
|
AddTLS([]byte)
|
||||||
|
HasObfuscated2([]byte) bool
|
||||||
|
HasTLS([]byte) bool
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Cache cache
|
Cache CacheInterface
|
||||||
initOnce sync.Once
|
initOnce sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
initOnce.Do(func() {
|
initOnce.Do(func() {
|
||||||
Cache.data = fastcache.New(config.C.AntiReplayMaxSize)
|
if config.C.AntiReplayMaxSize == 0 {
|
||||||
|
Cache = nilCache{}
|
||||||
|
} else {
|
||||||
|
Cache = cache{fastcache.New(config.C.AntiReplayMaxSize)}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package antireplay
|
||||||
|
|
||||||
|
type nilCache struct{}
|
||||||
|
|
||||||
|
func (n nilCache) AddObfuscated2(_ []byte) {}
|
||||||
|
func (n nilCache) AddTLS(_ []byte) {}
|
||||||
|
func (n nilCache) HasObfuscated2(_ []byte) bool { return false }
|
||||||
|
func (n nilCache) HasTLS(_ []byte) bool { return false }
|
||||||
Reference in New Issue
Block a user