From 9f9518a98f373998b77bb60ec1e677769192f7fd Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Mon, 10 Sep 2018 16:21:05 -0700 Subject: [PATCH] Rename `transparency` to `proxy` (#89) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change clarifies the naming and role of the `proxy` (née transparency) module. There are no functional changes. `proxy::tcp::Proxy` has been renamed to `proxy::tcp::Forward` to help disambiguate terminology: TCP connections may be _forwarded_ by the proxy server. --- src/bind.rs | 8 +++---- src/inbound.rs | 2 +- src/lib.rs | 4 ++-- src/outbound.rs | 2 +- src/{transparency => proxy}/client.rs | 0 src/{transparency => proxy}/glue.rs | 0 src/{transparency => proxy}/h1.rs | 0 src/proxy/mod.rs | 27 +++++++++++++++++++++++ src/{transparency => proxy}/orig_proto.rs | 0 src/{transparency => proxy}/protocol.rs | 0 src/{transparency => proxy}/server.rs | 12 +++++----- src/{transparency => proxy}/tcp.rs | 8 +++---- src/{transparency => proxy}/upgrade.rs | 0 src/telemetry/http/sensors.rs | 2 +- src/telemetry/http/service.rs | 2 +- src/transparency/mod.rs | 12 ---------- 16 files changed, 47 insertions(+), 32 deletions(-) rename src/{transparency => proxy}/client.rs (100%) rename src/{transparency => proxy}/glue.rs (100%) rename src/{transparency => proxy}/h1.rs (100%) create mode 100644 src/proxy/mod.rs rename src/{transparency => proxy}/orig_proto.rs (100%) rename src/{transparency => proxy}/protocol.rs (100%) rename src/{transparency => proxy}/server.rs (95%) rename src/{transparency => proxy}/tcp.rs (98%) rename src/{transparency => proxy}/upgrade.rs (100%) delete mode 100644 src/transparency/mod.rs diff --git a/src/bind.rs b/src/bind.rs index 2681e7bd6..bd3f5239d 100644 --- a/src/bind.rs +++ b/src/bind.rs @@ -13,7 +13,7 @@ use control::destination::Endpoint; use ctx; use svc::{NewClient, Reconnect}; use telemetry; -use transparency::{self, HttpBody, h1, orig_proto}; +use proxy::{self, HttpBody, h1, orig_proto}; use transport; use tls; use ctx::transport::TlsStatus; @@ -30,7 +30,7 @@ pub type TlsStack = telemetry::http::service::Http, B, HttpBod type HttpService = Reconnect< Arc, - transparency::Client< + proxy::Client< transport::metrics::Connect, ::logging::ClientExecutor<&'static str, SocketAddr>, telemetry::http::service::RequestBody, @@ -263,7 +263,7 @@ where client_ctx.clone(), Reconnect::new( client_ctx.clone(), - transparency::Client::new(protocol, connect, log.executor()) + proxy::Client::new(protocol, connect, log.executor()) ) ) } @@ -292,7 +292,7 @@ where // Rewrite the HTTP/1 URI, if the authorities in the Host header // and request URI are not in agreement, or are not present. // - // TODO move this into transparency::Client? + // TODO move this into proxy::Client? let normalize_uri = NormalizeUri::new(watch_tls, protocol.was_absolute_form()); // Upgrade HTTP/1.1 requests to be HTTP/2 if the endpoint supports HTTP/2. diff --git a/src/inbound.rs b/src/inbound.rs index 934e9ac0c..86c5b0ba1 100644 --- a/src/inbound.rs +++ b/src/inbound.rs @@ -9,7 +9,7 @@ use linkerd2_proxy_router::Recognize; use bind; use ctx; -use transparency::orig_proto; +use proxy::orig_proto; type Bind = bind::Bind; diff --git a/src/lib.rs b/src/lib.rs index 8752190ba..f5ebb2e12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,7 @@ pub mod stream; mod svc; pub mod task; pub mod telemetry; -mod transparency; +mod proxy; mod transport; pub mod timeout; mod tower_fn; // TODO: move to tower-fn @@ -102,7 +102,7 @@ use conditional::Conditional; use inbound::Inbound; use map_err::MapErr; use task::MainRuntime; -use transparency::{HttpBody, Server}; +use proxy::{HttpBody, Server}; use transport::{BoundPort, Connection}; pub use transport::{AddrInfo, GetOriginalDst, SoOriginalDst, tls}; use outbound::Outbound; diff --git a/src/outbound.rs b/src/outbound.rs index aaf848a70..ed06c0633 100644 --- a/src/outbound.rs +++ b/src/outbound.rs @@ -20,7 +20,7 @@ use svc::NewClient; use ctx; use telemetry::http::service::{ResponseBody as SensorBody}; use timeout::Timeout; -use transparency::{h1, HttpBody}; +use proxy::{h1, HttpBody}; use transport::{DnsNameAndPort, Host, HostAndPort}; type BindProtocol = bind::BindProtocol; diff --git a/src/transparency/client.rs b/src/proxy/client.rs similarity index 100% rename from src/transparency/client.rs rename to src/proxy/client.rs diff --git a/src/transparency/glue.rs b/src/proxy/glue.rs similarity index 100% rename from src/transparency/glue.rs rename to src/proxy/glue.rs diff --git a/src/transparency/h1.rs b/src/proxy/h1.rs similarity index 100% rename from src/transparency/h1.rs rename to src/proxy/h1.rs diff --git a/src/proxy/mod.rs b/src/proxy/mod.rs new file mode 100644 index 000000000..8ea7cb539 --- /dev/null +++ b/src/proxy/mod.rs @@ -0,0 +1,27 @@ +//! Reponsible for proxying traffic from a server interface. +//! +//! As the `Server` is invoked with transports, it may terminate a TLS session +//! and determine the peer's identity and determine whether the connection is +//! transporting HTTP. If the transport does not contain HTTP traffic, then the +//! TCP stream is blindly forwarded (according to the original socket's +//! `SO_ORIGINAL_DST` option). Otherwise, an HTTP service established for the +//! connection through which requests are dispatched. +//! +//! Once a request is routed, the `Client` type can be used to establish a +//! `Service` that hides the type differences between HTTP/1 and HTTP/2 clients. +//! +//! This module is intended only to store the infrastructure for building a +//! proxy. The specific logic implemented by a proxy should live elsewhere. + +mod client; +mod glue; +pub mod h1; +mod upgrade; +pub mod orig_proto; +mod protocol; +mod server; +mod tcp; + +pub use self::client::{Client, Error as ClientError}; +pub use self::glue::HttpBody; +pub use self::server::Server; diff --git a/src/transparency/orig_proto.rs b/src/proxy/orig_proto.rs similarity index 100% rename from src/transparency/orig_proto.rs rename to src/proxy/orig_proto.rs diff --git a/src/transparency/protocol.rs b/src/proxy/protocol.rs similarity index 100% rename from src/transparency/protocol.rs rename to src/proxy/protocol.rs diff --git a/src/transparency/server.rs b/src/proxy/server.rs similarity index 95% rename from src/transparency/server.rs rename to src/proxy/server.rs index 96be651b2..c8ba5bc59 100644 --- a/src/transparency/server.rs +++ b/src/proxy/server.rs @@ -46,7 +46,7 @@ where new_service: S, proxy_ctx: ProxyCtx, transport_registry: transport::metrics::Registry, - tcp: tcp::Proxy, + tcp: tcp::Forward, log: ::logging::Server, } @@ -82,7 +82,7 @@ where drain_signal: drain::Watch, ) -> Self { let recv_body_svc = HttpBodyNewSvc::new(stack.clone()); - let tcp = tcp::Proxy::new(tcp_connect_timeout, transport_registry.clone()); + let tcp = tcp::Forward::new(tcp_connect_timeout, transport_registry.clone()); let log = ::logging::Server::proxy(proxy_ctx, listen_addr); Server { disable_protocol_detection_ports, @@ -164,7 +164,7 @@ where .map_err(|e| debug!("peek error: {}", e)) .and_then(move |io| match Protocol::detect(io.peeked()) { Some(Protocol::Http1) => Either::A({ - trace!("transparency detected HTTP/1"); + trace!("detected HTTP/1"); let fut = new_service.new_service() .map_err(|e| trace!("h1 new_service error: {:?}", e)) @@ -191,7 +191,7 @@ where Either::A(fut) }), Some(Protocol::Http2) => Either::A({ - trace!("transparency detected HTTP/2"); + trace!("detected HTTP/2"); let set_ctx = move |request: &mut http::Request<()>| { request.extensions_mut().insert(srv_ctx.clone()); }; @@ -205,7 +205,7 @@ where Either::B(fut) }), None => { - trace!("transparency did not detect protocol, treating as TCP"); + trace!("did not detect protocol, treating as TCP"); Either::B(tcp_serve( &tcp, io, @@ -220,7 +220,7 @@ where } fn tcp_serve( - tcp: &tcp::Proxy, + tcp: &tcp::Forward, io: T, srv_ctx: Arc, drain_signal: drain::Watch, diff --git a/src/transparency/tcp.rs b/src/proxy/tcp.rs similarity index 98% rename from src/transparency/tcp.rs rename to src/proxy/tcp.rs index babe33a06..a9d0b212e 100644 --- a/src/transparency/tcp.rs +++ b/src/proxy/tcp.rs @@ -17,15 +17,15 @@ use timeout::Timeout; use transport::{self, tls}; use ctx::transport::TlsStatus; -/// TCP Server Proxy +/// Forwards a stream of bytes to the socket's `SO_ORIGINAL_DST` #[derive(Debug, Clone)] -pub struct Proxy { +pub struct Forward { connect_timeout: Duration, transport_registry: transport::metrics::Registry, } -impl Proxy { - /// Create a new TCP `Proxy`. +impl Forward { + /// Create a new TCP `Forward`. pub fn new( connect_timeout: Duration, transport_registry: transport::metrics::Registry diff --git a/src/transparency/upgrade.rs b/src/proxy/upgrade.rs similarity index 100% rename from src/transparency/upgrade.rs rename to src/proxy/upgrade.rs diff --git a/src/telemetry/http/sensors.rs b/src/telemetry/http/sensors.rs index 14de1a9ba..3ce8af5e4 100644 --- a/src/telemetry/http/sensors.rs +++ b/src/telemetry/http/sensors.rs @@ -6,7 +6,7 @@ use tower_h2::Body; use ctx; use telemetry::{http::event, tap}; -use transparency::ClientError; +use proxy::ClientError; use super::record::Record; use super::service::{Http, RequestBody}; diff --git a/src/telemetry/http/service.rs b/src/telemetry/http/service.rs index 10fc5d540..ec4d22a49 100644 --- a/src/telemetry/http/service.rs +++ b/src/telemetry/http/service.rs @@ -10,7 +10,7 @@ use tower_service::{NewService, Service}; use tower_h2::Body; use ctx; -use transparency::ClientError; +use proxy::ClientError; use super::event::{self, Event}; use super::sensors::Handle; diff --git a/src/transparency/mod.rs b/src/transparency/mod.rs deleted file mode 100644 index ca09f6170..000000000 --- a/src/transparency/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -mod client; -mod glue; -pub mod h1; -mod upgrade; -pub mod orig_proto; -mod protocol; -mod server; -mod tcp; - -pub use self::client::{Client, Error as ClientError}; -pub use self::glue::HttpBody; -pub use self::server::Server;