From c3c5873cc077d7286587ef994771ec7c8080cfe3 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Fri, 1 May 2026 15:38:14 +0800 Subject: [PATCH] fix network ets --- src/sdlan_network.erl | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/sdlan_network.erl b/src/sdlan_network.erl index 50429bf..7ed9b03 100644 --- a/src/sdlan_network.erl +++ b/src/sdlan_network.erl @@ -13,8 +13,6 @@ -behaviour(gen_server). --define(FLOW_REPORT_INTERVAL, 60 * 1000). - %% broadcast, "FF-FF-FF-FF-FF-FF" -define(BROADCAST_MAC, <<16#FF,16#FF,16#FF,16#FF,16#FF,16#FF>>). @@ -64,9 +62,7 @@ %% 设置网络带宽 throttle_key :: atom(), - endpoint_table :: ets:tid(), - %% 转发流量统计 - forward_bytes = 0 + endpoint_table :: ets:tid() }). %%%=================================================================== @@ -192,9 +188,6 @@ init([Id]) when is_integer(Id) -> %% 绑定到资源协调器 sdlan_network_coordinator:attach(self(), ThrottleKey), - %% 每分钟汇报一次转发的流量 - erlang:start_timer(?FLOW_REPORT_INTERVAL, self(), flow_report_ticker), - sdlan_domain_regedit:insert(Domain), %% 处理加密算法 @@ -383,21 +376,14 @@ handle_cast({update_hole, SessionToken, ClientId, Mac, Peer, NatType, V6Info}, S {noreply, NewState :: #state{}} | {noreply, NewState :: #state{}, timeout() | hibernate} | {stop, Reason :: term(), NewState :: #state{}}). -handle_info({timeout, _, flow_report_ticker}, State = #state{network_id = NetworkId, forward_bytes = ForwardBytes}) -> - erlang:start_timer(?FLOW_REPORT_INTERVAL, self(), flow_report_ticker), - case ForwardBytes > 0 of - true -> - catch sdlan_api:network_forward_report(NetworkId, ForwardBytes); - false -> - ok - end, - logger:debug("[sdlan_network] metrics: ~p", [network_metrics(State)]), - {noreply, State#state{forward_bytes = 0}}; - %% Channel进程退出, hole里面的数据也需要清理 handle_info({'DOWN', _MRef, process, ChannelPid, Reason}, State = #state{network_id = NetworkId, endpoint_table = EndpointTable}) -> logger:notice("[sdlan_network] network_id: ~p, channel_pid: ~p, close with reason: ~p", [NetworkId, ChannelPid, Reason]), remove_channel_endpoints(ChannelPid, EndpointTable), + {noreply, State}; + +handle_info(Info, State) -> + logger:debug("[sdlan_network] get unknown info: ~p", [Info]), {noreply, State}. %% @private @@ -651,12 +637,11 @@ format_endpoint({Mac, #endpoint{client_id = ClientId, ip = Ip, hole = undefined, v6_info => V6InfoMap }. -network_metrics(#state{network_id = NetworkId, endpoint_table = EndpointTable, forward_bytes = ForwardBytes}) -> +network_metrics(#state{network_id = NetworkId, endpoint_table = EndpointTable}) -> ProcInfo = maps:from_list(process_info(self(), [message_queue_len, memory, reductions])), ProcInfo#{ network_id => NetworkId, endpoint_count => endpoint_count(EndpointTable), - forward_bytes => ForwardBytes, channel_metrics => channel_metrics(EndpointTable) }.