From 63c71208ea7dbfde11051bd178add9e3e6b09fc1 Mon Sep 17 00:00:00 2001 From: Keivan-sf Date: Tue, 17 Oct 2023 18:42:18 +0330 Subject: [PATCH] Put config structs into `config_models` --- src/parser/config_models/mod.rs | 59 +++++++++++++++++++++++++++++++ src/parser/mod.rs | 2 +- src/parser/vless/mod.rs | 61 +-------------------------------- 3 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 src/parser/config_models/mod.rs diff --git a/src/parser/config_models/mod.rs b/src/parser/config_models/mod.rs new file mode 100644 index 0000000..1fd79cd --- /dev/null +++ b/src/parser/config_models/mod.rs @@ -0,0 +1,59 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub struct VlessUser { + pub id: String, + pub encryption: String, + pub flow: String, + pub level: u8, +} + +#[derive(Serialize, Deserialize)] +pub struct VlessServerObject { + pub address: String, + pub port: u16, + pub users: Vec, +} + +#[derive(Serialize, Deserialize)] +pub struct VlessOutboundSettings { + pub vnext: Vec, +} + +#[derive(Serialize, Deserialize)] +pub enum OutboundSettings { + Vless(VlessOutboundSettings), +} + +#[allow(non_snake_case)] +pub struct TlsSettings { + pub allowInsecure: bool, + pub certificates: u8, + pub serverName: String, + // u8 is a dummy type here + pub alpn: u8, + pub enableSessionResumption: bool, + pub disableSystemRoot: bool, + pub minVersion: String, + pub maxVersion: String, + pub cipherSuites: String, + pub preferServerCipherSuites: bool, + pub fingerprint: String, + pub rejectUnknownSni: bool, + pub pinnedPeerCertificateChainSha256: u8, + pub pinnedPeerCertificatePublicKeySha256: u8, +} + +#[allow(non_snake_case)] +pub struct StreamSettings { + pub network: String, + pub security: String, + pub tlsSettings: TlsSettings, +} + +#[derive(Serialize, Deserialize)] +pub struct Outbound { + pub settings: OutboundSettings, + pub protocol: String, + pub tag: String, +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index f0099f9..d21f404 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,7 +1,7 @@ use std::process::exit; mod uri_identifier; mod vless; - +pub mod config_models; pub fn parse(uri: &str) { let protocol = uri_identifier::get_uri_protocol(uri); match protocol { diff --git a/src/parser/vless/mod.rs b/src/parser/vless/mod.rs index 28138c1..7f73b3f 100644 --- a/src/parser/vless/mod.rs +++ b/src/parser/vless/mod.rs @@ -2,66 +2,7 @@ use querystring; mod models; use serde::{Deserialize, Serialize}; use std::process::exit; - -// Outbound structs - -#[derive(Serialize, Deserialize)] -struct VlessUser { - id: String, - encryption: String, - flow: String, - level: u8, -} - -#[derive(Serialize, Deserialize)] -struct VlessServerObject { - address: String, - port: u16, - users: Vec, -} - -#[derive(Serialize, Deserialize)] -struct VlessOutboundSettings { - vnext: Vec, -} - -#[derive(Serialize, Deserialize)] -enum OutboundSettings { - Vless(VlessOutboundSettings), -} - -#[allow(non_snake_case)] -struct TlsSettings { - allowInsecure: bool, - certificates: u8, - serverName: String, - // u8 is a dummy type here - alpn: u8, - enableSessionResumption: bool, - disableSystemRoot: bool, - minVersion: String, - maxVersion: String, - cipherSuites: String, - preferServerCipherSuites: bool, - fingerprint: String, - rejectUnknownSni: bool, - pinnedPeerCertificateChainSha256: u8, - pinnedPeerCertificatePublicKeySha256: u8, -} - -#[allow(non_snake_case)] -struct StreamSettings { - network: String, - security: String, - tlsSettings: TlsSettings, -} - -#[derive(Serialize, Deserialize)] -pub struct Outbound { - settings: OutboundSettings, - protocol: String, - tag: String, -} +use crate::parser::config_models::*; fn create_outbound_object(data: models::VlessData) -> Outbound { return Outbound {