fix network

This commit is contained in:
anlicheng 2026-03-17 15:11:02 +08:00
parent 55204a4204
commit c5abfd698a

View File

@ -18,9 +18,6 @@
%% broadcast, "FF-FF-FF-FF-FF-FF" %% broadcast, "FF-FF-FF-FF-FF-FF"
-define(BROADCAST_MAC, <<16#FF,16#FF,16#FF,16#FF,16#FF,16#FF>>). -define(BROADCAST_MAC, <<16#FF,16#FF,16#FF,16#FF,16#FF,16#FF>>).
%% salt
-define(REGION_SALT, "salt_fG7xQp2BzH9L").
%% 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]).
@ -232,7 +229,7 @@ handle_call({attach, ChannelPid, ClientId, Mac, Ip, Hostname}, _From,
client_id = ClientId, mac = Mac, ip = Ip, hostname = Hostname, session_token = SessionToken, last_seen = erlang:monotonic_time(second)}, client_id = ClientId, mac = Mac, ip = Ip, hostname = Hostname, session_token = SessionToken, last_seen = erlang:monotonic_time(second)},
%% id %% id
RegionId = gen_region_id(Ip, ?REGION_SALT), RegionId = gen_region_id(Ip),
{reply, {ok, Algorithm, Key, RegionId, SessionToken}, State#state{endpoints = maps:put(Mac, Endpoint, Endpoints)}}; {reply, {ok, Algorithm, Key, RegionId, SessionToken}, State#state{endpoints = maps:put(Mac, Endpoint, Endpoints)}};
@ -412,7 +409,7 @@ handle_info({'DOWN', _MRef, process, ChannelPid, Reason}, State = #state{network
%% necessary cleaning up. When it returns, the gen_server terminates %% necessary cleaning up. When it returns, the gen_server terminates
%% with Reason. The return value is ignored. %% with Reason. The return value is ignored.
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()), -spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
State :: #state{}) -> term()). State :: #state{}) -> none()).
terminate(Reason, #state{network_id = NetworkId, endpoints = Endpoints}) -> terminate(Reason, #state{network_id = NetworkId, endpoints = Endpoints}) ->
broadcast(fun(#endpoint{channel_pid = ChannelPid}) -> broadcast(fun(#endpoint{channel_pid = ChannelPid}) ->
case is_process_alive(ChannelPid) of case is_process_alive(ChannelPid) of
@ -541,12 +538,12 @@ gen_key(<<"aes">>) ->
gen_key(<<"chacha20">>) -> gen_key(<<"chacha20">>) ->
sdlan_util:rand_byte(32). sdlan_util:rand_byte(32).
-spec gen_region_id(IpInt :: integer(), Salt :: string()) -> integer(). -spec gen_region_id(IpInt :: integer()) -> integer().
gen_region_id(IpInt, Salt) -> gen_region_id(IpInt) ->
%% IP %% IP
IpStr = integer_to_list(IpInt), IpStr = integer_to_list(IpInt),
%% %%
FullStr = Salt ++ IpStr, FullStr = "salt_fG7xQp2BzH9L" ++ IpStr,
time33(FullStr, 5381). time33(FullStr, 5381).
%% Time33算法 %% Time33算法