fix network
This commit is contained in:
parent
55204a4204
commit
c5abfd698a
@ -18,9 +18,6 @@
|
||||
%% broadcast, "FF-FF-FF-FF-FF-FF"
|
||||
-define(BROADCAST_MAC, <<16#FF,16#FF,16#FF,16#FF,16#FF,16#FF>>).
|
||||
|
||||
%% 分区salt
|
||||
-define(REGION_SALT, "salt_fG7xQp2BzH9L").
|
||||
|
||||
%% API
|
||||
-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]).
|
||||
@ -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)},
|
||||
|
||||
%% 生成对应的分区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)}};
|
||||
|
||||
@ -412,7 +409,7 @@ handle_info({'DOWN', _MRef, process, ChannelPid, Reason}, State = #state{network
|
||||
%% necessary cleaning up. When it returns, the gen_server terminates
|
||||
%% with Reason. The return value is ignored.
|
||||
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
|
||||
State :: #state{}) -> term()).
|
||||
State :: #state{}) -> none()).
|
||||
terminate(Reason, #state{network_id = NetworkId, endpoints = Endpoints}) ->
|
||||
broadcast(fun(#endpoint{channel_pid = ChannelPid}) ->
|
||||
case is_process_alive(ChannelPid) of
|
||||
@ -541,12 +538,12 @@ gen_key(<<"aes">>) ->
|
||||
gen_key(<<"chacha20">>) ->
|
||||
sdlan_util:rand_byte(32).
|
||||
|
||||
-spec gen_region_id(IpInt :: integer(), Salt :: string()) -> integer().
|
||||
gen_region_id(IpInt, Salt) ->
|
||||
-spec gen_region_id(IpInt :: integer()) -> integer().
|
||||
gen_region_id(IpInt) ->
|
||||
%% 把整数 IP 转成字符串
|
||||
IpStr = integer_to_list(IpInt),
|
||||
%% 拼接盐
|
||||
FullStr = Salt ++ IpStr,
|
||||
FullStr = "salt_fG7xQp2BzH9L" ++ IpStr,
|
||||
time33(FullStr, 5381).
|
||||
|
||||
%% 核心Time33算法
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user