Move host address resolution logic to config

This commit is contained in:
Jackson Coxson 2022-06-23 22:59:19 -06:00
parent b108b5f404
commit 3ab108ad04
2 changed files with 27 additions and 18 deletions

View file

@ -36,16 +36,9 @@ impl WireGuardTunnel {
let source_peer_ip = config.source_peer_ip;
let peer = Self::create_tunnel(config)?;
let endpoint = config.endpoint_addr;
let udp = if let Some(host) = config.host_addr {
UdpSocket::bind(host).await
} else {
UdpSocket::bind(match endpoint {
SocketAddr::V4(_) => "0.0.0.0:0",
SocketAddr::V6(_) => "[::]:0",
})
let udp = UdpSocket::bind(config.host_addr)
.await
}
.with_context(|| "Failed to create UDP socket for WireGuard connection")?;
.with_context(|| "Failed to create UDP socket for WireGuard connection")?;
Ok(Self {
source_peer_ip,