fix
This commit is contained in:
parent
f947453e59
commit
8d89223f3c
@ -51,8 +51,7 @@ init([]) ->
|
||||
|
||||
%% @private
|
||||
%% @doc Handling call messages
|
||||
-spec(handle_call(Request :: term(), From :: {pid(), Tag :: term()},
|
||||
State :: #state{}) ->
|
||||
-spec(handle_call(Request :: term(), From :: {pid(), Tag :: term()}, State :: #state{}) ->
|
||||
{reply, Reply :: term(), NewState :: #state{}} |
|
||||
{reply, Reply :: term(), NewState :: #state{}, timeout() | hibernate} |
|
||||
{noreply, NewState :: #state{}} |
|
||||
@ -79,8 +78,28 @@ handle_cast(_Request, State = #state{}) ->
|
||||
{stop, Reason :: term(), NewState :: #state{}}).
|
||||
handle_info({timeout, _, create_transport}, State = #state{}) ->
|
||||
{ok, TransportPid} = efka_transport:start_link(self()),
|
||||
case efka_transport:auth_request(TransportPid, 5000) of
|
||||
%% 验证通过
|
||||
{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}};
|
||||
|
||||
%% 主机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}};
|
||||
|
||||
%% 验证不通过
|
||||
{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}};
|
||||
|
||||
{error, Reason} ->
|
||||
lager:debug("[efka_agent] auth_request failed, error: ~p", [Reason]),
|
||||
efka_transport:stop(TransportPid),
|
||||
{noreply, State#state{transport_pid = undefined}}
|
||||
end;
|
||||
|
||||
handle_info({'EXIT', _Pid, Reason}, State = #state{}) ->
|
||||
lager:debug("[efka_agent] transport exit with reason: ~p", [Reason]),
|
||||
retry_connect(),
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
%% API
|
||||
-export([start_link/1]).
|
||||
-export([auth_request/2, send/3, response/3]).
|
||||
-export([auth_request/2, send/3, response/3, stop/1]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
||||
@ -34,6 +34,7 @@
|
||||
%%% API
|
||||
%%%===================================================================
|
||||
|
||||
-spec auth_request(Pid :: pid(), Timeout :: integer()) -> {ok, AuthReply :: #auth_reply{}} | {error, Reason :: any()}.
|
||||
auth_request(Pid, Timeout) when is_pid(Pid), is_integer(Timeout) ->
|
||||
gen_server:call(Pid, {auth_request, Timeout}).
|
||||
|
||||
@ -43,6 +44,9 @@ send(Pid, Method, Packet) when is_pid(Pid), is_integer(Method), is_binary(Packet
|
||||
response(Pid, PacketId, Response) when is_pid(Pid), is_integer(PacketId) ->
|
||||
gen_server:cast(Pid, {response, PacketId, Response}).
|
||||
|
||||
stop(Pid) when is_pid(Pid) ->
|
||||
gen_server:stop(Pid).
|
||||
|
||||
%% @doc Spawns the server and registers the local name (unique)
|
||||
-spec(start_link(ParentPid :: pid()) ->
|
||||
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user