Skip to content

Commit

Permalink
feat: allow disabling the udp tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtread committed Oct 2, 2024
1 parent 5f7e5c4 commit aed657c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,36 @@ pub struct UdpTunnelConfig {
/// For cases such as different exposed port in docker or usage behind
/// a reverse proxy such as NGINX
pub external_port: Option<Port>,

/// Optionally choose to disable the tunnel if you don't intend to use it
/// default value is true
pub enabled: bool,
}

impl Default for UdpTunnelConfig {
fn default() -> Self {
Self {
port: 9032,
external_port: None,
enabled: true,
}
}
}

impl UdpTunnelConfig {
/// Get the port the exposed to the clients for the UDP
/// tunnel. This is [None] if the tunnel is disabled. Otherwise
/// its [UdpTunnelConfig::external_port] if set otherwise its
/// [UdpTunnelConfig::port]
pub fn get_exposed_port(&self) -> Option<Port> {
if !self.enabled {
return None;
}

Some(self.external_port.unwrap_or(self.port))
}
}

/// Configuration for the server QoS setup
#[derive(Debug, Default, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ async fn main() {
));
let retriever = Arc::new(retriever);

// Start the tunnel server
if tunnel_enabled {
// Start the tunnel server (If enabled)
if tunnel_enabled && config.udp_tunnel.enabled {
// Start the tunnel service server
if let Err(err) = start_udp_tunnel(tunnel_addr, udp_tunnel_service.clone()).await {
error!("failed to start udp tunnel server: {}", err);
Expand Down
7 changes: 2 additions & 5 deletions src/routes/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct ServerDetails {
/// Random association token for the client to use
association: String,
/// Port the tunnel server is running on
tunnel_port: u16,
tunnel_port: Option<u16>,
}

/// GET /api/server
Expand All @@ -56,10 +56,7 @@ pub async fn server_details(
ident: "POCKET_RELAY_SERVER",
version: VERSION,
association,
tunnel_port: config
.udp_tunnel
.external_port
.unwrap_or(config.udp_tunnel.port),
tunnel_port: config.udp_tunnel.get_exposed_port(),
})
}

Expand Down

0 comments on commit aed657c

Please sign in to comment.