fix
This commit is contained in:
parent
771896045b
commit
ab74389f07
@ -164,7 +164,7 @@ handle_info({tcp, Sock, <<PacketId:32, ?PACKET_REGISTER_SUPER, Body/binary>>}, S
|
||||
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",
|
||||
[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)),
|
||||
logger:debug("[sdlan_channel] client_id: ~p, set none online, result is: ~p", [ClientId, Result]),
|
||||
|
||||
@ -56,7 +56,16 @@ init([Port]) ->
|
||||
%% 需要提高进程的调度优先级
|
||||
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()),
|
||||
logger:debug("[sdlan_stun] start at port: ~p", [Port]),
|
||||
|
||||
|
||||
46
apps/sdlan/src/sdlan_stun_sup.erl
Normal file
46
apps/sdlan/src/sdlan_stun_sup.erl
Normal 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}}.
|
||||
@ -45,6 +45,7 @@ init([]) ->
|
||||
type => worker,
|
||||
modules => ['sdlan_network_coordinator']
|
||||
},
|
||||
|
||||
#{
|
||||
id => sdlan_network_sup,
|
||||
start => {sdlan_network_sup, start_link, []},
|
||||
@ -52,6 +53,15 @@ init([]) ->
|
||||
shutdown => 2000,
|
||||
type => supervisor,
|
||||
modules => ['sdlan_network_sup']
|
||||
},
|
||||
|
||||
#{
|
||||
id => sdlan_stun_sup,
|
||||
start => {sdlan_stun_sup, start_link, []},
|
||||
restart => permanent,
|
||||
shutdown => 2000,
|
||||
type => supervisor,
|
||||
modules => ['sdlan_stun_sup']
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
@ -18,8 +18,24 @@
|
||||
%% 网络带宽, 单位为: kb
|
||||
{band_width, 2048},
|
||||
|
||||
{stun_servers, [{'sdlan_stun:1:1', 1265}, {'sdlan_stun:1:2', 1266}]},
|
||||
{stun_assist, {{47,98,178,3}, 1266}},
|
||||
%% stun类型探测相当于有个类型
|
||||
{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}]},
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user