Просмотр исходного кода

Log proxt req header flags

tags/0.9
9seconds 7 лет назад
Родитель
Сommit
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
 package rpc
1
 package rpc
2
 
2
 
3
-import "encoding/binary"
3
+import (
4
+	"encoding/binary"
5
+	"strings"
6
+)
4
 
7
 
5
 type proxyRequestFlags uint32
8
 type proxyRequestFlags uint32
6
 
9
 
22
 
25
 
23
 	return converted
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
 	"bytes"
4
 	"bytes"
5
 	"crypto/rand"
5
 	"crypto/rand"
6
 	"encoding/binary"
6
 	"encoding/binary"
7
+	"fmt"
7
 	"net"
8
 	"net"
8
 
9
 
9
 	"github.com/juju/errors"
10
 	"github.com/juju/errors"
20
 	Options      *mtproto.ConnectionOpts
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
 	bufferLength := len(TagProxyRequest) +
25
 	bufferLength := len(TagProxyRequest) +
25
 		4 + // len(flags)
26
 		4 + // len(flags)
26
 		len(r.ConnectionID) +
27
 		len(r.ConnectionID) +
55
 	buf.Write(r.ADTag)
56
 	buf.Write(r.ADTag)
56
 	buf.Write(make([]byte, (4-buf.Len()%4)%4))
57
 	buf.Write(make([]byte, (4-buf.Len()%4)%4))
57
 
58
 
58
-	return buf
59
+	return buf, flags
59
 }
60
 }
60
 
61
 
61
 func NewProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*ProxyRequest, error) {
62
 func NewProxyRequest(clientAddr, ownAddr *net.TCPAddr, opts *mtproto.ConnectionOpts, adTag []byte) (*ProxyRequest, error) {

+ 2
- 1
wrappers/mtproto_proxy.go Просмотреть файл

107
 		"quick_ack", m.req.Options.ReadHacks.QuickAck,
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
 	if ce := m.logger.Desugar().Check(zap.DebugLevel, "RPC_PROXY_REQ header"); ce != nil {
111
 	if ce := m.logger.Desugar().Check(zap.DebugLevel, "RPC_PROXY_REQ header"); ce != nil {
112
 		ce.Write(
112
 		ce.Write(
113
 			zap.Int("length", len(p)),
113
 			zap.Int("length", len(p)),
115
 			zap.Bool("simple_ack", m.req.Options.ReadHacks.QuickAck),
115
 			zap.Bool("simple_ack", m.req.Options.ReadHacks.QuickAck),
116
 			zap.Bool("quick_ack", m.req.Options.ReadHacks.SimpleAck),
116
 			zap.Bool("quick_ack", m.req.Options.ReadHacks.SimpleAck),
117
 			zap.String("header", fmt.Sprintf("%v", header.Bytes())),
117
 			zap.String("header", fmt.Sprintf("%v", header.Bytes())),
118
+			zap.Stringer("flags", flags),
118
 		)
119
 		)
119
 	}
120
 	}
120
 	header.Write(p)
121
 	header.Write(p)

Загрузка…
Отмена
Сохранить