Skip to content

Commit

Permalink
Merge branch 'shadowsocks-not-working-with-new-servers-des-1634'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Jan 14, 2025
2 parents d23d7ba + 07905aa commit 5ef7ee1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Line wrap the file at 100 chars. Th
- Move changelog from a dialog to a separate view.
- Reduce the setup time of PQ tunnels by pre-computing McEliece keys.

### Fixed
- (macOS and Windows only) Add the correct route when using obfuscation with Wireguard.


## [2025.2] - 2025-01-08
### Fixed
Expand Down
21 changes: 2 additions & 19 deletions talpid-types/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,15 @@ impl TunnelParameters {
}
}

// Returns the endpoint that will be connected to
/// Returns the endpoint that will be connected to
pub fn get_next_hop_endpoint(&self) -> Endpoint {
match self {
TunnelParameters::OpenVpn(params) => params
.proxy
.as_ref()
.map(|proxy| proxy.get_remote_endpoint().endpoint)
.unwrap_or(params.config.endpoint),
TunnelParameters::Wireguard(params) => params
.obfuscation
.as_ref()
.map(Self::get_obfuscator_endpoint)
.unwrap_or_else(|| params.connection.get_endpoint()),
}
}

fn get_obfuscator_endpoint(obfuscator: &ObfuscatorConfig) -> Endpoint {
match obfuscator {
ObfuscatorConfig::Udp2Tcp { endpoint } => Endpoint {
address: *endpoint,
protocol: TransportProtocol::Tcp,
},
ObfuscatorConfig::Shadowsocks { endpoint } => Endpoint {
address: *endpoint,
protocol: TransportProtocol::Udp,
},
TunnelParameters::Wireguard(params) => params.get_next_hop_endpoint(),
}
}

Expand Down
17 changes: 17 additions & 0 deletions talpid-types/src/net/obfuscation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;

use super::{Endpoint, TransportProtocol};

#[derive(Clone, Eq, PartialEq, Deserialize, Serialize, Debug)]
pub enum ObfuscatorConfig {
Udp2Tcp { endpoint: SocketAddr },
Shadowsocks { endpoint: SocketAddr },
}

impl ObfuscatorConfig {
pub fn get_obfuscator_endpoint(&self) -> Endpoint {
match self {
ObfuscatorConfig::Udp2Tcp { endpoint } => Endpoint {
address: *endpoint,
protocol: TransportProtocol::Tcp,
},
ObfuscatorConfig::Shadowsocks { endpoint } => Endpoint {
address: *endpoint,
protocol: TransportProtocol::Udp,
},
}
}
}
10 changes: 10 additions & 0 deletions talpid-types/src/net/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ pub struct TunnelParameters {
pub obfuscation: Option<super::obfuscation::ObfuscatorConfig>,
}

impl TunnelParameters {
/// Returns the endpoint that will be connected to
pub fn get_next_hop_endpoint(&self) -> Endpoint {
self.obfuscation
.as_ref()
.map(|proxy| proxy.get_obfuscator_endpoint())
.unwrap_or_else(|| self.connection.get_endpoint())
}
}

/// Connection-specific configuration in [`TunnelParameters`].
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct ConnectionConfig {
Expand Down
2 changes: 1 addition & 1 deletion talpid-wireguard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl WireguardMonitor {
let mut config = crate::config::Config::from_parameters(params, desired_mtu)
.map_err(Error::WireguardConfigError)?;

let endpoint_addrs: Vec<IpAddr> = config.peers().map(|peer| peer.endpoint.ip()).collect();
let endpoint_addrs = [params.get_next_hop_endpoint().address.ip()];

let (close_obfs_sender, close_obfs_listener) = sync_mpsc::channel();
// Start obfuscation server and patch the WireGuard config to point the endpoint to it.
Expand Down

0 comments on commit 5ef7ee1

Please sign in to comment.