This commit is contained in:
anlicheng 2026-01-22 16:00:52 +08:00
parent 771896045b
commit ab74389f07
5 changed files with 85 additions and 4 deletions

View File

@ -164,7 +164,7 @@ handle_info({tcp, Sock, <<PacketId:32, ?PACKET_REGISTER_SUPER, Body/binary>>}, S
Transport:send(Sock, Reply), Transport:send(Sock, Reply),
logger:debug("[sdlan_channel] client_id: ~p, mac: ~p, alloc ip: ~p, register will send ack, aes_key: ~p, enc_aes_key: ~p", logger:debug("[sdlan_channel] client_id: ~p, mac: ~p, alloc ip: ~p, register will send ack, aes_key: ~p, enc_aes_key: ~p",
[ClientId, sdlan_util:format_mac(Mac), sdlan_ipaddr:int_to_ipv4(NetAddr), AesKey, EncodedAesKey]), [ClientId, sdlan_util:format_mac(Mac), sdlan_ipaddr:int_to_ipv4(NetAddr), AesKey, EncodedAesKey]),
%% 线 %% 线
Result = sdlan_api:node_online(ClientId, NetworkId, sdlan_ipaddr:int_to_ipv4(NetAddr)), Result = sdlan_api:node_online(ClientId, NetworkId, sdlan_ipaddr:int_to_ipv4(NetAddr)),
logger:debug("[sdlan_channel] client_id: ~p, set none online, result is: ~p", [ClientId, Result]), logger:debug("[sdlan_channel] client_id: ~p, set none online, result is: ~p", [ClientId, Result]),

View File

@ -56,7 +56,16 @@ init([Port]) ->
%% %%
erlang:process_flag(priority, max), erlang:process_flag(priority, max),
{ok, Socket} = gen_udp:open(Port, [binary, {active, true}, {recbuf, 5 * 1024 * 1024}, {sndbuf, 5 * 1024 * 1024}]), Opts = [
binary,
{reuseaddr, true},
{reuseport, true},
{active, true},
{recbuf, 5 * 1024 * 1024},
{sndbuf, 5 * 1024 * 1024}
],
{ok, Socket} = gen_udp:open(Port, Opts),
inet_udp:controlling_process(Socket, self()), inet_udp:controlling_process(Socket, self()),
logger:debug("[sdlan_stun] start at port: ~p", [Port]), logger:debug("[sdlan_stun] start at port: ~p", [Port]),

View File

@ -0,0 +1,46 @@
%%%-------------------------------------------------------------------
%% @doc sdlan top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module(sdlan_stun_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
-define(SERVER, ?MODULE).
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%% sup_flags() = #{strategy => strategy(), % optional
%% intensity => non_neg_integer(), % optional
%% period => pos_integer()} % optional
%% child_spec() = #{id => child_id(), % mandatory
%% start => mfargs(), % mandatory
%% restart => restart(), % optional
%% shutdown => shutdown(), % optional
%% type => worker(), % optional
%% modules => modules()} % optional
init([]) ->
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
{ok, StunServerProps} = application:get_env(sdlan, stun_servers),
Port = proplists:get_value(port, StunServerProps),
AcceptorNums = proplists:get_value(acceptor_nums, StunServerProps),
Specs = lists:map(fun(Id) ->
Name = sdlan_stun:get_name(Id),
#{
id => Name,
start => {sdlan_stun, start_link, [Name, Port]},
restart => permanent,
shutdown => 2000,
type => worker,
modules => ['sdlan_stun']
}
end, lists:seq(1, AcceptorNums)),
{ok, {SupFlags, Specs}}.

View File

@ -45,6 +45,7 @@ init([]) ->
type => worker, type => worker,
modules => ['sdlan_network_coordinator'] modules => ['sdlan_network_coordinator']
}, },
#{ #{
id => sdlan_network_sup, id => sdlan_network_sup,
start => {sdlan_network_sup, start_link, []}, start => {sdlan_network_sup, start_link, []},
@ -52,6 +53,15 @@ init([]) ->
shutdown => 2000, shutdown => 2000,
type => supervisor, type => supervisor,
modules => ['sdlan_network_sup'] modules => ['sdlan_network_sup']
},
#{
id => sdlan_stun_sup,
start => {sdlan_stun_sup, start_link, []},
restart => permanent,
shutdown => 2000,
type => supervisor,
modules => ['sdlan_stun_sup']
} }
], ],

View File

@ -18,8 +18,24 @@
%% 网络带宽, 单位为: kb %% 网络带宽, 单位为: kb
{band_width, 2048}, {band_width, 2048},
{stun_servers, [{'sdlan_stun:1:1', 1265}, {'sdlan_stun:1:2', 1266}]}, %% stun类型探测相当于有个类型
{stun_assist, {{47,98,178,3}, 1266}}, {stun_servers, [
{port, 1265},
{acceptor_nums, 50}
]},
{stun_port_assist, [
{port, 1266}
]},
{stun_peer_assist, [
{ip, {47,98,178,3}},
{port, 1266}
]},
%{stun_assist, {{47,98,178,3}, 1266}},
%{stun_servers, [{'sdlan_stun:1:1', 1265}, {'sdlan_stun:1:2', 1266}]},
%{stun_assist, {{47,98,178,3}, 1266}},
% {stun_servers, [{'sdlan_stun:2:1', 1265}, {'sdlan_stun:2:2', 1266}]}, % {stun_servers, [{'sdlan_stun:2:1', 1265}, {'sdlan_stun:2:2', 1266}]},