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
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637
  1. package antireplay
  2. import (
  3. "github.com/allegro/bigcache"
  4. "github.com/juju/errors"
  5. "github.com/9seconds/mtg/config"
  6. )
  7. // Cache defines storage for obfuscated2 handshake frames.
  8. type Cache struct {
  9. cache *bigcache.BigCache
  10. }
  11. func (a Cache) Add(frame []byte) {
  12. a.cache.Set(string(frame), nil) // nolint: errcheck
  13. }
  14. func (a Cache) Has(frame []byte) bool {
  15. _, err := a.cache.Get(string(frame))
  16. return err == nil
  17. }
  18. func NewCache(config *config.Config) (Cache, error) {
  19. cache, err := bigcache.NewBigCache(bigcache.Config{
  20. Shards: 1024,
  21. LifeWindow: config.AntiReplayEvictionTime,
  22. Hasher: hasher{},
  23. HardMaxCacheSize: config.AntiReplayMaxSize,
  24. })
  25. if err != nil {
  26. return Cache{}, errors.Annotate(err, "Cannot make cache")
  27. }
  28. return Cache{cache}, nil
  29. }