fix acl_changed event
This commit is contained in:
parent
f6e1cd7c5e
commit
5138a18364
@ -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, _, _) ->
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user