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
9422356a
Commit
9422356a
authored
Jun 25, 2018
by
Sergey Prokhorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make RPC flags meaningfull
parent
241bb35c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
14 deletions
+26
-14
mtp_rpc.erl
src/mtp_rpc.erl
+26
-14
No files found.
src/mtp_rpc.erl
View file @
9422356a
...
@@ -18,12 +18,21 @@
...
@@ -18,12 +18,21 @@
{
client_addr
::
binary
(),
{
client_addr
::
binary
(),
proxy_addr
::
binary
(),
proxy_addr
::
binary
(),
proxy_tag
::
binary
(),
proxy_tag
::
binary
(),
conn_id
::
binary
()}).
conn_id
::
integer
()}).
-
define
(
APP
,
mtproto_proxy
).
-
define
(
APP
,
mtproto_proxy
).
-
define
(
RPC_PROXY_ANS
,
13
,
218
,
3
,
68
).
-
define
(
RPC_PROXY_ANS
,
13
,
218
,
3
,
68
).
-
define
(
RPC_CLOSE_EXT
,
162
,
52
,
182
,
94
).
-
define
(
RPC_CLOSE_EXT
,
162
,
52
,
182
,
94
).
-
define
(
FLAG_NOT_ENCRYPTED
,
16#2
).
-
define
(
FLAG_HAS_AD_TAG
,
16#8
).
-
define
(
FLAG_MAGIC
,
16#1000
).
-
define
(
FLAG_EXTMODE2
,
16#20000
).
-
define
(
FLAG_INTERMEDIATE
,
16#20000000
).
-
define
(
FLAG_ABRIDGED
,
16#40000000
).
-
define
(
FLAG_QUICKACK
,
16#80000000
).
-
opaque
codec
()
::
#rpc_st
{}.
-
opaque
codec
()
::
#rpc_st
{}.
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
)
->
new
(
ClientIp
,
ClientPort
,
ProxyIp
,
ProxyPort
,
ProxyTag
)
->
...
@@ -34,7 +43,7 @@ new(ClientIp, ClientPort, ProxyIp, ProxyPort, ProxyTag, ConnId) ->
...
@@ -34,7 +43,7 @@ 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
=
<<
ConnId
:
64
/
little
-
signed
>>
}.
conn_id
=
ConnId
}.
%% 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
)
->
...
@@ -51,11 +60,22 @@ encode_packet(Msg, #rpc_st{client_addr = ClientAddr, proxy_addr = ProxyAddr,
...
@@ -51,11 +60,22 @@ 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
),
Flags1
=
(
?
FLAG_HAS_AD_TAG
bor
?
FLAG_MAGIC
bor
?
FLAG_EXTMODE2
bor
?
FLAG_ABRIDGED
),
Flags
=
case
Msg
of
%% XXX: what if Msg is iolist?
<<
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
_
/
binary
>>
->
Flags1
bor
?
FLAG_NOT_ENCRYPTED
;
_
->
Flags1
end
,
Req
=
Req
=
[
<<
238
,
241
,
206
,
54
>>
,
%RPC_PROXY_REQ
[
<<
238
,
241
,
206
,
54
,
%RPC_PROXY_REQ
Flags
,
%Flags
Flags
:
32
/
little
,
%Flags
ConnId
,
ClientAddr
,
ProxyAddr
,
ConnId
:
64
/
little
-
signed
>>
,
ClientAddr
,
ProxyAddr
,
<<
24
:
32
/
little
,
%ExtraSize
<<
24
:
32
/
little
,
%ExtraSize
174
,
38
,
30
,
219
,
%ProxyTag
174
,
38
,
30
,
219
,
%ProxyTag
(
byte_size
(
ProxyTag
)),
(
byte_size
(
ProxyTag
)),
...
@@ -66,14 +86,6 @@ encode_packet(Msg, #rpc_st{client_addr = ClientAddr, proxy_addr = ProxyAddr,
...
@@ -66,14 +86,6 @@ 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
>>
)
...
...
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