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
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

conns.go 673B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package mtglib
  2. import (
  3. "context"
  4. "net"
  5. "time"
  6. )
  7. type connTelegramTraffic struct {
  8. net.Conn
  9. connID string
  10. stream EventStream
  11. ctx context.Context
  12. }
  13. func (c connTelegramTraffic) Read(b []byte) (int, error) {
  14. n, err := c.Conn.Read(b)
  15. if n > 0 {
  16. c.stream.Send(c.ctx, EventTraffic{
  17. CreatedAt: time.Now(),
  18. ConnID: c.connID,
  19. Traffic: uint(n),
  20. IsRead: true,
  21. })
  22. }
  23. return n, err
  24. }
  25. func (c connTelegramTraffic) Write(b []byte) (int, error) {
  26. n, err := c.Conn.Write(b)
  27. if n > 0 {
  28. c.stream.Send(c.ctx, EventTraffic{
  29. CreatedAt: time.Now(),
  30. ConnID: c.connID,
  31. Traffic: uint(n),
  32. IsRead: false,
  33. })
  34. }
  35. return n, err
  36. }