mirror of
https://github.com/house-of-vanity/v2-uri-parser.git
synced 2025-12-16 06:57:52 +00:00
Add inbound generator
This commit is contained in:
@@ -136,5 +136,5 @@ pub struct Inbound {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub outbounds: Vec<Outbound>,
|
||||
pub inbounds: Option<Vec<Inbound>>,
|
||||
pub inbounds: Vec<Inbound>,
|
||||
}
|
||||
|
||||
64
src/lib/inboundGenerator.rs
Normal file
64
src/lib/inboundGenerator.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use crate::config_models;
|
||||
|
||||
pub struct InboundGenerationOptions {
|
||||
pub socks_port: Option<u16>,
|
||||
}
|
||||
|
||||
pub fn generate_inbound_config(options: InboundGenerationOptions) -> Vec<config_models::Inbound> {
|
||||
let mut inbounds: Vec<config_models::Inbound> = vec![];
|
||||
match options.socks_port {
|
||||
Some(port) => {
|
||||
inbounds.push(generate_socks_inbound(port));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
return inbounds;
|
||||
}
|
||||
|
||||
pub fn generate_socks_inbound(socks_port: u16) -> config_models::Inbound {
|
||||
return config_models::Inbound {
|
||||
protocol: String::from("socks5"),
|
||||
port: socks_port,
|
||||
tag: String::from("socks-in"),
|
||||
listen: String::from("127.0.0.1"),
|
||||
settings: config_models::InboundSettings { udp: true },
|
||||
sniffing: Some(config_models::SniffingSettings {
|
||||
enabled: Some(true),
|
||||
routeOnly: Some(true),
|
||||
metadataOnly: Some(false),
|
||||
domainsExcluded: None,
|
||||
destOverride: Some(vec![
|
||||
String::from("http"),
|
||||
String::from("tls"),
|
||||
String::from("quic"),
|
||||
]),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test_generate_socks_inboud() {
|
||||
let socks_inbound = generate_socks_inbound(2080);
|
||||
assert_eq!(socks_inbound.protocol, String::from("socks5"));
|
||||
assert_eq!(socks_inbound.listen, String::from("127.0.0.1"));
|
||||
assert_eq!(socks_inbound.tag, String::from("socks-in"));
|
||||
assert_eq!(socks_inbound.port, 2080);
|
||||
assert_eq!(socks_inbound.settings.udp, true);
|
||||
|
||||
let sniffing_obj = socks_inbound.sniffing.unwrap();
|
||||
assert_eq!(sniffing_obj.enabled, Some(true));
|
||||
assert_eq!(sniffing_obj.routeOnly, Some(true));
|
||||
assert_eq!(sniffing_obj.domainsExcluded, None);
|
||||
assert_eq!(
|
||||
sniffing_obj.destOverride,
|
||||
Some(vec![
|
||||
String::from("http"),
|
||||
String::from("tls"),
|
||||
String::from("quic"),
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
1
src/lib/mod.rs
Normal file
1
src/lib/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod inboundGenerator;
|
||||
@@ -2,6 +2,7 @@ mod parser;
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::path::PathBuf;
|
||||
pub mod config_models;
|
||||
pub mod lib;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::config_models;
|
||||
use crate::lib::inboundGenerator;
|
||||
use std::process::exit;
|
||||
|
||||
mod uri_identifier;
|
||||
@@ -12,9 +13,13 @@ pub fn create_json_config(uri: &str, socks_port: Option<u16>) -> String {
|
||||
|
||||
pub fn create_config(uri: &str, socks_port: Option<u16>) -> config_models::Config {
|
||||
let outbound_object = create_outbound_object(uri);
|
||||
let inbound_config =
|
||||
inboundGenerator::generate_inbound_config(inboundGenerator::InboundGenerationOptions {
|
||||
socks_port,
|
||||
});
|
||||
let config = config_models::Config {
|
||||
outbounds: vec![outbound_object],
|
||||
inbounds: None,
|
||||
inbounds: inbound_config,
|
||||
};
|
||||
return config;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user