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 794B

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