Skip to content

Commit fd2c1bb

Browse files
authored
Add BoxTcp and BoxNewTcp service type aliases (#1177)
We have BoxHttp and BoxNewHttp aliases that help reduce type boilerplate. This change adds similar aliases for TCP-forwarding stacks.
1 parent 46cd0d9 commit fd2c1bb

File tree

11 files changed

+27
-33
lines changed

11 files changed

+27
-33
lines changed

linkerd/app/core/src/svc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub type BoxHttp<B = http::BoxBody> =
3636

3737
pub type BoxNewHttp<T, B = http::BoxBody> = BoxNewService<T, BoxHttp<B>>;
3838

39+
pub type BoxTcp<I> = BoxService<I, (), Error>;
40+
41+
pub type BoxNewTcp<T, I> = BoxNewService<T, BoxTcp<I>>;
42+
3943
#[derive(Clone, Debug)]
4044
pub struct Layers<L>(L);
4145

linkerd/app/gateway/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn stack<I, O, P, R>(
7474
outbound: Outbound<O>,
7575
profiles: P,
7676
resolve: R,
77-
) -> svc::BoxNewService<GatewayConnection, svc::BoxService<I, (), Error>>
77+
) -> svc::BoxNewTcp<GatewayConnection, I>
7878
where
7979
I: io::AsyncRead + io::AsyncWrite + io::PeerAddr + fmt::Debug + Send + Sync + Unpin + 'static,
8080
O: Clone + Send + Sync + Unpin + 'static,

linkerd/app/inbound/src/http/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use linkerd_app_core::{
2323
use tracing::debug_span;
2424

2525
impl<H> Inbound<H> {
26-
pub fn push_http_server<T, I, HSvc>(
27-
self,
28-
) -> Inbound<svc::BoxNewService<T, svc::BoxService<I, (), Error>>>
26+
pub fn push_http_server<T, I, HSvc>(self) -> Inbound<svc::BoxNewTcp<T, I>>
2927
where
3028
T: Param<Version>
3129
+ Param<http::normalize_uri::DefaultAuthority>
@@ -351,7 +349,7 @@ pub mod fuzz_logic {
351349
rt: ProxyRuntime,
352350
profiles: resolver::Profiles,
353351
connect: Connect<Remote<ServerAddr>>,
354-
) -> svc::BoxNewService<HttpAccept, svc::BoxService<I, (), linkerd_app_core::Error>>
352+
) -> svc::BoxNewTcp<HttpAccept, I>
355353
where
356354
I: io::AsyncRead + io::AsyncWrite + io::PeerAddr + Send + Unpin + 'static,
357355
{

linkerd/app/inbound/src/http/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use linkerd_app_core::{
1313
svc::{self, NewService, Param},
1414
tls,
1515
transport::{ClientAddr, Remote, ServerAddr},
16-
Conditional, Error, NameAddr, ProxyRuntime,
16+
Conditional, NameAddr, ProxyRuntime,
1717
};
1818
use linkerd_app_test::connect::ConnectFuture;
1919
use linkerd_tracing::test::trace_init;
@@ -24,7 +24,7 @@ fn build_server<I>(
2424
rt: ProxyRuntime,
2525
profiles: resolver::Profiles,
2626
connect: Connect<Remote<ServerAddr>>,
27-
) -> svc::BoxNewService<HttpAccept, svc::BoxService<I, (), Error>>
27+
) -> svc::BoxNewTcp<HttpAccept, I>
2828
where
2929
I: io::AsyncRead + io::AsyncWrite + io::PeerAddr + Send + Unpin + 'static,
3030
{

linkerd/app/inbound/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ where
222222
proxy_port: u16,
223223
profiles: P,
224224
gateway: G,
225-
) -> Inbound<svc::BoxNewService<T, svc::BoxService<I, (), Error>>>
225+
) -> Inbound<svc::BoxNewTcp<T, I>>
226226
where
227227
T: svc::Param<Remote<ClientAddr>> + svc::Param<OrigDstAddr>,
228228
T: Clone + Send + 'static,
@@ -280,6 +280,7 @@ where
280280
detect_timeout,
281281
http::DetectHttp::default(),
282282
))
283+
.check_new_service::<TcpAccept, _>()
283284
.push_request_filter(require_id)
284285
.push(rt.metrics.transport.layer_accept())
285286
.push_request_filter(TcpAccept::try_from)

linkerd/app/outbound/src/endpoint.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use linkerd_app_core::{
55
proxy::{api_resolve::Metadata, resolve::map_endpoint::MapEndpoint},
66
svc, tls,
77
transport::{self, addrs::*},
8-
transport_header, Conditional, Error,
8+
transport_header, Conditional,
99
};
1010
use std::{fmt, net::SocketAddr};
1111

@@ -190,9 +190,7 @@ impl<P: Copy + std::fmt::Debug> MapEndpoint<Concrete<P>, Metadata> for FromMetad
190190
// === Outbound ===
191191

192192
impl<S> Outbound<S> {
193-
pub fn push_endpoint<I>(
194-
self,
195-
) -> Outbound<svc::BoxNewService<tcp::Endpoint, svc::BoxService<I, (), Error>>>
193+
pub fn push_endpoint<I>(self) -> Outbound<svc::BoxNewTcp<tcp::Endpoint, I>>
196194
where
197195
Self: Clone + 'static,
198196
S: svc::Service<tcp::Connect, Error = io::Error> + Clone + Send + Sync + Unpin + 'static,
@@ -220,7 +218,10 @@ pub mod tests {
220218
use super::*;
221219
use crate::test_util::*;
222220
use hyper::{client::conn::Builder as ClientBuilder, Body, Request};
223-
use linkerd_app_core::svc::{NewService, Service, ServiceExt};
221+
use linkerd_app_core::{
222+
svc::{NewService, Service, ServiceExt},
223+
Error,
224+
};
224225
use tokio::time;
225226

226227
/// Tests that socket errors cause HTTP clients to be disconnected.

linkerd/app/outbound/src/http/detect.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ use tracing::debug_span;
1111
pub struct Skip;
1212

1313
impl<N> Outbound<N> {
14-
pub fn push_detect_http<T, U, NSvc, H, HSvc, I>(
15-
self,
16-
http: H,
17-
) -> Outbound<svc::BoxNewService<T, svc::BoxService<I, (), Error>>>
14+
pub fn push_detect_http<T, U, NSvc, H, HSvc, I>(self, http: H) -> Outbound<svc::BoxNewTcp<T, I>>
1815
where
1916
I: io::AsyncRead + io::AsyncWrite + io::PeerAddr,
2017
I: std::fmt::Debug + Send + Sync + Unpin + 'static,

linkerd/app/outbound/src/ingress.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ impl Outbound<svc::BoxNewHttp<http::Endpoint>> {
5050
///
5151
/// This is only intended for Ingress configurations, where we assume all
5252
/// outbound traffic is HTTP.
53-
pub fn into_ingress<T, I, P, R>(
54-
self,
55-
profiles: P,
56-
resolve: R,
57-
) -> svc::BoxNewService<T, svc::BoxService<I, (), Error>>
53+
pub fn into_ingress<T, I, P, R>(self, profiles: P, resolve: R) -> svc::BoxNewTcp<T, I>
5854
where
5955
T: Param<OrigDstAddr> + Clone + Send + Sync + 'static,
6056
I: io::AsyncRead + io::AsyncWrite + io::PeerAddr + std::fmt::Debug + Send + Unpin + 'static,

linkerd/app/outbound/src/logical.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ impl<P> svc::Param<ConcreteAddr> for Concrete<P> {
114114
// === impl Outbound ===
115115

116116
impl<C> Outbound<C> {
117-
pub fn push_logical<R, I>(
118-
self,
119-
resolve: R,
120-
) -> Outbound<svc::BoxNewService<tcp::Logical, svc::BoxService<I, (), Error>>>
117+
pub fn push_logical<R, I>(self, resolve: R) -> Outbound<svc::BoxNewTcp<tcp::Logical, I>>
121118
where
122119
Self: Clone + 'static,
123120
C: Clone + Send + Sync + Unpin + 'static,

linkerd/app/outbound/src/switch_logical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<S> Outbound<S> {
1313
pub fn push_switch_logical<T, I, N, NSvc, SSvc>(
1414
self,
1515
logical: N,
16-
) -> Outbound<svc::BoxNewService<(Option<profiles::Receiver>, T), svc::BoxService<I, (), Error>>>
16+
) -> Outbound<svc::BoxNewTcp<(Option<profiles::Receiver>, T), I>>
1717
where
1818
Self: Clone + 'static,
1919
T: svc::Param<OrigDstAddr> + Clone + Send + Sync + 'static,

0 commit comments

Comments
 (0)