From 29e3e6ef501a2b9761a8a8bbd4cec9cc80d9adba Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Fri, 9 May 2025 22:35:21 +0800 Subject: [PATCH] fix --- apps/efka/include/efka.hrl | 4 +- apps/efka/include/message_pb.hrl | 6 +- apps/efka/src/efka_agent.erl | 62 ++++++++----- apps/efka/src/efka_transport.erl | 46 ++++------ apps/efka/src/proto/message_pb.erl | 142 ++++++++++++++--------------- message_pb.proto | 2 +- 6 files changed, 133 insertions(+), 129 deletions(-) diff --git a/apps/efka/include/efka.hrl b/apps/efka/include/efka.hrl index 2cacebd..4d5f217 100644 --- a/apps/efka/include/efka.hrl +++ b/apps/efka/include/efka.hrl @@ -19,8 +19,8 @@ -define(PACKET_COMMAND, 16#04). %% 服务器端推送消息 --define(PACKET_PUSH, 16#05). --define(PACKET_PUSH_REPLY, 16#06). +-define(PACKET_ASYNC_CALL, 16#05). +-define(PACKET_ASYNC_CALL_REPLY, 16#06). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% 二级分类定义 diff --git a/apps/efka/include/message_pb.hrl b/apps/efka/include/message_pb.hrl index 0032f5d..450e83e 100644 --- a/apps/efka/include/message_pb.hrl +++ b/apps/efka/include/message_pb.hrl @@ -35,9 +35,9 @@ }). -endif. --ifndef('PUSH_REPLY_PB_H'). --define('PUSH_REPLY_PB_H', true). --record(push_reply, +-ifndef('ASYNC_CALL_REPLY_PB_H'). +-define('ASYNC_CALL_REPLY_PB_H', true). +-record(async_call_reply, {code = 0 :: non_neg_integer() | undefined, % = 1, optional, 32 bits result = <<>> :: unicode:chardata() | undefined, % = 2, optional message = <<>> :: unicode:chardata() | undefined % = 3, optional diff --git a/apps/efka/src/efka_agent.erl b/apps/efka/src/efka_agent.erl index 0b27beb..c732444 100644 --- a/apps/efka/src/efka_agent.erl +++ b/apps/efka/src/efka_agent.erl @@ -168,7 +168,8 @@ handle_info({timeout, _, create_transport}, State = #state{status = ?STATE_DENIE handle_info({connect_reply, Reply}, State = #state{status = ?STATE_CONNECTING, transport_pid = TransportPid}) when is_pid(TransportPid) -> case Reply of ok -> - efka_transport:auth_request(TransportPid, 5000), + AuthBin = auth_request(), + efka_transport:auth_request(TransportPid, AuthBin, 5000), {noreply, State#state{status = ?STATE_AUTH}}; {error, Reason} -> lager:debug("[efka_agent] connect failed, error: ~p, pid: ~p", [Reason, TransportPid]), @@ -225,11 +226,11 @@ handle_info({server_push, PacketId, <>}, State %% 短暂的等待,efka_inetd收到消息后就立即返回了 Reply = case efka_inetd:deploy(TaskId, ServiceId, TarUrl) of ok -> - #push_reply{code = 1, message = <<"">>}; + #async_call_reply{code = 1, message = <<"">>}; {error, Reason} when is_binary(Reason) -> - #push_reply{code = 0, message = Reason} + #async_call_reply{code = 0, message = Reason} end, - is_pid(TransportPid) andalso efka_transport:push_response(TransportPid, PacketId, message_pb:encode_msg(Reply)), + is_pid(TransportPid) andalso efka_transport:async_call_reply(TransportPid, PacketId, message_pb:encode_msg(Reply)), {noreply, State}; @@ -239,8 +240,8 @@ handle_info({server_push, PacketId, <> case efka_service:get_pid(ServiceId) of undefined -> - Reply = #push_reply{code = 0, message = <<"service not run">>}, - is_pid(TransportPid) andalso efka_transport:push_response(TransportPid, PacketId, message_pb:encode_msg(Reply)), + Reply = #async_call_reply{code = 0, message = <<"service not run">>}, + is_pid(TransportPid) andalso efka_transport:async_call_reply(TransportPid, PacketId, message_pb:encode_msg(Reply)), {noreply, State}; ServicePid when is_pid(ServicePid) -> Ref = make_ref(), @@ -258,8 +259,8 @@ handle_info({server_push, PacketId, <>}, State %% 消息发送到订阅系统 case efka_service:get_pid(ServiceId) of undefined -> - Reply = #push_reply{code = 0, message = <<"micro_service not run">>, result = <<>>}, - safe_push_response(PacketId, message_pb:encode_msg(Reply), State), + Reply = #async_call_reply{code = 0, message = <<"micro_service not run">>, result = <<>>}, + safe_async_call_reply(PacketId, message_pb:encode_msg(Reply), State), {noreply, State}; ServicePid when is_pid(ServicePid) -> Ref = make_ref(), @@ -277,11 +278,11 @@ handle_info({server_push, PacketId, <>}, St Reply = case length(Logs) > 0 of true -> Result = iolist_to_binary(jiffy:encode(Logs, [force_utf8])), - #push_reply{code = 1, result = Result}; + #async_call_reply{code = 1, result = Result}; false -> - #push_reply{code = 1, result = <<"[]">>} + #async_call_reply{code = 1, result = <<"[]">>} end, - safe_push_response(PacketId, message_pb:encode_msg(Reply), State), + safe_async_call_reply(PacketId, message_pb:encode_msg(Reply), State), {noreply, State}; %% 处理命令 @@ -291,7 +292,8 @@ handle_info({server_command, ?COMMAND_AUTH, <>}, State = #state{transpor {noreply, State}; {1, ?STATE_DENIED} -> %% 重新激活, 需要重新校验 - efka_transport:auth_request(TransportPid, 5000), + AuthRequestBin = auth_request(), + efka_transport:auth_request(TransportPid, AuthRequestBin, 5000), {noreply, State#state{status = ?STATE_AUTH}}; {0, _} -> %% 这个时候的主机应该是受限制的状态,不允许发送消息;但是能够接受服务器推送的消息 @@ -314,11 +316,11 @@ handle_info({service_reply, Ref, EmsReply}, State = #state{inflight = Inflight}) {PacketId, NInflight} -> Reply = case EmsReply of ok -> - #push_reply{code = 1, message = <<"">>, result = <<>>}; + #async_call_reply{code = 1, message = <<"">>, result = <<>>}; {error, Reason} -> - #push_reply{code = 0, message = Reason} + #async_call_reply{code = 0, message = Reason} end, - safe_push_response(PacketId, message_pb:encode_msg(Reply), State), + safe_async_call_reply(PacketId, message_pb:encode_msg(Reply), State), {noreply, State#state{inflight = NInflight}} end; @@ -329,8 +331,8 @@ handle_info({timeout, _, {request_timeout, Ref}}, State = #state{inflight = Infl error -> {noreply, State}; {PacketId, NInflight} -> - Reply = #push_reply{code = 0, message = <<"reqeust timeout">>, result = <<>>}, - safe_push_response(PacketId, message_pb:encode_msg(Reply), State), + Reply = #async_call_reply{code = 0, message = <<"reqeust timeout">>, result = <<>>}, + safe_async_call_reply(PacketId, message_pb:encode_msg(Reply), State), {noreply, State#state{inflight = NInflight}} end; @@ -367,10 +369,10 @@ code_change(_OldVsn, State = #state{}, _Extra) -> %%%=================================================================== %% 安全回复 --spec safe_push_response(PacketId :: integer(), Reply :: binary(), State :: #state{}) -> no_return(). -safe_push_response(PacketId, Reply, #state{status = ?STATE_ACTIVATED, transport_pid = TransportPid}) when is_integer(PacketId), is_binary(Reply), is_pid(TransportPid) -> - is_process_alive(TransportPid) andalso efka_transport:push_response(TransportPid, PacketId, Reply); -safe_push_response(_PacketId, _Reply, #state{}) -> +-spec safe_async_call_reply(PacketId :: integer(), Reply :: binary(), State :: #state{}) -> no_return(). +safe_async_call_reply(PacketId, Reply, #state{status = ?STATE_ACTIVATED, transport_pid = TransportPid}) when is_integer(PacketId), is_binary(Reply), is_pid(TransportPid) -> + is_process_alive(TransportPid) andalso efka_transport:async_call_reply(TransportPid, PacketId, Reply); +safe_async_call_reply(_PacketId, _Reply, #state{}) -> ok. %% 当连接正常的时候发送,否则暂存数据 @@ -378,4 +380,20 @@ safe_push_response(_PacketId, _Reply, #state{}) -> safe_send(Method, Packet, #state{status = ?STATE_ACTIVATED, transport_pid = TransportPid}) when is_pid(TransportPid) -> efka_transport:send(TransportPid, Method, Packet); safe_send(Method, Packet, #state{}) -> - ok = cache_model:insert(Method, Packet). \ No newline at end of file + ok = cache_model:insert(Method, Packet). + +-spec auth_request() -> binary(). +auth_request() -> + {ok, AuthInfo} = application:get_env(efka, auth), + UUID = proplists:get_value(uuid, AuthInfo), + Username = proplists:get_value(username, AuthInfo), + Salt = proplists:get_value(salt, AuthInfo), + Token = proplists:get_value(token, AuthInfo), + + message_pb:encode_msg(#auth_request{ + uuid = unicode:characters_to_binary(UUID), + username = unicode:characters_to_binary(Username), + salt = unicode:characters_to_binary(Salt), + token = unicode:characters_to_binary(Token), + timestamp = efka_util:timestamp() + }). \ No newline at end of file diff --git a/apps/efka/src/efka_transport.erl b/apps/efka/src/efka_transport.erl index 96924e3..375b7f6 100644 --- a/apps/efka/src/efka_transport.erl +++ b/apps/efka/src/efka_transport.erl @@ -15,7 +15,7 @@ %% API -export([start_link/3]). --export([connect/1, auth_request/2, send/3, push_response/3, stop/1]). +-export([connect/1, auth_request/3, send/3, async_call_reply/3, stop/1]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). @@ -34,9 +34,9 @@ %%% API %%%=================================================================== --spec auth_request(Pid :: pid(), Timeout :: integer()) -> no_return(). -auth_request(Pid, Timeout) when is_pid(Pid), is_integer(Timeout) -> - gen_server:cast(Pid, {auth_request, Timeout}). +-spec auth_request(Pid :: pid(), AuthBin :: binary(), Timeout :: integer()) -> no_return(). +auth_request(Pid, AuthBin, Timeout) when is_pid(Pid), is_binary(AuthBin), is_integer(Timeout) -> + gen_server:cast(Pid, {auth_request, AuthBin, Timeout}). -spec connect(Pid :: pid()) -> no_return(). connect(Pid) when is_pid(Pid) -> @@ -46,9 +46,9 @@ connect(Pid) when is_pid(Pid) -> send(Pid, Method, Packet) when is_pid(Pid), is_integer(Method), is_binary(Packet) -> gen_server:cast(Pid, {send, Method, Packet}). --spec push_response(Pid :: pid(), PacketId :: integer(), Response :: binary()) -> no_return(). -push_response(Pid, PacketId, Response) when is_pid(Pid), is_integer(PacketId), is_binary(Response) -> - gen_server:cast(Pid, {push_response, PacketId, Response}). +-spec async_call_reply(Pid :: pid(), PacketId :: integer(), Response :: binary()) -> no_return(). +async_call_reply(Pid, PacketId, Response) when is_pid(Pid), is_integer(PacketId), is_binary(Response) -> + gen_server:cast(Pid, {async_call_reply, PacketId, Response}). -spec stop(Pid :: pid()) -> ok. stop(Pid) when is_pid(Pid) -> @@ -108,22 +108,8 @@ handle_cast(connect, State = #state{host = Host, port = Port, parent_pid = Paren end; %% auth校验 -handle_cast({auth_request, Timeout}, State = #state{parent_pid = ParentPid, socket = Socket, packet_id = PacketId}) -> - {ok, AuthInfo} = application:get_env(efka, auth), - UUID = proplists:get_value(uuid, AuthInfo), - Username = proplists:get_value(username, AuthInfo), - Salt = proplists:get_value(salt, AuthInfo), - Token = proplists:get_value(token, AuthInfo), - - RequestBin = message_pb:encode_msg(#auth_request{ - uuid = unicode:characters_to_binary(UUID), - username = unicode:characters_to_binary(Username), - salt = unicode:characters_to_binary(Salt), - token = unicode:characters_to_binary(Token), - timestamp = efka_util:timestamp() - }), - ok = ssl:send(Socket, <>), - +handle_cast({auth_request, AuthRequestBin, Timeout}, State = #state{parent_pid = ParentPid, socket = Socket, packet_id = PacketId}) -> + ok = ssl:send(Socket, <>), %% 需要等待auth返回的结果 receive {ssl, Socket, <>} -> @@ -135,12 +121,12 @@ handle_cast({auth_request, Timeout}, State = #state{parent_pid = ParentPid, sock end; handle_cast({send, Method, Packet}, State = #state{socket = Socket}) -> - ok = ssl:send(Socket, <>), + ok = ssl:send(Socket, <>), {noreply, State}; %% 服务push的消息的回复 -handle_cast({push_response, PacketId, Response}, State = #state{socket = Socket}) -> - ok = ssl:send(Socket, <>), +handle_cast({async_call_reply, PacketId, Response}, State = #state{socket = Socket}) -> + ok = ssl:send(Socket, <>), {noreply, State}. %% @private @@ -150,17 +136,17 @@ handle_cast({push_response, PacketId, Response}, State = #state{socket = Socket} {noreply, NewState :: #state{}, timeout() | hibernate} | {stop, Reason :: term(), NewState :: #state{}}). %% 服务器主动推送的数据,有packetId的是要求返回的;为0的表示不需要返回值 -handle_info({ssl, Socket, <>}, State = #state{socket = Socket, parent_pid = ParentPid}) -> +handle_info({ssl, Socket, <>}, State = #state{socket = Socket, parent_pid = ParentPid}) -> ParentPid ! {server_command, CommandType, Command}, {noreply, State}; -handle_info({ssl, Socket, <>}, State = #state{socket = Socket, parent_pid = ParentPid}) -> +handle_info({ssl, Socket, <>}, State = #state{socket = Socket, parent_pid = ParentPid}) -> #pub{topic = Topic, content = Content} = message_pb:decode_msg(PubBin, pub), ParentPid ! {server_pub, Topic, Content}, {noreply, State}; -handle_info({ssl, Socket, <>}, State = #state{socket = Socket, parent_pid = ParentPid}) -> - ParentPid ! {server_push, PacketId, PushBin}, +handle_info({ssl, Socket, <>}, State = #state{socket = Socket, parent_pid = ParentPid}) -> + ParentPid ! {server_push, PacketId, AsyncCallBin}, {noreply, State}; handle_info({ssl_error, Socket, Reason}, State = #state{socket = Socket}) -> diff --git a/apps/efka/src/proto/message_pb.erl b/apps/efka/src/proto/message_pb.erl index 056408d..44785e8 100644 --- a/apps/efka/src/proto/message_pb.erl +++ b/apps/efka/src/proto/message_pb.erl @@ -61,7 +61,7 @@ -type pub() :: #pub{}. --type push_reply() :: #push_reply{}. +-type async_call_reply() :: #async_call_reply{}. -type deploy() :: #deploy{}. @@ -79,9 +79,9 @@ -type event() :: #event{}. --export_type(['auth_request'/0, 'auth_reply'/0, 'pub'/0, 'push_reply'/0, 'deploy'/0, 'fetch_task_log'/0, 'invoke'/0, 'service_config'/0, 'data'/0, 'ping'/0, 'service_inform'/0, 'event'/0]). --type '$msg_name'() :: auth_request | auth_reply | pub | push_reply | deploy | fetch_task_log | invoke | service_config | data | ping | service_inform | event. --type '$msg'() :: auth_request() | auth_reply() | pub() | push_reply() | deploy() | fetch_task_log() | invoke() | service_config() | data() | ping() | service_inform() | event(). +-export_type(['auth_request'/0, 'auth_reply'/0, 'pub'/0, 'async_call_reply'/0, 'deploy'/0, 'fetch_task_log'/0, 'invoke'/0, 'service_config'/0, 'data'/0, 'ping'/0, 'service_inform'/0, 'event'/0]). +-type '$msg_name'() :: auth_request | auth_reply | pub | async_call_reply | deploy | fetch_task_log | invoke | service_config | data | ping | service_inform | event. +-type '$msg'() :: auth_request() | auth_reply() | pub() | async_call_reply() | deploy() | fetch_task_log() | invoke() | service_config() | data() | ping() | service_inform() | event(). -export_type(['$msg_name'/0, '$msg'/0]). -if(?OTP_RELEASE >= 24). @@ -111,7 +111,7 @@ encode_msg(Msg, MsgName, Opts) -> auth_request -> encode_msg_auth_request(id(Msg, TrUserData), TrUserData); auth_reply -> encode_msg_auth_reply(id(Msg, TrUserData), TrUserData); pub -> encode_msg_pub(id(Msg, TrUserData), TrUserData); - push_reply -> encode_msg_push_reply(id(Msg, TrUserData), TrUserData); + async_call_reply -> encode_msg_async_call_reply(id(Msg, TrUserData), TrUserData); deploy -> encode_msg_deploy(id(Msg, TrUserData), TrUserData); fetch_task_log -> encode_msg_fetch_task_log(id(Msg, TrUserData), TrUserData); invoke -> encode_msg_invoke(id(Msg, TrUserData), TrUserData); @@ -226,10 +226,10 @@ encode_msg_pub(#pub{topic = F1, content = F2}, Bin, TrUserData) -> end end. -encode_msg_push_reply(Msg, TrUserData) -> encode_msg_push_reply(Msg, <<>>, TrUserData). +encode_msg_async_call_reply(Msg, TrUserData) -> encode_msg_async_call_reply(Msg, <<>>, TrUserData). -encode_msg_push_reply(#push_reply{code = F1, result = F2, message = F3}, Bin, TrUserData) -> +encode_msg_async_call_reply(#async_call_reply{code = F1, result = F2, message = F3}, Bin, TrUserData) -> B1 = if F1 == undefined -> Bin; true -> begin @@ -778,7 +778,7 @@ decode_msg_1_catch(Bin, MsgName, TrUserData) -> decode_msg_2_doit(auth_request, Bin, TrUserData) -> id(decode_msg_auth_request(Bin, TrUserData), TrUserData); decode_msg_2_doit(auth_reply, Bin, TrUserData) -> id(decode_msg_auth_reply(Bin, TrUserData), TrUserData); decode_msg_2_doit(pub, Bin, TrUserData) -> id(decode_msg_pub(Bin, TrUserData), TrUserData); -decode_msg_2_doit(push_reply, Bin, TrUserData) -> id(decode_msg_push_reply(Bin, TrUserData), TrUserData); +decode_msg_2_doit(async_call_reply, Bin, TrUserData) -> id(decode_msg_async_call_reply(Bin, TrUserData), TrUserData); decode_msg_2_doit(deploy, Bin, TrUserData) -> id(decode_msg_deploy(Bin, TrUserData), TrUserData); decode_msg_2_doit(fetch_task_log, Bin, TrUserData) -> id(decode_msg_fetch_task_log(Bin, TrUserData), TrUserData); decode_msg_2_doit(invoke, Bin, TrUserData) -> id(decode_msg_invoke(Bin, TrUserData), TrUserData); @@ -964,63 +964,63 @@ skip_32_pub(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_rea skip_64_pub(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, TrUserData) -> dfp_read_field_def_pub(Rest, Z1, Z2, F, F@_1, F@_2, TrUserData). -decode_msg_push_reply(Bin, TrUserData) -> dfp_read_field_def_push_reply(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData). +decode_msg_async_call_reply(Bin, TrUserData) -> dfp_read_field_def_async_call_reply(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData). -dfp_read_field_def_push_reply(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_push_reply_code(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); -dfp_read_field_def_push_reply(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_push_reply_result(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); -dfp_read_field_def_push_reply(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_push_reply_message(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); -dfp_read_field_def_push_reply(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #push_reply{code = F@_1, result = F@_2, message = F@_3}; -dfp_read_field_def_push_reply(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_push_reply(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). +dfp_read_field_def_async_call_reply(<<8, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_async_call_reply_code(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_async_call_reply(<<18, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_async_call_reply_result(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_async_call_reply(<<26, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> d_field_async_call_reply_message(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +dfp_read_field_def_async_call_reply(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #async_call_reply{code = F@_1, result = F@_2, message = F@_3}; +dfp_read_field_def_async_call_reply(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dg_read_field_def_async_call_reply(Other, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). -dg_read_field_def_push_reply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_push_reply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); -dg_read_field_def_push_reply(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, TrUserData) -> +dg_read_field_def_async_call_reply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 32 - 7 -> dg_read_field_def_async_call_reply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +dg_read_field_def_async_call_reply(<<0:1, X:7, Rest/binary>>, N, Acc, _, F@_1, F@_2, F@_3, TrUserData) -> Key = X bsl N + Acc, case Key of - 8 -> d_field_push_reply_code(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); - 18 -> d_field_push_reply_result(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); - 26 -> d_field_push_reply_message(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 8 -> d_field_async_call_reply_code(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 18 -> d_field_async_call_reply_result(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); + 26 -> d_field_async_call_reply_message(Rest, 0, 0, 0, F@_1, F@_2, F@_3, TrUserData); _ -> case Key band 7 of - 0 -> skip_varint_push_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); - 1 -> skip_64_push_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); - 2 -> skip_length_delimited_push_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); - 3 -> skip_group_push_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); - 5 -> skip_32_push_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData) + 0 -> skip_varint_async_call_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 1 -> skip_64_async_call_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 2 -> skip_length_delimited_async_call_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 3 -> skip_group_async_call_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData); + 5 -> skip_32_async_call_reply(Rest, 0, 0, Key bsr 3, F@_1, F@_2, F@_3, TrUserData) end end; -dg_read_field_def_push_reply(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #push_reply{code = F@_1, result = F@_2, message = F@_3}. +dg_read_field_def_async_call_reply(<<>>, 0, 0, _, F@_1, F@_2, F@_3, _) -> #async_call_reply{code = F@_1, result = F@_2, message = F@_3}. -d_field_push_reply_code(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_push_reply_code(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); -d_field_push_reply_code(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, TrUserData) -> +d_field_async_call_reply_code(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_async_call_reply_code(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_async_call_reply_code(<<0:1, X:7, Rest/binary>>, N, Acc, F, _, F@_2, F@_3, TrUserData) -> {NewFValue, RestF} = {id((X bsl N + Acc) band 4294967295, TrUserData), Rest}, - dfp_read_field_def_push_reply(RestF, 0, 0, F, NewFValue, F@_2, F@_3, TrUserData). + dfp_read_field_def_async_call_reply(RestF, 0, 0, F, NewFValue, F@_2, F@_3, TrUserData). -d_field_push_reply_result(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_push_reply_result(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); -d_field_push_reply_result(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, TrUserData) -> +d_field_async_call_reply_result(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_async_call_reply_result(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_async_call_reply_result(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, _, F@_3, TrUserData) -> {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, - dfp_read_field_def_push_reply(RestF, 0, 0, F, F@_1, NewFValue, F@_3, TrUserData). + dfp_read_field_def_async_call_reply(RestF, 0, 0, F, F@_1, NewFValue, F@_3, TrUserData). -d_field_push_reply_message(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_push_reply_message(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); -d_field_push_reply_message(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, TrUserData) -> +d_field_async_call_reply_message(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> d_field_async_call_reply_message(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +d_field_async_call_reply_message(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, _, TrUserData) -> {NewFValue, RestF} = begin Len = X bsl N + Acc, <> = Rest, Bytes2 = binary:copy(Bytes), {id(Bytes2, TrUserData), Rest2} end, - dfp_read_field_def_push_reply(RestF, 0, 0, F, F@_1, F@_2, NewFValue, TrUserData). + dfp_read_field_def_async_call_reply(RestF, 0, 0, F, F@_1, F@_2, NewFValue, TrUserData). -skip_varint_push_reply(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_push_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); -skip_varint_push_reply(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_push_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). +skip_varint_async_call_reply(<<1:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> skip_varint_async_call_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData); +skip_varint_async_call_reply(<<0:1, _:7, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_async_call_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). -skip_length_delimited_push_reply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_push_reply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); -skip_length_delimited_push_reply(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) -> +skip_length_delimited_async_call_reply(<<1:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) when N < 57 -> skip_length_delimited_async_call_reply(Rest, N + 7, X bsl N + Acc, F, F@_1, F@_2, F@_3, TrUserData); +skip_length_delimited_async_call_reply(<<0:1, X:7, Rest/binary>>, N, Acc, F, F@_1, F@_2, F@_3, TrUserData) -> Length = X bsl N + Acc, <<_:Length/binary, Rest2/binary>> = Rest, - dfp_read_field_def_push_reply(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData). + dfp_read_field_def_async_call_reply(Rest2, 0, 0, F, F@_1, F@_2, F@_3, TrUserData). -skip_group_push_reply(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) -> +skip_group_async_call_reply(Bin, _, Z2, FNum, F@_1, F@_2, F@_3, TrUserData) -> {_, Rest} = read_group(Bin, FNum), - dfp_read_field_def_push_reply(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData). + dfp_read_field_def_async_call_reply(Rest, 0, Z2, FNum, F@_1, F@_2, F@_3, TrUserData). -skip_32_push_reply(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_push_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). +skip_32_async_call_reply(<<_:32, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_async_call_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). -skip_64_push_reply(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_push_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). +skip_64_async_call_reply(<<_:64, Rest/binary>>, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData) -> dfp_read_field_def_async_call_reply(Rest, Z1, Z2, F, F@_1, F@_2, F@_3, TrUserData). decode_msg_deploy(Bin, TrUserData) -> dfp_read_field_def_deploy(Bin, 0, 0, 0, id(0, TrUserData), id(<<>>, TrUserData), id(<<>>, TrUserData), TrUserData). @@ -1710,7 +1710,7 @@ merge_msgs(Prev, New, MsgName, Opts) -> auth_request -> merge_msg_auth_request(Prev, New, TrUserData); auth_reply -> merge_msg_auth_reply(Prev, New, TrUserData); pub -> merge_msg_pub(Prev, New, TrUserData); - push_reply -> merge_msg_push_reply(Prev, New, TrUserData); + async_call_reply -> merge_msg_async_call_reply(Prev, New, TrUserData); deploy -> merge_msg_deploy(Prev, New, TrUserData); fetch_task_log -> merge_msg_fetch_task_log(Prev, New, TrUserData); invoke -> merge_msg_invoke(Prev, New, TrUserData); @@ -1766,20 +1766,20 @@ merge_msg_pub(#pub{topic = PFtopic, content = PFcontent}, #pub{topic = NFtopic, true -> NFcontent end}. --compile({nowarn_unused_function,merge_msg_push_reply/3}). -merge_msg_push_reply(#push_reply{code = PFcode, result = PFresult, message = PFmessage}, #push_reply{code = NFcode, result = NFresult, message = NFmessage}, _) -> - #push_reply{code = - if NFcode =:= undefined -> PFcode; - true -> NFcode - end, - result = - if NFresult =:= undefined -> PFresult; - true -> NFresult - end, - message = - if NFmessage =:= undefined -> PFmessage; - true -> NFmessage - end}. +-compile({nowarn_unused_function,merge_msg_async_call_reply/3}). +merge_msg_async_call_reply(#async_call_reply{code = PFcode, result = PFresult, message = PFmessage}, #async_call_reply{code = NFcode, result = NFresult, message = NFmessage}, _) -> + #async_call_reply{code = + if NFcode =:= undefined -> PFcode; + true -> NFcode + end, + result = + if NFresult =:= undefined -> PFresult; + true -> NFresult + end, + message = + if NFmessage =:= undefined -> PFmessage; + true -> NFmessage + end}. -compile({nowarn_unused_function,merge_msg_deploy/3}). merge_msg_deploy(#deploy{task_id = PFtask_id, service_id = PFservice_id, tar_url = PFtar_url}, #deploy{task_id = NFtask_id, service_id = NFservice_id, tar_url = NFtar_url}, _) -> @@ -1958,7 +1958,7 @@ verify_msg(Msg, MsgName, Opts) -> auth_request -> v_msg_auth_request(Msg, [MsgName], TrUserData); auth_reply -> v_msg_auth_reply(Msg, [MsgName], TrUserData); pub -> v_msg_pub(Msg, [MsgName], TrUserData); - push_reply -> v_msg_push_reply(Msg, [MsgName], TrUserData); + async_call_reply -> v_msg_async_call_reply(Msg, [MsgName], TrUserData); deploy -> v_msg_deploy(Msg, [MsgName], TrUserData); fetch_task_log -> v_msg_fetch_task_log(Msg, [MsgName], TrUserData); invoke -> v_msg_invoke(Msg, [MsgName], TrUserData); @@ -2016,9 +2016,9 @@ v_msg_pub(#pub{topic = F1, content = F2}, Path, TrUserData) -> ok; v_msg_pub(X, Path, _TrUserData) -> mk_type_error({expected_msg, pub}, X, Path). --compile({nowarn_unused_function,v_msg_push_reply/3}). --dialyzer({nowarn_function,v_msg_push_reply/3}). -v_msg_push_reply(#push_reply{code = F1, result = F2, message = F3}, Path, TrUserData) -> +-compile({nowarn_unused_function,v_msg_async_call_reply/3}). +-dialyzer({nowarn_function,v_msg_async_call_reply/3}). +v_msg_async_call_reply(#async_call_reply{code = F1, result = F2, message = F3}, Path, TrUserData) -> if F1 == undefined -> ok; true -> v_type_uint32(F1, [code | Path], TrUserData) end, @@ -2029,7 +2029,7 @@ v_msg_push_reply(#push_reply{code = F1, result = F2, message = F3}, Path, TrUser true -> v_type_string(F3, [message | Path], TrUserData) end, ok; -v_msg_push_reply(X, Path, _TrUserData) -> mk_type_error({expected_msg, push_reply}, X, Path). +v_msg_async_call_reply(X, Path, _TrUserData) -> mk_type_error({expected_msg, async_call_reply}, X, Path). -compile({nowarn_unused_function,v_msg_deploy/3}). -dialyzer({nowarn_function,v_msg_deploy/3}). @@ -2262,7 +2262,7 @@ get_msg_defs() -> #field{name = timestamp, fnum = 6, rnum = 6, type = uint32, occurrence = optional, opts = []}]}, {{msg, auth_reply}, [#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []}, #field{name = message, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]}, {{msg, pub}, [#field{name = topic, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = content, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]}, - {{msg, push_reply}, + {{msg, async_call_reply}, [#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []}, #field{name = result, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}, #field{name = message, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}]}, @@ -2308,13 +2308,13 @@ get_msg_defs() -> #field{name = params, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}]}]. -get_msg_names() -> [auth_request, auth_reply, pub, push_reply, deploy, fetch_task_log, invoke, service_config, data, ping, service_inform, event]. +get_msg_names() -> [auth_request, auth_reply, pub, async_call_reply, deploy, fetch_task_log, invoke, service_config, data, ping, service_inform, event]. get_group_names() -> []. -get_msg_or_group_names() -> [auth_request, auth_reply, pub, push_reply, deploy, fetch_task_log, invoke, service_config, data, ping, service_inform, event]. +get_msg_or_group_names() -> [auth_request, auth_reply, pub, async_call_reply, deploy, fetch_task_log, invoke, service_config, data, ping, service_inform, event]. get_enum_names() -> []. @@ -2339,7 +2339,7 @@ find_msg_def(auth_request) -> #field{name = timestamp, fnum = 6, rnum = 6, type = uint32, occurrence = optional, opts = []}]; find_msg_def(auth_reply) -> [#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []}, #field{name = message, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]; find_msg_def(pub) -> [#field{name = topic, fnum = 1, rnum = 2, type = string, occurrence = optional, opts = []}, #field{name = content, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}]; -find_msg_def(push_reply) -> +find_msg_def(async_call_reply) -> [#field{name = code, fnum = 1, rnum = 2, type = uint32, occurrence = optional, opts = []}, #field{name = result, fnum = 2, rnum = 3, type = string, occurrence = optional, opts = []}, #field{name = message, fnum = 3, rnum = 4, type = string, occurrence = optional, opts = []}]; @@ -2444,7 +2444,7 @@ service_and_rpc_name_to_fqbins(S, R) -> error({gpb_error, {badservice_or_rpc, {S fqbin_to_msg_name(<<"AuthRequest">>) -> auth_request; fqbin_to_msg_name(<<"AuthReply">>) -> auth_reply; fqbin_to_msg_name(<<"Pub">>) -> pub; -fqbin_to_msg_name(<<"PushReply">>) -> push_reply; +fqbin_to_msg_name(<<"AsyncCallReply">>) -> async_call_reply; fqbin_to_msg_name(<<"Deploy">>) -> deploy; fqbin_to_msg_name(<<"FetchTaskLog">>) -> fetch_task_log; fqbin_to_msg_name(<<"Invoke">>) -> invoke; @@ -2459,7 +2459,7 @@ fqbin_to_msg_name(E) -> error({gpb_error, {badmsg, E}}). msg_name_to_fqbin(auth_request) -> <<"AuthRequest">>; msg_name_to_fqbin(auth_reply) -> <<"AuthReply">>; msg_name_to_fqbin(pub) -> <<"Pub">>; -msg_name_to_fqbin(push_reply) -> <<"PushReply">>; +msg_name_to_fqbin(async_call_reply) -> <<"AsyncCallReply">>; msg_name_to_fqbin(deploy) -> <<"Deploy">>; msg_name_to_fqbin(fetch_task_log) -> <<"FetchTaskLog">>; msg_name_to_fqbin(invoke) -> <<"Invoke">>; @@ -2506,7 +2506,7 @@ get_all_source_basenames() -> ["message_pb.proto"]. get_all_proto_names() -> ["message_pb"]. -get_msg_containment("message_pb") -> [auth_reply, auth_request, data, deploy, event, fetch_task_log, invoke, ping, pub, push_reply, service_config, service_inform]; +get_msg_containment("message_pb") -> [async_call_reply, auth_reply, auth_request, data, deploy, event, fetch_task_log, invoke, ping, pub, service_config, service_inform]; get_msg_containment(P) -> error({gpb_error, {badproto, P}}). @@ -2534,9 +2534,9 @@ get_proto_by_msg_name_as_fqbin(<<"Invoke">>) -> "message_pb"; get_proto_by_msg_name_as_fqbin(<<"ServiceConfig">>) -> "message_pb"; get_proto_by_msg_name_as_fqbin(<<"Ping">>) -> "message_pb"; get_proto_by_msg_name_as_fqbin(<<"FetchTaskLog">>) -> "message_pb"; -get_proto_by_msg_name_as_fqbin(<<"PushReply">>) -> "message_pb"; get_proto_by_msg_name_as_fqbin(<<"Deploy">>) -> "message_pb"; get_proto_by_msg_name_as_fqbin(<<"AuthReply">>) -> "message_pb"; +get_proto_by_msg_name_as_fqbin(<<"AsyncCallReply">>) -> "message_pb"; get_proto_by_msg_name_as_fqbin(<<"ServiceInform">>) -> "message_pb"; get_proto_by_msg_name_as_fqbin(E) -> error({gpb_error, {badmsg, E}}). diff --git a/message_pb.proto b/message_pb.proto index a2098b8..b86db26 100644 --- a/message_pb.proto +++ b/message_pb.proto @@ -24,7 +24,7 @@ message Pub { ///// 服务器主动推送的消息 -message PushReply { +message AsyncCallReply { // 0: 表示失败,1: 成功 uint32 code = 1; string result = 2;