Skip to content

Commit

Permalink
chore: Update to tower 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Sep 6, 2024
1 parent e92b9fe commit 457468f
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 19 deletions.
5 changes: 3 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ tower = ["dep:hyper", "dep:hyper-util", "dep:tower", "tower?/timeout", "dep:http
json-codec = ["dep:serde", "dep:serde_json", "dep:bytes"]
compression = ["tonic/gzip"]
tls = ["tonic/tls"]
tls-rustls = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:hyper-rustls", "dep:tower", "tower-http/util", "tower-http/add-extension", "dep:rustls-pemfile", "dep:tokio-rustls", "dep:pin-project", "dep:http-body-util"]
tls-rustls = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:hyper-rustls", "dep:tower04", "tower-http/util", "tower-http/add-extension", "dep:rustls-pemfile", "dep:tokio-rustls", "dep:pin-project", "dep:http-body-util"]
dynamic-load-balance = ["dep:tower"]
timeout = ["tokio/time", "dep:tower", "tower?/timeout"]
tls-client-auth = ["tonic/tls"]
Expand All @@ -300,7 +300,8 @@ tonic-types = { path = "../tonic-types", optional = true }
async-stream = { version = "0.3", optional = true }
tokio-stream = { version = "0.1", optional = true }
tokio-util = { version = "0.7.8", optional = true }
tower = { version = "0.4", optional = true }
tower = { version = "0.5", optional = true }
tower04 = { package = "tower", version = "0.4", optional = true }
rand = { version = "0.8", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
Expand Down
1 change: 1 addition & 0 deletions examples/src/tls_rustls/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! This examples shows how you can combine `hyper-rustls` and `tonic` to
//! provide a custom `ClientConfig` for the tls configuration.
use tower04 as tower;

pub mod pb {
tonic::include_proto!("/grpc.examples.unaryecho");
Expand Down
2 changes: 2 additions & 0 deletions examples/src/tls_rustls/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tower04 as tower;

pub mod pb {
tonic::include_proto!("/grpc.examples.unaryecho");
}
Expand Down
2 changes: 1 addition & 1 deletion interop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ prost = "0.13"
tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros"]}
tokio-stream = "0.1"
tonic = {path = "../tonic", features = ["tls"]}
tower = {version = "0.4"}
tower = "0.5"
tracing-subscriber = {version = "0.3"}

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion tests/compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ prost = "0.13"
tokio = {version = "1.0", features = ["macros", "rt-multi-thread", "net"]}
tokio-stream = "0.1"
tonic = {path = "../../tonic", features = ["gzip", "zstd"]}
tower = {version = "0.4", features = []}
tower = "0.5"
tower-http = {version = "0.5", features = ["map-response-body", "map-request-body"]}

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ http = "1"
http-body = "1"
hyper-util = "0.1"
tokio-stream = {version = "0.1.5", features = ["net"]}
tower = {version = "0.4", features = []}
tower = "0.5"
tower-http = { version = "0.5", features = ["set-header", "trace"] }
tower-service = "0.3"
tracing = "0.1"
Expand Down
6 changes: 3 additions & 3 deletions tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ server = [
channel = [
"dep:hyper", "hyper?/client",
"dep:hyper-util", "hyper-util?/client-legacy",
"dep:tower", "tower?/balance", "tower?/buffer", "tower?/discover", "tower?/limit",
"dep:tower", "tower?/balance", "tower?/buffer", "tower?/discover", "tower?/limit", "tower?/util",
"dep:tokio", "tokio?/time",
"dep:hyper-timeout",
]
Expand Down Expand Up @@ -84,7 +84,7 @@ hyper = {version = "1", features = ["http1", "http2"], optional = true}
hyper-util = { version = "0.1.4", features = ["tokio"], optional = true }
socket2 = { version = "0.5", optional = true, features = ["all"] }
tokio = {version = "1", default-features = false, optional = true}
tower = {version = "0.4.7", default-features = false, optional = true}
tower = {version = "0.5", default-features = false, optional = true}
axum = {version = "0.7", default-features = false, optional = true}

# rustls
Expand All @@ -107,7 +107,7 @@ quickcheck_macros = "1.0"
rand = "0.8"
static_assertions = "1.0"
tokio = {version = "1.0", features = ["rt", "macros"]}
tower = {version = "0.4.7", features = ["full"]}
tower = {version = "0.5", features = ["full"]}

[package.metadata.docs.rs]
all-features = true
Expand Down
15 changes: 8 additions & 7 deletions tonic/src/transport/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ use tower::balance::p2c::Balance;
use tower::{
buffer::{self, Buffer},
discover::{Change, Discover},
util::{BoxService, Either},
util::BoxService,
Service,
};

type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
type Svc = Either<Connection, BoxService<Request<BoxBody>, Response<BoxBody>, crate::Error>>;

const DEFAULT_BUFFER_SIZE: usize = 1024;

Expand Down Expand Up @@ -65,14 +64,15 @@ const DEFAULT_BUFFER_SIZE: usize = 1024;
/// cloning the `Channel` type is cheap and encouraged.
#[derive(Clone)]
pub struct Channel {
svc: Buffer<Svc, Request<BoxBody>>,
svc: Buffer<Request<BoxBody>, BoxFuture<'static, Result<Response<BoxBody>, crate::Error>>>,
}

/// A future that resolves to an HTTP response.
///
/// This is returned by the `Service::call` on [`Channel`].
pub struct ResponseFuture {
inner: buffer::future::ResponseFuture<<Svc as Service<Request<BoxBody>>>::Future>,
inner:
buffer::future::ResponseFuture<BoxFuture<'static, Result<Response<BoxBody>, crate::Error>>>,
}

impl Channel {
Expand Down Expand Up @@ -156,7 +156,8 @@ impl Channel {
let executor = endpoint.executor.clone();

let svc = Connection::lazy(connector, endpoint);
let (svc, worker) = Buffer::pair(Either::A(svc), buffer_size);
let (svc, worker) = Buffer::pair(svc, buffer_size);

executor.execute(worker);

Channel { svc }
Expand All @@ -175,7 +176,7 @@ impl Channel {
let svc = Connection::connect(connector, endpoint)
.await
.map_err(super::Error::from_source)?;
let (svc, worker) = Buffer::pair(Either::A(svc), buffer_size);
let (svc, worker) = Buffer::pair(svc, buffer_size);
executor.execute(worker);

Ok(Channel { svc })
Expand All @@ -191,7 +192,7 @@ impl Channel {
let svc = Balance::new(discover);

let svc = BoxService::new(svc);
let (svc, worker) = Buffer::pair(Either::B(svc), buffer_size);
let (svc, worker) = Buffer::pair(svc, buffer_size);
executor.execute(Box::pin(worker));

Channel { svc }
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,10 @@ where
.layer(BoxCloneService::layer())
.map_request(move |mut request: Request<BoxBody>| {
match &conn_info {
tower::util::Either::A(inner) => {
tower::util::Either::Left(inner) => {
request.extensions_mut().insert(inner.clone());
}
tower::util::Either::B(inner) => {
tower::util::Either::Right(inner) => {
#[cfg(feature = "tls")]
{
request.extensions_mut().insert(inner.clone());
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/server/service/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl<IO> ServerIo<IO> {
IO: Connected,
{
match self {
Self::Io(io) => Either::A(io.connect_info()),
Self::Io(io) => Either::Left(io.connect_info()),
#[cfg(feature = "tls")]
Self::TlsIo(io) => Either::B(io.connect_info()),
Self::TlsIo(io) => Either::Right(io.connect_info()),
}
}
}
Expand Down

0 comments on commit 457468f

Please sign in to comment.