fix acl_changed event

This commit is contained in:
anlicheng 2026-05-26 14:09:29 +08:00
parent f6e1cd7c5e
commit 5138a18364
2 changed files with 13 additions and 7 deletions

View File

@ -28,8 +28,12 @@ handle_request("POST", "/node/acl_changed", _, #{<<"network_id">> := NetworkId,
undefined ->
{ok, 200, sdlan_util:json_error(-1, <<"network not found">>)};
Pid ->
sdlan_network:acl_changed(Pid, ClientId),
{ok, 200, sdlan_util:json_data(<<"success">>)}
case sdlan_network:acl_changed(Pid, ClientId) of
ok ->
{ok, 200, sdlan_util:json_data(<<"success">>)};
{error, Reason} ->
{ok, 200, sdlan_util:json_error(-1, Reason)}
end
end;
handle_request(_, Path, _, _) ->

View File

@ -155,7 +155,7 @@ update_hole(Pid, SessionToken, ClientId, Mac, Peer, NatType, V6Info) when is_pid
disable_client(Pid, ClientId) when is_pid(Pid), is_binary(ClientId) ->
gen_server:call(Pid, {disable_client, ClientId}).
-spec acl_changed(Pid :: pid(), ClientId :: binary()) -> ok | error.
-spec acl_changed(Pid :: pid(), ClientId :: binary()) -> ok | {error, Reason :: binary()}.
acl_changed(Pid, ClientId) when is_pid(Pid), is_binary(ClientId) ->
gen_server:call(Pid, {acl_changed, ClientId}).
@ -323,15 +323,17 @@ handle_call({command, ReceiverPid, ClientId, SubCommand}, _From, State = #state{
end;
%% acl改变
handle_call({acl_changed, ReceiverPid, ClientId, SubCommand}, _From, State = #state{endpoint_table = EndpointTable}) ->
handle_call({acl_changed, ClientId}, _From, State = #state{endpoint_table = EndpointTable}) ->
MatchSpec = ets:fun2ms(fun(Object = {_Mac, #endpoint{client_id = ClientId0}}) when ClientId0 =:= ClientId ->
Object
end),
case select_endpoint(EndpointTable, MatchSpec) of
{ok, _Mac, #endpoint{channel_pid = ChannelPid, transport = Transport}} ->
Ref = make_ref(),
Transport:command(ChannelPid, Ref, ReceiverPid, SubCommand),
{reply, {ok, Ref}, State};
ExposedServiceChangedEvent = sdlan_pb:encode_msg(#'SDLEvent' {
event = {exposed_service_changed, #'SDLEvent.ExposedServiceChanged'{}}
}),
Transport:send_event(ChannelPid, ExposedServiceChangedEvent),
{reply, ok, State};
error ->
{reply, {error, <<"目标Node不在线"/utf8>>}, State}
end;