Преглед изворни кода

Add possibility to disable antireplay cache

tags/v1.0.2^2
9seconds пре 6 година
родитељ
комит
a47edf08d0
3 измењених фајлова са 25 додато и 6 уклоњено
  1. 4
    4
      antireplay/cache.go
  2. 13
    2
      antireplay/init.go
  3. 8
    0
      antireplay/nilcache.go

+ 4
- 4
antireplay/cache.go Прегледај датотеку

11
 	data *fastcache.Cache
11
 	data *fastcache.Cache
12
 }
12
 }
13
 
13
 
14
-func (c *cache) AddObfuscated2(data []byte) {
14
+func (c cache) AddObfuscated2(data []byte) {
15
 	c.data.Set(keyObfuscated2(data), nil)
15
 	c.data.Set(keyObfuscated2(data), nil)
16
 }
16
 }
17
 
17
 
18
-func (c *cache) AddTLS(data []byte) {
18
+func (c cache) AddTLS(data []byte) {
19
 	c.data.Set(keyTLS(data), nil)
19
 	c.data.Set(keyTLS(data), nil)
20
 }
20
 }
21
 
21
 
22
-func (c *cache) HasObfuscated2(data []byte) bool {
22
+func (c cache) HasObfuscated2(data []byte) bool {
23
 	return c.data.Has(keyObfuscated2(data))
23
 	return c.data.Has(keyObfuscated2(data))
24
 }
24
 }
25
 
25
 
26
-func (c *cache) HasTLS(data []byte) bool {
26
+func (c cache) HasTLS(data []byte) bool {
27
 	return c.data.Has(keyTLS(data))
27
 	return c.data.Has(keyTLS(data))
28
 }
28
 }
29
 
29
 

+ 13
- 2
antireplay/init.go Прегледај датотеку

8
 	"github.com/9seconds/mtg/config"
8
 	"github.com/9seconds/mtg/config"
9
 )
9
 )
10
 
10
 
11
+type CacheInterface interface {
12
+	AddObfuscated2([]byte)
13
+	AddTLS([]byte)
14
+	HasObfuscated2([]byte) bool
15
+	HasTLS([]byte) bool
16
+}
17
+
11
 var (
18
 var (
12
-	Cache    cache
19
+	Cache    CacheInterface
13
 	initOnce sync.Once
20
 	initOnce sync.Once
14
 )
21
 )
15
 
22
 
16
 func Init() {
23
 func Init() {
17
 	initOnce.Do(func() {
24
 	initOnce.Do(func() {
18
-		Cache.data = fastcache.New(config.C.AntiReplayMaxSize)
25
+		if config.C.AntiReplayMaxSize == 0 {
26
+			Cache = nilCache{}
27
+		} else {
28
+			Cache = cache{fastcache.New(config.C.AntiReplayMaxSize)}
29
+		}
19
 	})
30
 	})
20
 }
31
 }

+ 8
- 0
antireplay/nilcache.go Прегледај датотеку

1
+package antireplay
2
+
3
+type nilCache struct{}
4
+
5
+func (n nilCache) AddObfuscated2(_ []byte)      {}
6
+func (n nilCache) AddTLS(_ []byte)              {}
7
+func (n nilCache) HasObfuscated2(_ []byte) bool { return false }
8
+func (n nilCache) HasTLS(_ []byte) bool         { return false }

Loading…
Откажи
Сачувај