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.

conn.go 608B

12345678910111213141516171819202122232425262728293031323334353637
  1. package obfuscated2
  2. import (
  3. "crypto/cipher"
  4. "github.com/9seconds/mtg/v2/essentials"
  5. )
  6. type Conn struct {
  7. essentials.Conn
  8. Encryptor cipher.Stream
  9. Decryptor cipher.Stream
  10. }
  11. func (c Conn) Read(p []byte) (int, error) {
  12. n, err := c.Conn.Read(p)
  13. if err != nil {
  14. return n, err // nolint: wrapcheck
  15. }
  16. c.Decryptor.XORKeyStream(p, p[:n])
  17. return n, nil
  18. }
  19. func (c Conn) Write(p []byte) (int, error) {
  20. buf := acquireBytesBuffer()
  21. defer releaseBytesBuffer(buf)
  22. buf.Write(p)
  23. payload := buf.Bytes()
  24. c.Encryptor.XORKeyStream(payload, payload)
  25. return c.Conn.Write(payload) // nolint: wrapcheck
  26. }