fix ssl channel
This commit is contained in:
parent
5511ed6be2
commit
2ff3f3b2c1
@ -266,24 +266,26 @@ handle_event({call, From}, {activate, false}, _, State = #state{uuid = UUID, cha
|
|||||||
{next_state, ?STATE_DENIED, State#state{channel_pid = undefined, has_session = false}, [{reply, From, ok}]};
|
{next_state, ?STATE_DENIED, State#state{channel_pid = undefined, has_session = false}, [{reply, From, ok}]};
|
||||||
|
|
||||||
%% 绑定channel
|
%% 绑定channel
|
||||||
handle_event({call, From}, {attach_channel, ChannelPid}, StateName, State = #state{uuid = UUID, channel_pid = undefined}) ->
|
handle_event({call, From}, {attach_channel, ChannelPid}, StateName, State = #state{uuid = UUID, channel_pid = OldChannelPid}) ->
|
||||||
case StateName of
|
case OldChannelPid == undefined orelse OldChannelPid =:= ChannelPid of
|
||||||
?STATE_ACTIVATED ->
|
true ->
|
||||||
erlang:monitor(process, ChannelPid),
|
case StateName of
|
||||||
%% 更新主机为在线状态
|
?STATE_ACTIVATED ->
|
||||||
ChangeResult = iot_api_client:change_host_status(UUID, ?HOST_ONLINE),
|
erlang:monitor(process, ChannelPid),
|
||||||
logger:debug("[iot_host] host_id(attach_channel) uuid: ~p, will change status, result: ~p", [UUID, ChangeResult]),
|
%% 更新主机为在线状态
|
||||||
{keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]};
|
ChangeResult = iot_api_client:change_host_status(UUID, ?HOST_ONLINE),
|
||||||
%% 主机未激活
|
logger:debug("[iot_host] host_id(attach_channel) uuid: ~p, will change status, result: ~p", [UUID, ChangeResult]),
|
||||||
?STATE_DENIED ->
|
{keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]};
|
||||||
logger:notice("[iot_host] attach_channel host_id uuid: ~p, channel: ~p, host inactivated", [UUID, ChannelPid]),
|
%% 主机未激活
|
||||||
erlang:monitor(process, ChannelPid),
|
?STATE_DENIED ->
|
||||||
{keep_state, State#state{channel_pid = ChannelPid}, [{reply, From, {denied, <<"host inactivated">>}}]}
|
logger:notice("[iot_host] attach_channel host_id uuid: ~p, channel: ~p, host inactivated", [UUID, ChannelPid]),
|
||||||
|
erlang:monitor(process, ChannelPid),
|
||||||
|
{keep_state, State#state{channel_pid = ChannelPid}, [{reply, From, {denied, <<"host inactivated">>}}]}
|
||||||
|
end;
|
||||||
|
false ->
|
||||||
|
logger:notice("[iot_host] attach_channel host_id uuid: ~p, old channel exists: ~p", [UUID, OldChannelPid]),
|
||||||
|
{keep_state, State, [{reply, From, {error, <<"channel existed">>}}]}
|
||||||
end;
|
end;
|
||||||
%% 已经绑定了channel
|
|
||||||
handle_event({call, From}, {attach_channel, _}, _, State = #state{uuid = UUID, channel_pid = OldChannelPid}) ->
|
|
||||||
logger:notice("[iot_host] attach_channel host_id uuid: ~p, old channel exists: ~p", [UUID, OldChannelPid]),
|
|
||||||
{keep_state, State, [{reply, From, {error, <<"channel existed">>}}]};
|
|
||||||
|
|
||||||
%% 数据分发
|
%% 数据分发
|
||||||
handle_event(cast, {handle, {data, RouteKey, MetricBin}}, ?STATE_ACTIVATED,
|
handle_event(cast, {handle, {data, RouteKey, MetricBin}}, ?STATE_ACTIVATED,
|
||||||
|
|||||||
@ -55,10 +55,10 @@ command(Pid, Command) when is_pid(Pid) ->
|
|||||||
-spec activate(Pid :: pid(), Auth :: boolean()) -> no_return().
|
-spec activate(Pid :: pid(), Auth :: boolean()) -> no_return().
|
||||||
activate(Pid, Auth) when is_pid(Pid), is_boolean(Auth) ->
|
activate(Pid, Auth) when is_pid(Pid), is_boolean(Auth) ->
|
||||||
Cmd = case Auth of true -> 'ACTIVATE'; false -> 'DEACTIVATE' end,
|
Cmd = case Auth of true -> 'ACTIVATE'; false -> 'DEACTIVATE' end,
|
||||||
Command = #'CastFrame.Command'{
|
Command = #'CastFrame.Command'{
|
||||||
command = {auth, #'CastFrame.Command.Authorization'{cmd = Cmd}}
|
command = {auth, #'CastFrame.Command.Authorization'{cmd = Cmd}}
|
||||||
},
|
},
|
||||||
command(Pid, Command).
|
gen_server:cast(Pid, {command, Command}).
|
||||||
|
|
||||||
-spec container_call(Pid :: pid(), ReceiverPid :: pid(), Request :: message_pb:'ContainerRequest'()) -> Ref :: reference().
|
-spec container_call(Pid :: pid(), ReceiverPid :: pid(), Request :: message_pb:'ContainerRequest'()) -> Ref :: reference().
|
||||||
container_call(Pid, ReceiverPid, Request) when is_pid(Pid), is_pid(ReceiverPid), is_record(Request, 'ContainerRequest') ->
|
container_call(Pid, ReceiverPid, Request) when is_pid(Pid), is_pid(ReceiverPid), is_record(Request, 'ContainerRequest') ->
|
||||||
@ -114,7 +114,7 @@ handle_cast({pub, Topic, Qos, Content}, State = #state{transport = Transport, so
|
|||||||
%% 发送Command消息
|
%% 发送Command消息
|
||||||
handle_cast({command, Command}, State = #state{transport = Transport, socket = Socket}) ->
|
handle_cast({command, Command}, State = #state{transport = Transport, socket = Socket}) ->
|
||||||
Encoded = message_pb:encode_msg(#'CastFrame'{
|
Encoded = message_pb:encode_msg(#'CastFrame'{
|
||||||
body = Command
|
body = {command, Command}
|
||||||
}),
|
}),
|
||||||
Transport:send(Socket, <<?FRAME_CAST, Encoded/binary>>),
|
Transport:send(Socket, <<?FRAME_CAST, Encoded/binary>>),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user