This commit is contained in:
anlicheng 2025-04-22 16:18:40 +08:00
parent 8d89223f3c
commit 5a795fc142
2 changed files with 10 additions and 7 deletions

View File

@ -19,10 +19,14 @@
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
-define(SERVER, ?MODULE).
-define(STATE_DENIED, denied).
-define(STATE_ACTIVATED, activated).
-record(state, {
transport_pid :: undefined | pid()
transport_pid :: undefined | pid(),
status = ?STATE_DENIED
}).
%%%===================================================================
@ -82,22 +86,22 @@ handle_info({timeout, _, create_transport}, State = #state{}) ->
%%
{ok, #auth_reply{code = 1, message = Message, repository_url = RepositoryUrl}} ->
lager:debug("[efka_agent] auth result: ~p, repository_url: ~p", [Message, RepositoryUrl]),
{noreply, State#state{transport_pid = TransportPid}};
{noreply, State#state{transport_pid = TransportPid, status = ?STATE_ACTIVATED}};
%% denied状态
{ok, #auth_reply{code = -1, message = Message, repository_url = RepositoryUrl}} ->
lager:debug("[efka_agent] auth failed, message: ~p, repository_url: ~p", [Message, RepositoryUrl]),
{noreply, State#state{transport_pid = TransportPid}};
{noreply, State#state{transport_pid = TransportPid, status = ?STATE_DENIED}};
%%
{ok, #auth_reply{code = -2, message = Message, repository_url = RepositoryUrl}} ->
lager:debug("[efka_agent] auth failed, message: ~p, repository_url: ~p", [Message, RepositoryUrl]),
{noreply, State#state{transport_pid = undefined}};
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}};
{error, Reason} ->
lager:debug("[efka_agent] auth_request failed, error: ~p", [Reason]),
efka_transport:stop(TransportPid),
{noreply, State#state{transport_pid = undefined}}
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}}
end;
handle_info({'EXIT', _Pid, Reason}, State = #state{}) ->

View File

@ -106,7 +106,6 @@ handle_call({auth_request, Timeout}, _From, State = #state{socket = Socket, pack
%% auth返回的结果
receive
{ssl, Socket, <<?PACKET_RESPONSE, PacketId:32, ?METHOD_AUTH, ReplyBin/binary>>} ->
lager:debug("[efka_agent] get a reply bin: ~p", [ReplyBin]),
{reply, {ok, message_pb:decode_msg(ReplyBin, auth_reply)}, State#state{packet_id = PacketId + 1}}
after
Timeout ->