From 6ea4f3dbc2b6de1f5fe1c89439ec724d7c049329 Mon Sep 17 00:00:00 2001 From: 9seconds Date: Sun, 8 Jul 2018 18:43:27 +0300 Subject: [PATCH] Log proxt req header flags --- mtproto/rpc/proxy_flags.go | 33 ++++++++++++++++++++++++++++++++- mtproto/rpc/proxy_request.go | 5 +++-- wrappers/mtproto_proxy.go | 3 ++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/mtproto/rpc/proxy_flags.go b/mtproto/rpc/proxy_flags.go index 0ac3c30..5599537 100644 --- a/mtproto/rpc/proxy_flags.go +++ b/mtproto/rpc/proxy_flags.go @@ -1,6 +1,9 @@ package rpc -import "encoding/binary" +import ( + "encoding/binary" + "strings" +) type proxyRequestFlags uint32 @@ -22,3 +25,31 @@ func (r proxyRequestFlags) Bytes() []byte { return converted } + +func (r proxyRequestFlags) String() string { + flags := make([]string, 0, 7) + + if r&proxyRequestFlagsHasAdTag != 0 { + flags = append(flags, "HAS_AD_TAG") + } + if r&proxyRequestFlagsEncrypted != 0 { + flags = append(flags, "ENCRYPTED") + } + if r&proxyRequestFlagsMagic != 0 { + flags = append(flags, "MAGIC") + } + if r&proxyRequestFlagsExtMode2 != 0 { + flags = append(flags, "EXT_MODE_2") + } + if r&proxyRequestFlagsIntermediate != 0 { + flags = append(flags, "INTERMEDIATE") + } + if r&proxyRequestFlagsAbdridged != 0 { + flags = append(flags, "ABRIDGED") + } + if r&proxyRequestFlagsQuickAck != 0 { + flags = append(flags, "QUICK_ACK") + } + + return strings.Join(flags, " | ") +} diff --git a/mtproto/rpc/proxy_request.go b/mtproto/rpc/proxy_request.go index c8666be..40ab3cf 100644 --- a/mtproto/rpc/proxy_request.go +++ b/mtproto/rpc/proxy_request.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/rand" "encoding/binary" + "fmt" "net" "github.com/juju/errors" @@ -20,7 +21,7 @@ type ProxyRequest struct { Options *mtproto.ConnectionOpts } -func (r *ProxyRequest) MakeHeader(message []byte) *bytes.Buffer { +func (r *ProxyRequest) MakeHeader(message []byte) (*bytes.Buffer, fmt.Stringer) { bufferLength := len(TagProxyRequest) + 4 + // len(flags) len(r.ConnectionID) + @@ -55,7 +56,7 @@ func (r *ProxyRequest) MakeHeader(message []byte) *bytes.Buffer { buf.Write(r.ADTag) buf.Write(make([]byte, (4-buf.Len()%4)%4)) - return buf + return buf, flags } func NewProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*ProxyRequest, error) { diff --git a/wrappers/mtproto_proxy.go b/wrappers/mtproto_proxy.go index c56e9a2..8415038 100644 --- a/wrappers/mtproto_proxy.go +++ b/wrappers/mtproto_proxy.go @@ -107,7 +107,7 @@ func (m *MTProtoProxy) Write(p []byte) (int, error) { "quick_ack", m.req.Options.ReadHacks.QuickAck, ) - header := m.req.MakeHeader(p) + header, flags := 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)), @@ -115,6 +115,7 @@ func (m *MTProtoProxy) Write(p []byte) (int, error) { 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())), + zap.Stringer("flags", flags), ) } header.Write(p)