Skip to content

Commit d02ee2d

Browse files
xumaplemapxu
andauthored
Separate out Tls ConnectInfo trait support into separate tls feature (#2402)
## Motivation #2360 ## Solution Added the `tls-connect-info` feature which derives from `_tls-any` feature. --------- Co-authored-by: Maple Xu <[email protected]>
1 parent 52f9de8 commit d02ee2d

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,14 @@ jobs:
234234
echo "PROTOC_INCLUDE=${PROTOC_DIR}/include" >> $GITHUB_ENV
235235
fi
236236
- uses: Swatinem/rust-cache@v2
237-
- run: cargo hack udeps --workspace --exclude-features=_tls-any,tls,tls-aws-lc,tls-ring --each-feature
237+
- run: cargo hack udeps --workspace --exclude-features=_tls-any,tls,tls-aws-lc,tls-ring,tls-connect-info --each-feature
238238
- run: cargo udeps --package tonic --features tls-ring,transport
239239
- run: cargo udeps --package tonic --features tls-ring,server
240240
- run: cargo udeps --package tonic --features tls-ring,channel
241241
- run: cargo udeps --package tonic --features tls-aws-lc,transport
242242
- run: cargo udeps --package tonic --features tls-aws-lc,server
243243
- run: cargo udeps --package tonic --features tls-aws-lc,channel
244+
- run: cargo udeps --package tonic --features tls-connect-info
244245

245246
check:
246247
runs-on: ${{ matrix.os }}

tonic/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ gzip = ["dep:flate2"]
2525
deflate = ["dep:flate2"]
2626
zstd = ["dep:zstd"]
2727
default = ["router", "transport", "codegen"]
28-
_tls-any = ["dep:tokio-rustls", "dep:tokio", "tokio?/rt", "tokio?/macros"] # Internal. Please choose one of `tls-ring` or `tls-aws-lc`
28+
_tls-any = ["dep:tokio", "tokio?/rt", "tokio?/macros", "tls-connect-info"] # Internal. Please choose one of `tls-ring` or `tls-aws-lc`
2929
tls-ring = ["_tls-any", "tokio-rustls/ring"]
3030
tls-aws-lc = ["_tls-any", "tokio-rustls/aws-lc-rs"]
3131
tls-native-roots = ["_tls-any", "channel", "dep:rustls-native-certs"]
3232
tls-webpki-roots = ["_tls-any","channel", "dep:webpki-roots"]
33+
tls-connect-info = ["dep:tokio-rustls"]
3334
router = ["dep:axum", "dep:tower", "tower?/util"]
3435
server = [
3536
"dep:h2",

tonic/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
//! [`rustls-native-certs`] crate. Not enabled by default.
3333
//! - `tls-webpki-roots`: Add the standard trust roots from the [`webpki-roots`] crate to
3434
//! `rustls`-based gRPC clients. Not enabled by default.
35+
//! - `tls-connect-info`: Adds additional implementations of [`Connected`]
36+
//! on common TLS connectors. Not enabled by default, unless any of the other `tls-*`
37+
//! features are enabled. This feature is useful for when trying to use a custom
38+
//! TLS connector with `connect_with_connector` without enabling any `tls-*` features.
3539
//! - `gzip`: Enables compressing requests, responses, and streams. Depends on [`flate2`].
3640
//! Not enabled by default.
3741
//! - `deflate`: Enables compressing requests, responses, and streams. Depends on [`flate2`].
@@ -78,6 +82,7 @@
7882
//! [`Codec`]: codec/trait.Codec.html
7983
//! [`Channel`]: transport/struct.Channel.html
8084
//! [`Server`]: transport/struct.Server.html
85+
//! [`Connected`]: transport/server/trait.Connected.html
8186
//! [`rustls`]: https://docs.rs/rustls
8287
//! [`client`]: client/index.html
8388
//! [`transport`]: transport/index.html

tonic/src/transport/server/conn.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::net::SocketAddr;
22
use tokio::net::TcpStream;
33

4-
#[cfg(feature = "_tls-any")]
4+
#[cfg(feature = "tls-connect-info")]
55
use std::sync::Arc;
6-
#[cfg(feature = "_tls-any")]
6+
#[cfg(feature = "tls-connect-info")]
77
use tokio_rustls::rustls::pki_types::CertificateDer;
8-
#[cfg(feature = "_tls-any")]
8+
#[cfg(feature = "tls-connect-info")]
99
use tokio_rustls::server::TlsStream;
1010

1111
/// Trait that connected IO resources implement and use to produce info about the connection.
@@ -102,7 +102,7 @@ impl Connected for tokio::io::DuplexStream {
102102
fn connect_info(&self) -> Self::ConnectInfo {}
103103
}
104104

105-
#[cfg(feature = "_tls-any")]
105+
#[cfg(feature = "tls-connect-info")]
106106
impl<T> Connected for TlsStream<T>
107107
where
108108
T: Connected,
@@ -128,14 +128,14 @@ where
128128
/// See [`Connected`] for more details.
129129
///
130130
/// [ext]: crate::Request::extensions
131-
#[cfg(feature = "_tls-any")]
131+
#[cfg(feature = "tls-connect-info")]
132132
#[derive(Debug, Clone)]
133133
pub struct TlsConnectInfo<T> {
134134
inner: T,
135135
certs: Option<Arc<Vec<CertificateDer<'static>>>>,
136136
}
137137

138-
#[cfg(feature = "_tls-any")]
138+
#[cfg(feature = "tls-connect-info")]
139139
impl<T> TlsConnectInfo<T> {
140140
/// Get a reference to the underlying connection info.
141141
pub fn get_ref(&self) -> &T {

0 commit comments

Comments
 (0)