1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4#[serde(tag = "type", rename_all = "kebab-case")]
5pub enum Protocol {
6 Shadowsocks {
7 method: String,
8 password: String,
9 },
10 Trojan {
11 password: String,
12 },
13 Vmess {
15 id: String,
16 security: Option<String>,
17 },
18 Vless {
19 id: String,
20 },
21}
22
23impl Protocol {
24 pub fn name(&self) -> &'static str {
25 match self {
26 Protocol::Shadowsocks { .. } => "shadowsocks",
27 Protocol::Trojan { .. } => "trojan",
28 Protocol::Vmess { .. } => "vmess",
29 Protocol::Vless { .. } => "vless",
30 }
31 }
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
35#[serde(tag = "transport", rename_all = "kebab-case")]
36pub enum Transport {
37 Tcp,
38 Ws {
39 path: Option<String>,
40 headers: Option<Vec<(String, String)>>,
41 },
42 H2,
43 Grpc {
44 service_name: Option<String>,
45 },
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
49pub struct Tls {
50 pub enabled: bool,
51 pub server_name: Option<String>,
52 pub alpn: Option<Vec<String>>,
53 pub insecure: Option<bool>,
54 pub utls_fingerprint: Option<String>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
58pub struct Node {
59 pub name: String,
60 pub server: String,
61 pub port: u16,
62 pub protocol: Protocol,
63 pub transport: Option<Transport>,
64 pub tls: Option<Tls>,
65 pub tags: Vec<String>,
66}