From 55c658a7335d97d3cb528f3d65324fea7d12a867 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sat, 13 Dec 2025 17:11:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API.md | 26 ++++++++++++++++++++++++++ apps/sdlan/src/sdlan_channel.erl | 4 ++-- apps/sdlan/src/sdlan_network.erl | 11 ++++++----- message.proto | 7 ++++--- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/API.md b/API.md index 02f65d1..601c448 100644 --- a/API.md +++ b/API.md @@ -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 diff --git a/apps/sdlan/src/sdlan_channel.erl b/apps/sdlan/src/sdlan_channel.erl index 73985d9..8c8e19c 100644 --- a/apps/sdlan/src/sdlan_channel.erl +++ b/apps/sdlan/src/sdlan_channel.erl @@ -139,7 +139,7 @@ handle_info({tcp, Sock, <>}, 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), diff --git a/apps/sdlan/src/sdlan_network.erl b/apps/sdlan/src/sdlan_network.erl index f5e4f85..0513d0c 100644 --- a/apps/sdlan/src/sdlan_network.erl +++ b/apps/sdlan/src/sdlan_network.erl @@ -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; diff --git a/message.proto b/message.proto index 9e4c270..4256b36 100644 --- a/message.proto +++ b/message.proto @@ -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通讯消息