Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mtproto_proxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mtproto_proxy
Commits
102bec59
Unverified
Commit
102bec59
authored
Jun 18, 2018
by
Сергей Прохоров
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix RPC flags (recent server changes)
parent
e7bf7af3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
mtp_rpc.erl
src/mtp_rpc.erl
+19
-7
No files found.
src/mtp_rpc.erl
View file @
102bec59
...
@@ -27,10 +27,14 @@
...
@@ -27,10 +27,14 @@
-
opaque
codec
()
::
#rpc_st
{}.
-
opaque
codec
()
::
#rpc_st
{}.
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
)
->
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
)
->
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
,
erlang
:
unique_integer
()).
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
,
ConnId
)
->
#rpc_st
{
client_addr
=
iolist_to_binary
(
encode_ip_port
(
ClientIp
,
ClientPort
)),
#rpc_st
{
client_addr
=
iolist_to_binary
(
encode_ip_port
(
ClientIp
,
ClientPort
)),
proxy_addr
=
iolist_to_binary
(
encode_ip_port
(
ProxyIp
,
ProxyPort
)),
proxy_addr
=
iolist_to_binary
(
encode_ip_port
(
ProxyIp
,
ProxyPort
)),
proxy_tag
=
ProxyTag
,
proxy_tag
=
ProxyTag
,
conn_id
=
<<
(
erlang
:
unique_integer
())
:
64
/
little
-
signed
>>
}.
conn_id
=
<<
ConnId
:
64
/
little
-
signed
>>
}.
%% It expects that packet segmentation was done on previous layer
%% It expects that packet segmentation was done on previous layer
try_decode_packet
(
<<?
RPC_PROXY_ANS
,
_
AnsFlags
:
4
/
binary
,
_
ConnId
:
8
/
binary
,
Data
/
binary
>>
=
_
Msg
,
S
)
->
try_decode_packet
(
<<?
RPC_PROXY_ANS
,
_
AnsFlags
:
4
/
binary
,
_
ConnId
:
8
/
binary
,
Data
/
binary
>>
=
_
Msg
,
S
)
->
...
@@ -47,10 +51,10 @@ encode_packet(Msg, #rpc_st{client_addr = ClientAddr, proxy_addr = ProxyAddr,
...
@@ -47,10 +51,10 @@ encode_packet(Msg, #rpc_st{client_addr = ClientAddr, proxy_addr = ProxyAddr,
conn_id
=
ConnId
,
proxy_tag
=
ProxyTag
}
=
S
)
->
conn_id
=
ConnId
,
proxy_tag
=
ProxyTag
}
=
S
)
->
((
iolist_size
(
Msg
)
rem
4
)
==
0
)
((
iolist_size
(
Msg
)
rem
4
)
==
0
)
orelse
error
(
not_aligned
),
orelse
error
(
not_aligned
),
Flags
=
make_flags
(
Msg
),
Req
=
Req
=
[
<<
238
,
241
,
206
,
54
,
%RPC_PROXY_REQ
[
<<
238
,
241
,
206
,
54
>>
,
%RPC_PROXY_REQ
8
,
16
,
2
,
64
%Flags
Flags
,
%Flags
>>
,
ConnId
,
ClientAddr
,
ProxyAddr
,
ConnId
,
ClientAddr
,
ProxyAddr
,
<<
24
:
32
/
little
,
%ExtraSize
<<
24
:
32
/
little
,
%ExtraSize
174
,
38
,
30
,
219
,
%ProxyTag
174
,
38
,
30
,
219
,
%ProxyTag
...
@@ -62,6 +66,14 @@ encode_packet(Msg, #rpc_st{client_addr = ClientAddr, proxy_addr = ProxyAddr,
...
@@ -62,6 +66,14 @@ encode_packet(Msg, #rpc_st{client_addr = ClientAddr, proxy_addr = ProxyAddr,
],
],
{
Req
,
S
}.
{
Req
,
S
}.
make_flags
(
<<
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
_
/
binary
>>
)
->
<<
10
,
16
,
2
,
64
>>
;
make_flags
(
Bin
)
when
is_binary
(
Bin
)
->
<<
8
,
16
,
2
,
64
>>
;
make_flags
(
Iodata
)
when
is_list
(
Iodata
)
->
%% TODO: do iolist_to_binary for 1st 8 bytes somehow
make_flags
(
iolist_to_binary
(
Iodata
)).
encode_ip_port
(
IPv4
,
Port
)
when
tuple_size
(
IPv4
)
==
4
->
encode_ip_port
(
IPv4
,
Port
)
when
tuple_size
(
IPv4
)
==
4
->
IpBin
=
inet_pton
(
IPv4
),
IpBin
=
inet_pton
(
IPv4
),
[
lists
:
duplicate
(
10
,
<<
0
>>
)
[
lists
:
duplicate
(
10
,
<<
0
>>
)
...
@@ -86,7 +98,7 @@ tst_new() ->
...
@@ -86,7 +98,7 @@ tst_new() ->
ProxyIp
=
{
80
,
211
,
29
,
34
},
ProxyIp
=
{
80
,
211
,
29
,
34
},
ProxyPort
=
53634
,
ProxyPort
=
53634
,
ProxyTag
=
<<
220
,
190
,
143
,
20
,
147
,
250
,
76
,
217
,
171
,
48
,
8
,
145
,
192
,
181
,
179
,
38
>>
,
ProxyTag
=
<<
220
,
190
,
143
,
20
,
147
,
250
,
76
,
217
,
171
,
48
,
8
,
145
,
192
,
181
,
179
,
38
>>
,
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
).
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
,
1
).
decode_none_test
()
->
decode_none_test
()
->
S
=
tst_new
(),
S
=
tst_new
(),
...
@@ -97,9 +109,9 @@ encode_test() ->
...
@@ -97,9 +109,9 @@ encode_test() ->
S
=
tst_new
(),
S
=
tst_new
(),
Samples
=
Samples
=
[{
<<
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
61
,
2
,
24
,
91
,
20
,
0
,
0
,
0
,
120
,
151
,
70
,
96
,
153
,
197
,
142
,
238
,
245
,
139
,
85
,
208
,
160
,
241
,
68
,
89
,
106
,
7
,
118
,
167
>>
,
[{
<<
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
61
,
2
,
24
,
91
,
20
,
0
,
0
,
0
,
120
,
151
,
70
,
96
,
153
,
197
,
142
,
238
,
245
,
139
,
85
,
208
,
160
,
241
,
68
,
89
,
106
,
7
,
118
,
167
>>
,
<<
238
,
241
,
206
,
54
,
8
,
16
,
2
,
64
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
109
,
238
,
131
,
159
,
104
,
4
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
80
,
211
,
29
,
34
,
130
,
209
,
0
,
0
,
24
,
0
,
0
,
0
,
174
,
38
,
30
,
219
,
16
,
220
,
190
,
143
,
20
,
147
,
250
,
76
,
217
,
171
,
48
,
8
,
145
,
192
,
181
,
179
,
38
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
61
,
2
,
24
,
91
,
20
,
0
,
0
,
0
,
120
,
151
,
70
,
96
,
153
,
197
,
142
,
238
,
245
,
139
,
85
,
208
,
160
,
241
,
68
,
89
,
106
,
7
,
118
,
167
>>
},
<<
238
,
241
,
206
,
54
,
10
,
16
,
2
,
64
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
109
,
238
,
131
,
159
,
104
,
4
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
80
,
211
,
29
,
34
,
130
,
209
,
0
,
0
,
24
,
0
,
0
,
0
,
174
,
38
,
30
,
219
,
16
,
220
,
190
,
143
,
20
,
147
,
250
,
76
,
217
,
171
,
48
,
8
,
145
,
192
,
181
,
179
,
38
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
61
,
2
,
24
,
91
,
20
,
0
,
0
,
0
,
120
,
151
,
70
,
96
,
153
,
197
,
142
,
238
,
245
,
139
,
85
,
208
,
160
,
241
,
68
,
89
,
106
,
7
,
118
,
167
>>
},
{
<<
14
,
146
,
6
,
159
,
99
,
150
,
29
,
221
,
115
,
87
,
68
,
198
,
122
,
39
,
38
,
249
,
153
,
87
,
37
,
105
,
4
,
111
,
147
,
70
,
54
,
179
,
134
,
12
,
90
,
4
,
223
,
155
,
206
,
220
,
167
,
201
,
203
,
176
,
123
,
181
,
103
,
176
,
49
,
216
,
163
,
106
,
54
,
148
,
133
,
51
,
206
,
212
,
81
,
90
,
47
,
26
,
3
,
161
,
149
,
251
,
182
,
90
,
190
,
51
,
213
,
7
,
107
,
176
,
112
,
220
,
25
,
144
,
183
,
249
,
149
,
182
,
172
,
194
,
218
,
146
,
161
,
191
,
247
,
4
,
250
,
123
,
230
,
251
,
41
,
181
,
139
,
177
,
55
,
171
,
253
,
198
,
153
,
183
,
61
,
53
,
119
,
115
,
46
,
174
,
172
,
245
,
90
,
166
,
215
,
99
,
181
,
58
,
236
,
129
,
103
,
80
,
218
,
244
,
81
,
45
,
142
,
128
,
177
,
146
,
26
,
131
,
184
,
155
,
22
,
217
,
218
,
187
,
209
,
155
,
156
,
64
,
219
,
235
,
175
,
40
,
249
,
235
,
77
,
82
,
212
,
73
,
11
,
133
,
52
,
4
,
222
,
157
,
67
,
176
,
251
,
46
,
254
,
241
,
15
,
192
,
215
,
192
,
186
,
82
,
233
,
68
,
147
,
234
,
88
,
250
,
96
,
14
,
172
,
179
,
7
,
159
,
28
,
11
,
237
,
48
,
44
,
33
,
137
,
185
,
166
,
166
,
173
,
103
,
136
,
174
,
31
,
35
,
77
,
151
,
76
,
55
,
176
,
211
,
230
,
176
,
118
,
144
,
139
,
77
,
0
,
213
,
68
,
179
,
73
,
58
,
58
,
80
,
238
,
120
,
197
,
67
,
241
,
210
,
210
,
156
,
72
,
105
,
60
,
125
,
239
,
98
,
7
,
19
,
234
,
249
,
222
,
194
,
166
,
37
,
46
,
100
,
1
,
65
,
225
,
224
,
244
,
57
,
147
,
119
,
49
,
20
,
1
,
160
,
4
,
51
,
247
,
161
,
142
,
11
,
131
,
11
,
27
,
166
,
159
,
110
,
145
,
78
,
55
,
205
,
126
,
246
,
126
,
68
,
44
,
114
,
91
,
191
,
213
,
241
,
242
,
9
,
33
,
16
,
30
,
228
>>
,
{
<<
14
,
146
,
6
,
159
,
99
,
150
,
29
,
221
,
115
,
87
,
68
,
198
,
122
,
39
,
38
,
249
,
153
,
87
,
37
,
105
,
4
,
111
,
147
,
70
,
54
,
179
,
134
,
12
,
90
,
4
,
223
,
155
,
206
,
220
,
167
,
201
,
203
,
176
,
123
,
181
,
103
,
176
,
49
,
216
,
163
,
106
,
54
,
148
,
133
,
51
,
206
,
212
,
81
,
90
,
47
,
26
,
3
,
161
,
149
,
251
,
182
,
90
,
190
,
51
,
213
,
7
,
107
,
176
,
112
,
220
,
25
,
144
,
183
,
249
,
149
,
182
,
172
,
194
,
218
,
146
,
161
,
191
,
247
,
4
,
250
,
123
,
230
,
251
,
41
,
181
,
139
,
177
,
55
,
171
,
253
,
198
,
153
,
183
,
61
,
53
,
119
,
115
,
46
,
174
,
172
,
245
,
90
,
166
,
215
,
99
,
181
,
58
,
236
,
129
,
103
,
80
,
218
,
244
,
81
,
45
,
142
,
128
,
177
,
146
,
26
,
131
,
184
,
155
,
22
,
217
,
218
,
187
,
209
,
155
,
156
,
64
,
219
,
235
,
175
,
40
,
249
,
235
,
77
,
82
,
212
,
73
,
11
,
133
,
52
,
4
,
222
,
157
,
67
,
176
,
251
,
46
,
254
,
241
,
15
,
192
,
215
,
192
,
186
,
82
,
233
,
68
,
147
,
234
,
88
,
250
,
96
,
14
,
172
,
179
,
7
,
159
,
28
,
11
,
237
,
48
,
44
,
33
,
137
,
185
,
166
,
166
,
173
,
103
,
136
,
174
,
31
,
35
,
77
,
151
,
76
,
55
,
176
,
211
,
230
,
176
,
118
,
144
,
139
,
77
,
0
,
213
,
68
,
179
,
73
,
58
,
58
,
80
,
238
,
120
,
197
,
67
,
241
,
210
,
210
,
156
,
72
,
105
,
60
,
125
,
239
,
98
,
7
,
19
,
234
,
249
,
222
,
194
,
166
,
37
,
46
,
100
,
1
,
65
,
225
,
224
,
244
,
57
,
147
,
119
,
49
,
20
,
1
,
160
,
4
,
51
,
247
,
161
,
142
,
11
,
131
,
11
,
27
,
166
,
159
,
110
,
145
,
78
,
55
,
205
,
126
,
246
,
126
,
68
,
44
,
114
,
91
,
191
,
213
,
241
,
242
,
9
,
33
,
16
,
30
,
228
>>
,
<<
238
,
241
,
206
,
54
,
8
,
16
,
2
,
64
,
2
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
109
,
238
,
131
,
159
,
104
,
4
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
80
,
211
,
29
,
34
,
130
,
209
,
0
,
0
,
24
,
0
,
0
,
0
,
174
,
38
,
30
,
219
,
16
,
220
,
190
,
143
,
20
,
147
,
250
,
76
,
217
,
171
,
48
,
8
,
145
,
192
,
181
,
179
,
38
,
0
,
0
,
0
,
14
,
146
,
6
,
159
,
99
,
150
,
29
,
221
,
115
,
87
,
68
,
198
,
122
,
39
,
38
,
249
,
153
,
87
,
37
,
105
,
4
,
111
,
147
,
70
,
54
,
179
,
134
,
12
,
90
,
4
,
223
,
155
,
206
,
220
,
167
,
201
,
203
,
176
,
123
,
181
,
103
,
176
,
49
,
216
,
163
,
106
,
54
,
148
,
133
,
51
,
206
,
212
,
81
,
90
,
47
,
26
,
3
,
161
,
149
,
251
,
182
,
90
,
190
,
51
,
213
,
7
,
107
,
176
,
112
,
220
,
25
,
144
,
183
,
249
,
149
,
182
,
172
,
194
,
218
,
146
,
161
,
191
,
247
,
4
,
250
,
123
,
230
,
251
,
41
,
181
,
139
,
177
,
55
,
171
,
253
,
198
,
153
,
183
,
61
,
53
,
119
,
115
,
46
,
174
,
172
,
245
,
90
,
166
,
215
,
99
,
181
,
58
,
236
,
129
,
103
,
80
,
218
,
244
,
81
,
45
,
142
,
128
,
177
,
146
,
26
,
131
,
184
,
155
,
22
,
217
,
218
,
187
,
209
,
155
,
156
,
64
,
219
,
235
,
175
,
40
,
249
,
235
,
77
,
82
,
212
,
73
,
11
,
133
,
52
,
4
,
222
,
157
,
67
,
176
,
251
,
46
,
254
,
241
,
15
,
192
,
215
,
192
,
186
,
82
,
233
,
68
,
147
,
234
,
88
,
250
,
96
,
14
,
172
,
179
,
7
,
159
,
28
,
11
,
237
,
48
,
44
,
33
,
137
,
185
,
166
,
166
,
173
,
103
,
136
,
174
,
31
,
35
,
77
,
151
,
76
,
55
,
176
,
211
,
230
,
176
,
118
,
144
,
139
,
77
,
0
,
213
,
68
,
179
,
73
,
58
,
58
,
80
,
238
,
120
,
197
,
67
,
241
,
210
,
210
,
156
,
72
,
105
,
60
,
125
,
239
,
98
,
7
,
19
,
234
,
249
,
222
,
194
,
166
,
37
,
46
,
100
,
1
,
65
,
225
,
224
,
244
,
57
,
147
,
119
,
49
,
20
,
1
,
160
,
4
,
51
,
247
,
161
,
142
,
11
,
131
,
11
,
27
,
166
,
159
,
110
,
145
,
78
,
55
,
205
,
126
,
246
,
126
,
68
,
44
,
114
,
91
,
191
,
213
,
241
,
242
,
9
,
33
,
16
,
30
,
228
>>
}],
<<
238
,
241
,
206
,
54
,
8
,
16
,
2
,
64
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
109
,
238
,
131
,
159
,
104
,
4
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
80
,
211
,
29
,
34
,
130
,
209
,
0
,
0
,
24
,
0
,
0
,
0
,
174
,
38
,
30
,
219
,
16
,
220
,
190
,
143
,
20
,
147
,
250
,
76
,
217
,
171
,
48
,
8
,
145
,
192
,
181
,
179
,
38
,
0
,
0
,
0
,
14
,
146
,
6
,
159
,
99
,
150
,
29
,
221
,
115
,
87
,
68
,
198
,
122
,
39
,
38
,
249
,
153
,
87
,
37
,
105
,
4
,
111
,
147
,
70
,
54
,
179
,
134
,
12
,
90
,
4
,
223
,
155
,
206
,
220
,
167
,
201
,
203
,
176
,
123
,
181
,
103
,
176
,
49
,
216
,
163
,
106
,
54
,
148
,
133
,
51
,
206
,
212
,
81
,
90
,
47
,
26
,
3
,
161
,
149
,
251
,
182
,
90
,
190
,
51
,
213
,
7
,
107
,
176
,
112
,
220
,
25
,
144
,
183
,
249
,
149
,
182
,
172
,
194
,
218
,
146
,
161
,
191
,
247
,
4
,
250
,
123
,
230
,
251
,
41
,
181
,
139
,
177
,
55
,
171
,
253
,
198
,
153
,
183
,
61
,
53
,
119
,
115
,
46
,
174
,
172
,
245
,
90
,
166
,
215
,
99
,
181
,
58
,
236
,
129
,
103
,
80
,
218
,
244
,
81
,
45
,
142
,
128
,
177
,
146
,
26
,
131
,
184
,
155
,
22
,
217
,
218
,
187
,
209
,
155
,
156
,
64
,
219
,
235
,
175
,
40
,
249
,
235
,
77
,
82
,
212
,
73
,
11
,
133
,
52
,
4
,
222
,
157
,
67
,
176
,
251
,
46
,
254
,
241
,
15
,
192
,
215
,
192
,
186
,
82
,
233
,
68
,
147
,
234
,
88
,
250
,
96
,
14
,
172
,
179
,
7
,
159
,
28
,
11
,
237
,
48
,
44
,
33
,
137
,
185
,
166
,
166
,
173
,
103
,
136
,
174
,
31
,
35
,
77
,
151
,
76
,
55
,
176
,
211
,
230
,
176
,
118
,
144
,
139
,
77
,
0
,
213
,
68
,
179
,
73
,
58
,
58
,
80
,
238
,
120
,
197
,
67
,
241
,
210
,
210
,
156
,
72
,
105
,
60
,
125
,
239
,
98
,
7
,
19
,
234
,
249
,
222
,
194
,
166
,
37
,
46
,
100
,
1
,
65
,
225
,
224
,
244
,
57
,
147
,
119
,
49
,
20
,
1
,
160
,
4
,
51
,
247
,
161
,
142
,
11
,
131
,
11
,
27
,
166
,
159
,
110
,
145
,
78
,
55
,
205
,
126
,
246
,
126
,
68
,
44
,
114
,
91
,
191
,
213
,
241
,
242
,
9
,
33
,
16
,
30
,
228
>>
}],
lists
:
foldl
(
lists
:
foldl
(
fun
({
In
,
Out
},
S1
)
->
fun
({
In
,
Out
},
S1
)
->
{
Enc
,
S2
}
=
encode_packet
(
In
,
S1
),
{
Enc
,
S2
}
=
encode_packet
(
In
,
S1
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment