fix ssl channel

This commit is contained in:
anlicheng 2026-04-24 16:17:03 +08:00
parent 5511ed6be2
commit 2ff3f3b2c1
2 changed files with 22 additions and 20 deletions

View File

@ -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}]};
%% channel
handle_event({call, From}, {attach_channel, ChannelPid}, StateName, State = #state{uuid = UUID, channel_pid = undefined}) ->
case StateName of
?STATE_ACTIVATED ->
erlang:monitor(process, ChannelPid),
%% 线
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]),
{keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]};
%%
?STATE_DENIED ->
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">>}}]}
handle_event({call, From}, {attach_channel, ChannelPid}, StateName, State = #state{uuid = UUID, channel_pid = OldChannelPid}) ->
case OldChannelPid == undefined orelse OldChannelPid =:= ChannelPid of
true ->
case StateName of
?STATE_ACTIVATED ->
erlang:monitor(process, ChannelPid),
%% 线
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]),
{keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]};
%%
?STATE_DENIED ->
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;
%% 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,

View File

@ -55,10 +55,10 @@ command(Pid, Command) when is_pid(Pid) ->
-spec activate(Pid :: pid(), Auth :: boolean()) -> no_return().
activate(Pid, Auth) when is_pid(Pid), is_boolean(Auth) ->
Cmd = case Auth of true -> 'ACTIVATE'; false -> 'DEACTIVATE' end,
Command = #'CastFrame.Command'{
Command = #'CastFrame.Command'{
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().
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消息
handle_cast({command, Command}, State = #state{transport = Transport, socket = Socket}) ->
Encoded = message_pb:encode_msg(#'CastFrame'{
body = Command
body = {command, Command}
}),
Transport:send(Socket, <<?FRAME_CAST, Encoded/binary>>),
{noreply, State};