removed ssl parameter from configs, it will be detected automatically

This commit is contained in:
Ara Sadoyan
2025-05-09 19:41:12 +02:00
parent c2d847f2aa
commit 75486ca73d
5 changed files with 43 additions and 25 deletions

View File

@@ -20,22 +20,29 @@ pub async fn hc2(upslist: Arc<UpstreamsDashMap>, fullist: Arc<UpstreamsDashMap>,
for val in fclone.iter() {
let host = val.key();
let inner = DashMap::new();
let mut _scheme: (String, u16, bool) = ("".to_string(), 0, false);
for path_entry in val.value().iter() {
// let inner = DashMap::new();
let path = path_entry.key();
let mut innervec= Vec::new();
for k in path_entry.value().0.iter().enumerate() {
let (ip, port, ssl) = k.1;
for k in path_entry.value().0 .iter().enumerate() {
let (ip, port, _ssl) = k.1;
let mut _pref = "";
match ssl {
let tls = detect_tls(ip, port).await;
match tls {
true => _pref = "https://",
false => _pref = "http://",
}
if _pref == "https://" {
_scheme = (ip.to_string(), *port, true);
}else {
_scheme = (ip.to_string(), *port, false);
}
let link = format!("{}{}:{}{}", _pref, ip, port, path);
let resp = http_request(link.as_str(), params.0, "").await;
match resp {
true => {
innervec.push(k.1.clone());
innervec.push(_scheme.clone());
}
false => {
warn!("Dead Upstream : {}", link);
@@ -48,8 +55,9 @@ pub async fn hc2(upslist: Arc<UpstreamsDashMap>, fullist: Arc<UpstreamsDashMap>,
}
if first_run == 1 {
info!("Synchronising inner hashmaps");
info!("Performing initial hatchecks and upstreams ssl detection");
clone_idmap_into(&totest, &idlist);
info!("Gazan is up and ready to serve requests");
}
first_run+=1;
@@ -58,7 +66,7 @@ pub async fn hc2(upslist: Arc<UpstreamsDashMap>, fullist: Arc<UpstreamsDashMap>,
clone_dashmap_into(&totest, &upslist);
clone_idmap_into(&totest, &idlist);
}
// print!("{:?}", idlist);
}
}
}
@@ -107,3 +115,22 @@ pub async fn ping_grpc(addr: &str) -> bool {
false
}
}
async fn detect_tls(ip: &str, port: &u16) -> bool {
let url = format!("https://{}:{}", ip, port);
let client = Client::builder()
.timeout(Duration::from_secs(2))
.danger_accept_invalid_certs(true) // skip cert validation for testing
.build()
.unwrap();
match client.get(&url).send().await {
Ok(_) => true,
Err(e) => {
if e.is_builder() || e.is_connect() || e.to_string().contains("tls") {
false
} else {
false
}
}
}
}

View File

@@ -86,7 +86,8 @@ pub fn load_configuration(d: &str, kind: &str) -> Option<Configuration> {
for server in path_config.servers {
if let Some((ip, port_str)) = server.split_once(':') {
if let Ok(port) = port_str.parse::<u16>() {
server_list.push((ip.to_string(), port, path_config.ssl));
// server_list.push((ip.to_string(), port, path_config.ssl));
server_list.push((ip.to_string(), port, true));
}
}
}

View File

@@ -41,7 +41,6 @@ pub struct HostConfig {
#[derive(Debug, Serialize, Deserialize)]
pub struct PathConfig {
pub ssl: bool,
pub servers: Vec<String>,
pub headers: Option<Vec<String>>,
}