Skip to content

Commit

Permalink
Merge branch 'hyper-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Oct 16, 2024
2 parents 9aa62fb + 74b278a commit 0b6e087
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 444 deletions.
203 changes: 126 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ futures = "0.3.15"
# Tonic and related crates
tonic = "0.12.3"
tonic-build = { version = "0.10.0", default-features = false }
tower = "0.4"
tower = { version = "0.5.1", features = ["util"] }
prost = "0.13.3"
prost-types = "0.13.3"
hyper-util = "0.1.8"
hyper-util = {version = "0.1.8", features = ["client", "client-legacy", "http2"]}

env_logger = "0.10.0"
thiserror = "1.0.57"
Expand Down
11 changes: 7 additions & 4 deletions mullvad-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ libc = "0.2"
chrono = { workspace = true }
thiserror = { workspace = true }
futures = { workspace = true }
http = "0.2"
hyper = { version = "0.14", features = ["client", "stream", "http1", "tcp" ] }
http = "1.1.0"
hyper = { version = "1.4.1", features = ["client", "http1"] }
hyper-util = { workspace = true}
http-body-util = "0.1.2"
tower = { workspace = true }
ipnetwork = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread", "net", "io-std", "io-util", "fs"] }
tokio-rustls = "0.24.1"
tokio-rustls = { version = "0.26.0", features = ["logging", "tls12", "ring"], default-features = false}
tokio-socks = "0.5.1"
rustls-pemfile = "1.0.3"
rustls-pemfile = "2.1.3"

mullvad-fs = { path = "../mullvad-fs" }
mullvad-types = { path = "../mullvad-types" }
Expand Down
2 changes: 1 addition & 1 deletion mullvad-api/src/abortable_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! immediately instead of after the socket times out.
use futures::{channel::oneshot, future::Fuse, FutureExt};
use hyper::client::connect::{Connected, Connection};
use hyper_util::client::legacy::connect::{Connected, Connection};
use std::{
future::Future,
io,
Expand Down
13 changes: 7 additions & 6 deletions mullvad-api/src/https_client_with_sni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use futures::{channel::mpsc, future, pin_mut, StreamExt};
#[cfg(target_os = "android")]
use futures::{channel::oneshot, sink::SinkExt};
use http::uri::Scheme;
use hyper::{
client::connect::dns::{GaiResolver, Name},
service::Service,
Uri,
use hyper::Uri;
use hyper_util::{
client::legacy::connect::dns::{GaiResolver, Name},
rt::TokioIo,
};
use shadowsocks::{
config::ServerType,
Expand Down Expand Up @@ -39,6 +39,7 @@ use tokio::{
net::{TcpSocket, TcpStream},
time::timeout,
};
use tower::Service;

#[cfg(feature = "api-override")]
use crate::{proxy::ConnectionDecorator, API};
Expand Down Expand Up @@ -407,7 +408,7 @@ impl fmt::Debug for HttpsConnectorWithSni {
}

impl Service<Uri> for HttpsConnectorWithSni {
type Response = AbortableStream<ApiConnection>;
type Response = TokioIo<AbortableStream<ApiConnection>>;
type Error = io::Error;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
Expand Down Expand Up @@ -472,7 +473,7 @@ impl Service<Uri> for HttpsConnectorWithSni {
inner.stream_handles.push(socket_handle);
}

Ok(stream)
Ok(TokioIo::new(stream))
};

Box::pin(fut)
Expand Down
3 changes: 1 addition & 2 deletions mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(rustdoc::private_intra_doc_links)]
#[cfg(target_os = "android")]
use futures::channel::mpsc;
use hyper::Method;
#[cfg(target_os = "android")]
use mullvad_types::account::{PlayPurchase, PlayPurchasePaymentToken};
use mullvad_types::{
Expand Down Expand Up @@ -710,7 +709,7 @@ impl AppVersionProxy {
let service = self.handle.service.clone();

let path = format!("{APP_URL_PREFIX}/releases/{platform}/{app_version}");
let request = self.handle.factory.request(&path, Method::GET);
let request = self.handle.factory.get(&path);

async move {
let request = request?
Expand Down
21 changes: 8 additions & 13 deletions mullvad-api/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hyper::client::connect::Connected;
use hyper_util::client::legacy::connect::{Connected, Connection};
use serde::{Deserialize, Serialize};
use std::{
fmt, io,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl ApiConnectionMode {
}
}

/// Implements `hyper::client::connect::Connection` by wrapping a type.
/// Implements `Connection` by wrapping a type.
pub struct ConnectionDecorator<T: AsyncRead + AsyncWrite>(pub T);

impl<T: AsyncRead + AsyncWrite + Unpin> AsyncRead for ConnectionDecorator<T> {
Expand Down Expand Up @@ -223,26 +223,21 @@ impl<T: AsyncRead + AsyncWrite + Unpin> AsyncWrite for ConnectionDecorator<T> {
}
}

impl<T: AsyncRead + AsyncWrite> hyper::client::connect::Connection for ConnectionDecorator<T> {
impl<T: AsyncRead + AsyncWrite> Connection for ConnectionDecorator<T> {
fn connected(&self) -> Connected {
Connected::new()
}
}

trait Connection: AsyncRead + AsyncWrite + Unpin + hyper::client::connect::Connection + Send {}
trait ConnectionMullvad: AsyncRead + AsyncWrite + Unpin + Connection + Send {}

impl<T: AsyncRead + AsyncWrite + Unpin + hyper::client::connect::Connection + Send> Connection
for T
{
}
impl<T: AsyncRead + AsyncWrite + Unpin + Connection + Send> ConnectionMullvad for T {}

/// Stream that represents a Mullvad API connection
pub struct ApiConnection(Box<dyn Connection>);
pub struct ApiConnection(Box<dyn ConnectionMullvad>);

impl ApiConnection {
pub fn new<
T: AsyncRead + AsyncWrite + Unpin + hyper::client::connect::Connection + Send + 'static,
>(
pub fn new<T: AsyncRead + AsyncWrite + Unpin + Connection + Send + 'static>(
conn: Box<T>,
) -> Self {
Self(conn)
Expand Down Expand Up @@ -277,7 +272,7 @@ impl AsyncWrite for ApiConnection {
}
}

impl hyper::client::connect::Connection for ApiConnection {
impl Connection for ApiConnection {
fn connected(&self) -> Connected {
self.0.connected()
}
Expand Down
4 changes: 2 additions & 2 deletions mullvad-api/src/relay_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::rest;

use hyper::{header, Method, StatusCode};
use hyper::{header, StatusCode};
use mullvad_types::{location, relay_list};
use talpid_types::net::wireguard;

Expand Down Expand Up @@ -34,7 +34,7 @@ impl RelayListProxy {
etag: Option<String>,
) -> impl Future<Output = Result<Option<relay_list::RelayList>, rest::Error>> {
let service = self.handle.service.clone();
let request = self.handle.factory.request("app/v1/relays", Method::GET);
let request = self.handle.factory.get("app/v1/relays");

async move {
let mut request = request?
Expand Down
Loading

0 comments on commit 0b6e087

Please sign in to comment.