1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use cyfs_base::BuckyError;
use std::str::FromStr;
pub const CYFS_OBJECT_MIME_STRING: &str = "application/octet-stream";
lazy_static::lazy_static! {
pub static ref CYFS_OBJECT_MIME: http_types::Mime = http_types::Mime::from_str(CYFS_OBJECT_MIME_STRING).unwrap();
}
#[derive(Clone, Eq, Debug, PartialEq)]
pub enum NONProtocol {
Native,
Meta,
Sync,
HttpBdt,
HttpLocal,
HttpLocalAuth,
DatagramBdt,
DataBdt,
}
impl NONProtocol {
pub fn is_local(&self) -> bool {
match *self {
Self::Native | Self::HttpLocal | Self::HttpLocalAuth => true,
Self::HttpBdt | Self::DatagramBdt | Self::DataBdt => false,
Self::Meta | Self::Sync => false,
}
}
pub fn is_remote(&self) -> bool {
!self.is_local()
}
pub fn is_require_acl(&self) -> bool {
match *self {
Self::HttpBdt | Self::DatagramBdt | Self::DataBdt => true,
Self::Native | Self::HttpLocal | Self::Meta | Self::Sync | Self::HttpLocalAuth => false,
}
}
}
impl ToString for NONProtocol {
fn to_string(&self) -> String {
(match *self {
Self::Native => "native",
Self::Meta => "meta",
Self::Sync => "sync",
Self::HttpBdt => "http-bdt",
Self::HttpLocal => "http-local",
Self::HttpLocalAuth => "http-local-auth",
Self::DatagramBdt => "datagram-bdt",
Self::DataBdt => "data-bdt",
})
.to_owned()
}
}
impl FromStr for NONProtocol {
type Err = BuckyError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let ret = match value {
"native" => Self::Native,
"meta" => Self::Meta,
"sync" => Self::Sync,
"http-bdt" => Self::HttpBdt,
"http-local" => Self::HttpLocal,
"http-local-auth" => Self::HttpLocalAuth,
"datagram-bdt" => Self::DatagramBdt,
"data-bdt" => Self::DataBdt,
v @ _ => {
let msg = format!("unknown non input protocol: {}", v);
error!("{}", msg);
return Err(BuckyError::from(msg));
}
};
Ok(ret)
}
}
pub const ROUTER_WS_EVENT_CMD_ADD: u16 = 1;
pub const ROUTER_WS_EVENT_CMD_REMOVE: u16 = 2;
pub const ROUTER_WS_EVENT_CMD_EVENT: u16 = 3;
pub const ROUTER_WS_HANDLER_CMD_ADD: u16 = 11;
pub const ROUTER_WS_HANDLER_CMD_REMOVE: u16 = 12;
pub const ROUTER_WS_HANDLER_CMD_EVENT: u16 = 13;
pub const HTTP_CMD_REQUEST: u16 = 21;