Skip to content

Commit

Permalink
hyper-util-0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
junkurihara committed Nov 17, 2023
1 parent 40b276d commit c5f6088
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "submodules/hyper-util"]
path = submodules/hyper-util
url = git@github.com:junkurihara/hyper-util.git
[submodule "submodules/hyper-tls"]
path = submodules/hyper-tls
url = git@github.com:junkurihara/hyper-tls.git
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]

members = ["relay-bin", "relay-lib"]
exclude = ["submodules/hyper-util/", "submodule/hyper-tls"]
exclude = ["submodules/hyper-tls"]
resolver = "2"

[profile.release]
Expand Down
4 changes: 2 additions & 2 deletions relay-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ async-trait = "0.1.74"
# http handling
url = "2.4.1"
rustc-hash = "1.1.0"
hyper = { version = "1.0.0", default-features = false }
hyper = { version = "1.0.1", default-features = false }
http = "1.0.0"
http-body-util = "0.1.0"
hyper-util = { path = "../submodules/hyper-util/", features = ["full"] }
hyper-util = { version = "0.1.0", features = ["full"] }
hyper-tls = { path = "../submodules/hyper-tls/", default-features = false }
# hyper-rustls = { version = "0.24.2", default-features = false, features = [
# "tokio-runtime",
Expand Down
15 changes: 9 additions & 6 deletions relay-lib/src/http_client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::hyper_executor::LocalExecutor;
use http::Request;
use hyper::body::Body;
use http::{Request, Response};
use hyper::body::{Body, Incoming};
use hyper_tls::HttpsConnector;
use hyper_util::client::{
use hyper_util::client::legacy::{
connect::{Connect, HttpConnector},
legacy::{Client, ResponseFuture},
Client,
};

#[derive(Clone)]
Expand All @@ -27,8 +27,11 @@ where
<B as Body>::Error: Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>,
{
/// wrapper request fn
pub fn request(&self, req: Request<B>) -> ResponseFuture {
self.inner.request(req)
pub async fn request(
&self,
req: Request<B>,
) -> std::result::Result<Response<Incoming>, hyper_util::client::legacy::Error> {
self.inner.request(req).await
}
}

Expand Down
2 changes: 1 addition & 1 deletion relay-lib/src/relay/forwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use http::{
};
use hyper::body::{Body, Incoming};
use hyper_tls::HttpsConnector;
use hyper_util::client::connect::{Connect, HttpConnector};
use hyper_util::client::legacy::connect::{Connect, HttpConnector};
use std::{net::SocketAddr, sync::Arc};
use url::Url;

Expand Down
2 changes: 1 addition & 1 deletion relay-lib/src/relay/forwarder_handle_url.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::forwarder::InnerForwarder;
use crate::{constants::HOSTNAME, error::*, log::*};
use hyper::body::Body;
use hyper_util::client::connect::Connect;
use hyper_util::client::legacy::connect::Connect;
use rustc_hash::FxHashMap as HashMap;
use url::Url;

Expand Down
20 changes: 12 additions & 8 deletions relay-lib/src/relay/relay_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ use super::{
use crate::{
error::*, globals::Globals, hyper_executor::LocalExecutor, log::*, relay::passthrough_response, validator::Validator,
};
use hyper::{body::Incoming, header, service::service_fn, Request, StatusCode};
use hyper::{
body::Incoming,
header,
rt::{Read, Write},
service::service_fn,
Request, StatusCode,
};
use hyper_tls::HttpsConnector;
use hyper_util::{
client::connect::{Connect, HttpConnector},
client::legacy::connect::{Connect, HttpConnector},
rt::TokioIo,
server::{self, conn::auto::Builder as ConnectionBuilder},
};
use std::{net::SocketAddr, sync::Arc, time::Duration};
use tokio::{
io::{AsyncRead, AsyncWrite},
time::timeout,
};
use tokio::time::timeout;

/// (M)ODoH Relay main object
pub struct Relay<C>
Expand Down Expand Up @@ -81,7 +85,7 @@ where
/// Serve tcp stream
fn serve_connection<I>(&self, stream: I, peer_addr: SocketAddr)
where
I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
I: Read + Write + Unpin + Send + 'static,
{
let request_count = self.request_count.clone();
if request_count.increment() > self.globals.relay_config.max_clients {
Expand Down Expand Up @@ -119,7 +123,7 @@ where
let tcp_listener = tcp_socket.listen(self.globals.relay_config.tcp_listen_backlog)?;
info!("Start TCP listener serving with HTTP request for configured host names");
while let Ok((stream, peer_addr)) = tcp_listener.accept().await {
self.serve_connection(stream, peer_addr);
self.serve_connection(TokioIo::new(stream), peer_addr);
}
Ok(()) as Result<()>
};
Expand Down
2 changes: 1 addition & 1 deletion relay-lib/src/validator/validator_jwks_service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::validator_main::Validator;
use crate::{constants::JWKS_REFETCH_DELAY_SEC, error::*, log::*};
use futures::{select, FutureExt};
use hyper_util::client::connect::Connect;
use hyper_util::client::legacy::connect::Connect;
use std::{sync::Arc, time::Duration};
use tokio::time::sleep;

Expand Down
2 changes: 1 addition & 1 deletion relay-lib/src/validator/validator_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use http::{header, HeaderValue, Method, Request};
use http_body_util::{combinators::BoxBody, BodyExt, Empty};
use hyper::body::{Body, Buf, Bytes};
use hyper_tls::HttpsConnector;
use hyper_util::client::connect::{Connect, HttpConnector};
use hyper_util::client::legacy::connect::{Connect, HttpConnector};
use serde::de::DeserializeOwned;
use std::{sync::Arc, time::Duration};
use url::Url;
Expand Down
2 changes: 1 addition & 1 deletion submodules/hyper-tls
Submodule hyper-tls updated 3 files
+5 −5 Cargo.toml
+1 −1 src/client.rs
+1 −1 src/stream.rs
1 change: 0 additions & 1 deletion submodules/hyper-util
Submodule hyper-util deleted from e91fba

0 comments on commit c5f6088

Please sign in to comment.