Accept unexpected RPC packets from Telegram backend

This commit is contained in:
Sergey Prokhorov 2022-11-23 01:34:31 +01:00
parent 9cb1984889
commit 60d2934bcf
No known key found for this signature in database
GPG key ID: 1C570244E4EF3337
2 changed files with 9 additions and 3 deletions

View file

@ -286,7 +286,11 @@ handle_rpc({close_ext, ConnId}, St) ->
St1
end;
handle_rpc({simple_ack, ConnId, Confirm}, S) ->
up_send({simple_ack, self(), Confirm}, ConnId, S).
up_send({simple_ack, self(), Confirm}, ConnId, S);
handle_rpc({unknown, Tag, Tail}, S) ->
?log(info, "Unknown packet from backend. Tag ~p, tail: ~p", [Tag, Tail]),
S.
-spec down_send(iodata(), #state{}) -> {ok, #state{}}.
down_send(Packet, #state{sock = Sock, codec = Codec, dc_id = DcId} = St) ->

View file

@ -86,7 +86,7 @@ encode_handshake({handshake, SenderPID, PeerPID}) ->
%% It expects that packet segmentation was done on previous layer
%% See mtproto/mtproto-proxy.c:process_client_packet
-spec decode_packet(binary()) -> packet() | error.
-spec decode_packet(binary()) -> packet() | {unknown, binary(), binary()}.
decode_packet(<<?RPC_PROXY_ANS, _AnsFlags:4/binary, ConnId:64/signed-little, Data/binary>>) ->
%% mtproto/mtproto-proxy.c:client_send_message
{proxy_ans, ConnId, Data};
@ -94,7 +94,9 @@ decode_packet(<<?RPC_CLOSE_EXT, ConnId:64/signed-little>>) ->
{close_ext, ConnId};
decode_packet(<<?RPC_SIMPLE_ACK, ConnId:64/signed-little, Confirm:4/binary>>) ->
%% mtproto/mtproto-proxy.c:push_rpc_confirmation
{simple_ack, ConnId, Confirm}.
{simple_ack, ConnId, Confirm};
decode_packet(<<Tag:4/binary, Tail/binary>>) ->
{unknown, Tag, Tail}.
encode_packet({data, Msg}, {{ConnId, ClientAddr, ProxyTag}, ProxyAddr}) ->