增加对域名的支持

This commit is contained in:
anlicheng 2025-12-13 17:11:38 +08:00
parent 7cbc95759e
commit 55c658a733
4 changed files with 38 additions and 10 deletions

26
API.md
View File

@ -45,6 +45,7 @@ return:
"id": 1,
"name": "网络1",
"ipaddr": "192.168.0.1/24",
"domain": "punchnet.cn",
"owner_id": 1234,
"disabled_clients": ["client_id_xyz", "client_id_xyz1"]
}
@ -78,6 +79,31 @@ return:
code = 2, Client Connection Disable
```
### 3.网络校验
```text
url: /api/check_network
method: post
params:
client_id: string
code: string,
version: int // 当前客户端版本
return:
{"result":
{
"network_id": 8,
"upgrade_type": 0, // 升级类型0: 不升级1: 普通升级2: 强制升级
"upgrade_prompt": "升级提升语"
"upgrade_address": "升级提升语"
}
}
{"error": {"code": 1, "message": "错误描述"}}
code = 1, Token does not exists
code = 2, Client Connection Disable
```
### 4.设置节点的状态
```text
url: /api/set_node_status

View File

@ -139,7 +139,7 @@ handle_info({tcp, Sock, <<PacketId:32, ?PACKET_REGISTER_SUPER, Body/binary>>}, S
case sdlan_network:get_pid(NetworkId) of
NetworkPid when is_pid(NetworkPid) ->
try sdlan_network:assign_ip_addr(NetworkPid, self(), ClientId, Mac, NetAddr0) of
{ok, NetAddr, NetBitLen, AesKey} ->
{ok, Domain, NetAddr, NetBitLen, AesKey} ->
RsaPubKey = sdlan_cipher:rsa_pem_decode(PubKey),
EncodedAesKey = rsa_encode(AesKey, RsaPubKey),
@ -253,7 +253,7 @@ handle_info({move_network, ReceiverPid, Ref, NetworkPid},
%% network的对应关系
case sdlan_network:assign_ip_addr(NetworkPid, self(), ClientId, Mac, 0) of
{ok, NetAddr, NetBitLen, AesKey} ->
{ok, Domain, NetAddr, NetBitLen, AesKey} ->
RsaPubKey = sdlan_cipher:rsa_pem_decode(PubKey),
EncodedAesKey = rsa_encode(AesKey, RsaPubKey),

View File

@ -48,6 +48,7 @@
-record(state, {
network_id :: integer(),
name :: binary(),
domain :: binary(),
ipaddr :: binary(),
mask_len :: integer(),
owner_id :: integer(),
@ -90,7 +91,7 @@ reload(Pid) when is_pid(Pid) ->
gen_server:call(Pid, reload).
-spec assign_ip_addr(Pid :: pid(), ChannelPid :: pid(), ClientId :: binary(), Mac :: binary(), NetAddr :: integer()) ->
{ok, NetAddr :: integer(), MaskLen :: integer(), AesKey :: binary()} | {error, Reason :: any()}.
{ok, Domain :: binary(), NetAddr :: integer(), MaskLen :: integer(), AesKey :: binary()} | {error, Reason :: any()}.
assign_ip_addr(Pid, ChannelPid, ClientId, Mac, NetAddr) when is_pid(Pid), is_pid(ChannelPid), is_binary(ClientId), is_binary(Mac), is_integer(NetAddr) ->
gen_server:call(Pid, {assign_ip_addr, ChannelPid, ClientId, Mac, NetAddr}).
@ -159,7 +160,7 @@ init([Id]) when is_integer(Id) ->
case sdlan_api:get_network(Id) of
{ok, #{<<"ipaddr">> := Null}} when Null == <<"null">>; Null == <<"NULL">> ->
ignore;
{ok, #{<<"id">> := Id, <<"name">> := Name, <<"ipaddr">> := IpAddr0, <<"owner_id">> := OwnerId}} ->
{ok, #{<<"id">> := Id, <<"name">> := Name, <<"domain">> := Domain, <<"ipaddr">> := IpAddr0, <<"owner_id">> := OwnerId}} ->
{IpAddr, MaskLen} = parse_ipaddr(IpAddr0),
Ips = sdlan_ipaddr:ips(IpAddr, MaskLen),
AesKey = sdlan_util:rand_byte(32),
@ -176,7 +177,7 @@ init([Id]) when is_integer(Id) ->
lager:debug("[sdlan_network] network: ~p, ips: ~p", [Id, lists:map(fun sdlan_ipaddr:int_to_ipv4/1, Ips)]),
{ok, #state{network_id = Id, name = Name, ipaddr = IpAddr, owner_id = OwnerId, mask_len = MaskLen, ips = Ips, aes_key = AesKey, throttle_key = ThrottleKey}};
{ok, #state{network_id = Id, name = Name, domain = Domain, ipaddr = IpAddr, owner_id = OwnerId, mask_len = MaskLen, ips = Ips, aes_key = AesKey, throttle_key = ThrottleKey}};
{error, Reason} ->
lager:warning("[sdlan_network] load network: ~p, get error: ~p", [Id, Reason]),
ignore
@ -221,7 +222,7 @@ handle_call(reload, _From, State = #state{network_id = Id, ipaddr = OldIpAddr, m
%% ip地址
handle_call({assign_ip_addr, ChannelPid, ClientId, Mac, NetAddr0}, _From,
State = #state{network_id = NetworkId, ips = Ips, used_map = UsedMap, mask_len = MaskLen, aes_key = AesKey}) ->
State = #state{network_id = NetworkId, domain = Domain, ips = Ips, used_map = UsedMap, mask_len = MaskLen, aes_key = AesKey}) ->
%% ip地址的时候mac地址为唯一基准
lager:debug("[sdlan_network] alloc_ip, network_id: ~p, ips: ~p, client_id: ~p, mac: ~p, net_addr: ~p",
@ -236,7 +237,7 @@ handle_call({assign_ip_addr, ChannelPid, ClientId, Mac, NetAddr0}, _From,
MRef = monitor(process, ChannelPid),
NUsedMap = maps:put(Mac, #host{client_id = ClientId, mac = Mac, ip = Ip, channel_pid = ChannelPid, monitor_ref = MRef}, UsedMap),
{reply, {ok, Ip, MaskLen, AesKey}, State#state{used_map = NUsedMap}};
{reply, {ok, Domain, Ip, MaskLen, AesKey}, State#state{used_map = NUsedMap}};
{error, Reason} ->
{reply, {error, Reason}, State}
end;

View File

@ -16,9 +16,10 @@ message SDLV6Info {
//
message SDLDevAddr {
uint32 network_id = 1;
bytes mac = 2;
uint32 net_addr = 3;
uint32 net_bit_len = 4;
string network_domain = 2;
bytes mac = 3;
uint32 net_addr = 4;
uint32 net_bit_len = 5;
}
// tcp通讯消息