this resolves #24 and #26

This commit is contained in:
Jun Kurihara 2023-03-31 17:31:42 +09:00
commit bb42d3b49e
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
3 changed files with 51 additions and 35 deletions

View file

@ -16,17 +16,17 @@ default = ["http3"]
http3 = ["quinn", "h3", "h3-quinn"] http3 = ["quinn", "h3", "h3-quinn"]
[dependencies] [dependencies]
env_logger = "0.10.0"
anyhow = "1.0.70" anyhow = "1.0.70"
clap = { version = "4.2.1", features = ["std", "cargo", "wrap_help"] } clap = { version = "4.2.1", features = ["std", "cargo", "wrap_help"] }
rand = "0.8.5"
toml = { version = "0.7.3", default-features = false, features = ["parse"] }
rustc-hash = "1.1.0"
serde = { version = "1.0.159", default-features = false, features = ["derive"] }
bytes = "1.4.0"
thiserror = "1.0.40"
x509-parser = "0.15.0"
derive_builder = "0.12.0"
futures = { version = "0.3.28", features = ["alloc", "async-await"] } futures = { version = "0.3.28", features = ["alloc", "async-await"] }
hyper = { version = "0.14.25", default-features = false, features = [
"server",
"http1",
"http2",
"stream",
] }
log = "0.4.17"
tokio = { version = "1.27.0", default-features = false, features = [ tokio = { version = "1.27.0", default-features = false, features = [
"net", "net",
"rt-multi-thread", "rt-multi-thread",
@ -35,26 +35,32 @@ tokio = { version = "1.27.0", default-features = false, features = [
"sync", "sync",
"macros", "macros",
] } ] }
tokio-rustls = { version = "0.23.4", features = ["early-data"] }
rustls-pemfile = "1.0.2" # http and tls
rustls = { version = "0.20.8", default-features = false } hyper = { version = "0.14.25", default-features = false, features = [
rand = "0.8.5" "server",
toml = { version = "0.7.3", default-features = false, features = ["parse"] } "http1",
rustc-hash = "1.1.0" "http2",
serde = { version = "1.0.159", default-features = false, features = ["derive"] } "stream",
] }
hyper-rustls = { version = "0.23.2", default-features = false, features = [ hyper-rustls = { version = "0.23.2", default-features = false, features = [
"tokio-runtime", "tokio-runtime",
"webpki-tokio", "webpki-tokio",
"http1", "http1",
"http2", "http2",
] } ] }
bytes = "1.4.0" tokio-rustls = { version = "0.23.4", features = ["early-data"] }
rustls-pemfile = "1.0.2"
rustls = { version = "0.20.8", default-features = false }
# logging
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
# http/3
quinn = { version = "0.9.3", optional = true } quinn = { version = "0.9.3", optional = true }
h3 = { path = "./h3/h3/", optional = true } h3 = { path = "./h3/h3/", optional = true }
h3-quinn = { path = "./h3/h3-quinn/", optional = true } h3-quinn = { path = "./h3/h3-quinn/", optional = true }
thiserror = "1.0.40"
x509-parser = "0.15.0"
derive_builder = "0.12.0"
[target.'cfg(not(target_env = "msvc"))'.dependencies] [target.'cfg(not(target_env = "msvc"))'.dependencies]

View file

@ -1,6 +1,6 @@
use crate::utils::ToCanonical; use crate::utils::ToCanonical;
pub use log::{debug, error, info, warn, Level};
use std::net::SocketAddr; use std::net::SocketAddr;
pub use tracing::{debug, error, info, warn};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MessageLog { pub struct MessageLog {
@ -95,3 +95,26 @@ impl MessageLog {
); );
} }
} }
pub fn init_logger() {
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
let format_layer = fmt::layer()
.with_line_number(false)
.with_thread_ids(false)
.with_target(false)
.with_thread_names(true)
.with_target(true)
.with_level(true)
.compact();
// This limits the logger to emits only rpxy crate
let level_string = std::env::var(EnvFilter::DEFAULT_ENV).unwrap_or_else(|_| "info".to_string());
let filter_layer = EnvFilter::new(format!("{}={}", env!("CARGO_PKG_NAME"), level_string));
// let filter_layer = EnvFilter::from_default_env();
tracing_subscriber::registry()
.with(format_layer)
.with(filter_layer)
.init();
}

View file

@ -30,24 +30,11 @@ use futures::future::select_all;
use hyper::Client; use hyper::Client;
// use hyper_trust_dns::TrustDnsResolver; // use hyper_trust_dns::TrustDnsResolver;
use rustc_hash::FxHashMap as HashMap; use rustc_hash::FxHashMap as HashMap;
use std::{io::Write, sync::Arc}; use std::sync::Arc;
use tokio::time::Duration; use tokio::time::Duration;
fn main() { fn main() {
// env::set_var("RUST_LOG", "info"); init_logger();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.format(|buf, rec| {
let ts = buf.timestamp();
match rec.level() {
log::Level::Debug => {
writeln!(buf, "{} [{}] {} ({})", ts, rec.level(), rec.args(), rec.target(),)
}
_ => {
writeln!(buf, "{} [{}] {}", ts, rec.level(), rec.args(),)
}
}
})
.init();
let mut runtime_builder = tokio::runtime::Builder::new_multi_thread(); let mut runtime_builder = tokio::runtime::Builder::new_multi_thread();
runtime_builder.enable_all(); runtime_builder.enable_all();