Fix RPC protocol flags and add RPC_PING/PONG response

- protocol_flag/1: map client protocol to correct RPC_PROXY_REQ flags
  mtp_abridged     -> FLAG_ABRIDGED (0x40000000 = RPC_F_COMPACT)
  mtp_intermediate -> FLAG_INTERMEDIATE (0x20000000 = RPC_F_MEDIUM)
  mtp_secure       -> FLAG_INTERMEDIATE | FLAG_PAD (0x28000000)
  Previously always sent FLAG_ABRIDGED regardless of protocol.

- Decode RPC_PING from Telegram and respond with RPC_PONG
  Matches reference C implementation (tcp_rpcs_default_execute).

- Expand UpsStatic tuple to 4 elements (ConnId, Addr, AdTag, Protocol)
  so protocol is available at encode time.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Sergey Prokhorov 2026-04-07 19:12:28 +02:00
parent 2dd6e6d589
commit 84cceaee48
No known key found for this signature in database
GPG key ID: 1C570244E4EF3337
2 changed files with 30 additions and 13 deletions

View file

@ -75,17 +75,18 @@ c2s_packet_gen() ->
{{data,
mtp_prop_gen:packet_4b() %Data
},
{{proper_types:integer(), %ConnId
proper_types:binary(20), %ClientAddr
proper_types:binary(16) %ProxyTag
},
proper_types:binary(20) %ProxyAddr
}},
{{proper_types:integer(), %ConnId
proper_types:binary(20), %ClientAddr
proper_types:binary(16), %ProxyTag
proper_types:oneof([mtp_abridged, mtp_intermediate, mtp_secure]) %Protocol
},
proper_types:binary(20) %ProxyAddr
}},
{remote_closed,
proper_types:integer()}
]).
c2s_packet({{data, Data} = Packet, {{ConnId, _, _}, _} = Static}) ->
c2s_packet({{data, Data} = Packet, {{ConnId, _, _, _}, _} = Static}) ->
Bin = mtp_rpc:encode_packet(Packet, Static),
{data, ConnId, Data} == mtp_rpc:srv_decode_packet(iolist_to_binary(Bin));
c2s_packet({remote_closed, ConnId} = Packet) ->