Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Reidel <[email protected]>
  • Loading branch information
Gelbpunkt committed Jan 29, 2024
1 parent dd16c3b commit 045d122
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 372 deletions.
719 changes: 393 additions & 326 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions drill-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ edition = "2021"
[dependencies]
clap = { version = "4", default-features = false, features = ["derive", "help", "std", "usage"] }
drill-proto = { path = "../drill-proto" }
env_logger = { version = "0.10", default-features = false, features = ["humantime"] }
futures-util = { version = "0.3", default-features = false }
http = "0.2"
env_logger = { version = "0.11", default-features = false, features = ["humantime"] }
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
http = "1"
log = "0.4"
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros", "time"] }
tokio-websockets = { version = "0.3", default-features = false, features = ["client", "fastrand", "rustls-webpki-roots"] }
tokio-websockets = { version = "0.5", default-features = false, features = ["client", "fastrand", "ring", "rustls-webpki-roots"] }
9 changes: 4 additions & 5 deletions drill-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, net::SocketAddr, str::FromStr};

use clap::Parser;
use drill_proto::{AuthMode, Event};
use futures_util::SinkExt;
use futures_util::{SinkExt, StreamExt};
use http::{
uri::{PathAndQuery, Scheme},
Uri,
Expand Down Expand Up @@ -52,14 +52,13 @@ async fn run(mut args: args::Args) -> Result<(), Error> {
args.drill = Uri::from_parts(parts).unwrap();
}

let mut ws = tokio_websockets::ClientBuilder::from_uri(args.drill)
.fail_fast_on_invalid_utf8(false)
let (mut ws, _) = tokio_websockets::ClientBuilder::from_uri(args.drill)
.connect()
.await?;

// Receive a Hello message
let msg = ws.next().await.ok_or(Error::UnexpectedClose)??;
let hello = Event::deserialize(msg.as_data())?;
let hello = Event::deserialize(msg.as_payload())?;

let token = match hello {
Event::Hello {
Expand Down Expand Up @@ -103,7 +102,7 @@ async fn run(mut args: args::Args) -> Result<(), Error> {
tokio::select! {
Some(Ok(msg)) = ws.next() => {
let event = if msg.is_binary() || msg.is_text() {
Event::deserialize(msg.as_data())?
Event::deserialize(msg.as_payload())?
} else {
continue;
};
Expand Down
1 change: 1 addition & 0 deletions drill-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bytes = "1"
51 changes: 31 additions & 20 deletions drill-proto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::slice::SliceIndex;

use bytes::{BufMut, BytesMut};

/// The version of the protocol implemented by the crate.
/// The first two bytes of the `Hello` [`Event`] must match this integer.
const IMPLEMENTED_PROTO_VERSION: u16 = 1;
Expand Down Expand Up @@ -234,31 +236,31 @@ impl<'a> Event<'a> {
}

#[must_use]
pub fn serialize(&self) -> Vec<u8> {
pub fn serialize(&self) -> BytesMut {
match self {
Self::Hello {
proto_version,
auth_mode,
description,
} => {
let mut serialized = Vec::with_capacity(4 + description.len());
serialized.push(HELLO);
serialized.extend_from_slice(&proto_version.to_be_bytes());
serialized.push(*auth_mode as u8);
let mut serialized = BytesMut::with_capacity(4 + description.len());
serialized.put_u8(HELLO);
serialized.put_u16(*proto_version);
serialized.put_u8(*auth_mode as u8);
serialized.extend_from_slice(description.as_bytes());

serialized
}
Self::AoAuth { character_name } => {
let mut serialized = Vec::with_capacity(1 + character_name.len());
serialized.push(AO_AUTH);
let mut serialized = BytesMut::with_capacity(1 + character_name.len());
serialized.put_u8(AO_AUTH);
serialized.extend_from_slice(character_name.as_bytes());

serialized
}
Self::TokenInAoTell { sender } => {
let mut serialized = Vec::with_capacity(1 + sender.len());
serialized.push(TOKEN_IN_AO_TELL);
let mut serialized = BytesMut::with_capacity(1 + sender.len());
serialized.put_u8(TOKEN_IN_AO_TELL);
serialized.extend_from_slice(sender.as_bytes());

serialized
Expand All @@ -267,40 +269,49 @@ impl<'a> Event<'a> {
token,
desired_subdomain,
} => {
let mut serialized = Vec::with_capacity(37 + desired_subdomain.len());
serialized.push(PRESENT_TOKEN);
let mut serialized = BytesMut::with_capacity(37 + desired_subdomain.len());
serialized.put_u8(PRESENT_TOKEN);
serialized.extend_from_slice(token.as_bytes());
serialized.extend_from_slice(desired_subdomain.as_bytes());

serialized
}
Self::LetsGo { public_url } => {
let mut serialized = Vec::with_capacity(1 + public_url.len());
serialized.push(LETS_GO);
let mut serialized = BytesMut::with_capacity(1 + public_url.len());
serialized.put_u8(LETS_GO);
serialized.extend_from_slice(public_url.as_bytes());

serialized
}
Self::AuthFailed => {
vec![AUTH_FAILED]
let mut serialized = BytesMut::with_capacity(1);
serialized.put_u8(AUTH_FAILED);

serialized
}
Self::OutOfCapacity => {
vec![OUT_OF_CAPACITY]
let mut serialized = BytesMut::with_capacity(1);
serialized.put_u8(OUT_OF_CAPACITY);

serialized
}
Self::DisallowedPacket => {
vec![DISALLOWED_PACKET]
let mut serialized = BytesMut::with_capacity(1);
serialized.put_u8(DISALLOWED_PACKET);

serialized
}
Self::Data { id, data } => {
let mut serialized = Vec::with_capacity(37 + data.len());
serialized.push(DATA);
let mut serialized = BytesMut::with_capacity(37 + data.len());
serialized.put_u8(DATA);
serialized.extend_from_slice(id.as_bytes());
serialized.extend_from_slice(data);

serialized
}
Self::Closed { id } => {
let mut serialized = Vec::with_capacity(37);
serialized.push(CLOSED);
let mut serialized = BytesMut::with_capacity(37);
serialized.put_u8(CLOSED);
serialized.extend_from_slice(id.as_bytes());

serialized
Expand Down
13 changes: 8 additions & 5 deletions drill-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bytes = "1"
clap = { version = "4", default-features = false, features = ["derive", "help", "std", "usage"] }
dashmap = "5.4"
drill-proto = { path = "../drill-proto" }
env_logger = { version = "0.10", default-features = false, features = ["humantime"] }
env_logger = { version = "0.11", default-features = false, features = ["humantime"] }
fastrand = "2"
futures-util = { version = "0.3", default-features = false }
httparse = "1.8"
libc = "0.2"
log = "0.4"
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros", "time"] }
tokio-websockets = { version = "0.3", default-features = false, features = ["server", "sha1_smol"] }
tokio-websockets = { version = "0.5", default-features = false, features = ["server", "sha1_smol"] }
uuid = { version = "1.3", features = ["v4"] }

# Required for AO tell authentication
nadylib = { git = "https://github.com/Nadybot/nadylib.git", default-features = false, features = ["account-management", "async"], optional = true }

# Required for authentication via dynamic HTTP backend
hyper = { version = "0.14", default-features = false, features = ["http1", "client", "runtime", "tcp"], optional = true }
hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "tokio-runtime", "webpki-roots"], optional = true }
http-body-util = { version = "0.1", optional = true }
hyper = { version = "1", default-features = false, optional = true }
hyper-util = { version = "0.1", default-features = false, features = ["http1", "client-legacy"], optional = true }
hyper-rustls = { version = "0.26", default-features = false, features = ["http1", "webpki-roots"], optional = true }

[features]
ao = ["nadylib"]
dynamic = ["hyper", "hyper-rustls"]
dynamic = ["http-body-util", "hyper", "hyper-util", "hyper-rustls"]
18 changes: 12 additions & 6 deletions drill-server/src/auth/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use hyper::{body, client::HttpConnector, Body, Client, Method, Request, Uri};
use bytes::Bytes;
use http_body_util::{BodyExt, Empty};
use hyper::{Method, Request, Uri};
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use hyper_util::{
client::legacy::{connect::HttpConnector, Client},
rt::TokioExecutor,
};

pub struct DynamicAuthProvider {
api_endpoint: Uri,
client: Client<HttpsConnector<HttpConnector>>,
client: Client<HttpsConnector<HttpConnector>, Empty<Bytes>>,
}

impl DynamicAuthProvider {
Expand All @@ -16,7 +22,7 @@ impl DynamicAuthProvider {

Self {
api_endpoint,
client: Client::builder().build(connector),
client: Client::builder(TokioExecutor::new()).build(connector),
}
}

Expand All @@ -28,15 +34,15 @@ impl DynamicAuthProvider {
let req = Request::builder()
.method(Method::GET)
.uri(uri)
.body(Body::empty())
.body(Empty::new())
.unwrap();

if let Ok(mut response) = self.client.request(req).await {
let status = response.status();

if status.is_success() {
if let Ok(subdomain_bytes) = body::to_bytes(response.body_mut()).await {
if let Ok(subdomain) = String::from_utf8(subdomain_bytes.to_vec()) {
if let Ok(subdomain_bytes) = response.body_mut().collect().await {
if let Ok(subdomain) = String::from_utf8(subdomain_bytes.to_bytes().to_vec()) {
Some(subdomain)
} else {
log::error!("Token verification endpoint returned invalid UTF-8");
Expand Down
11 changes: 5 additions & 6 deletions drill-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use std::{
time::Duration,
};

use bytes::Bytes;
use clap::Parser;
use config::Args;
use drill_proto::{AuthMode, Event};
use futures_util::SinkExt;
use futures_util::{SinkExt, StreamExt};
use httparse::Status;
use libc::{c_int, sighandler_t, signal, SIGINT, SIGTERM};
use state::State;
Expand Down Expand Up @@ -38,8 +39,7 @@ const HOST_NOT_UTF8: &[u8] =
const HOST_NO_SUBDOMAIN: &[u8] =
b"HTTP/1.1 400\r\nContent-Length: 28\r\n\r\nHost header has no subdomain";
const NOT_FOUND: &[u8] = b"HTTP/1.1 404\r\nContent-Length: 0\r\n\r\n";
const SERVICE_ALIVE: &[u8] =
b"HTTP/1.1 200\r\nContent-Length: 19\r\n\r\nDrill service alive";
const SERVICE_ALIVE: &[u8] = b"HTTP/1.1 200\r\nContent-Length: 19\r\n\r\nDrill service alive";

async fn handle_stream(state: State, mut stream: TcpStream, mut ip: IpAddr) -> io::Result<()> {
// The first thing sent by a client MUST be a HTTP request - either to the
Expand Down Expand Up @@ -182,7 +182,6 @@ async fn handle_client(
ip: IpAddr,
) -> Result<(), tokio_websockets::Error> {
let mut ws = tokio_websockets::ServerBuilder::new()
.fail_fast_on_invalid_utf8(false)
.accept(stream)
.await?;

Expand Down Expand Up @@ -252,7 +251,7 @@ async fn handle_client(

log::trace!("Sending ping to websocket");

if ws.send(WebsocketMessage::ping("")).await.is_err() {
if ws.send(WebsocketMessage::ping(Bytes::new())).await.is_err() {
break;
};
i_am_waiting_for_pong = true;
Expand All @@ -266,7 +265,7 @@ async fn handle_client(
}

if msg.is_binary() || msg.is_text() {
let payload = msg.into_data();
let payload = msg.into_payload();

if let Ok(evt) = Event::deserialize(&payload) {
match evt {
Expand Down

0 comments on commit 045d122

Please sign in to comment.