From f320526f2dc1f6c3154b9ade81c556af0d068378 Mon Sep 17 00:00:00 2001 From: asxalex Date: Thu, 20 Jun 2024 23:02:44 +0800 Subject: [PATCH] added encode error --- Cargo.toml | 1 + docs/http_api.md | 5 ++++- docs/protocol.md | 2 +- src/utils/error.rs | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9acbed..db8e947 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ dashmap = "5.5.3" futures = "0.3.30" # lazy_static = "1.4.0" once_cell = "1.19.0" +prost = "0.12.6" rand = "0.8.5" rolling-file = { git = "https://git.asxalex.pw/rust/rolling-file" } rsa = "0.9.6" diff --git a/docs/http_api.md b/docs/http_api.md index fa57741..bcfe250 100644 --- a/docs/http_api.md +++ b/docs/http_api.md @@ -219,4 +219,7 @@ POST /peer/unauthorize // 如果code不为0,则error表示出错信息 "error": $string } -``` \ No newline at end of file +``` + +# 2.0 sdlan中心节点使用的数据库结构 +在中心节点收到客户端上线请求之后,如果这个节点是第一次上线,则会将相关信息插入到 \ No newline at end of file diff --git a/docs/protocol.md b/docs/protocol.md index b59b2f4..75236eb 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -26,7 +26,7 @@ sdlan协议的总体格式如下: 其中,version占用一个字节,用于标识协议版本。id用于唯一标识某个客户端,为长度为32字节的uuid,token是用户生成的邀请码,占用8个字节(64比特的大端序整型数字)。之后的ttl占用一个字节,当ttl为0,则直接丢弃该数据包。后面的flag占用2字节,用于标识数据包属性,目前拥有的标识如下: -* `federation`: `0x0010`,表示这个数据包是从其他的supernode主动发送过来的,比如,其他supernode主动发送过来的RegisterSuper;其他supernode +* `federation`: `0x0010`,表示这个数据包是从其他的supernode主动发送过来的,比如,其他supernode主动发送过来的RegisterSuper;其他supernode收到情短请求之后,主动将请求以Command的形式广播给其他supernode等。 * `from_sn`: `0x0020`,表示这个数据包是从服务端发送过来的。 * `socket`: `0x0040`,表示这个数据包里面包含了有用的socket信息(通常在服务端转发的时候有用)。 * `v6_info`: `0x0080`,表示这个数据包里面包含了ipv6信息(专门用在packet数据包里面,目前只有这个数据包使用了该标识)。 diff --git a/src/utils/error.rs b/src/utils/error.rs index cc1ee61..3edbe9e 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -10,6 +10,7 @@ pub enum SDLanError { SerializeError(String), EncryptError(String), DBError(String), + PBError(String), } impl SDLanError { @@ -21,6 +22,7 @@ impl SDLanError { Self::SerializeError(ref e) => e, Self::EncryptError(ref e) => e, Self::DBError(ref e) => e, + Self::PBError(ref e) => e, } } } @@ -31,6 +33,12 @@ impl From for SDLanError { } } +impl From for SDLanError { + fn from(value: prost::EncodeError) -> Self { + Self::PBError(value.to_string()) + } +} + impl From<&'static str> for SDLanError { fn from(value: &'static str) -> Self { Self::NormalError(value)