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 ->
|
undefined ->
|
||||||
{ok, 200, sdlan_util:json_error(-1, <<"network not found">>)};
|
{ok, 200, sdlan_util:json_error(-1, <<"network not found">>)};
|
||||||
Pid ->
|
Pid ->
|
||||||
sdlan_network:acl_changed(Pid, ClientId),
|
case sdlan_network:acl_changed(Pid, ClientId) of
|
||||||
{ok, 200, sdlan_util:json_data(<<"success">>)}
|
ok ->
|
||||||
|
{ok, 200, sdlan_util:json_data(<<"success">>)};
|
||||||
|
{error, Reason} ->
|
||||||
|
{ok, 200, sdlan_util:json_error(-1, Reason)}
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_request(_, Path, _, _) ->
|
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) ->
|
disable_client(Pid, ClientId) when is_pid(Pid), is_binary(ClientId) ->
|
||||||
gen_server:call(Pid, {disable_client, 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) ->
|
acl_changed(Pid, ClientId) when is_pid(Pid), is_binary(ClientId) ->
|
||||||
gen_server:call(Pid, {acl_changed, ClientId}).
|
gen_server:call(Pid, {acl_changed, ClientId}).
|
||||||
|
|
||||||
@ -323,15 +323,17 @@ handle_call({command, ReceiverPid, ClientId, SubCommand}, _From, State = #state{
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
%% 触发acl改变
|
%% 触发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 ->
|
MatchSpec = ets:fun2ms(fun(Object = {_Mac, #endpoint{client_id = ClientId0}}) when ClientId0 =:= ClientId ->
|
||||||
Object
|
Object
|
||||||
end),
|
end),
|
||||||
case select_endpoint(EndpointTable, MatchSpec) of
|
case select_endpoint(EndpointTable, MatchSpec) of
|
||||||
{ok, _Mac, #endpoint{channel_pid = ChannelPid, transport = Transport}} ->
|
{ok, _Mac, #endpoint{channel_pid = ChannelPid, transport = Transport}} ->
|
||||||
Ref = make_ref(),
|
ExposedServiceChangedEvent = sdlan_pb:encode_msg(#'SDLEvent' {
|
||||||
Transport:command(ChannelPid, Ref, ReceiverPid, SubCommand),
|
event = {exposed_service_changed, #'SDLEvent.ExposedServiceChanged'{}}
|
||||||
{reply, {ok, Ref}, State};
|
}),
|
||||||
|
Transport:send_event(ChannelPid, ExposedServiceChangedEvent),
|
||||||
|
{reply, ok, State};
|
||||||
error ->
|
error ->
|
||||||
{reply, {error, <<"目标Node不在线"/utf8>>}, State}
|
{reply, {error, <<"目标Node不在线"/utf8>>}, State}
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user