mirror of
https://github.com/htrefil/rkvm.git
synced 2024-12-27 09:58:13 +01:00
Move socket configuration to a dedicated function in rkvm-net
This commit is contained in:
parent
c4ff4232ae
commit
de45d872c3
8 changed files with 26 additions and 30 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -778,7 +778,6 @@ dependencies = [
|
|||
"rkvm-net",
|
||||
"rustls-pemfile",
|
||||
"serde",
|
||||
"socket2 0.5.3",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
|
@ -813,6 +812,7 @@ dependencies = [
|
|||
"rkvm-input",
|
||||
"serde",
|
||||
"sha2",
|
||||
"socket2 0.5.3",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
@ -830,7 +830,6 @@ dependencies = [
|
|||
"rustls-pemfile",
|
||||
"serde",
|
||||
"slab",
|
||||
"socket2 0.5.3",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
|
|
|
@ -19,7 +19,6 @@ clap = { version = "4.2.2", features = ["derive"] }
|
|||
thiserror = "1.0.40"
|
||||
tokio-rustls = "0.24.0"
|
||||
rustls-pemfile = "1.0.2"
|
||||
socket2 = { version = "0.5.3", features = ["all"] }
|
||||
|
||||
[package.metadata.rpm]
|
||||
package = "rkvm-client"
|
||||
|
|
|
@ -2,12 +2,10 @@ use rkvm_input::writer::Writer;
|
|||
use rkvm_net::auth::{AuthChallenge, AuthStatus};
|
||||
use rkvm_net::message::Message;
|
||||
use rkvm_net::version::Version;
|
||||
use rkvm_net::Update;
|
||||
use socket2::{SockRef, TcpKeepalive};
|
||||
use rkvm_net::{socket, Update};
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
use thiserror::Error;
|
||||
use tokio::io::{AsyncWriteExt, BufStream};
|
||||
use tokio::net::TcpStream;
|
||||
|
@ -42,17 +40,7 @@ pub async fn run(
|
|||
_ => unimplemented!("Unhandled rustls ServerName variant: {:?}", hostname),
|
||||
};
|
||||
|
||||
stream.set_linger(None).map_err(Error::Network)?;
|
||||
stream.set_nodelay(false).map_err(Error::Network)?;
|
||||
|
||||
SockRef::from(&stream)
|
||||
.set_tcp_keepalive(
|
||||
&TcpKeepalive::new()
|
||||
.with_time(Duration::from_secs(1))
|
||||
.with_interval(Duration::from_secs(10))
|
||||
.with_retries(1),
|
||||
)
|
||||
.map_err(Error::Network)?;
|
||||
socket::configure(&stream).map_err(Error::Network)?;
|
||||
|
||||
log::info!("Connected to server");
|
||||
|
||||
|
|
|
@ -17,3 +17,4 @@ hmac = "0.12.1"
|
|||
sha2 = "0.10.6"
|
||||
rand = "0.8.5"
|
||||
log = "0.4.11"
|
||||
socket2 = { version = "0.5.3", features = ["all"] }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod auth;
|
||||
pub mod message;
|
||||
pub mod socket;
|
||||
pub mod version;
|
||||
|
||||
use rkvm_input::abs::{AbsAxis, AbsInfo};
|
||||
|
|
18
rkvm-net/src/socket.rs
Normal file
18
rkvm-net/src/socket.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use socket2::{SockRef, TcpKeepalive};
|
||||
use std::io::Error;
|
||||
use std::time::Duration;
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
pub fn configure(stream: &TcpStream) -> Result<(), Error> {
|
||||
stream.set_linger(None)?;
|
||||
stream.set_nodelay(false)?;
|
||||
|
||||
SockRef::from(&stream).set_tcp_keepalive(
|
||||
&TcpKeepalive::new()
|
||||
.with_time(Duration::from_secs(1))
|
||||
.with_interval(Duration::from_secs(10))
|
||||
.with_retries(1),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -21,7 +21,6 @@ rustls-pemfile = "1.0.2"
|
|||
thiserror = "1.0.40"
|
||||
slab = "0.4.8"
|
||||
rand = "0.8.5"
|
||||
socket2 = { version = "0.5.3", features = ["all"] }
|
||||
|
||||
[package.metadata.rpm]
|
||||
package = "rkvm-server"
|
||||
|
|
|
@ -6,9 +6,8 @@ use rkvm_input::rel::RelAxis;
|
|||
use rkvm_net::auth::{AuthChallenge, AuthResponse, AuthStatus};
|
||||
use rkvm_net::message::Message;
|
||||
use rkvm_net::version::Version;
|
||||
use rkvm_net::Update;
|
||||
use rkvm_net::{socket, Update};
|
||||
use slab::Slab;
|
||||
use socket2::{SockRef, TcpKeepalive};
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::ffi::CString;
|
||||
use std::io::{self, ErrorKind};
|
||||
|
@ -265,15 +264,7 @@ async fn client(
|
|||
password: &str,
|
||||
) -> Result<(), ClientError> {
|
||||
let negotiate = async {
|
||||
stream.set_linger(None)?;
|
||||
stream.set_nodelay(false)?;
|
||||
|
||||
SockRef::from(&stream).set_tcp_keepalive(
|
||||
&TcpKeepalive::new()
|
||||
.with_time(Duration::from_secs(1))
|
||||
.with_interval(Duration::from_secs(10))
|
||||
.with_retries(1),
|
||||
)?;
|
||||
socket::configure(&stream)?;
|
||||
|
||||
let stream = acceptor.accept(stream).await?;
|
||||
log::info!("{}: TLS connected", addr);
|
||||
|
|
Loading…
Reference in a new issue