增加对域名的支持
This commit is contained in:
parent
7cbc95759e
commit
55c658a733
26
API.md
26
API.md
@ -45,6 +45,7 @@ return:
|
|||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "网络1",
|
"name": "网络1",
|
||||||
"ipaddr": "192.168.0.1/24",
|
"ipaddr": "192.168.0.1/24",
|
||||||
|
"domain": "punchnet.cn",
|
||||||
"owner_id": 1234,
|
"owner_id": 1234,
|
||||||
"disabled_clients": ["client_id_xyz", "client_id_xyz1"]
|
"disabled_clients": ["client_id_xyz", "client_id_xyz1"]
|
||||||
}
|
}
|
||||||
@ -78,6 +79,31 @@ return:
|
|||||||
code = 2, Client Connection Disable
|
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.设置节点的状态
|
### 4.设置节点的状态
|
||||||
```text
|
```text
|
||||||
url: /api/set_node_status
|
url: /api/set_node_status
|
||||||
|
|||||||
@ -139,7 +139,7 @@ handle_info({tcp, Sock, <<PacketId:32, ?PACKET_REGISTER_SUPER, Body/binary>>}, S
|
|||||||
case sdlan_network:get_pid(NetworkId) of
|
case sdlan_network:get_pid(NetworkId) of
|
||||||
NetworkPid when is_pid(NetworkPid) ->
|
NetworkPid when is_pid(NetworkPid) ->
|
||||||
try sdlan_network:assign_ip_addr(NetworkPid, self(), ClientId, Mac, NetAddr0) of
|
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),
|
RsaPubKey = sdlan_cipher:rsa_pem_decode(PubKey),
|
||||||
EncodedAesKey = rsa_encode(AesKey, RsaPubKey),
|
EncodedAesKey = rsa_encode(AesKey, RsaPubKey),
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ handle_info({move_network, ReceiverPid, Ref, NetworkPid},
|
|||||||
|
|
||||||
%% 建立到network的对应关系
|
%% 建立到network的对应关系
|
||||||
case sdlan_network:assign_ip_addr(NetworkPid, self(), ClientId, Mac, 0) of
|
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),
|
RsaPubKey = sdlan_cipher:rsa_pem_decode(PubKey),
|
||||||
EncodedAesKey = rsa_encode(AesKey, RsaPubKey),
|
EncodedAesKey = rsa_encode(AesKey, RsaPubKey),
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,7 @@
|
|||||||
-record(state, {
|
-record(state, {
|
||||||
network_id :: integer(),
|
network_id :: integer(),
|
||||||
name :: binary(),
|
name :: binary(),
|
||||||
|
domain :: binary(),
|
||||||
ipaddr :: binary(),
|
ipaddr :: binary(),
|
||||||
mask_len :: integer(),
|
mask_len :: integer(),
|
||||||
owner_id :: integer(),
|
owner_id :: integer(),
|
||||||
@ -90,7 +91,7 @@ reload(Pid) when is_pid(Pid) ->
|
|||||||
gen_server:call(Pid, reload).
|
gen_server:call(Pid, reload).
|
||||||
|
|
||||||
-spec assign_ip_addr(Pid :: pid(), ChannelPid :: pid(), ClientId :: binary(), Mac :: binary(), NetAddr :: integer()) ->
|
-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) ->
|
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}).
|
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
|
case sdlan_api:get_network(Id) of
|
||||||
{ok, #{<<"ipaddr">> := Null}} when Null == <<"null">>; Null == <<"NULL">> ->
|
{ok, #{<<"ipaddr">> := Null}} when Null == <<"null">>; Null == <<"NULL">> ->
|
||||||
ignore;
|
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),
|
{IpAddr, MaskLen} = parse_ipaddr(IpAddr0),
|
||||||
Ips = sdlan_ipaddr:ips(IpAddr, MaskLen),
|
Ips = sdlan_ipaddr:ips(IpAddr, MaskLen),
|
||||||
AesKey = sdlan_util:rand_byte(32),
|
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)]),
|
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} ->
|
{error, Reason} ->
|
||||||
lager:warning("[sdlan_network] load network: ~p, get error: ~p", [Id, Reason]),
|
lager:warning("[sdlan_network] load network: ~p, get error: ~p", [Id, Reason]),
|
||||||
ignore
|
ignore
|
||||||
@ -221,7 +222,7 @@ handle_call(reload, _From, State = #state{network_id = Id, ipaddr = OldIpAddr, m
|
|||||||
|
|
||||||
%% 给客户端分配ip地址
|
%% 给客户端分配ip地址
|
||||||
handle_call({assign_ip_addr, ChannelPid, ClientId, Mac, NetAddr0}, _From,
|
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地址为唯一基准
|
%% 分配ip地址的时候,以mac地址为唯一基准
|
||||||
lager:debug("[sdlan_network] alloc_ip, network_id: ~p, ips: ~p, client_id: ~p, mac: ~p, net_addr: ~p",
|
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),
|
MRef = monitor(process, ChannelPid),
|
||||||
NUsedMap = maps:put(Mac, #host{client_id = ClientId, mac = Mac, ip = Ip, channel_pid = ChannelPid, monitor_ref = MRef}, UsedMap),
|
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} ->
|
{error, Reason} ->
|
||||||
{reply, {error, Reason}, State}
|
{reply, {error, Reason}, State}
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -16,9 +16,10 @@ message SDLV6Info {
|
|||||||
// 设备网络地址信息
|
// 设备网络地址信息
|
||||||
message SDLDevAddr {
|
message SDLDevAddr {
|
||||||
uint32 network_id = 1;
|
uint32 network_id = 1;
|
||||||
bytes mac = 2;
|
string network_domain = 2;
|
||||||
uint32 net_addr = 3;
|
bytes mac = 3;
|
||||||
uint32 net_bit_len = 4;
|
uint32 net_addr = 4;
|
||||||
|
uint32 net_bit_len = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tcp通讯消息
|
// tcp通讯消息
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user