Skip to content

Commit

Permalink
reuse port, and revert hbbr -k
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed May 24, 2024
1 parent a22dacc commit 5078a1f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hbbs"
version = "1.1.11"
version = "1.1.11-1"
authors = ["rustdesk <[email protected]>"]
edition = "2021"
build = "build.rs"
Expand Down
4 changes: 4 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
rustdesk-server (1.1.11-1) UNRELEASED; urgency=medium
* set reuse port to make restart friendly
* revert hbbr `-k` to not ruin back-compatibility

rustdesk-server (1.1.11) UNRELEASED; urgency=medium
* change -k to default '-', so you need not to set -k any more

Expand Down
10 changes: 9 additions & 1 deletion libs/hbb_common/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,16 @@ pub async fn new_listener<T: ToSocketAddrs>(addr: T, reuse: bool) -> ResultType<
}
}

pub async fn listen_any(port: u16) -> ResultType<TcpListener> {
pub async fn listen_any(port: u16, reuse: bool) -> ResultType<TcpListener> {
if let Ok(mut socket) = TcpSocket::new_v6() {
if reuse {
// windows has no reuse_port, but it's reuse_address
// almost equals to unix's reuse_port + reuse_address,
// though may introduce nondeterministic behavior
#[cfg(unix)]
socket.set_reuseport(true).ok();
socket.set_reuseaddr(true).ok();
}
#[cfg(unix)]
{
use std::os::unix::io::{FromRawFd, IntoRawFd};
Expand Down
2 changes: 1 addition & 1 deletion src/hbbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() -> ResultType<()> {
matches.value_of("port").unwrap_or(&port.to_string()),
matches
.value_of("key")
.unwrap_or(&std::env::var("KEY").unwrap_or("-".to_owned())),
.unwrap_or(&std::env::var("KEY").unwrap_or_default()),
)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/relay_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub async fn start(port: &str, key: &str) -> ResultType<()> {
let main_task = async move {
loop {
log::info!("Start");
io_loop(listen_any(port).await?, listen_any(port2).await?, &key).await;
io_loop(listen_any(port, true).await?, listen_any(port2, true).await?, &key).await;
}
};
let listen_signal = crate::common::listen_signal();
Expand Down
6 changes: 3 additions & 3 deletions src/rendezvous_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,19 +1294,19 @@ async fn send_rk_res(

async fn create_udp_listener(port: i32, rmem: usize) -> ResultType<FramedSocket> {
let addr = SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), port as _);
if let Ok(s) = FramedSocket::new_reuse(&addr, false, rmem).await {
if let Ok(s) = FramedSocket::new_reuse(&addr, true, rmem).await {
log::debug!("listen on udp {:?}", s.local_addr());
return Ok(s);
}
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), port as _);
let s = FramedSocket::new_reuse(&addr, false, rmem).await?;
let s = FramedSocket::new_reuse(&addr, true, rmem).await?;
log::debug!("listen on udp {:?}", s.local_addr());
Ok(s)
}

#[inline]
async fn create_tcp_listener(port: i32) -> ResultType<TcpListener> {
let s = listen_any(port as _).await?;
let s = listen_any(port as _, true).await?;
log::debug!("listen on tcp {:?}", s.local_addr());
Ok(s)
}

0 comments on commit 5078a1f

Please sign in to comment.