Skip to content

Commit b947e1a

Browse files
authored
feat(channel): Make channel feature additive (#1574)
* feat(channel): Make channel feature additive * chore(channel): Move add_origin service module to channel module * chore(channel): Move user_agent service to channel module * chore(channel): Move reconnect service to channel module * chore(channel): Move connection service to channel module * chore(channel): Move discover service to channel module * feat(channel): Remove unused Connected implement for BoxedIo * chore(channel): Move channel part of io service to channel module * chore(channel): Move channel part of tls service to channel module * chore(channel): Move connector service to channel module * chore(channel): Move executor service to channel module * chore(channel): Clean up scope of channel service module * chore(channel): Clean up importing in channel service * chore(doc): Update feature flag document about transport and channel
1 parent e2c506a commit b947e1a

File tree

22 files changed

+242
-210
lines changed

22 files changed

+242
-210
lines changed

examples/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ tracing = ["dep:tracing", "dep:tracing-subscriber"]
276276
uds = ["tokio-stream/net", "dep:tower", "dep:hyper", "dep:hyper-util"]
277277
streaming = ["tokio-stream", "dep:h2"]
278278
mock = ["tokio-stream", "dep:tower", "dep:hyper-util"]
279-
tower = ["dep:hyper", "dep:hyper-util", "dep:tower", "dep:http"]
279+
tower = ["dep:hyper", "dep:hyper-util", "dep:tower", "tower?/timeout", "dep:http"]
280280
json-codec = ["dep:serde", "dep:serde_json", "dep:bytes"]
281281
compression = ["tonic/gzip"]
282282
tls = ["tonic/tls"]
283283
tls-rustls = ["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"]
284284
dynamic-load-balance = ["dep:tower"]
285-
timeout = ["tokio/time", "dep:tower"]
285+
timeout = ["tokio/time", "dep:tower", "tower?/timeout"]
286286
tls-client-auth = ["tonic/tls"]
287287
types = ["dep:tonic-types"]
288288
h2c = ["dep:hyper", "dep:tower", "dep:http", "dep:hyper-util"]

tonic/Cargo.toml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,29 @@ version = "0.11.0"
2626
codegen = ["dep:async-trait"]
2727
gzip = ["dep:flate2"]
2828
zstd = ["dep:zstd"]
29-
default = ["transport", "codegen", "prost"]
29+
default = ["channel", "codegen", "prost"]
3030
prost = ["dep:prost"]
3131
tls = ["dep:rustls-pemfile", "transport", "dep:tokio-rustls", "dep:tokio", "tokio?/rt", "tokio?/macros"]
3232
tls-roots = ["tls-roots-common", "dep:rustls-native-certs"]
33-
tls-roots-common = ["tls"]
33+
tls-roots-common = ["tls", "channel"]
3434
tls-webpki-roots = ["tls-roots-common", "dep:webpki-roots"]
3535
router = ["dep:axum"]
3636
transport = [
3737
"router",
3838
"dep:async-stream",
39-
"channel",
4039
"dep:h2",
41-
"dep:hyper", "dep:hyper-util", "dep:hyper-timeout",
40+
"dep:hyper", "dep:hyper-util",
4241
"dep:socket2",
4342
"dep:tokio", "tokio?/macros", "tokio?/net", "tokio?/time",
44-
"dep:tower",
43+
"dep:tower", "tower?/util", "tower?/limit",
44+
]
45+
channel = [
46+
"transport",
47+
"dep:hyper", "hyper?/client",
48+
"dep:hyper-util", "hyper-util?/client-legacy",
49+
"dep:tower", "tower?/balance", "tower?/buffer", "tower?/discover", "tower?/load", "tower?/make",
50+
"dep:hyper-timeout",
4551
]
46-
channel = []
4752

4853
# [[bench]]
4954
# name = "bench_main"
@@ -71,13 +76,12 @@ async-trait = {version = "0.1.13", optional = true}
7176
# transport
7277
async-stream = {version = "0.3", optional = true}
7378
h2 = {version = "0.4", optional = true}
74-
hyper = {version = "1", features = ["full"], optional = true}
75-
hyper-util = { version = ">=0.1.4, <0.2", features = ["full"], optional = true }
76-
hyper-timeout = {version = "0.5", optional = true}
79+
hyper = {version = "1", features = ["http1", "http2", "server"], optional = true}
80+
hyper-util = { version = ">=0.1.4, <0.2", features = ["service", "server-auto", "tokio"], optional = true }
7781
socket2 = { version = ">=0.4.7, <0.6.0", optional = true, features = ["all"] }
7882
tokio = {version = "1", default-features = false, optional = true}
7983
tokio-stream = { version = "0.1", features = ["net"] }
80-
tower = {version = "0.4.7", default-features = false, features = ["balance", "buffer", "discover", "limit", "load", "make", "timeout", "util"], optional = true}
84+
tower = {version = "0.4.7", default-features = false, optional = true}
8185
axum = {version = "0.7", default-features = false, optional = true}
8286

8387
# rustls
@@ -90,6 +94,9 @@ webpki-roots = { version = "0.26", optional = true }
9094
flate2 = {version = "1.0", optional = true}
9195
zstd = { version = "0.13.0", optional = true }
9296

97+
# channel
98+
hyper-timeout = {version = "0.5", optional = true}
99+
93100
[dev-dependencies]
94101
bencher = "0.1.5"
95102
quickcheck = "1.0"

tonic/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
//!
1717
//! # Feature Flags
1818
//!
19-
//! - `transport`: Enables the fully featured, batteries included client and server
20-
//! implementation based on [`hyper`], [`tower`] and [`tokio`]. Enabled by default.
21-
//! - `channel`: Enables just the full featured channel/client portion of the `transport`
22-
//! feature.
19+
//! - `transport`: Enables just the full featured server portion of the `channel` feature.
20+
//! - `channel`: Enables the fully featured, batteries included client and server
21+
//! implementation based on [`hyper`], [`tower`] and [`tokio`]. Enabled by default.
2322
//! - `codegen`: Enables all the required exports and optional dependencies required
2423
//! for [`tonic-build`]. Enabled by default.
2524
//! - `tls`: Enables the `rustls` based TLS options for the `transport` feature. Not

tonic/src/status.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,10 @@ fn find_status_in_source_chain(err: &(dyn Error + 'static)) -> Option<Status> {
617617
// matches the spec of:
618618
// > The service is currently unavailable. This is most likely a transient condition that
619619
// > can be corrected if retried with a backoff.
620-
#[cfg(feature = "transport")]
621-
if let Some(connect) = err.downcast_ref::<crate::transport::ConnectError>() {
620+
#[cfg(feature = "channel")]
621+
if let Some(connect) =
622+
err.downcast_ref::<crate::transport::channel::service::ConnectError>()
623+
{
622624
return Some(Status::unavailable(connect.to_string()));
623625
}
624626

tonic/src/transport/channel/endpoint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use super::super::service;
1+
#[cfg(feature = "tls")]
2+
use super::service::TlsConnector;
3+
use super::service::{self, Executor, SharedExec};
24
use super::Channel;
35
#[cfg(feature = "tls")]
46
use super::ClientTlsConfig;
5-
#[cfg(feature = "tls")]
6-
use crate::transport::service::TlsConnector;
7-
use crate::transport::{service::SharedExec, Error, Executor};
7+
use crate::transport::Error;
88
use bytes::Bytes;
99
use http::{uri::Uri, HeaderValue};
1010
use hyper::rt;

tonic/src/transport/channel/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Client implementation and builder.
22
33
mod endpoint;
4+
pub(crate) mod service;
45
#[cfg(feature = "tls")]
56
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
67
mod tls;
@@ -9,9 +10,8 @@ pub use endpoint::Endpoint;
910
#[cfg(feature = "tls")]
1011
pub use tls::ClientTlsConfig;
1112

12-
use super::service::{Connection, DynamicServiceStream, SharedExec};
13+
use self::service::{Connection, DynamicServiceStream, Executor, SharedExec};
1314
use crate::body::BoxBody;
14-
use crate::transport::Executor;
1515
use bytes::Bytes;
1616
use http::{
1717
uri::{InvalidUri, Uri},
File renamed without changes.

tonic/src/transport/service/connection.rs renamed to tonic/src/transport/channel/service/connection.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use super::SharedExec;
2-
use super::{grpc_timeout::GrpcTimeout, reconnect::Reconnect, AddOrigin, UserAgent};
1+
use super::{AddOrigin, Reconnect, SharedExec, UserAgent};
32
use crate::{
43
body::{boxed, BoxBody},
5-
transport::{BoxFuture, Endpoint},
4+
transport::{service::GrpcTimeout, BoxFuture, Endpoint},
65
};
76
use http::Uri;
87
use hyper::rt;
@@ -36,7 +35,7 @@ impl Connection {
3635
C::Future: Unpin + Send,
3736
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
3837
{
39-
let mut settings: Builder<super::SharedExec> = Builder::new(endpoint.executor.clone())
38+
let mut settings: Builder<SharedExec> = Builder::new(endpoint.executor.clone())
4039
.initial_stream_window_size(endpoint.init_stream_window_size)
4140
.initial_connection_window_size(endpoint.init_connection_window_size)
4241
.keep_alive_interval(endpoint.http2_keep_alive_interval)
@@ -158,12 +157,12 @@ impl tower::Service<http::Request<BoxBody>> for SendRequest {
158157

159158
struct MakeSendRequestService<C> {
160159
connector: C,
161-
executor: super::SharedExec,
162-
settings: Builder<super::SharedExec>,
160+
executor: SharedExec,
161+
settings: Builder<SharedExec>,
163162
}
164163

165164
impl<C> MakeSendRequestService<C> {
166-
fn new(connector: C, executor: SharedExec, settings: Builder<super::SharedExec>) -> Self {
165+
fn new(connector: C, executor: SharedExec, settings: Builder<SharedExec>) -> Self {
167166
Self {
168167
connector,
169168
executor,

tonic/src/transport/service/connector.rs renamed to tonic/src/transport/channel/service/connector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::super::BoxFuture;
2-
use super::io::BoxedIo;
1+
use super::BoxedIo;
32
#[cfg(feature = "tls")]
4-
use super::tls::TlsConnector;
3+
use super::TlsConnector;
4+
use crate::transport::BoxFuture;
55
use http::Uri;
66
use std::fmt;
77
use std::task::{Context, Poll};

tonic/src/transport/service/discover.rs renamed to tonic/src/transport/channel/service/discover.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use super::connection::Connection;
2-
use crate::transport::Endpoint;
1+
use super::super::{Connection, Endpoint};
32

43
use hyper_util::client::legacy::connect::HttpConnector;
54
use std::{

0 commit comments

Comments
 (0)