Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Set TCP_KEEPALIVE on sockets
cloudhead committed 1 year ago
commit a85e7f7442117271c97ffbedc1671a7b1ea996a5
parent 90deb2040538b24721ed00ef1a0b81d2438a980d
3 files changed +12 -1
modified Cargo.lock
@@ -2683,6 +2683,7 @@ dependencies = [
 "serde",
 "serde_json",
 "snapbox",
+
 "socket2",
 "sqlite",
 "tempfile",
 "thiserror",
modified radicle-node/Cargo.toml
@@ -39,6 +39,7 @@ scrypt = { version = "0.11.0", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
snapbox = { version = "0.4.3", optional = true }
+
socket2 = { version = "0.5.7" }
tempfile = { version = "3.3.0" }
thiserror = { version = "1" }

modified radicle-node/src/wire/protocol.rs
@@ -1181,8 +1181,17 @@ fn session<G: Signer + Ecdh<Pk = NodeId>>(
    connection.set_read_timeout(Some(DEFAULT_CONNECTION_TIMEOUT))?;
    connection.set_write_timeout(Some(DEFAULT_CONNECTION_TIMEOUT))?;

+
    let sock = socket2::Socket::from(connection);
+
    let ka = socket2::TcpKeepalive::new()
+
        .with_time(time::Duration::from_secs(30))
+
        .with_interval(time::Duration::from_secs(10))
+
        .with_retries(3);
+
    if let Err(e) = sock.set_tcp_keepalive(&ka) {
+
        log::warn!(target: "wire", "Unable to set TCP_KEEPALIVE on fd {}: {e}", sock.as_raw_fd());
+
    }
+

    let socks5 = socks5::Socks5::with(remote_addr, force_proxy);
-
    let proxy = Socks5Session::with(connection, socks5);
+
    let proxy = Socks5Session::with(sock.into(), socks5);
    let pair = G::generate_keypair();
    let keyset = Keyset {
        e: pair.0,