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.

middle.go 816B

123456789101112131415161718192021222324252627282930
  1. package client
  2. import (
  3. "net"
  4. "github.com/9seconds/mtg/config"
  5. "github.com/9seconds/mtg/mtproto"
  6. mtwrappers "github.com/9seconds/mtg/mtproto/wrappers"
  7. "github.com/9seconds/mtg/wrappers"
  8. )
  9. func MiddleInit(conn net.Conn, socketID string, conf *config.Config) (wrappers.ReadWriteCloserWithAddr, *mtproto.ConnectionOpts, error) {
  10. newConn, opts, err := DirectInit(conn, socketID, conf)
  11. if err != nil {
  12. return nil, nil, err
  13. }
  14. if opts.ConnectionType == mtproto.ConnectionTypeAbridged {
  15. newConn = mtwrappers.NewAbridgedRWC(newConn, opts)
  16. } else {
  17. newConn = mtwrappers.NewIntermediateRWC(newConn, opts)
  18. }
  19. opts.ConnectionProto = mtproto.ConnectionProtocolIPv4
  20. if conn.LocalAddr().(*net.TCPAddr).IP.To4() == nil {
  21. opts.ConnectionProto = mtproto.ConnectionProtocolIPv6
  22. }
  23. return newConn, opts, nil
  24. }