mirror of
https://github.com/mikedilger/chorus.git
synced 2026-05-03 06:51:42 +00:00
Remove http server from globals, create one each time (cheap)
This commit is contained in:
parent
9759fe6e28
commit
fde63df92b
@ -124,18 +124,8 @@ async fn main() -> Result<(), Error> {
|
|||||||
},
|
},
|
||||||
None => Box::new(counting_stream)
|
None => Box::new(counting_stream)
|
||||||
};
|
};
|
||||||
if let Err(e) = chorus::serve(stream, hashed_peer).await {
|
chorus::serve(stream, hashed_peer).await;
|
||||||
log::error!(
|
|
||||||
target: "Client",
|
|
||||||
"{}: {}", hashed_peer, e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Err(e) => log::error!(
|
|
||||||
//target: "Client",
|
|
||||||
//"{}: {}", hashed_peer, e
|
|
||||||
//),
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::ip::HashedIp;
|
use crate::ip::HashedIp;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use hyper::server::conn::Http;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use pocket_db::Store;
|
use pocket_db::Store;
|
||||||
@ -17,7 +16,6 @@ pub struct Globals {
|
|||||||
pub bytes_outbound: AtomicU64,
|
pub bytes_outbound: AtomicU64,
|
||||||
pub config: RwLock<Config>,
|
pub config: RwLock<Config>,
|
||||||
pub store: OnceLock<Store>,
|
pub store: OnceLock<Store>,
|
||||||
pub http_server: Http,
|
|
||||||
pub rid: OnceLock<String>,
|
pub rid: OnceLock<String>,
|
||||||
|
|
||||||
/// This is a broadcast channel where new incoming events are advertised by their offset.
|
/// This is a broadcast channel where new incoming events are advertised by their offset.
|
||||||
@ -33,10 +31,6 @@ pub struct Globals {
|
|||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref GLOBALS: Globals = {
|
pub static ref GLOBALS: Globals = {
|
||||||
let mut http_server = hyper::server::conn::Http::new();
|
|
||||||
http_server.http1_only(true);
|
|
||||||
http_server.http1_keep_alive(true);
|
|
||||||
|
|
||||||
let (new_events, _) = tokio::sync::broadcast::channel(512);
|
let (new_events, _) = tokio::sync::broadcast::channel(512);
|
||||||
let (shutting_down, _) = tokio::sync::watch::channel(false);
|
let (shutting_down, _) = tokio::sync::watch::channel(false);
|
||||||
|
|
||||||
@ -46,7 +40,6 @@ lazy_static! {
|
|||||||
bytes_outbound: AtomicU64::new(0),
|
bytes_outbound: AtomicU64::new(0),
|
||||||
config: RwLock::new(Default::default()),
|
config: RwLock::new(Default::default()),
|
||||||
store: OnceLock::new(),
|
store: OnceLock::new(),
|
||||||
http_server,
|
|
||||||
rid: OnceLock::new(),
|
rid: OnceLock::new(),
|
||||||
new_events,
|
new_events,
|
||||||
num_connections: AtomicUsize::new(0),
|
num_connections: AtomicUsize::new(0),
|
||||||
|
|||||||
50
src/lib.rs
50
src/lib.rs
@ -48,34 +48,42 @@ impl FullStream for CountingStream<TcpStream> {}
|
|||||||
impl FullStream for TlsStream<CountingStream<TcpStream>> {}
|
impl FullStream for TlsStream<CountingStream<TcpStream>> {}
|
||||||
|
|
||||||
/// Serve a single network connection
|
/// Serve a single network connection
|
||||||
pub async fn serve(stream: Box<dyn FullStream>, peer: HashedPeer) -> Result<(), Error> {
|
pub async fn serve(stream: Box<dyn FullStream>, peer: HashedPeer) {
|
||||||
// Serve the network stream with our http server and our HttpService
|
// Serve the network stream with our http server and our HttpService
|
||||||
let service = HttpService { peer };
|
let service = HttpService { peer };
|
||||||
|
|
||||||
let connection = GLOBALS
|
let mut http_server = hyper::server::conn::Http::new();
|
||||||
.http_server
|
http_server.http1_only(true);
|
||||||
|
http_server.http1_keep_alive(true);
|
||||||
|
let connection = http_server
|
||||||
.serve_connection(stream, service)
|
.serve_connection(stream, service)
|
||||||
.with_upgrades();
|
.with_upgrades();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
/* hyper 1
|
||||||
// If our service exits with an error, log the error
|
let mut http1builder = http1::Builder::new();
|
||||||
if let Err(he) = connection.await {
|
http1builder.half_close(true);
|
||||||
if let Some(src) = he.source() {
|
http1builder.keep_alive(true);
|
||||||
if &*format!("{}", src) == "Transport endpoint is not connected (os error 107)" {
|
http1builder.header_read_timeout(Duration::from_secs(5));
|
||||||
// do nothing
|
let connection = http1builder
|
||||||
} else {
|
.serve_connection(stream, service)
|
||||||
// Print in detail
|
.with_upgrades();
|
||||||
log::error!(target: "Client", "{}: {:?}", peer, src);
|
*/
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Print in less detail
|
|
||||||
let e: Error = he.into();
|
|
||||||
log::error!(target: "Client", "{}: {}", peer, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
// If our service exits with an error, log the error
|
||||||
|
if let Err(he) = connection.await {
|
||||||
|
if let Some(src) = he.source() {
|
||||||
|
if &*format!("{}", src) == "Transport endpoint is not connected (os error 107)" {
|
||||||
|
// do nothing
|
||||||
|
} else {
|
||||||
|
// Print in detail
|
||||||
|
log::error!(target: "Client", "{}: {:?}", peer, src);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Print in less detail
|
||||||
|
let e: Error = he.into();
|
||||||
|
log::error!(target: "Client", "{}: {}", peer, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is our per-connection HTTP service
|
// This is our per-connection HTTP service
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user