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