Skip to content

Commit

Permalink
remove addr from establishConnection type
Browse files Browse the repository at this point in the history
  • Loading branch information
soundofspace authored and GlenDC committed Feb 27, 2025
1 parent 0d6344e commit 4434b07
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 199 deletions.
236 changes: 147 additions & 89 deletions rama-haproxy/src/client/layer.rs

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions rama-http-backend/src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ where
#[cfg(not(any(feature = "rustls", feature = "boring")))]
req,
conn,
addr,
} = self.inner.connect(ctx, req).await.map_err(Into::into)?;

#[cfg(any(feature = "rustls", feature = "boring"))]
Expand Down Expand Up @@ -120,7 +119,6 @@ where
ctx,
req,
conn: svc,
addr,
})
}
Version::HTTP_11 | Version::HTTP_10 | Version::HTTP_09 => {
Expand All @@ -139,7 +137,6 @@ where
ctx,
req,
conn: svc,
addr,
})
}
version => Err(OpaqueError::from_display(format!(
Expand Down
2 changes: 1 addition & 1 deletion rama-http-backend/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ where
// so that the other end can read it... This might however give issues in
// case switching http versions requires more work than version. If so,
// your first place will be to check here and/or in the [`HttpConnector`].
let EstablishedClientConnection { ctx, req, conn, .. } = connector
let EstablishedClientConnection { ctx, req, conn } = connector
.connect(ctx, req)
.await
.map_err(|err| OpaqueError::from_boxed(err).with_context(|| uri.to_string()))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,21 @@ where
tracing::trace!(
"http proxy connector: no proxy required or set: proceed with direct connection"
);
let EstablishedClientConnection {
ctx,
req,
conn,
addr,
} = established_conn;
let EstablishedClientConnection { ctx, req, conn } = established_conn;
return Ok(EstablishedClientConnection {
ctx,
req,
conn: Either::A(conn),
addr,
});
};
}
};
// and do the handshake otherwise...

let EstablishedClientConnection {
ctx,
req,
conn,
addr,
} = established_conn;
let EstablishedClientConnection { ctx, req, conn } = established_conn;

tracing::trace!(
authority = %transport_ctx.authority,
proxy_addr = %addr,
"http proxy connector: connected to proxy",
);

Expand All @@ -190,7 +178,6 @@ where
ctx,
req,
conn: Either::A(conn),
addr,
});
}

Expand All @@ -214,14 +201,12 @@ where

tracing::trace!(
authority = %transport_ctx.authority,
proxy_addr = %addr,
"http proxy connector: connected to proxy: ready secure request",
);
Ok(EstablishedClientConnection {
ctx,
req,
conn: Either::B(conn),
addr,
})
}
}
6 changes: 1 addition & 5 deletions rama-net/src/client/conn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rama_core::{Context, Service, error::BoxError};
use std::{fmt, future::Future, net::SocketAddr};
use std::{fmt, future::Future};

/// The established connection to a server returned for the http client to be used.
pub struct EstablishedClientConnection<S, State, Request> {
Expand All @@ -9,8 +9,6 @@ pub struct EstablishedClientConnection<S, State, Request> {
pub req: Request,
/// The established connection stream/service/... to the server.
pub conn: S,
/// The target address connected to.
pub addr: SocketAddr,
}

impl<S: fmt::Debug, State: fmt::Debug, Request: fmt::Debug> fmt::Debug
Expand All @@ -21,7 +19,6 @@ impl<S: fmt::Debug, State: fmt::Debug, Request: fmt::Debug> fmt::Debug
.field("ctx", &self.ctx)
.field("req", &self.req)
.field("conn", &self.conn)
.field("addr", &self.addr)
.finish()
}
}
Expand All @@ -34,7 +31,6 @@ impl<S: Clone, State: Clone, Request: Clone> Clone
ctx: self.ctx.clone(),
req: self.req.clone(),
conn: self.conn.clone(),
addr: self.addr,
}
}
}
Expand Down
15 changes: 3 additions & 12 deletions rama-net/src/stream/layer/tracker/outgoing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,12 @@ where
ctx: Context<State>,
req: Request,
) -> Result<Self::Response, Self::Error> {
let EstablishedClientConnection {
mut ctx,
req,
conn,
addr,
} = self.inner.connect(ctx, req).await?;
let EstablishedClientConnection { mut ctx, req, conn } =
self.inner.connect(ctx, req).await?;
let conn = BytesRWTracker::new(conn);
let handle = conn.handle();
ctx.insert(handle);
Ok(EstablishedClientConnection {
ctx,
req,
conn,
addr,
})
Ok(EstablishedClientConnection { ctx, req, conn })
}
}

Expand Down
18 changes: 4 additions & 14 deletions rama-tcp/src/client/service/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
.map_err(Into::into)?;

if let Some(proxy) = ctx.get::<ProxyAddress>() {
let (conn, addr) = crate::client::tcp_connect(
let (conn, _addr) = crate::client::tcp_connect(
&ctx,
proxy.authority.clone(),
true,
Expand All @@ -116,12 +116,7 @@ where
)
.await
.context("tcp connector: conncept to proxy")?;
return Ok(EstablishedClientConnection {
ctx,
req,
conn,
addr,
});
return Ok(EstablishedClientConnection { ctx, req, conn });
}

let transport_ctx = ctx
Expand All @@ -143,16 +138,11 @@ where
}

let authority = transport_ctx.authority.clone();
let (conn, addr) =
let (conn, _addr) =
crate::client::tcp_connect(&ctx, authority, false, self.dns.clone(), connector)
.await
.context("tcp connector: connect to server")?;

Ok(EstablishedClientConnection {
ctx,
req,
conn,
addr,
})
Ok(EstablishedClientConnection { ctx, req, conn })
}
}
35 changes: 7 additions & 28 deletions rama-tls/src/boring/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,8 @@ where
ctx: Context<State>,
req: Request,
) -> Result<Self::Response, Self::Error> {
let EstablishedClientConnection {
mut ctx,
req,
conn,
addr,
} = self.inner.connect(ctx, req).await.map_err(Into::into)?;
let EstablishedClientConnection { mut ctx, req, conn } =
self.inner.connect(ctx, req).await.map_err(Into::into)?;

let transport_ctx = ctx
.get_or_try_insert_with_ctx(|ctx| req.try_ref_into_transport_ctx(ctx))
Expand All @@ -260,7 +256,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Plain { inner: conn },
},
addr,
});
}

Expand All @@ -282,7 +277,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Secure { inner: stream },
},
addr,
})
}
}
Expand All @@ -303,12 +297,8 @@ where
ctx: Context<State>,
req: Request,
) -> Result<Self::Response, Self::Error> {
let EstablishedClientConnection {
mut ctx,
req,
conn,
addr,
} = self.inner.connect(ctx, req).await.map_err(Into::into)?;
let EstablishedClientConnection { mut ctx, req, conn } =
self.inner.connect(ctx, req).await.map_err(Into::into)?;

let transport_ctx = ctx
.get_or_try_insert_with_ctx(|ctx| req.try_ref_into_transport_ctx(ctx))
Expand All @@ -328,12 +318,7 @@ where
let (conn, negotiated_params) = self.handshake(connector_data, host, conn).await?;
ctx.insert(negotiated_params);

Ok(EstablishedClientConnection {
ctx,
req,
conn,
addr,
})
Ok(EstablishedClientConnection { ctx, req, conn })
}
}

Expand All @@ -351,12 +336,8 @@ where
ctx: Context<State>,
req: Request,
) -> Result<Self::Response, Self::Error> {
let EstablishedClientConnection {
mut ctx,
req,
conn,
addr,
} = self.inner.connect(ctx, req).await.map_err(Into::into)?;
let EstablishedClientConnection { mut ctx, req, conn } =
self.inner.connect(ctx, req).await.map_err(Into::into)?;

let host = match ctx
.get::<TlsTunnel>()
Expand All @@ -375,7 +356,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Plain { inner: conn },
},
addr,
});
}
};
Expand All @@ -391,7 +371,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Secure { inner: stream },
},
addr,
})
}
}
Expand Down
35 changes: 7 additions & 28 deletions rama-tls/src/rustls/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,8 @@ where
ctx: Context<State>,
req: Request,
) -> Result<Self::Response, Self::Error> {
let EstablishedClientConnection {
mut ctx,
req,
conn,
addr,
} = self.inner.connect(ctx, req).await.map_err(Into::into)?;
let EstablishedClientConnection { mut ctx, req, conn } =
self.inner.connect(ctx, req).await.map_err(Into::into)?;
let transport_ctx = ctx
.get_or_try_insert_with_ctx(|ctx| req.try_ref_into_transport_ctx(ctx))
.map_err(|err| {
Expand All @@ -261,7 +257,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Plain { inner: conn },
},
addr,
});
}

Expand Down Expand Up @@ -290,7 +285,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Secure { inner: stream },
},
addr,
})
}
}
Expand All @@ -311,12 +305,8 @@ where
ctx: Context<State>,
req: Request,
) -> Result<Self::Response, Self::Error> {
let EstablishedClientConnection {
mut ctx,
req,
conn,
addr,
} = self.inner.connect(ctx, req).await.map_err(Into::into)?;
let EstablishedClientConnection { mut ctx, req, conn } =
self.inner.connect(ctx, req).await.map_err(Into::into)?;

let transport_ctx = ctx
.get_or_try_insert_with_ctx(|ctx| req.try_ref_into_transport_ctx(ctx))
Expand All @@ -336,12 +326,7 @@ where
let (conn, negotiated_params) = self.handshake(connector_data, server_host, conn).await?;
ctx.insert(negotiated_params);

Ok(EstablishedClientConnection {
ctx,
req,
conn,
addr,
})
Ok(EstablishedClientConnection { ctx, req, conn })
}
}

Expand All @@ -359,12 +344,8 @@ where
ctx: Context<State>,
req: Request,
) -> Result<Self::Response, Self::Error> {
let EstablishedClientConnection {
mut ctx,
req,
conn,
addr,
} = self.inner.connect(ctx, req).await.map_err(Into::into)?;
let EstablishedClientConnection { mut ctx, req, conn } =
self.inner.connect(ctx, req).await.map_err(Into::into)?;

let server_host = match ctx
.get::<TlsTunnel>()
Expand All @@ -383,7 +364,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Plain { inner: conn },
},
addr,
});
}
};
Expand All @@ -399,7 +379,6 @@ where
conn: AutoTlsStream {
inner: AutoTlsStreamData::Secure { inner: conn },
},
addr,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ where
TlsConnector::auto(tcp_connector).with_connector_data(tls_connector_data),
);

let EstablishedClientConnection { ctx, req, conn, .. } =
connector.connect(ctx, req).await?;
let EstablishedClientConnection { ctx, req, conn } = connector.connect(ctx, req).await?;

// Extra logic to extract certificates
let params = ctx.get::<NegotiatedTlsParameters>().unwrap();
Expand Down

0 comments on commit 4434b07

Please sign in to comment.