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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stream_info.go 976B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package stats
  2. import (
  3. "net"
  4. "strconv"
  5. "time"
  6. statsd "github.com/smira/go-statsd"
  7. )
  8. type streamInfo struct {
  9. startTime time.Time
  10. tags map[string]string
  11. }
  12. func (s *streamInfo) SetStartTime(tme time.Time) {
  13. s.startTime = tme
  14. }
  15. func (s *streamInfo) SetClientIP(ip net.IP) {
  16. if ip.To4() != nil {
  17. s.tags[TagIPFamily] = TagIPFamilyIPv4
  18. } else {
  19. s.tags[TagIPFamily] = TagIPFamilyIPv6
  20. }
  21. }
  22. func (s *streamInfo) SetTelegramIP(ip net.IP) {
  23. s.tags[TagTelegramIP] = ip.String()
  24. }
  25. func (s *streamInfo) SetDC(dc int) {
  26. s.tags[TagDC] = strconv.Itoa(dc)
  27. }
  28. func (s *streamInfo) V(key string) string {
  29. return s.tags[key]
  30. }
  31. func (s *streamInfo) TV(key string) statsd.Tag {
  32. return statsd.StringTag(key, s.tags[key])
  33. }
  34. func (s *streamInfo) Reset() {
  35. s.startTime = time.Time{}
  36. for k := range s.tags {
  37. delete(s.tags, k)
  38. }
  39. }
  40. func getDirection(isRead bool) string {
  41. if isRead { // for telegram
  42. return TagDirectionToClient
  43. }
  44. return TagDirectionFromClient
  45. }