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

stats_telegram.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package stream
  2. import (
  3. "net"
  4. "sync"
  5. "time"
  6. "github.com/9seconds/mtg/conntypes"
  7. "github.com/9seconds/mtg/stats"
  8. "go.uber.org/zap"
  9. )
  10. type wrapperTelegramStats struct {
  11. parent conntypes.StreamReadWriteCloser
  12. dc conntypes.DC
  13. once sync.Once
  14. }
  15. func (w *wrapperTelegramStats) Write(p []byte) (int, error) {
  16. return w.parent.Write(p) // nolint: wrapcheck
  17. }
  18. func (w *wrapperTelegramStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
  19. return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck
  20. }
  21. func (w *wrapperTelegramStats) Read(p []byte) (int, error) {
  22. return w.parent.Read(p) // nolint: wrapcheck
  23. }
  24. func (w *wrapperTelegramStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
  25. return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck
  26. }
  27. func (w *wrapperTelegramStats) Conn() net.Conn {
  28. return w.parent.Conn()
  29. }
  30. func (w *wrapperTelegramStats) Logger() *zap.SugaredLogger {
  31. return w.parent.Logger().Named("stats-telegram")
  32. }
  33. func (w *wrapperTelegramStats) LocalAddr() *net.TCPAddr {
  34. return w.parent.LocalAddr()
  35. }
  36. func (w *wrapperTelegramStats) RemoteAddr() *net.TCPAddr {
  37. return w.parent.RemoteAddr()
  38. }
  39. func (w *wrapperTelegramStats) Close() error {
  40. var err error
  41. w.once.Do(func() {
  42. err = w.parent.Close()
  43. stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr())
  44. })
  45. return err // nolint: wrapcheck
  46. }
  47. func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
  48. conn := &wrapperTelegramStats{
  49. parent: parent,
  50. dc: dc,
  51. }
  52. stats.Stats.TelegramConnected(dc, parent.RemoteAddr())
  53. return conn
  54. }