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
8b685c94
Unverified
Commit
8b685c94
authored
Oct 13, 2018
by
Сергей Прохоров
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move hot function clause to be 1st clause
parent
02bcdf53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
27 deletions
+27
-27
mtp_handler.erl
src/mtp_handler.erl
+27
-27
No files found.
src/mtp_handler.erl
View file @
8b685c94
...
...
@@ -216,6 +216,19 @@ state_timeout(stop) ->
%% Stream handlers
%% Handle telegram client -> proxy stream
handle_upstream_data
(
Bin
,
#state
{
stage
=
tunnel
,
up_codec
=
UpCodec
}
=
S
)
->
{
ok
,
S3
,
UpCodec1
}
=
mtp_layer
:
fold_packets
(
fun
(
Decoded
,
S1
)
->
mtp_metric
:
histogram_observe
(
[
?
APP
,
tg_packet_size
,
bytes
],
byte_size
(
Decoded
),
#
{
labels
=>
[
upstream_to_downstream
]}),
{
ok
,
S2
}
=
down_send
(
Decoded
,
S1
),
S2
end
,
S
,
Bin
,
UpCodec
),
{
ok
,
S3
#state
{
up_codec
=
UpCodec1
}};
handle_upstream_data
(
<<
Header
:
64
/
binary
,
Rest
/
binary
>>
,
#state
{
stage
=
init
,
stage_state
=
<<>>
,
secret
=
Secret
}
=
S
)
->
case
mtp_obfuscated
:
from_header
(
Header
,
Secret
)
of
...
...
@@ -240,19 +253,6 @@ handle_upstream_data(Bin, #state{stage = init, stage_state = <<>>} = S) ->
{
ok
,
S
#state
{
stage_state
=
Bin
}};
handle_upstream_data
(
Bin
,
#state
{
stage
=
init
,
stage_state
=
Buf
}
=
S
)
->
handle_upstream_data
(
<<
Buf
/
binary
,
Bin
/
binary
>>
,
S
#state
{
stage_state
=
<<>>
});
handle_upstream_data
(
Bin
,
#state
{
stage
=
tunnel
,
up_codec
=
UpCodec
}
=
S
)
->
{
ok
,
S3
,
UpCodec1
}
=
mtp_layer
:
fold_packets
(
fun
(
Decoded
,
S1
)
->
mtp_metric
:
histogram_observe
(
[
?
APP
,
tg_packet_size
,
bytes
],
byte_size
(
Decoded
),
#
{
labels
=>
[
upstream_to_downstream
]}),
{
ok
,
S2
}
=
down_send
(
Decoded
,
S1
),
S2
end
,
S
,
Bin
,
UpCodec
),
{
ok
,
S3
#state
{
up_codec
=
UpCodec1
}};
handle_upstream_data
(
Bin
,
#state
{
stage
=
Stage
,
up_acc
=
Acc
}
=
S
)
when
Stage
=/=
init
,
Stage
=/=
tunnel
->
%% We are in downstream handshake; it would be better to leave socked in passive mode,
...
...
@@ -263,6 +263,19 @@ handle_upstream_data(Bin, #state{stage = Stage, up_acc = Acc} = S) when Stage =/
%% Handle telegram server -> proxy stream
handle_downstream_data
(
Bin
,
#state
{
stage
=
tunnel
,
down_codec
=
DownCodec
}
=
S
)
->
{
ok
,
S3
,
DownCodec1
}
=
mtp_layer
:
fold_packets
(
fun
(
Decoded
,
S1
)
->
mtp_metric
:
histogram_observe
(
[
?
APP
,
tg_packet_size
,
bytes
],
byte_size
(
Decoded
),
#
{
labels
=>
[
downstream_to_upstream
]}),
{
ok
,
S2
}
=
up_send
(
Decoded
,
S1
),
S2
end
,
S
,
Bin
,
DownCodec
),
{
ok
,
S3
#state
{
down_codec
=
DownCodec1
}};
handle_downstream_data
(
Bin
,
#state
{
stage
=
down_handshake_1
,
down_codec
=
DownCodec
}
=
S
)
->
case
mtp_layer
:
try_decode_packet
(
Bin
,
DownCodec
)
of
...
...
@@ -284,20 +297,7 @@ handle_downstream_data(Bin, #state{stage = down_handshake_2,
handle_upstream_data
(
UpAcc
,
S2
#state
{
up_acc
=
[]});
{
incomplete
,
DownCodec1
}
->
{
ok
,
S
#state
{
down_codec
=
DownCodec1
}}
end
;
handle_downstream_data
(
Bin
,
#state
{
stage
=
tunnel
,
down_codec
=
DownCodec
}
=
S
)
->
{
ok
,
S3
,
DownCodec1
}
=
mtp_layer
:
fold_packets
(
fun
(
Decoded
,
S1
)
->
mtp_metric
:
histogram_observe
(
[
?
APP
,
tg_packet_size
,
bytes
],
byte_size
(
Decoded
),
#
{
labels
=>
[
downstream_to_upstream
]}),
{
ok
,
S2
}
=
up_send
(
Decoded
,
S1
),
S2
end
,
S
,
Bin
,
DownCodec
),
{
ok
,
S3
#state
{
down_codec
=
DownCodec1
}}.
end
.
up_send
(
Packet
,
#state
{
stage
=
tunnel
,
...
...
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