Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect() Sessions socket to Endpoint address #538

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/proxy/sessions/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::fmt::{self, Display, Formatter};
pub enum Error {
BindUdpSocket(tokio::io::Error),
UpdateSessionExpiration(String),
ToSocketAddr(eyre::Report),
}

impl Display for Error {
Expand All @@ -31,6 +32,9 @@ impl Display for Error {
Error::UpdateSessionExpiration(reason) => {
write!(f, "failed to update session expiration time: {}", reason)
}
Error::ToSocketAddr(reason) => {
write!(f, "failed to convert endpoint to address: {}", reason)
}
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/proxy/sessions/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ impl Session {
async fn new(args: SessionArgs) -> Result<Self> {
let addr = (std::net::Ipv4Addr::UNSPECIFIED, 0);
let socket = Arc::new(UdpSocket::bind(addr).await.map_err(Error::BindUdpSocket)?);
socket
.connect(
args.dest
.address
.to_socket_addr()
.map_err(Error::ToSocketAddr)?,
)
.await
.map_err(Error::BindUdpSocket)?;
let (shutdown_tx, shutdown_rx) = watch::channel::<()>(());

let expiration = Arc::new(AtomicU64::new(0));
Expand Down Expand Up @@ -321,7 +330,7 @@ impl Session {
/// the number of bytes written.
pub async fn do_send(&self, buf: &[u8]) -> crate::Result<usize> {
self.socket
.send_to(buf, &self.dest.address.to_socket_addr()?)
.send(buf)
.await
.map_err(|error| eyre::eyre!(error))
}
Expand Down