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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

counting_conn.go 784B

1234567891011121314151617181920212223242526272829303132333435
  1. package mtglib
  2. import (
  3. "github.com/dolonet/mtg-multi/essentials"
  4. )
  5. // countingConn wraps essentials.Conn and counts bytes through a cached
  6. // *secretStats pointer. The pointer is resolved once at construction time
  7. // so Read/Write never need to acquire a lock.
  8. type countingConn struct {
  9. essentials.Conn
  10. st *secretStats
  11. }
  12. func newCountingConn(conn essentials.Conn, stats *ProxyStats, secretName string) *countingConn {
  13. return &countingConn{Conn: conn, st: stats.getOrCreate(secretName)}
  14. }
  15. func (c *countingConn) Read(p []byte) (int, error) {
  16. n, err := c.Conn.Read(p)
  17. if n > 0 {
  18. c.st.bytesIn.Add(int64(n))
  19. }
  20. return n, err
  21. }
  22. func (c *countingConn) Write(p []byte) (int, error) {
  23. n, err := c.Conn.Write(p)
  24. if n > 0 {
  25. c.st.bytesOut.Add(int64(n))
  26. }
  27. return n, err
  28. }