Преглед изворни кода

Log proxt req header flags

tags/0.9
9seconds пре 7 година
родитељ
комит
6ea4f3dbc2
3 измењених фајлова са 37 додато и 4 уклоњено
  1. 32
    1
      mtproto/rpc/proxy_flags.go
  2. 3
    2
      mtproto/rpc/proxy_request.go
  3. 2
    1
      wrappers/mtproto_proxy.go

+ 32
- 1
mtproto/rpc/proxy_flags.go Прегледај датотеку

@@ -1,6 +1,9 @@
1 1
 package rpc
2 2
 
3
-import "encoding/binary"
3
+import (
4
+	"encoding/binary"
5
+	"strings"
6
+)
4 7
 
5 8
 type proxyRequestFlags uint32
6 9
 
@@ -22,3 +25,31 @@ func (r proxyRequestFlags) Bytes() []byte {
22 25
 
23 26
 	return converted
24 27
 }
28
+
29
+func (r proxyRequestFlags) String() string {
30
+	flags := make([]string, 0, 7)
31
+
32
+	if r&proxyRequestFlagsHasAdTag != 0 {
33
+		flags = append(flags, "HAS_AD_TAG")
34
+	}
35
+	if r&proxyRequestFlagsEncrypted != 0 {
36
+		flags = append(flags, "ENCRYPTED")
37
+	}
38
+	if r&proxyRequestFlagsMagic != 0 {
39
+		flags = append(flags, "MAGIC")
40
+	}
41
+	if r&proxyRequestFlagsExtMode2 != 0 {
42
+		flags = append(flags, "EXT_MODE_2")
43
+	}
44
+	if r&proxyRequestFlagsIntermediate != 0 {
45
+		flags = append(flags, "INTERMEDIATE")
46
+	}
47
+	if r&proxyRequestFlagsAbdridged != 0 {
48
+		flags = append(flags, "ABRIDGED")
49
+	}
50
+	if r&proxyRequestFlagsQuickAck != 0 {
51
+		flags = append(flags, "QUICK_ACK")
52
+	}
53
+
54
+	return strings.Join(flags, " | ")
55
+}

+ 3
- 2
mtproto/rpc/proxy_request.go Прегледај датотеку

@@ -4,6 +4,7 @@ import (
4 4
 	"bytes"
5 5
 	"crypto/rand"
6 6
 	"encoding/binary"
7
+	"fmt"
7 8
 	"net"
8 9
 
9 10
 	"github.com/juju/errors"
@@ -20,7 +21,7 @@ type ProxyRequest struct {
20 21
 	Options      *mtproto.ConnectionOpts
21 22
 }
22 23
 
23
-func (r *ProxyRequest) MakeHeader(message []byte) *bytes.Buffer {
24
+func (r *ProxyRequest) MakeHeader(message []byte) (*bytes.Buffer, fmt.Stringer) {
24 25
 	bufferLength := len(TagProxyRequest) +
25 26
 		4 + // len(flags)
26 27
 		len(r.ConnectionID) +
@@ -55,7 +56,7 @@ func (r *ProxyRequest) MakeHeader(message []byte) *bytes.Buffer {
55 56
 	buf.Write(r.ADTag)
56 57
 	buf.Write(make([]byte, (4-buf.Len()%4)%4))
57 58
 
58
-	return buf
59
+	return buf, flags
59 60
 }
60 61
 
61 62
 func NewProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*ProxyRequest, error) {

+ 2
- 1
wrappers/mtproto_proxy.go Прегледај датотеку

@@ -107,7 +107,7 @@ func (m *MTProtoProxy) Write(p []byte) (int, error) {
107 107
 		"quick_ack", m.req.Options.ReadHacks.QuickAck,
108 108
 	)
109 109
 
110
-	header := m.req.MakeHeader(p)
110
+	header, flags := m.req.MakeHeader(p)
111 111
 	if ce := m.logger.Desugar().Check(zap.DebugLevel, "RPC_PROXY_REQ header"); ce != nil {
112 112
 		ce.Write(
113 113
 			zap.Int("length", len(p)),
@@ -115,6 +115,7 @@ func (m *MTProtoProxy) Write(p []byte) (int, error) {
115 115
 			zap.Bool("simple_ack", m.req.Options.ReadHacks.QuickAck),
116 116
 			zap.Bool("quick_ack", m.req.Options.ReadHacks.SimpleAck),
117 117
 			zap.String("header", fmt.Sprintf("%v", header.Bytes())),
118
+			zap.Stringer("flags", flags),
118 119
 		)
119 120
 	}
120 121
 	header.Write(p)

Loading…
Откажи
Сачувај