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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package essentials
  2. import (
  3. "io"
  4. "net"
  5. )
  6. // CloseableReader is an [io.Reader] interface that can close its reading end.
  7. type CloseableReader interface {
  8. io.Reader
  9. CloseRead() error
  10. }
  11. // CloseableWriter is an [io.Writer] that can close its writing end.
  12. type CloseableWriter interface {
  13. io.Writer
  14. CloseWrite() error
  15. }
  16. // Conn is an extension of [net.Conn] that can close its ends. This mostly
  17. // implies TCP connections.
  18. type Conn interface {
  19. net.Conn
  20. CloseableReader
  21. CloseableWriter
  22. }
  23. type netConnWrapper struct {
  24. net.Conn
  25. }
  26. func (n netConnWrapper) CloseRead() error {
  27. if conn, ok := n.Conn.(CloseableReader); ok {
  28. return conn.CloseRead()
  29. }
  30. return n.Close()
  31. }
  32. func (n netConnWrapper) CloseWrite() error {
  33. if conn, ok := n.Conn.(CloseableWriter); ok {
  34. return conn.CloseWrite()
  35. }
  36. return n.Close()
  37. }
  38. // WrapConn wraps a generic [net.Conn] into Conn.
  39. func WrapNetConn(conn net.Conn) Conn {
  40. return netConnWrapper{conn}
  41. }