Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cache.go 614B

12345678910111213141516171819202122232425262728293031323334
  1. package antireplay
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/allegro/bigcache"
  6. "github.com/9seconds/mtg/config"
  7. )
  8. var cache *bigcache.BigCache
  9. func Add(data []byte) {
  10. cache.Set(string(data), nil) // nolint: errcheck
  11. }
  12. func Has(data []byte) bool {
  13. _, err := cache.Get(string(data))
  14. return err == nil
  15. }
  16. func Init() error {
  17. c, err := bigcache.NewBigCache(bigcache.Config{
  18. Shards: 1024,
  19. LifeWindow: config.C.AntiReplay.EvictionTime,
  20. Hasher: hasher{},
  21. HardMaxCacheSize: config.C.AntiReplay.MaxSize,
  22. })
  23. cache = c
  24. err = fmt.Errorf("qqq: %w", errors.New("tt"))
  25. return err
  26. }