fix activate
This commit is contained in:
parent
bd418e8e6a
commit
b5717b1f78
@ -137,7 +137,7 @@ handle_request("POST", "/host/activate", _, #{<<"uuid">> := UUID, <<"auth">> :=
|
|||||||
%% 等待主机返回确认消息
|
%% 等待主机返回确认消息
|
||||||
receive
|
receive
|
||||||
{host_reply, Assoc, #{<<"code">> := 1}} ->
|
{host_reply, Assoc, #{<<"code">> := 1}} ->
|
||||||
ok = iot_host:activate(Pid),
|
ok = iot_host:activate(Pid, Auth),
|
||||||
{ok, 200, iot_util:json_data(<<"success">>)};
|
{ok, 200, iot_util:json_data(<<"success">>)};
|
||||||
{host_reply, Assoc, #{<<"code">> := 0, <<"message">> := Message}} when is_binary(Message) ->
|
{host_reply, Assoc, #{<<"code">> := 0, <<"message">> := Message}} when is_binary(Message) ->
|
||||||
{ok, 200, iot_util:json_error(401, <<"操作失败: "/utf8, Message/binary>>)}
|
{ok, 200, iot_util:json_error(401, <<"操作失败: "/utf8, Message/binary>>)}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
-define(TICKER_INTERVAL, 5000 * 2).
|
-define(TICKER_INTERVAL, 5000 * 2).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/2, get_name/1, get_pid/1, handle/2, reload/1, activate/1]).
|
-export([start_link/2, get_name/1, get_pid/1, handle/2, reload/1, activate/2]).
|
||||||
-export([get_metric/1, aes_encode/3, downstream_topic/1, upstream_topic/1, get_aes/1, make_assoc/1, rsa_encode/3]).
|
-export([get_metric/1, aes_encode/3, downstream_topic/1, upstream_topic/1, get_aes/1, make_assoc/1, rsa_encode/3]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
@ -100,10 +100,10 @@ get_aes(Pid) when is_pid(Pid) ->
|
|||||||
make_assoc(Pid) when is_pid(Pid) ->
|
make_assoc(Pid) when is_pid(Pid) ->
|
||||||
gen_server:call(Pid, {make_assoc, self()}).
|
gen_server:call(Pid, {make_assoc, self()}).
|
||||||
|
|
||||||
%% 激活主机
|
%% 激活主机, true 表示激活; false表示关闭激活
|
||||||
-spec activate(Pid :: pid()) -> ok.
|
-spec activate(Pid :: pid(), Auth :: boolean()) -> ok.
|
||||||
activate(Pid) when is_pid(Pid) ->
|
activate(Pid, Auth) when is_pid(Pid), is_binary(Auth) ->
|
||||||
gen_server:call(Pid, activate).
|
gen_server:call(Pid, {activate, Auth}).
|
||||||
|
|
||||||
-spec get_metric(Pid :: pid()) -> {ok, MetricInfo :: map()}.
|
-spec get_metric(Pid :: pid()) -> {ok, MetricInfo :: map()}.
|
||||||
get_metric(Pid) when is_pid(Pid) ->
|
get_metric(Pid) when is_pid(Pid) ->
|
||||||
@ -185,9 +185,15 @@ handle_call(reload, _From, State = #state{uuid = UUID}) ->
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
% 处理主机的激活
|
% 处理主机的激活
|
||||||
handle_call(activate, _From, State = #state{uuid = UUID, is_activated = IsActivated}) ->
|
handle_call({activate, Auth}, _From, State = #state{uuid = UUID, is_activated = IsActivated}) ->
|
||||||
lager:debug("[iot_host] host uuid: ~p, activated, before status is: ~p", [UUID, IsActivated]),
|
lager:debug("[iot_host] host uuid: ~p, new activate status: ~p, before status is: ~p", [UUID, Auth, IsActivated]),
|
||||||
|
%% 关闭授权时,认为会话时关闭状态
|
||||||
|
case Auth of
|
||||||
|
true ->
|
||||||
{reply, ok, State#state{is_activated = true}};
|
{reply, ok, State#state{is_activated = true}};
|
||||||
|
false ->
|
||||||
|
{reply, ok, State#state{is_activated = false, has_session = false, pub_key = <<>>}}
|
||||||
|
end;
|
||||||
|
|
||||||
%% 创建命令
|
%% 创建命令
|
||||||
handle_call({aes_encode, _, _}, _From, State = #state{has_session = false}) ->
|
handle_call({aes_encode, _, _}, _From, State = #state{has_session = false}) ->
|
||||||
@ -297,7 +303,7 @@ handle_message(#{<<"method">> := <<"create_session">>, <<"params">> := #{<<"pub_
|
|||||||
receive
|
receive
|
||||||
{ok, Ref, PacketId} ->
|
{ok, Ref, PacketId} ->
|
||||||
lager:debug("[iot_host] host_id uuid: ~p, packet_id: ~p, publish register reply success", [UUID, PacketId]),
|
lager:debug("[iot_host] host_id uuid: ~p, packet_id: ~p, publish register reply success", [UUID, PacketId]),
|
||||||
State#state{pub_key = PubKey, aes = Aes, has_session = true}
|
State#state{pub_key = PubKey, has_session = true}
|
||||||
after 10000 ->
|
after 10000 ->
|
||||||
lager:debug("[iot_host] host_id uuid: ~p, publish register reply get error is: timeout", [UUID]),
|
lager:debug("[iot_host] host_id uuid: ~p, publish register reply get error is: timeout", [UUID]),
|
||||||
State
|
State
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user