mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
Code cleanup, nothing special
This commit is contained in:
@@ -19,6 +19,7 @@ dashmap = "7.0.0-rc2"
|
|||||||
pingora-core = "0.5.0"
|
pingora-core = "0.5.0"
|
||||||
pingora-proxy = "0.5.0"
|
pingora-proxy = "0.5.0"
|
||||||
pingora-http = "0.5.0"
|
pingora-http = "0.5.0"
|
||||||
|
#pingora-pool = "0.5.0"
|
||||||
async-trait = "0.1.88"
|
async-trait = "0.1.88"
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
|
|||||||
@@ -73,14 +73,6 @@ pub struct AppConfig {
|
|||||||
pub config_tls_key_file: Option<String>,
|
pub config_tls_key_file: Option<String>,
|
||||||
pub proxy_address_tls: Option<String>,
|
pub proxy_address_tls: Option<String>,
|
||||||
pub proxy_port_tls: Option<u16>,
|
pub proxy_port_tls: Option<u16>,
|
||||||
// pub tls_certificate: Option<String>,
|
|
||||||
// pub tls_key_file: Option<String>,
|
|
||||||
pub local_server: Option<(String, u16)>,
|
pub local_server: Option<(String, u16)>,
|
||||||
pub proxy_certificates: Option<String>,
|
pub proxy_certificates: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Debug)]
|
|
||||||
// pub struct CertificateMove {
|
|
||||||
// pub cert_tx: Sender<CertificateConfig>,
|
|
||||||
// pub cert_rx: Receiver<CertificateConfig>,
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ pub struct Context {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ProxyHttp for LB {
|
impl ProxyHttp for LB {
|
||||||
// type CTX = ();
|
|
||||||
// fn new_ctx(&self) -> Self::CTX {}
|
|
||||||
type CTX = Context;
|
type CTX = Context;
|
||||||
fn new_ctx(&self) -> Self::CTX {
|
fn new_ctx(&self) -> Self::CTX {
|
||||||
Context {
|
Context {
|
||||||
@@ -60,7 +58,6 @@ impl ProxyHttp for LB {
|
|||||||
let host_name = return_header_host(&session);
|
let host_name = return_header_host(&session);
|
||||||
match host_name {
|
match host_name {
|
||||||
Some(hostname) => {
|
Some(hostname) => {
|
||||||
// session.req_header_mut().headers.insert("X-Host-Name", host.to_string().parse().unwrap());
|
|
||||||
let mut backend_id = None;
|
let mut backend_id = None;
|
||||||
|
|
||||||
if self.extraparams.load().sticky_sessions {
|
if self.extraparams.load().sticky_sessions {
|
||||||
@@ -82,6 +79,26 @@ impl ProxyHttp for LB {
|
|||||||
match ddr {
|
match ddr {
|
||||||
Some((address, port, ssl, is_h2, to_https)) => {
|
Some((address, port, ssl, is_h2, to_https)) => {
|
||||||
let mut peer = Box::new(HttpPeer::new((address.clone(), port.clone()), ssl, String::new()));
|
let mut peer = Box::new(HttpPeer::new((address.clone(), port.clone()), ssl, String::new()));
|
||||||
|
/*
|
||||||
|
let key = PeerKey {
|
||||||
|
addr: address.clone(),
|
||||||
|
port: port,
|
||||||
|
ssl: ssl,
|
||||||
|
};
|
||||||
|
|
||||||
|
let gk = key.get_hash();
|
||||||
|
let pooled_conn = self.connection_pool.connections.get(&gk);
|
||||||
|
match pooled_conn {
|
||||||
|
Some(conn) => {
|
||||||
|
peer = Box::from(conn);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let id = self.connection_pool.next_id();
|
||||||
|
self.connection_pool.connections.put(&ConnectionMeta { key: gk, id: id }, *peer.clone());
|
||||||
|
debug!("Added peer to pool: {}", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
// if session.is_http2() {
|
// if session.is_http2() {
|
||||||
if is_h2 {
|
if is_h2 {
|
||||||
peer.options.alpn = ALPN::H2;
|
peer.options.alpn = ALPN::H2;
|
||||||
@@ -91,7 +108,7 @@ impl ProxyHttp for LB {
|
|||||||
peer.options.verify_cert = false;
|
peer.options.verify_cert = false;
|
||||||
peer.options.verify_hostname = false;
|
peer.options.verify_hostname = false;
|
||||||
}
|
}
|
||||||
// println!("{}, {}, alpn {}, h2 {:?}, to_https {}", hostname, address.as_str(), peer.options.alpn, is_h2, _to_https);
|
|
||||||
if self.extraparams.load().to_https.unwrap_or(false) || to_https {
|
if self.extraparams.load().to_https.unwrap_or(false) || to_https {
|
||||||
if let Some(stream) = session.stream() {
|
if let Some(stream) = session.stream() {
|
||||||
if stream.get_ssl().is_none() {
|
if stream.get_ssl().is_none() {
|
||||||
@@ -108,6 +125,11 @@ impl ProxyHttp for LB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.backend_id = format!("{}:{}:{}", address.clone(), port.clone(), ssl);
|
ctx.backend_id = format!("{}:{}:{}", address.clone(), port.clone(), ssl);
|
||||||
|
/*
|
||||||
|
ctx.peer = Some(peer.clone());
|
||||||
|
ctx.peer_key = Some(key.clone());
|
||||||
|
ctx.group_key = Some(gk.clone());
|
||||||
|
*/
|
||||||
Ok(peer)
|
Ok(peer)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@@ -155,6 +177,12 @@ impl ProxyHttp for LB {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async fn request_body_filter(&self, _session: &mut Session, _body: &mut Option<Bytes>, _end_of_stream: bool, _ctx: &mut Self::CTX) -> Result<()>
|
||||||
|
// where
|
||||||
|
// Self::CTX: Send + Sync,
|
||||||
|
// {
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
async fn response_filter(&self, session: &mut Session, _upstream_response: &mut ResponseHeader, ctx: &mut Self::CTX) -> Result<()> {
|
async fn response_filter(&self, session: &mut Session, _upstream_response: &mut ResponseHeader, ctx: &mut Self::CTX) -> Result<()> {
|
||||||
// _upstream_response.insert_header("X-Proxied-From", "Fooooooooooooooo").unwrap();
|
// _upstream_response.insert_header("X-Proxied-From", "Fooooooooooooooo").unwrap();
|
||||||
if self.extraparams.load().sticky_sessions {
|
if self.extraparams.load().sticky_sessions {
|
||||||
@@ -195,6 +223,7 @@ impl ProxyHttp for LB {
|
|||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
session.set_keepalive(Some(300));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,10 +256,3 @@ fn return_header_host(session: &Session) -> Option<&str> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn return_no_host(inp: &Option<(String, u16)>) -> Box<HttpPeer> {
|
|
||||||
// match inp {
|
|
||||||
// Some(t) => Box::new(HttpPeer::new(t, false, String::new())),
|
|
||||||
// None => Box::new(HttpPeer::new(("0.0.0.0", 0), false, String::new())),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ pub fn run() {
|
|||||||
let ff_config = Arc::new(DashMap::new());
|
let ff_config = Arc::new(DashMap::new());
|
||||||
let im_config = Arc::new(DashMap::new());
|
let im_config = Arc::new(DashMap::new());
|
||||||
let hh_config = Arc::new(DashMap::new());
|
let hh_config = Arc::new(DashMap::new());
|
||||||
|
|
||||||
let ec_config = Arc::new(ArcSwap::from_pointee(Extraparams {
|
let ec_config = Arc::new(ArcSwap::from_pointee(Extraparams {
|
||||||
sticky_sessions: false,
|
sticky_sessions: false,
|
||||||
to_https: None,
|
to_https: None,
|
||||||
@@ -37,25 +38,13 @@ pub fn run() {
|
|||||||
let cfg = Arc::new(maincfg);
|
let cfg = Arc::new(maincfg);
|
||||||
|
|
||||||
let lb = LB {
|
let lb = LB {
|
||||||
ump_upst: uf_config.clone(),
|
ump_upst: uf_config,
|
||||||
ump_full: ff_config.clone(),
|
ump_full: ff_config,
|
||||||
ump_byid: im_config.clone(),
|
ump_byid: im_config,
|
||||||
config: cfg.clone(),
|
config: cfg.clone(),
|
||||||
headers: hh_config.clone(),
|
headers: hh_config,
|
||||||
extraparams: ec_config.clone(),
|
extraparams: ec_config,
|
||||||
};
|
};
|
||||||
// let bg = LB {
|
|
||||||
// ump_upst: uf_config.clone(),
|
|
||||||
// ump_full: ff_config.clone(),
|
|
||||||
// ump_byid: im_config.clone(),
|
|
||||||
// config: cfg.clone(),
|
|
||||||
// headers: hh_config.clone(),
|
|
||||||
// extraparams: ec_config.clone(),
|
|
||||||
// config_rx: Arc::from(Mutex::new(rx)),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// env_logger::Env::new();
|
|
||||||
// env_logger::init();
|
|
||||||
|
|
||||||
let log_level = cfg.log_level.clone();
|
let log_level = cfg.log_level.clone();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
Reference in New Issue
Block a user