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.

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