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
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

pools.go 770B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package relay
  2. import (
  3. "context"
  4. "sync"
  5. "time"
  6. )
  7. var relayPool = sync.Pool{
  8. New: func() interface{} {
  9. return &Relay{
  10. tickChannel: make(chan struct{}),
  11. errorChannel: make(chan error, 1),
  12. }
  13. },
  14. }
  15. func AcquireRelay(ctx context.Context, logger Logger, bufferSize int, idleTimeout time.Duration) *Relay {
  16. ctx, cancel := context.WithCancel(ctx)
  17. r, ok := relayPool.Get().(*Relay)
  18. if !ok {
  19. panic("Relay pool has no relay!")
  20. }
  21. r.ctx = ctx
  22. r.ctxCancel = cancel
  23. r.logger = logger
  24. r.tickTimeout = idleTimeout
  25. if len(r.eastBuffer) != bufferSize {
  26. r.eastBuffer = make([]byte, bufferSize)
  27. }
  28. if len(r.westBuffer) != bufferSize {
  29. r.westBuffer = make([]byte, bufferSize)
  30. }
  31. return r
  32. }
  33. func ReleaseRelay(r *Relay) {
  34. r.Reset()
  35. relayPool.Put(r)
  36. }