Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions russh-config/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::process::Stdio;
use futures::ready;
use futures::task::*;
use tokio::io::ReadBuf;
use tokio::net::TcpStream;
use tokio::net::ToSocketAddrs;
use tokio::net::{TcpStream, ToSocketAddrs};
use tokio::process::Command;

/// A type to implement either a TCP socket, or proxying through an external command.
Expand Down
8 changes: 7 additions & 1 deletion russh/examples/client_open_direct_tcpip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use anyhow::Result;
use clap::Parser;
use key::PrivateKeyWithHashAlg;
use log::info;
use russh::client::Config;
use russh::keys::*;
use russh::*;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
Expand Down Expand Up @@ -81,7 +82,12 @@ impl Session {
addrs: A,
) -> Result<Self> {
let key_pair = load_secret_key(key_path, None)?;
let config = client::Config::default();

let config = Config {
nodelay: true,
..Default::default()
};

// load ssh certificate
let mut openssh_cert = None;
if openssh_cert_path.is_some() {
Expand Down
11 changes: 10 additions & 1 deletion russh/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use std::time::Duration;
use futures::task::{Context, Poll};
use futures::Future;
use kex::ClientKex;
use log::{debug, error, trace};
use log::{debug, error, trace, warn};
use russh_util::time::Instant;
use ssh_encoding::Decode;
use ssh_key::{Algorithm, Certificate, HashAlg, PrivateKey, PublicKey};
Expand Down Expand Up @@ -876,6 +876,12 @@ pub async fn connect<H: Handler + Send + 'static, A: tokio::net::ToSocketAddrs>(
handler: H,
) -> Result<Handle<H>, H::Error> {
let socket = map_err!(tokio::net::TcpStream::connect(addrs).await)?;
if config.as_ref().nodelay {
if let Err(e) = socket.set_nodelay(true) {
warn!("set_nodelay() failed: {e:?}");
}
}

connect_stream(config, socket, handler).await
}

Expand Down Expand Up @@ -1650,6 +1656,8 @@ pub struct Config {
pub anonymous: bool,
/// DH dynamic group exchange parameters.
pub gex: GexParams,
/// If active, invoke `set_nodelay(true)` on the ssh socket; disabled by default (i.e. Nagle's algorithm is active).
pub nodelay: bool,
}

impl Default for Config {
Expand All @@ -1670,6 +1678,7 @@ impl Default for Config {
keepalive_max: 3,
anonymous: false,
gex: Default::default(),
nodelay: false,
}
}
}
Expand Down