mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-04-29 17:36:35 +08:00
refactor: 删除未使用的公共 STUN/TURN 逻辑
This commit is contained in:
19
build.rs
19
build.rs
@@ -64,25 +64,6 @@ fn generate_secrets() {
|
|||||||
pub mod ice {
|
pub mod ice {
|
||||||
/// Google public STUN server URL (hardcoded)
|
/// Google public STUN server URL (hardcoded)
|
||||||
pub const STUN_SERVER: &str = "stun:stun.l.google.com:19302";
|
pub const STUN_SERVER: &str = "stun:stun.l.google.com:19302";
|
||||||
|
|
||||||
/// TURN server URLs - not provided, users must configure their own
|
|
||||||
pub const TURN_URLS: &str = "";
|
|
||||||
|
|
||||||
/// TURN authentication username
|
|
||||||
pub const TURN_USERNAME: &str = "";
|
|
||||||
|
|
||||||
/// TURN authentication password
|
|
||||||
pub const TURN_PASSWORD: &str = "";
|
|
||||||
|
|
||||||
/// Always returns true since we have STUN
|
|
||||||
pub const fn is_configured() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Always returns false since TURN is not provided
|
|
||||||
pub const fn has_turn() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RustDesk public server configuration - NOT PROVIDED
|
/// RustDesk public server configuration - NOT PROVIDED
|
||||||
|
|||||||
21
src/main.rs
21
src/main.rs
@@ -288,23 +288,12 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.map(|s| !s.is_empty())
|
.map(|s| !s.is_empty())
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
// If no custom servers, use public ICE servers (like RustDesk)
|
// If no custom servers, use baked-in public STUN
|
||||||
if !has_custom_stun && !has_custom_turn {
|
if !has_custom_stun && !has_custom_turn {
|
||||||
use one_kvm::webrtc::config::public_ice;
|
use one_kvm::webrtc::config::public_ice;
|
||||||
if public_ice::is_configured() {
|
let stun = public_ice::stun_server().to_string();
|
||||||
if let Some(stun) = public_ice::stun_server() {
|
tracing::info!("Using public STUN server: {}", stun);
|
||||||
stun_servers.push(stun.clone());
|
stun_servers.push(stun);
|
||||||
tracing::info!("Using public STUN server: {}", stun);
|
|
||||||
}
|
|
||||||
for turn in public_ice::turn_servers() {
|
|
||||||
tracing::info!("Using public TURN server: {:?}", turn.urls);
|
|
||||||
turn_servers.push(turn);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tracing::info!(
|
|
||||||
"No public ICE servers configured, using host candidates only"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Use custom servers
|
// Use custom servers
|
||||||
if let Some(ref stun) = config.stream.stun_server {
|
if let Some(ref stun) = config.stream.stun_server {
|
||||||
@@ -342,7 +331,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
};
|
};
|
||||||
WebRtcStreamer::with_config(webrtc_config)
|
WebRtcStreamer::with_config(webrtc_config)
|
||||||
};
|
};
|
||||||
tracing::info!("WebRTC streamer created (supports H264, extensible to VP8/VP9/H265)");
|
tracing::info!("WebRTC streamer created");
|
||||||
|
|
||||||
// Create OTG Service (single instance for centralized USB gadget management)
|
// Create OTG Service (single instance for centralized USB gadget management)
|
||||||
let otg_service = Arc::new(OtgService::new());
|
let otg_service = Arc::new(OtgService::new());
|
||||||
|
|||||||
@@ -2048,14 +2048,12 @@ pub async fn webrtc_ice_servers(State(state): State<Arc<AppState>>) -> Json<IceS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No custom servers configured - use Google STUN as default
|
// No custom servers — baked-in public STUN
|
||||||
if let Some(stun) = public_ice::stun_server() {
|
ice_servers.push(IceServerInfo {
|
||||||
ice_servers.push(IceServerInfo {
|
urls: vec![public_ice::stun_server().to_string()],
|
||||||
urls: vec![stun],
|
username: None,
|
||||||
username: None,
|
credential: None,
|
||||||
credential: None,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
// Note: TURN servers are not provided - users must configure their own
|
// Note: TURN servers are not provided - users must configure their own
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,42 +2,18 @@
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::secrets;
|
/// ICE server utilities — public STUN only (TURN must be user-configured).
|
||||||
|
|
||||||
/// ICE server utilities - Only provides Google STUN, no TURN
|
|
||||||
pub mod public_ice {
|
pub mod public_ice {
|
||||||
use super::*;
|
/// Whether a build-time public STUN URL exists (always true for stock builds).
|
||||||
|
#[inline]
|
||||||
/// Always returns true (we have Google STUN)
|
|
||||||
pub fn is_configured() -> bool {
|
pub fn is_configured() -> bool {
|
||||||
secrets::ice::is_configured()
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Always returns false (TURN not provided)
|
/// Build-time public STUN URL (`secrets::ice::STUN_SERVER`).
|
||||||
pub fn has_turn() -> bool {
|
#[inline]
|
||||||
secrets::ice::has_turn()
|
pub fn stun_server() -> &'static str {
|
||||||
}
|
crate::secrets::ice::STUN_SERVER
|
||||||
|
|
||||||
/// Get the Google STUN server URL
|
|
||||||
pub fn stun_server() -> Option<String> {
|
|
||||||
let server = secrets::ice::STUN_SERVER;
|
|
||||||
if server.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(server.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Always returns empty vector (TURN not provided)
|
|
||||||
pub fn turn_servers() -> Vec<TurnServer> {
|
|
||||||
vec![]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get all public ICE servers (STUN only, no TURN)
|
|
||||||
pub fn get_all_servers() -> (Vec<String>, Vec<TurnServer>) {
|
|
||||||
let stun_servers = stun_server().into_iter().collect();
|
|
||||||
let turn_servers = vec![];
|
|
||||||
(stun_servers, turn_servers)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -759,7 +759,7 @@ impl WebRtcStreamer {
|
|||||||
/// Note: Changes take effect for new sessions only.
|
/// Note: Changes take effect for new sessions only.
|
||||||
/// Existing sessions need to be reconnected to use the new ICE config.
|
/// Existing sessions need to be reconnected to use the new ICE config.
|
||||||
///
|
///
|
||||||
/// If both stun_server and turn_server are empty/None, uses public ICE servers.
|
/// If both stun_server and turn_server are empty/None, uses baked-in public STUN.
|
||||||
pub async fn update_ice_config(
|
pub async fn update_ice_config(
|
||||||
&self,
|
&self,
|
||||||
stun_server: Option<String>,
|
stun_server: Option<String>,
|
||||||
@@ -777,21 +777,12 @@ impl WebRtcStreamer {
|
|||||||
let has_custom_stun = stun_server.as_ref().map(|s| !s.is_empty()).unwrap_or(false);
|
let has_custom_stun = stun_server.as_ref().map(|s| !s.is_empty()).unwrap_or(false);
|
||||||
let has_custom_turn = turn_server.as_ref().map(|s| !s.is_empty()).unwrap_or(false);
|
let has_custom_turn = turn_server.as_ref().map(|s| !s.is_empty()).unwrap_or(false);
|
||||||
|
|
||||||
// If no custom servers, use public ICE servers (like RustDesk)
|
// If no custom servers, use baked-in public STUN
|
||||||
if !has_custom_stun && !has_custom_turn {
|
if !has_custom_stun && !has_custom_turn {
|
||||||
use crate::webrtc::config::public_ice;
|
use crate::webrtc::config::public_ice;
|
||||||
if public_ice::is_configured() {
|
let stun = public_ice::stun_server().to_string();
|
||||||
if let Some(stun) = public_ice::stun_server() {
|
info!("Using public STUN server: {}", stun);
|
||||||
config.webrtc.stun_servers.push(stun.clone());
|
config.webrtc.stun_servers.push(stun);
|
||||||
info!("Using public STUN server: {}", stun);
|
|
||||||
}
|
|
||||||
for turn in public_ice::turn_servers() {
|
|
||||||
info!("Using public TURN server: {:?}", turn.urls);
|
|
||||||
config.webrtc.turn_servers.push(turn);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
info!("No public ICE servers configured, using host candidates only");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Use custom servers
|
// Use custom servers
|
||||||
if let Some(ref stun) = stun_server {
|
if let Some(ref stun) = stun_server {
|
||||||
|
|||||||
Reference in New Issue
Block a user