From 742b8e09a5ad8fad5a3f08f146ebe97a84181f1c Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 14 Jul 2023 00:24:19 -0400 Subject: [PATCH] revert binding change --- veilid-core/src/network_manager/native/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/veilid-core/src/network_manager/native/mod.rs b/veilid-core/src/network_manager/native/mod.rs index afc6888a..a4cf7854 100644 --- a/veilid-core/src/network_manager/native/mod.rs +++ b/veilid-core/src/network_manager/native/mod.rs @@ -307,6 +307,22 @@ impl Network { local_port } + fn get_preferred_local_address(&self, dial_info: &DialInfo) -> SocketAddr { + let inner = self.inner.lock(); + + let local_port = match dial_info.protocol_type() { + ProtocolType::UDP => inner.udp_port, + ProtocolType::TCP => inner.tcp_port, + ProtocolType::WS => inner.ws_port, + ProtocolType::WSS => inner.wss_port, + }; + + match dial_info.address_type() { + AddressType::IPV4 => SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), local_port), + AddressType::IPV6 => SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), local_port), + } + } + pub fn is_usable_interface_address(&self, addr: IpAddr) -> bool { let usable_addrs = self.get_usable_interface_addresses(); usable_addrs.contains(&addr) @@ -578,9 +594,10 @@ impl Network { .wrap_err("failed to send data to dial info")?); } else { // Handle connection-oriented protocols + let local_addr = self.get_preferred_local_address(&dial_info); let conn = network_result_try!( self.connection_manager() - .get_or_create_connection(None, dial_info.clone()) + .get_or_create_connection(Some(local_addr), dial_info.clone()) .await? );