Skip to content

Commit 67e99b7

Browse files
authored
Eliminate the ConnectAddr trait (#649)
The connect module can use the more standard `Into<SocketAddr>`. No need for a special trait.
1 parent 6a85ac7 commit 67e99b7

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

linkerd/app/core/src/control.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ mod balance {
268268

269269
/// Creates a client suitable for gRPC.
270270
mod client {
271-
use crate::transport::{connect, tls};
271+
use crate::transport::tls;
272272
use crate::{proxy::http, svc};
273273
use linkerd2_proxy_http::h2::Settings as H2Settings;
274274
use std::{
@@ -295,8 +295,8 @@ mod client {
295295

296296
// === impl Target ===
297297

298-
impl connect::ConnectAddr for Target {
299-
fn connect_addr(&self) -> SocketAddr {
298+
impl Into<SocketAddr> for Target {
299+
fn into(self) -> SocketAddr {
300300
self.addr
301301
}
302302
}

linkerd/app/inbound/src/endpoint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use linkerd2_app_core::{
44
http_request_l5d_override_dst_addr, metric_labels, profiles,
55
proxy::{http, identity, tap},
66
router, stack_tracing,
7-
transport::{connect, listen, tls},
7+
transport::{listen, tls},
88
Addr, Conditional, CANONICAL_DST_HEADER, DST_OVERRIDE_HEADER,
99
};
1010
use std::fmt;
@@ -41,8 +41,8 @@ pub struct ProfileTarget;
4141

4242
// === impl HttpEndpoint ===
4343

44-
impl connect::ConnectAddr for HttpEndpoint {
45-
fn connect_addr(&self) -> SocketAddr {
44+
impl Into<SocketAddr> for HttpEndpoint {
45+
fn into(self) -> SocketAddr {
4646
([127, 0, 0, 1], self.port).into()
4747
}
4848
}
@@ -86,8 +86,8 @@ impl From<tls::accept::Meta> for TcpEndpoint {
8686
}
8787
}
8888

89-
impl connect::ConnectAddr for TcpEndpoint {
90-
fn connect_addr(&self) -> SocketAddr {
89+
impl Into<SocketAddr> for TcpEndpoint {
90+
fn into(self) -> SocketAddr {
9191
([127, 0, 0, 1], self.port).into()
9292
}
9393
}

linkerd/app/outbound/src/endpoint.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use linkerd2_app_core::{
1313
tap,
1414
},
1515
router,
16-
transport::{connect, listen, tls},
16+
transport::{listen, tls},
1717
Addr, Conditional, L5D_REQUIRE_ID,
1818
};
1919
use std::net::SocketAddr;
@@ -144,9 +144,9 @@ impl<T: tap::Inspect> tap::Inspect for Target<T> {
144144
}
145145
}
146146

147-
impl<T: connect::ConnectAddr> connect::ConnectAddr for Target<T> {
148-
fn connect_addr(&self) -> SocketAddr {
149-
self.inner.connect_addr()
147+
impl<T: Into<SocketAddr>> Into<SocketAddr> for Target<T> {
148+
fn into(self) -> SocketAddr {
149+
self.inner.into()
150150
}
151151
}
152152

@@ -195,8 +195,8 @@ impl tls::HasPeerIdentity for HttpEndpoint {
195195
}
196196
}
197197

198-
impl connect::ConnectAddr for HttpEndpoint {
199-
fn connect_addr(&self) -> SocketAddr {
198+
impl Into<SocketAddr> for HttpEndpoint {
199+
fn into(self) -> SocketAddr {
200200
self.addr
201201
}
202202
}
@@ -322,8 +322,8 @@ impl From<listen::Addrs> for TcpEndpoint {
322322
}
323323
}
324324

325-
impl connect::ConnectAddr for TcpEndpoint {
326-
fn connect_addr(&self) -> SocketAddr {
325+
impl Into<SocketAddr> for TcpEndpoint {
326+
fn into(self) -> SocketAddr {
327327
self.addr
328328
}
329329
}

linkerd/proxy/transport/src/connect.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ use std::{future::Future, io, net::SocketAddr, pin::Pin, time::Duration};
33
use tokio::net::TcpStream;
44
use tracing::debug;
55

6-
pub trait ConnectAddr {
7-
fn connect_addr(&self) -> SocketAddr;
8-
}
9-
106
#[derive(Copy, Clone, Debug)]
117
pub struct Connect {
128
keepalive: Option<Duration>,
@@ -18,7 +14,7 @@ impl Connect {
1814
}
1915
}
2016

21-
impl<C: ConnectAddr> tower::Service<C> for Connect {
17+
impl<T: Into<SocketAddr>> tower::Service<T> for Connect {
2218
type Response = TcpStream;
2319
type Error = io::Error;
2420
type Future =
@@ -28,9 +24,9 @@ impl<C: ConnectAddr> tower::Service<C> for Connect {
2824
Poll::Ready(Ok(()))
2925
}
3026

31-
fn call(&mut self, c: C) -> Self::Future {
27+
fn call(&mut self, t: T) -> Self::Future {
3228
let keepalive = self.keepalive;
33-
let addr = c.connect_addr();
29+
let addr = t.into();
3430
debug!(peer.addr = %addr, "Connecting");
3531
Box::pin(async move {
3632
let io = TcpStream::connect(&addr).await?;

linkerd/proxy/transport/tests/tls_accept.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ struct Target(SocketAddr, Conditional<Name>);
303303
#[derive(Clone)]
304304
struct ClientTls(CrtKey);
305305

306-
impl connect::ConnectAddr for Target {
307-
fn connect_addr(&self) -> SocketAddr {
306+
impl Into<SocketAddr> for Target {
307+
fn into(self) -> SocketAddr {
308308
self.0
309309
}
310310
}

0 commit comments

Comments
 (0)