Make datagram support configurable

This commit is contained in:
Jan Trefil 2024-07-21 15:57:53 +02:00
parent 897eb0a68e
commit c4bad45532
4 changed files with 14 additions and 3 deletions

View file

@ -1,9 +1,17 @@
listen = "0.0.0.0:5258" listen = "0.0.0.0:5258"
# See `switch-keys.md` in the repository root for the list of all possible keys. # See `switch-keys.md` in the repository root for the list of all possible keys.
switch-keys = ["left-alt", "left-ctrl"] switch-keys = ["left-alt", "left-ctrl"]
# Whether switch key presses should be propagated on the server and its clients. # Whether switch key presses should be propagated on the server and its clients.
# Optional, defaults to true. # Optional, defaults to true.
# propagate-switch-keys = true # propagate-switch-keys = true
# Whether mouse events should be sent as datagrams.
# Enabling this can improve mouse input latency significantly at the cost of
# losing mouse events if the network is congested, making mouse appear janky.
# Optional, defaults to false.
# enable-datagrams = false
certificate = "/etc/rkvm/certificate.pem" certificate = "/etc/rkvm/certificate.pem"
key = "/etc/rkvm/key.pem" key = "/etc/rkvm/key.pem"

View file

@ -13,6 +13,7 @@ pub struct Config {
pub password: String, pub password: String,
pub switch_keys: HashSet<SwitchKey>, pub switch_keys: HashSet<SwitchKey>,
pub propagate_switch_keys: Option<bool>, pub propagate_switch_keys: Option<bool>,
pub enable_datagrams: Option<bool>,
} }
#[derive(Deserialize, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Deserialize, Clone, Copy, PartialEq, Eq, Hash)]

View file

@ -69,9 +69,10 @@ async fn main() -> ExitCode {
let switch_keys = config.switch_keys.into_iter().map(Into::into).collect(); let switch_keys = config.switch_keys.into_iter().map(Into::into).collect();
let propagate_switch_keys = config.propagate_switch_keys.unwrap_or(true); let propagate_switch_keys = config.propagate_switch_keys.unwrap_or(true);
let enable_datagrams = config.enable_datagrams.unwrap_or(false);
tokio::select! { tokio::select! {
result = server::run(config.listen, server_config, &config.password, &switch_keys, propagate_switch_keys) => { result = server::run(config.listen, server_config, &config.password, &switch_keys, propagate_switch_keys, enable_datagrams) => {
if let Err(err) = result { if let Err(err) = result {
tracing::error!("Error: {}", err); tracing::error!("Error: {}", err);
return ExitCode::FAILURE; return ExitCode::FAILURE;

View file

@ -37,6 +37,7 @@ pub async fn run(
password: &str, password: &str,
switch_keys: &HashSet<Key>, switch_keys: &HashSet<Key>,
propagate_switch_keys: bool, propagate_switch_keys: bool,
enable_datagrams: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
config.transport_config(rkvm_net::transport_config().into()); config.transport_config(rkvm_net::transport_config().into());
@ -115,7 +116,7 @@ pub async fn run(
async move { async move {
tracing::info!("Connected"); tracing::info!("Connected");
match client(init_updates, receiver, connection, &password).await { match client(init_updates, receiver, connection, &password, enable_datagrams).await {
Ok(()) => tracing::info!("Disconnected"), Ok(()) => tracing::info!("Disconnected"),
Err(err) => tracing::error!("Disconnected: {}", err), Err(err) => tracing::error!("Disconnected: {}", err),
} }
@ -354,6 +355,7 @@ async fn client(
mut receiver: Receiver<Update>, mut receiver: Receiver<Update>,
connection: Incoming, connection: Incoming,
password: &str, password: &str,
mut enable_datagrams: bool,
) -> Result<(), ClientError> { ) -> Result<(), ClientError> {
let connection = connection.await?; let connection = connection.await?;
@ -399,7 +401,6 @@ async fn client(
data_write.shutdown().await?; data_write.shutdown().await?;
let mut enable_datagrams = true;
let mut datagram_events = Vec::new(); let mut datagram_events = Vec::new();
loop { loop {