From 17da7862e35b25a8da20195161e8c57182fc168d Mon Sep 17 00:00:00 2001 From: Ara Sadoyan Date: Wed, 18 Mar 2026 20:06:50 +0100 Subject: [PATCH] upstreams ID hashing update --- src/utils/tools.rs | 18 ++++++++++++++++-- src/web/proxyhttp.rs | 28 ++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/utils/tools.rs b/src/utils/tools.rs index 45bb88b..dbc7a7a 100644 --- a/src/utils/tools.rs +++ b/src/utils/tools.rs @@ -166,8 +166,22 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) { let new_vec = vec.clone(); for x in vec.iter() { let mut id = String::new(); - write!(&mut id, "{}:{}:{}:{}", outer_entry.key(), x.address, x.port, x.is_ssl).unwrap(); + write!( + &mut id, + "{}:{}:{}:{}:{}:{}:{}:{:?}", + outer_entry.key(), + x.address, + x.port, + x.is_http2, + x.to_https, + x.rate_limit.unwrap_or_default(), + x.healthcheck.unwrap_or_default(), + x.authorization + ) + .unwrap_or(()); let mut hasher = Sha256::new(); + // address: "127.0.0.3", port: 8000, is_ssl: false, is_http2: false, to_https: false, rate_limit: Some(200), healthcheck: None, authorization: None } } + hasher.update(id.clone().into_bytes()); let hash = hasher.finalize(); let hex_hash = base16ct::lower::encode_string(&hash); @@ -182,7 +196,6 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) { healthcheck: None, authorization: None, }; - cloned.insert(id, Arc::from(to_add)); cloned.insert(hh, Arc::from(x.to_owned())); // println!("CLONNED :===========> {:?}", cloned); @@ -190,6 +203,7 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) { new_inner_map.insert(path.clone(), new_vec); } } + info!("Upstreams are fully populated, ready to server requests"); } pub fn listdir(dir: String) -> Vec { diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs index 0727b12..b69067a 100644 --- a/src/web/proxyhttp.rs +++ b/src/web/proxyhttp.rs @@ -181,8 +181,32 @@ impl ProxyHttp for LB { if ctx.extraparams.sticky_sessions { let mut s = String::with_capacity(64); - write!(&mut s, "{}:{}:{}:{}", hostname, innermap.address, innermap.port, innermap.is_ssl).unwrap(); - // write!(&mut s, "{}:{}:{}", innermap.address, innermap.port, innermap.is_ssl).unwrap(); + // write!(&mut s, "{}:{}:{}:{}", hostname, innermap.address, innermap.port, innermap.is_ssl).unwrap(); + write!( + &mut s, + "{}:{}:{}:{}:{}:{}:{}:{:?}", + hostname, + innermap.address, + innermap.port, + innermap.is_http2, + innermap.to_https, + innermap.rate_limit.unwrap_or_default(), + innermap.healthcheck.unwrap_or_default(), + innermap.authorization + ) + .unwrap_or(()); + // println!( + // "{}:{}:{}:{}:{}:{}:{}:{:?}", + // hostname, + // innermap.address, + // innermap.port, + // innermap.is_http2, + // innermap.to_https, + // innermap.rate_limit.unwrap_or_default(), + // innermap.healthcheck.unwrap_or_default(), + // innermap.authorization + // ); + ctx.backend_id = Some(s); ctx.sticky_sessions = true; }