mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:14:02 +03:00
Send correct proxy header
This commit is contained in:
@@ -36,5 +36,7 @@ func DirectInit(socket net.Conn, connID string, conf *config.Config) (wrappers.W
|
|||||||
|
|
||||||
conn = wrappers.NewStreamCipher(conn, obfs2.Encryptor, obfs2.Decryptor)
|
conn = wrappers.NewStreamCipher(conn, obfs2.Encryptor, obfs2.Decryptor)
|
||||||
|
|
||||||
|
conn.Logger().Infow("Client connection initialized")
|
||||||
|
|
||||||
return conn, connOpts, nil
|
return conn, connOpts, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,20 @@ type ProxyRequest struct {
|
|||||||
Options *mtproto.ConnectionOpts
|
Options *mtproto.ConnectionOpts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ProxyRequest) Bytes(message []byte) []byte {
|
func (r *ProxyRequest) MakeHeader(message []byte) *bytes.Buffer {
|
||||||
|
bufferLength := len(TagProxyRequest) +
|
||||||
|
4 + // len(flags)
|
||||||
|
len(r.ConnectionID) +
|
||||||
|
len(r.ClientIPPort) +
|
||||||
|
len(r.OurIPPort) +
|
||||||
|
len(ProxyRequestExtraSize) +
|
||||||
|
len(ProxyRequestProxyTag) +
|
||||||
|
1 + // len(AdTag)
|
||||||
|
len(r.ADTag)
|
||||||
|
bufferLength += bufferLength % 4
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
buf.Grow(bufferLength)
|
||||||
|
|
||||||
flags := r.Flags
|
flags := r.Flags
|
||||||
if r.Options.ReadHacks.QuickAck {
|
if r.Options.ReadHacks.QuickAck {
|
||||||
@@ -42,9 +54,8 @@ func (r *ProxyRequest) Bytes(message []byte) []byte {
|
|||||||
buf.WriteByte(byte(len(r.ADTag)))
|
buf.WriteByte(byte(len(r.ADTag)))
|
||||||
buf.Write(r.ADTag)
|
buf.Write(r.ADTag)
|
||||||
buf.Write(make([]byte, (4-buf.Len()%4)%4))
|
buf.Write(make([]byte, (4-buf.Len()%4)%4))
|
||||||
buf.Write(message)
|
|
||||||
|
|
||||||
return buf.Bytes()
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*ProxyRequest, error) {
|
func NewProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*ProxyRequest, error) {
|
||||||
|
|||||||
+7
-1
@@ -43,7 +43,13 @@ func (t *MiddleTelegram) Init(connOpts *mtproto.ConnectionOpts, conn wrappers.St
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrappers.NewMTProtoProxy(frameConn, connOpts, t.conf.AdTag)
|
proxyConn, err := wrappers.NewMTProtoProxy(frameConn, connOpts, t.conf.AdTag)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
proxyConn.Logger().Infow("Telegram connection initialized")
|
||||||
|
|
||||||
|
return proxyConn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MiddleTelegram) sendRPCNonceRequest(conn wrappers.PacketWriter) (*rpc.NonceRequest, error) {
|
func (t *MiddleTelegram) sendRPCNonceRequest(conn wrappers.PacketWriter) (*rpc.NonceRequest, error) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package wrappers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
@@ -100,7 +101,19 @@ func (m *MTProtoProxy) Write(p []byte) (int, error) {
|
|||||||
)
|
)
|
||||||
m.writeCounter++
|
m.writeCounter++
|
||||||
|
|
||||||
if _, err := m.conn.Write(p); err != nil {
|
header := m.req.MakeHeader(p)
|
||||||
|
if ce := m.logger.Desugar().Check(zap.DebugLevel, "RPC_PROXY_REQ header"); ce != nil {
|
||||||
|
ce.Write(
|
||||||
|
zap.Int("length", len(p)),
|
||||||
|
zap.Uint32("counter", m.writeCounter),
|
||||||
|
zap.Bool("simple_ack", m.req.Options.ReadHacks.QuickAck),
|
||||||
|
zap.Bool("quick_ack", m.req.Options.ReadHacks.SimpleAck),
|
||||||
|
zap.String("header", fmt.Sprintf("%v", header.Bytes())),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
header.Write(p)
|
||||||
|
|
||||||
|
if _, err := m.conn.Write(header.Bytes()); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user