Skip to content

Commit

Permalink
feat(core): update core config
Browse files Browse the repository at this point in the history
  • Loading branch information
DefectingCat committed Dec 26, 2024
1 parent 20a2112 commit dad7486
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 25 deletions.
19 changes: 15 additions & 4 deletions config.json → config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"log": {
"loglevel": "warning"
},
"stats": {},
"api": {
"tag": "api",
"services": ["HandlerService", "LoggerService", "StatsService"]
},
"stats": {},
"inbounds": [
{
"port": 10808,
"listen": "127.0.0.1",
"tag": "socks-inbound",
"tag": "socks",
"protocol": "socks",
"settings": {
"auth": "noauth",
Expand All @@ -25,7 +25,7 @@
{
"port": 10809,
"listen": "127.0.0.1",
"tag": "http-inbound",
"tag": "http",
"protocol": "http",
"settings": {
"auth": "noauth",
Expand All @@ -35,6 +35,15 @@
"enabled": true,
"destOverride": ["http", "tls"]
}
},
{
"port": 10086,
"listen": "127.0.0.1",
"tag": "api",
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
}
}
],
"outbounds": [
Expand Down Expand Up @@ -96,7 +105,9 @@
"levels": {
"0": {
"uplinkOnly": 0,
"downlinkOnly": 0
"downlinkOnly": 0,
"statsUserUplink": true,
"statsUserDownlink": true
}
},
"system": {
Expand Down
File renamed without changes.
77 changes: 56 additions & 21 deletions venus-core/src/config/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, path::PathBuf};
use std::{borrow::Cow, collections::HashMap, path::PathBuf};

use crate::consts::VERSION;

Expand Down Expand Up @@ -160,13 +160,31 @@ impl NodeType {
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CoreConfig {
pub log: Log,
#[serde(skip_serializing_if = "Option::is_none")]
pub stats: Option<Stats>,
#[serde(skip_serializing_if = "Option::is_none")]
pub log: Option<Log>,
#[serde(skip_serializing_if = "Option::is_none")]
pub api: Option<Api>,
pub inbounds: Vec<Inbound>,
pub outbounds: Vec<Outbound>,
pub routing: Routing,
pub dns: Dns,
#[serde(skip_serializing_if = "Option::is_none")]
pub dns: Option<Dns>,
pub policy: Policy,
pub other: Other,
#[serde(skip_serializing_if = "Option::is_none")]
pub other: Option<Other>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Stats {}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Api {
pub tag: Cow<'static, str>,
pub services: Vec<Cow<'static, str>>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand All @@ -184,7 +202,8 @@ pub struct Log {
pub struct Inbound {
pub port: u16,
// Listen address
pub listen: Cow<'static, str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub listen: Option<Cow<'static, str>>,
pub tag: Cow<'static, str>,
pub protocol: Cow<'static, str>,
pub settings: InboundSettings,
Expand All @@ -198,12 +217,25 @@ pub struct Inbound {
pub struct InboundSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub auth: Option<Cow<'static, str>>,
pub udp: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub udp: Option<bool>,
// pub ip: Cow<'static, str>,
// for dokodemo-door
// pub address: Option<Cow<'static, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub address: Option<Cow<'static, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_transparent: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub clients: Option<Vec<Client>>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Client {
pub id: Cow<'static, str>,
pub alter_id: u16,
pub email: Cow<'static, str>,
// pub security: Cow<'static, str>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -516,31 +548,34 @@ pub struct Servers {
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Policy {
pub levels: Levels,
pub levels: HashMap<String, Levels>,
pub system: System,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Levels {
#[serde(rename = "0")]
pub n0: N0,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct N0 {
pub uplink_only: i64,
pub downlink_only: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub uplink_only: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub downlink_only: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stats_user_uplink: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stats_user_downlink: Option<bool>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct System {
pub stats_inbound_uplink: bool,
pub stats_inbound_downlink: bool,
pub stats_outbound_uplink: bool,
pub stats_outbound_downlink: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub stats_inbound_uplink: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stats_inbound_downlink: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stats_outbound_uplink: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stats_outbound_downlink: Option<bool>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down

0 comments on commit dad7486

Please sign in to comment.