packet struct

This commit is contained in:
asxalex 2024-03-07 22:53:45 +08:00
parent 42f3da666b
commit 6e66713b43
5 changed files with 57 additions and 3 deletions

View File

@ -1,5 +1,5 @@
# sdlan-sn设计 # sdlan-sn设计
服务端为单体应用,多个服务端可以同时启动,后面的服务端启动时,可以指定`--fedration x.x.x.x:7655,y.y.y.y:7656`命令行参数来指定其他的服务端,服务端将其他服务端的信息保存在`fedration`这个network里面。 服务端为单体应用,多个服务端可以同时启动,后面的服务端启动时,可以指定`--federation x.x.x.x:7655,y.y.y.y:7656`命令行参数来指定其他的服务端,服务端将其他服务端的信息保存在`federation`这个network里面。
比如有如下的结构: 比如有如下的结构:

21
docs/interactive.md Normal file
View File

@ -0,0 +1,21 @@
# sdlan交互逻辑
sdlan节点上线流程如下
1. 用户在平台注册,获取自身`user_id`,这个`user_id`有可以创建网络个数和可以上线机器数量的限制。
2. 用户创建一个或者多个token得到`token_id``token_id`可以设置过期时间。
3. 运行客户端,填写`token_id`,将机器纳入到自己的管理域。
当一个`token_id`过期则使用该id的节点在他注册的sn上会下线并告知id过期。之后如果使用该过期id上线就会立即下线。但是如果此时该节点使用另外一个有效的token上线
* 该新的token为同一个用户的另一个token
* 该token有效
* 该token无效
* 该新的token为另一个用户的token:
* 该token有效
* 该token无效
当一个`token_id`被删除则该节点会在他注册的sn上被删除并且数据库删除该节点的网络信息以及与token的绑定信息。该节点成为自由节点
当一个节点上次用某个用户的token登录之后然后下次使用同一个用户的另外的token登录是否允许应该允许
当一个节点上次用某个用户的token登录之后下次使用另一个用户的token登录是否允许

View File

@ -1,9 +1,23 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_repr::{Deserialize_repr, Serialize_repr};
#[derive(Debug, PartialEq, Serialize_repr, Deserialize_repr, Copy, Clone)]
#[repr(u8)]
pub enum CommandType {
AuthorizePeer,
MovePeer,
}
#[derive(Serialize, Deserialize)]
pub struct Command { pub struct Command {
pub cookie: u32, pub cmd_type: CommandType,
pub message: Value,
} }
#[derive(Serialize, Deserialize)]
pub struct CommandResp { pub struct CommandResp {
pub cookie: u32, cmd_type: CommandType,
resp_code: i8,
resp_information: Value,
} }

View File

@ -67,6 +67,17 @@ impl<'a> Common<'a> {
Ok((common, &value[7 + id_len..])) Ok((common, &value[7 + id_len..]))
} }
pub fn from_old_common(cmn: &'a Common) -> Self {
return Common {
packet_id: cmn.packet_id,
id: cmn.id,
version: cmn.version,
ttl: cmn.ttl,
pc: cmn.pc,
flags: cmn.flags,
};
}
pub fn new(id: &'a str) -> Self { pub fn new(id: &'a str) -> Self {
return Common { return Common {
packet_id: 0, packet_id: 0,

View File

@ -121,3 +121,11 @@ pub fn ip_to_string(ip: u32) -> String {
(ip & 0xff) as u8, (ip & 0xff) as u8,
) )
} }
pub fn net_bit_len_to_mask(len: u8) -> u32 {
let mut res = 0u32;
for i in 1..=len {
res |= 1 << (32 - i);
}
res
}