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 символов.

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package hub
  2. import (
  3. "context"
  4. "sync"
  5. "github.com/9seconds/mtg/protocol"
  6. )
  7. type hub struct {
  8. muxes map[int32]*mux
  9. mutex sync.RWMutex
  10. ctx context.Context
  11. }
  12. func (h *hub) Register(req *protocol.TelegramRequest) (*ProxyConn, error) {
  13. return h.getMux(req).Get(req)
  14. }
  15. func (h *hub) getMux(req *protocol.TelegramRequest) *mux {
  16. var key int32 = 32767 + int32(req.ClientProtocol.DC()) + 100000*int32(req.ClientProtocol.ConnectionProtocol())
  17. h.mutex.RLock()
  18. m, ok := h.muxes[key]
  19. h.mutex.RUnlock()
  20. if !ok {
  21. h.mutex.Lock()
  22. m, ok = h.muxes[key]
  23. if !ok {
  24. m = newMux(h.ctx)
  25. h.muxes[key] = m
  26. }
  27. h.mutex.Unlock()
  28. }
  29. return m
  30. }