fix quic proto
This commit is contained in:
parent
a7f43b7260
commit
07bdfb5f31
@ -23,6 +23,15 @@ handle_request("POST", "/node/disable", _, #{<<"network_id">> := NetworkId, <<"c
|
|||||||
{ok, 200, sdlan_util:json_data(<<"success">>)}
|
{ok, 200, sdlan_util:json_data(<<"success">>)}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
handle_request("POST", "/node/acl_changed", _, #{<<"network_id">> := NetworkId, <<"client_id">> := ClientId}) when NetworkId > 0 ->
|
||||||
|
case sdlan_network:get_pid(NetworkId) of
|
||||||
|
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">>)}
|
||||||
|
end;
|
||||||
|
|
||||||
handle_request(_, Path, _, _) ->
|
handle_request(_, Path, _, _) ->
|
||||||
Path1 = list_to_binary(Path),
|
Path1 = list_to_binary(Path),
|
||||||
{ok, 200, sdlan_util:json_error(-1, <<"url: ", Path1/binary, " not found">>)}.
|
{ok, 200, sdlan_util:json_error(-1, <<"url: ", Path1/binary, " not found">>)}.
|
||||||
|
|||||||
@ -1,48 +0,0 @@
|
|||||||
%%%-------------------------------------------------------------------
|
|
||||||
%%% @author anlicheng
|
|
||||||
%%% @copyright (C) 2026, <COMPANY>
|
|
||||||
%%% @doc
|
|
||||||
%%% Compatibility facade for the QUIC channel API.
|
|
||||||
%%% @end
|
|
||||||
%%%-------------------------------------------------------------------
|
|
||||||
-module(sdlan_quic_channel).
|
|
||||||
-author("anlicheng").
|
|
||||||
|
|
||||||
%% API
|
|
||||||
-export([start_link/2]).
|
|
||||||
-export([accept_stream/1, send_event/2, command/4, stop/2, debug_info/1]).
|
|
||||||
-export([test_rules/2]).
|
|
||||||
|
|
||||||
%%%===================================================================
|
|
||||||
%%% API
|
|
||||||
%%%===================================================================
|
|
||||||
|
|
||||||
%% 测试规则函数
|
|
||||||
-spec test_rules(SrcIdentityId :: integer(), DstIdentityId :: integer()) -> binary().
|
|
||||||
test_rules(SrcIdentityId, DstIdentityId) when is_integer(SrcIdentityId), is_integer(DstIdentityId) ->
|
|
||||||
sdlan_session:test_rules(SrcIdentityId, DstIdentityId).
|
|
||||||
|
|
||||||
-spec send_event(Pid :: pid(), Event :: binary()) -> ok.
|
|
||||||
send_event(Pid, ProtobufEvent) when is_pid(Pid), is_binary(ProtobufEvent) ->
|
|
||||||
sdlan_quic_transport:send_event(Pid, ProtobufEvent).
|
|
||||||
|
|
||||||
-spec command(Pid :: pid(), Ref :: reference(), ReceiverPid :: pid(), {Tag :: atom(), SubCommand :: any()}) -> ok.
|
|
||||||
command(Pid, Ref, ReceiverPid, SubCommand) when is_pid(Pid), is_pid(ReceiverPid) ->
|
|
||||||
sdlan_quic_transport:command(Pid, Ref, ReceiverPid, SubCommand).
|
|
||||||
|
|
||||||
-spec accept_stream(Pid :: pid()) -> ok.
|
|
||||||
accept_stream(Pid) when is_pid(Pid) ->
|
|
||||||
sdlan_quic_transport:accept_stream(Pid).
|
|
||||||
|
|
||||||
-spec stop(Pid :: pid(), Reason :: term()) -> ok.
|
|
||||||
stop(Pid, Reason) when is_pid(Pid) ->
|
|
||||||
sdlan_quic_transport:stop(Pid, Reason).
|
|
||||||
|
|
||||||
-spec debug_info(Pid :: pid()) -> map().
|
|
||||||
debug_info(Pid) when is_pid(Pid) ->
|
|
||||||
sdlan_quic_transport:debug_info(Pid).
|
|
||||||
|
|
||||||
%% @doc Creates a transport process. Kept for existing supervisor specs.
|
|
||||||
-spec start_link(Conn :: quicer:connection_handle(), Limits :: proplists:proplist()) -> gen_statem:start_ret().
|
|
||||||
start_link(Conn, Limits) when is_list(Limits) ->
|
|
||||||
sdlan_quic_transport:start_link(Conn, Limits).
|
|
||||||
@ -66,7 +66,7 @@ loop_accept(L, Limits, AcceptorId) ->
|
|||||||
logger:debug("[sdlan_quic_server] acceptor: ~p, accept a new connection: ~p", [AcceptorId, Conn]),
|
logger:debug("[sdlan_quic_server] acceptor: ~p, accept a new connection: ~p", [AcceptorId, Conn]),
|
||||||
case quicer:handshake(Conn) of
|
case quicer:handshake(Conn) of
|
||||||
{ok, NConn} ->
|
{ok, NConn} ->
|
||||||
case sdlan_quic_channel_sup:start_channel(NConn, Limits) of
|
case sdlan_quic_transport_sup:start_transport(NConn, Limits) of
|
||||||
{ok, ChannelPid} ->
|
{ok, ChannelPid} ->
|
||||||
logger:debug("[sdlan_quic_server] conn: ~p, handshake success, channel pid: ~p", [NConn, ChannelPid]),
|
logger:debug("[sdlan_quic_server] conn: ~p, handshake success, channel pid: ~p", [NConn, ChannelPid]),
|
||||||
case quicer:controlling_process(NConn, ChannelPid) of
|
case quicer:controlling_process(NConn, ChannelPid) of
|
||||||
|
|||||||
@ -6,14 +6,14 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%% Created : 13. 2月 2026 18:00
|
%%% Created : 13. 2月 2026 18:00
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(sdlan_quic_channel_sup).
|
-module(sdlan_quic_transport_sup).
|
||||||
-author("anlicheng").
|
-author("anlicheng").
|
||||||
|
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0]).
|
-export([start_link/0]).
|
||||||
-export([start_channel/2]).
|
-export([start_transport/2]).
|
||||||
|
|
||||||
%% Supervisor callbacks
|
%% Supervisor callbacks
|
||||||
-export([init/1]).
|
-export([init/1]).
|
||||||
@ -58,6 +58,6 @@ init([]) ->
|
|||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
-spec start_channel(NConn :: quicer:connection_handle(), Limits :: proplists:proplist()) -> supervisor:startchild_ret().
|
-spec start_transport(NConn :: quicer:connection_handle(), Limits :: proplists:proplist()) -> supervisor:startchild_ret().
|
||||||
start_channel(NConn, Limits) when is_list(Limits) ->
|
start_transport(NConn, Limits) when is_list(Limits) ->
|
||||||
supervisor:start_child(?MODULE, [NConn, Limits]).
|
supervisor:start_child(?MODULE, [NConn, Limits]).
|
||||||
@ -20,7 +20,7 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([start_link/2]).
|
-export([start_link/2]).
|
||||||
-export([get_name/1, get_pid/1, lookup_pid/1, peer_info/3, unregister/3, debug_info/1, get_network_id/1, attach/6, arp_request/2]).
|
-export([get_name/1, get_pid/1, lookup_pid/1, peer_info/3, unregister/3, debug_info/1, get_network_id/1, attach/6, arp_request/2]).
|
||||||
-export([forward_by_ets/5, update_hole/7, disable_client/2, get_channel/2]).
|
-export([forward_by_ets/5, update_hole/7, disable_client/2, get_channel/2, acl_changed/2]).
|
||||||
-export([command/4, wait_command_ack/2]).
|
-export([command/4, wait_command_ack/2]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
@ -153,6 +153,10 @@ 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.
|
||||||
|
acl_changed(Pid, ClientId) when is_pid(Pid), is_binary(ClientId) ->
|
||||||
|
gen_server:call(Pid, {acl_changed, ClientId}).
|
||||||
|
|
||||||
-spec get_channel(Pid :: pid(), ClientId :: binary()) -> error | {ok, ChannelPid :: pid()}.
|
-spec get_channel(Pid :: pid(), ClientId :: binary()) -> error | {ok, ChannelPid :: pid()}.
|
||||||
get_channel(Pid, ClientId) when is_pid(Pid), is_binary(ClientId) ->
|
get_channel(Pid, ClientId) when is_pid(Pid), is_binary(ClientId) ->
|
||||||
gen_server:call(Pid, {get_channel, ClientId}).
|
gen_server:call(Pid, {get_channel, ClientId}).
|
||||||
@ -282,7 +286,7 @@ handle_call({peer_info, SrcMac, DstMac}, _From, State = #state{endpoint_table =
|
|||||||
}),
|
}),
|
||||||
logger:debug("Event: send_register, for peer_info"),
|
logger:debug("Event: send_register, for peer_info"),
|
||||||
|
|
||||||
sdlan_quic_channel:send_event(DstChannelPid, RegisterEvent)
|
sdlan_quic_transport:send_event(DstChannelPid, RegisterEvent)
|
||||||
end,
|
end,
|
||||||
{reply, {ok, {DstNatPeer, DstNatType}, DstV6Info}, State};
|
{reply, {ok, {DstNatPeer, DstNatType}, DstV6Info}, State};
|
||||||
_ ->
|
_ ->
|
||||||
@ -309,7 +313,21 @@ handle_call({command, ReceiverPid, ClientId, SubCommand}, _From, State = #state{
|
|||||||
case select_endpoint(EndpointTable, MatchSpec) of
|
case select_endpoint(EndpointTable, MatchSpec) of
|
||||||
{ok, _Mac, #endpoint{channel_pid = ChannelPid}} ->
|
{ok, _Mac, #endpoint{channel_pid = ChannelPid}} ->
|
||||||
Ref = make_ref(),
|
Ref = make_ref(),
|
||||||
sdlan_quic_channel:command(ChannelPid, Ref, ReceiverPid, SubCommand),
|
sdlan_quic_transport:command(ChannelPid, Ref, ReceiverPid, SubCommand),
|
||||||
|
{reply, {ok, Ref}, State};
|
||||||
|
error ->
|
||||||
|
{reply, {error, <<"目标Node不在线"/utf8>>}, State}
|
||||||
|
end;
|
||||||
|
|
||||||
|
%% 触发acl改变
|
||||||
|
handle_call({acl_changed, ReceiverPid, ClientId, SubCommand}, _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}} ->
|
||||||
|
Ref = make_ref(),
|
||||||
|
sdlan_quic_transport:command(ChannelPid, Ref, ReceiverPid, SubCommand),
|
||||||
{reply, {ok, Ref}, State};
|
{reply, {ok, Ref}, State};
|
||||||
error ->
|
error ->
|
||||||
{reply, {error, <<"目标Node不在线"/utf8>>}, State}
|
{reply, {error, <<"目标Node不在线"/utf8>>}, State}
|
||||||
@ -363,7 +381,7 @@ handle_cast({update_hole, SessionToken, ClientId, Mac, Peer, NatType, V6Info}, S
|
|||||||
|
|
||||||
logger:debug("[sdlan_network] Event: nat_changed, update_hole, client_id: ~p(~p), hole changed", [ClientId, Ip]),
|
logger:debug("[sdlan_network] Event: nat_changed, update_hole, client_id: ~p(~p), hole changed", [ClientId, Ip]),
|
||||||
broadcast(fun(#endpoint{channel_pid = ChannelPid}) ->
|
broadcast(fun(#endpoint{channel_pid = ChannelPid}) ->
|
||||||
sdlan_quic_channel:send_event(ChannelPid, NatChangedEvent)
|
sdlan_quic_transport:send_event(ChannelPid, NatChangedEvent)
|
||||||
end, [Mac], EndpointTable)
|
end, [Mac], EndpointTable)
|
||||||
end,
|
end,
|
||||||
NEndpoint = Endpoint0#endpoint{hole = NHole, v6_info = V6Info, last_seen = erlang:monotonic_time(second)},
|
NEndpoint = Endpoint0#endpoint{hole = NHole, v6_info = V6Info, last_seen = erlang:monotonic_time(second)},
|
||||||
@ -410,8 +428,8 @@ terminate(Reason, #state{network_id = NetworkId, endpoint_table = EndpointTable}
|
|||||||
|
|
||||||
logger:debug("[sdlan_network] Event: shutdown"),
|
logger:debug("[sdlan_network] Event: shutdown"),
|
||||||
|
|
||||||
sdlan_quic_channel:send_event(ChannelPid, NetworkShutdownEvent),
|
sdlan_quic_transport:send_event(ChannelPid, NetworkShutdownEvent),
|
||||||
sdlan_quic_channel:stop(ChannelPid, normal);
|
sdlan_quic_transport:stop(ChannelPid, normal);
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
@ -572,7 +590,7 @@ maybe_nat_changed(ChannelPid, Mac, Ip, EndpointTable) ->
|
|||||||
logger:debug("Event: nat_changed, for attach"),
|
logger:debug("Event: nat_changed, for attach"),
|
||||||
|
|
||||||
broadcast(fun(#endpoint{channel_pid = ChannelPid0}) ->
|
broadcast(fun(#endpoint{channel_pid = ChannelPid0}) ->
|
||||||
sdlan_quic_channel:send_event(ChannelPid0, Event)
|
sdlan_quic_transport:send_event(ChannelPid0, Event)
|
||||||
end, [Mac], EndpointTable)
|
end, [Mac], EndpointTable)
|
||||||
end,
|
end,
|
||||||
%% 重复attach需要清理之前的绑定信息;即使IP未变化,也不能保留旧channel。
|
%% 重复attach需要清理之前的绑定信息;即使IP未变化,也不能保留旧channel。
|
||||||
@ -584,7 +602,7 @@ cleanup_endpoint(#endpoint{channel_ref = ChannelRef, channel_pid = ChannelPid},
|
|||||||
is_reference(ChannelRef) andalso erlang:demonitor(ChannelRef, [flush]),
|
is_reference(ChannelRef) andalso erlang:demonitor(ChannelRef, [flush]),
|
||||||
case should_stop_channel(ChannelPid, KeepChannelPid) of
|
case should_stop_channel(ChannelPid, KeepChannelPid) of
|
||||||
true ->
|
true ->
|
||||||
catch sdlan_quic_channel:stop(ChannelPid, Reason),
|
catch sdlan_quic_transport:stop(ChannelPid, Reason),
|
||||||
ok;
|
ok;
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
|
|||||||
@ -76,12 +76,12 @@ init([]) ->
|
|||||||
},
|
},
|
||||||
|
|
||||||
#{
|
#{
|
||||||
id => sdlan_quic_channel_sup,
|
id => sdlan_quic_transport_sup,
|
||||||
start => {sdlan_quic_channel_sup, start_link, []},
|
start => {sdlan_quic_transport_sup, start_link, []},
|
||||||
restart => permanent,
|
restart => permanent,
|
||||||
shutdown => 2000,
|
shutdown => 2000,
|
||||||
type => supervisor,
|
type => supervisor,
|
||||||
modules => ['sdlan_quic_channel_sup']
|
modules => ['sdlan_quic_transport_sup']
|
||||||
},
|
},
|
||||||
|
|
||||||
#{
|
#{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user