Update tokio & rustls, remove async-std & async-tls #19
14
Cargo.toml
14
Cargo.toml
|
@ -10,8 +10,6 @@ repository = "https://tulpa.dev/cadey/maj"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-std = { version = "1.6", optional = true }
|
|
||||||
async-tls = { default-features = false, optional = true, version = "0" }
|
|
||||||
async-trait = { version = "0", optional = true }
|
async-trait = { version = "0", optional = true }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mime_guess = "2.0"
|
mime_guess = "2.0"
|
||||||
|
@ -19,11 +17,11 @@ num = "0.2"
|
||||||
num-derive = "0.3"
|
num-derive = "0.3"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
once_cell = "1.4"
|
once_cell = "1.4"
|
||||||
rustls = { version = "0.18", optional = true, features = ["dangerous_configuration"] }
|
rustls = { version = "0.19", optional = true, features = ["dangerous_configuration"] }
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
tokio-rustls = { version = "0.14", features = ["dangerous_configuration"], optional = true }
|
tokio-rustls = { version = "0.21", features = ["dangerous_configuration"] }
|
||||||
tokio = { version = "0.2", features = ["full"], optional = true }
|
tokio = { version = "0.3", features = ["full"] }
|
||||||
url = "2"
|
url = "2"
|
||||||
webpki-roots = { version = "0.20", optional = true }
|
webpki-roots = { version = "0.20", optional = true }
|
||||||
webpki = { version = "0.21.0", optional = true }
|
webpki = { version = "0.21.0", optional = true }
|
||||||
|
@ -37,12 +35,8 @@ pretty_env_logger = "0.4"
|
||||||
default = ["client", "server"]
|
default = ["client", "server"]
|
||||||
|
|
||||||
client = [
|
client = [
|
||||||
"tokio-rustls",
|
|
||||||
"webpki",
|
"webpki",
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
"tokio",
|
|
||||||
"async-std",
|
|
||||||
"async-tls/client"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
server = [
|
server = [
|
||||||
|
@ -50,8 +44,6 @@ server = [
|
||||||
"webpki",
|
"webpki",
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"async-std",
|
|
||||||
"async-tls/server"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -11,7 +11,7 @@ cursive = "0.15"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
url = "2"
|
url = "2"
|
||||||
webpki = "0.21.0"
|
webpki = "0.21.0"
|
||||||
rustls = { version = "0.18", features = ["dangerous_configuration"] }
|
rustls = { version = "0.19", features = ["dangerous_configuration"] }
|
||||||
smol = { version = "0.3", features = ["tokio02"] }
|
smol = { version = "0.3", features = ["tokio02"] }
|
||||||
|
|
||||||
maj = { path = ".." }
|
maj = { path = ".." }
|
||||||
|
|
|
@ -8,15 +8,14 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
async-std = "1.5"
|
|
||||||
async-trait = "0"
|
async-trait = "0"
|
||||||
atom_syndication = "0.9"
|
atom_syndication = "0.9"
|
||||||
chrono = "*"
|
chrono = "*"
|
||||||
log = "0"
|
log = "0"
|
||||||
pretty_env_logger = "0.4"
|
pretty_env_logger = "0.4"
|
||||||
webpki = "0.21.0"
|
webpki = "0.21.0"
|
||||||
rustls = { version = "0.18", features = ["dangerous_configuration"] }
|
rustls = { version = "0.19", features = ["dangerous_configuration"] }
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
tokio = { version = "0.2", features = ["full"] }
|
tokio = { version = "0.3", features = ["full"] }
|
||||||
|
|
||||||
maj = { path = "../..", features = ["server", "client"], default-features = false }
|
maj = { path = "../..", features = ["server", "client"], default-features = false }
|
||||||
|
|
|
@ -9,7 +9,6 @@ build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
async-std = "1.5"
|
|
||||||
async-trait = "0"
|
async-trait = "0"
|
||||||
dnd_dice_roller = "0.3"
|
dnd_dice_roller = "0.3"
|
||||||
env_logger = "0"
|
env_logger = "0"
|
||||||
|
@ -17,13 +16,14 @@ log = "0"
|
||||||
mime = "0.3.0"
|
mime = "0.3.0"
|
||||||
percent-encoding = "2"
|
percent-encoding = "2"
|
||||||
rand = "0"
|
rand = "0"
|
||||||
rustls = { version = "0.18", features = ["dangerous_configuration"] }
|
rustls = { version = "0.19", features = ["dangerous_configuration"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
smol = { version = "0.3", features = ["tokio02"] }
|
smol = { version = "0.3", features = ["tokio02"] }
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
url = "2"
|
url = "2"
|
||||||
warp = "0.2"
|
warp = "0.2"
|
||||||
|
tokio = { version = "0.3", features = ["rt"] }
|
||||||
|
|
||||||
maj = { path = "..", features = ["server"], default-features = false }
|
maj = { path = "..", features = ["server"], default-features = false }
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use async_std::task;
|
|
||||||
use rustls::{
|
use rustls::{
|
||||||
internal::pemfile::{certs, pkcs8_private_keys},
|
internal::pemfile::{certs, pkcs8_private_keys},
|
||||||
AllowAnyAnonymousOrAuthenticatedClient, Certificate, PrivateKey, RootCertStore, ServerConfig,
|
AllowAnyAnonymousOrAuthenticatedClient, Certificate, PrivateKey, RootCertStore, ServerConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, BufReader},
|
io::{self, BufReader},
|
||||||
|
@ -64,7 +64,8 @@ fn load_keys(path: &Path) -> io::Result<Vec<PrivateKey>> {
|
||||||
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid key"))
|
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid key"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), maj::server::Error> {
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), maj::server::Error> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let opts = Options::from_args();
|
let opts = Options::from_args();
|
||||||
let certs = load_certs(&opts.cert).unwrap();
|
let certs = load_certs(&opts.cert).unwrap();
|
||||||
|
@ -96,7 +97,7 @@ fn main() -> Result<(), maj::server::Error> {
|
||||||
thread::spawn(move || http::run(h.clone(), port));
|
thread::spawn(move || http::run(h.clone(), port));
|
||||||
}
|
}
|
||||||
|
|
||||||
task::block_on(maj::server::serve(h.clone(), config, opts.host, opts.port))?;
|
maj::server::serve(h.clone(), config, opts.host, opts.port).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl MajHandler for Handler {
|
||||||
|
|
||||||
log::debug!("opening file {:?}", path);
|
log::debug!("opening file {:?}", path);
|
||||||
|
|
||||||
match async_std::fs::metadata(&path).await {
|
match tokio::fs::metadata(&path).await {
|
||||||
Ok(stat) => {
|
Ok(stat) => {
|
||||||
if stat.is_dir() {
|
if stat.is_dir() {
|
||||||
if r.url.as_str().ends_with('/') {
|
if r.url.as_str().ends_with('/') {
|
||||||
|
@ -43,9 +43,9 @@ impl MajHandler for Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = async_std::fs::File::open(&path).await?;
|
let mut file = tokio::fs::File::open(&path).await?;
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
async_std::io::copy(&mut file, &mut buf).await?;
|
tokio::io::copy(&mut file, &mut buf).await?;
|
||||||
|
|
||||||
// Send header.
|
// Send header.
|
||||||
if path.extension() == Some(OsStr::new("gmi"))
|
if path.extension() == Some(OsStr::new("gmi"))
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
use crate::{Response, StatusCode};
|
use crate::{Response, StatusCode};
|
||||||
use async_std::{
|
use tokio::{
|
||||||
io::prelude::*,
|
prelude::*,
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
stream::StreamExt,
|
|
||||||
task,
|
task,
|
||||||
};
|
};
|
||||||
use async_tls::TlsAcceptor;
|
use tokio_rustls::TlsAcceptor;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rustls::Certificate;
|
use rustls::Certificate;
|
||||||
use std::{error::Error as StdError, net::SocketAddr, sync::Arc};
|
use std::{error::Error as StdError, net::SocketAddr, sync::Arc};
|
||||||
|
@ -53,12 +52,10 @@ where
|
||||||
{
|
{
|
||||||
let cfg = Arc::new(cfg);
|
let cfg = Arc::new(cfg);
|
||||||
let listener = TcpListener::bind(&format!("{}:{}", host, port)).await?;
|
let listener = TcpListener::bind(&format!("{}:{}", host, port)).await?;
|
||||||
let mut incoming = listener.incoming();
|
|
||||||
let acceptor = Arc::new(TlsAcceptor::from(cfg.clone()));
|
let acceptor = Arc::new(TlsAcceptor::from(cfg.clone()));
|
||||||
while let Some(Ok(stream)) = incoming.next().await {
|
while let Ok((stream, addr)) = listener.accept().await {
|
||||||
let h = h.clone();
|
let h = h.clone();
|
||||||
let acceptor = acceptor.clone();
|
let acceptor = acceptor.clone();
|
||||||
let addr = stream.peer_addr().unwrap();
|
|
||||||
let port = port.clone();
|
let port = port.clone();
|
||||||
|
|
||||||
task::spawn(handle_request(h, stream, acceptor, addr, port));
|
task::spawn(handle_request(h, stream, acceptor, addr, port));
|
||||||
|
@ -83,7 +80,7 @@ async fn handle_request(
|
||||||
if let Some(u_port) = url.port() {
|
if let Some(u_port) = url.port() {
|
||||||
if port != u_port {
|
if port != u_port {
|
||||||
let _ = write_header(
|
let _ = write_header(
|
||||||
&mut stream,
|
stream,
|
||||||
StatusCode::ProxyRequestRefused,
|
StatusCode::ProxyRequestRefused,
|
||||||
"Cannot proxy to that URL",
|
"Cannot proxy to that URL",
|
||||||
)
|
)
|
||||||
|
@ -117,7 +114,7 @@ async fn handle_request(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn write_header<W: Write + Unpin>(
|
pub async fn write_header<W: AsyncWrite + Unpin>(
|
||||||
mut stream: W,
|
mut stream: W,
|
||||||
status: StatusCode,
|
status: StatusCode,
|
||||||
meta: &str,
|
meta: &str,
|
||||||
|
@ -129,7 +126,7 @@ pub async fn write_header<W: Write + Unpin>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the URL requested by the client.
|
/// Return the URL requested by the client.
|
||||||
async fn parse_request<R: Read + Unpin>(mut stream: R) -> Result<Url> {
|
async fn parse_request<R: AsyncRead + Unpin>(mut stream: R) -> Result<Url> {
|
||||||
// Because requests are limited to 1024 bytes (plus 2 bytes for CRLF), we
|
// Because requests are limited to 1024 bytes (plus 2 bytes for CRLF), we
|
||||||
// can use a fixed-sized buffer on the stack, avoiding allocations and
|
// can use a fixed-sized buffer on the stack, avoiding allocations and
|
||||||
// copying, and stopping bad clients from making us use too much memory.
|
// copying, and stopping bad clients from making us use too much memory.
|
||||||
|
@ -167,7 +164,7 @@ async fn handle<T>(
|
||||||
stream: &mut T,
|
stream: &mut T,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
) where
|
) where
|
||||||
T: Write + Unpin,
|
T: AsyncWrite + Unpin,
|
||||||
{
|
{
|
||||||
let u = req.url.clone();
|
let u = req.url.clone();
|
||||||
match h.handle(req).await {
|
match h.handle(req).await {
|
||||||
|
|
Loading…
Reference in New Issue