This commit is contained in:
anlicheng 2026-04-02 17:09:31 +08:00
parent 08e4a9cbcb
commit 32fc75648b
3 changed files with 12 additions and 13 deletions

2
API.md
View File

@ -121,7 +121,7 @@ method: post
params:
id: int, //网络id
action: int // 0: 关闭1: 开启
dst_mac: string // 目标节点的mac地址
client_id: string // 目标节点的mac地址
remark: string // 下发的标签,用于跟踪测试问题,可为空
timeout: int // 超时设置,单位为秒
return:

View File

@ -36,7 +36,7 @@ handle_request("POST", "/network/delete", _, #{<<"id">> := NetworkId}) when Netw
end
end;
handle_request("POST", "/network/exit_node_control", _, #{<<"id">> := NetworkId, <<"action">> := Action, <<"dst_mac">> := DstMac0, <<"remark">> := Remark, <<"timeout">> := Timeout}) when NetworkId > 0 ->
handle_request("POST", "/network/exit_node_control", _, #{<<"id">> := NetworkId, <<"action">> := Action, <<"client_id">> := ClientId, <<"remark">> := Remark, <<"timeout">> := Timeout}) when NetworkId > 0 ->
case sdlan_network:get_pid(NetworkId) of
undefined ->
{ok, 200, sdlan_util:json_data(<<"network not found">>)};
@ -46,8 +46,7 @@ handle_request("POST", "/network/exit_node_control", _, #{<<"id">> := NetworkId,
action = Action,
remark = Remark
}},
DstMac = sdlan_util:mac_str_to_bin(DstMac0),
case sdlan_network:command(NetworkId, ReceiverPid, DstMac, SubCommand) of
case sdlan_network:command(NetworkId, ReceiverPid, ClientId, SubCommand) of
{error, Reason} ->
{ok, 200, sdlan_util:json_error(-1, Reason)};
{ok, Ref} ->

View File

@ -118,10 +118,10 @@ peer_info(Pid, SrcMac, DstMac) when is_pid(Pid), is_binary(SrcMac), is_binary(Ds
arp_request(Pid, TargetIp) when is_pid(Pid), is_integer(TargetIp) ->
gen_server:call(Pid, {arp_request, TargetIp}).
-spec command(Pid :: pid(), ReceiverPid :: pid(), DstMac :: binary(), {Tag :: atom(), SubCommand :: any()}) ->
-spec command(Pid :: pid(), ReceiverPid :: pid(), ClientId :: binary(), {Tag :: atom(), SubCommand :: any()}) ->
{error, Reason :: binary()} | {ok, Ref :: reference()}.
command(Pid, ReceiverPid, DstMac, SubCommand) when is_pid(Pid), is_pid(ReceiverPid), is_binary(DstMac) ->
gen_server:call(Pid, {command, ReceiverPid, DstMac, SubCommand}).
command(Pid, ReceiverPid, ClientId, SubCommand) when is_pid(Pid), is_pid(ReceiverPid), is_binary(DstMac) ->
gen_server:call(Pid, {command, ReceiverPid, ClientId, SubCommand}).
-spec wait_command_ack(Ref :: reference(), Timeout :: integer()) -> {error, timeout} | {ok, CommandAck :: #'SDLCommandAck'{}}.
wait_command_ack(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) ->
@ -307,14 +307,14 @@ handle_call({arp_request, TargetIp}, _From, State = #state{endpoints = Endpoints
end;
%%
handle_call({command, ReceiverPid, DstMac, SubCommand}, _From, State = #state{endpoints = Endpoints}) ->
case maps:find(DstMac, Endpoints) of
error ->
{reply, {error, <<"目标Node不在线"/utf8>>}};
{ok, #endpoint{channel_pid = ChannelPid}} ->
handle_call({command, ReceiverPid, ClientId, SubCommand}, _From, State = #state{endpoints = Endpoints}) ->
case search_endpoint(fun(_, #endpoint{client_id = ClientId0}) -> ClientId =:= ClientId0 end, Endpoints) of
{ok, _Mac, #endpoint{channel_pid = ChannelPid}} ->
Ref = make_ref(),
sdlan_quic_channel:command(ChannelPid, Ref, ReceiverPid, SubCommand),
{reply, {ok, Ref}, State}
{reply, {ok, Ref}, State};
error ->
{reply, {error, <<"目标Node不在线"/utf8>>}}
end;
handle_call(debug_info, _From, State = #state{network_id = NetworkId, ipaddr = IpAddr, mask_len = MaskLen, owner_id = OwnerId, endpoints = Endpoints}) ->