mirror of
https://github.com/house-of-vanity/v2-uri-parser.git
synced 2025-12-17 23:37:52 +00:00
Use a shared raw data model for easier implementation
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use crate::config_models;
|
||||
use crate::utils::inbound_generator;
|
||||
use std::process::exit;
|
||||
use crate::config_models::{
|
||||
self, GRPCSettings, KCPSettings, NonHeaderObject, Outbound, OutboundSettings, QuicSettings,
|
||||
RawData, RealitySettings, StreamSettings, TCPHeader, TCPSettings, TlsSettings, WsSettings,
|
||||
XHTTPSettings,
|
||||
};
|
||||
use crate::utils::{inbound_generator, parse_raw_json};
|
||||
|
||||
mod uri_identifier;
|
||||
mod vless;
|
||||
@@ -31,19 +34,124 @@ pub fn create_config(
|
||||
|
||||
pub fn create_outbound_object(uri: &str) -> config_models::Outbound {
|
||||
let protocol = uri_identifier::get_uri_protocol(uri);
|
||||
match protocol {
|
||||
let (name, data, outbound_settings): (String, RawData, OutboundSettings) = match protocol {
|
||||
Some(uri_identifier::Protocols::Vless) => {
|
||||
let vless_data = vless::data::get_data(uri);
|
||||
let outbound_object = vless::create_outbound_object(vless_data);
|
||||
return outbound_object;
|
||||
let d = vless::data::get_data(uri);
|
||||
let s = vless::create_outbound_settings(&d);
|
||||
(String::from("vless"), d, s)
|
||||
}
|
||||
Some(_) => {
|
||||
println!("The protocol was recognized but is not supported yet");
|
||||
exit(0);
|
||||
panic!("The protocol was recognized but is not supported yet");
|
||||
}
|
||||
None => {
|
||||
println!("The protcol is not supported");
|
||||
exit(0);
|
||||
panic!("The protocol is not supported");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let network_type = data.r#type.clone().unwrap_or(String::from(""));
|
||||
let allow_insecure = data.allowInsecure == Some(String::from("true"))
|
||||
|| data.allowInsecure == Some(String::from("1"));
|
||||
|
||||
let outbound = Outbound {
|
||||
protocol: name,
|
||||
tag: String::from("proxy"),
|
||||
streamSettings: StreamSettings {
|
||||
network: data.r#type.clone(),
|
||||
security: data.security.clone(),
|
||||
tlsSettings: if data.security == Some(String::from("tls")) {
|
||||
Some(TlsSettings {
|
||||
alpn: data.alpn.map(|alpn| vec![alpn]),
|
||||
rejectUnknownSni: None,
|
||||
enableSessionResumption: None,
|
||||
minVersion: None,
|
||||
maxVersion: None,
|
||||
cipherSuites: None,
|
||||
disableSystemRoot: None,
|
||||
preferServerCipherSuites: None,
|
||||
fingerprint: data.fp.clone(),
|
||||
serverName: data.sni.clone(),
|
||||
allowInsecure: allow_insecure,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
wsSettings: if network_type == String::from("ws") {
|
||||
Some(WsSettings {
|
||||
Host: data.host.clone(),
|
||||
path: data.path.clone(),
|
||||
acceptProxyProtocol: None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
tcpSettings: if network_type == String::from("tcp") {
|
||||
Some(TCPSettings {
|
||||
header: Some(TCPHeader {
|
||||
r#type: Some(data.header_type.unwrap_or(String::from("none"))),
|
||||
}),
|
||||
acceptProxyProtocol: None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
realitySettings: if network_type == String::from("reality") {
|
||||
Some(RealitySettings {
|
||||
publicKey: data.pbk,
|
||||
serverName: data.sni.clone(),
|
||||
shortId: data.sid,
|
||||
spiderX: Some(String::from("")),
|
||||
fingerprint: data.fp.clone(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
grpcSettings: if network_type == String::from("grpc") {
|
||||
Some(GRPCSettings {
|
||||
authority: data.authority,
|
||||
multiMode: Some(false),
|
||||
serviceName: data.service_name,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
quicSettings: if network_type == String::from("quic") {
|
||||
Some(QuicSettings {
|
||||
header: Some(NonHeaderObject {
|
||||
r#type: Some(String::from("none")),
|
||||
}),
|
||||
security: Some(String::from("none")),
|
||||
key: Some(String::from("")),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
kcpSettings: if network_type == String::from("kcp") {
|
||||
Some(KCPSettings {
|
||||
mtu: None,
|
||||
tti: None,
|
||||
congestion: None,
|
||||
uplinkCapacity: None,
|
||||
readBufferSize: None,
|
||||
writeBufferSize: None,
|
||||
downlinkCapacity: None,
|
||||
seed: data.seed,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
xhttpSettings: if network_type == String::from("xhttp") {
|
||||
Some(XHTTPSettings {
|
||||
host: data.host.clone(),
|
||||
path: data.path.clone(),
|
||||
mode: data.mode,
|
||||
extra: data.extra.and_then(|e| parse_raw_json(e.as_str())),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
},
|
||||
settings: outbound_settings,
|
||||
};
|
||||
|
||||
return outbound;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user