Documentation
¶
Overview ¶
Package sshtuning holds the process-wide SSH/TCP connection tuning that is applied to every outbound SSH connection — both interactive terminal sessions (internal/service/ssh_svc) and pooled connections (internal/sshpool). It is a single mutable source of truth (mirroring the way sshkeepalive used to expose one global interval constant) so that a user changing the settings updates all future connections without re-wiring.
Index ¶
Constants ¶
const ( DefaultKeepAliveInterval = 30 * time.Second DefaultDialTimeout = 30 * time.Second )
Default values used when a setting is left unconfigured. The 30s keepalive is deliberately shorter than a "typical" 60s: NAT gateways, home routers and proxy chains (e.g. a transparent mihomo/Clash side-router routing SSH through an overseas proxy) commonly reap idle TCP connections within 30-60s, and only the SSH-level heartbeat traverses the whole proxy chain — so a 60s heartbeat races the reaper and the session drops. 30s keeps idle sessions alive in those setups; users on an aggressive proxy can lower it further. The 30s heartbeat is still negligible traffic (one tiny request/reply per connection per interval).
Variables ¶
This section is empty.
Functions ¶
func ResolveKeepAlive ¶
ResolveKeepAlive returns the effective SSH keepalive heartbeat interval for a single connection: a positive per-asset override (in seconds) wins, otherwise the process-wide default is used. This is the one place the "override else default" precedence lives, so callers pass the raw per-asset seconds (0 = inherit) and don't re-implement the fallback.
Types ¶
type Settings ¶
type Settings struct {
// TCPNoDelay disables Nagle's algorithm (TCP_NODELAY) on the underlying
// socket so small interactive writes are sent immediately.
TCPNoDelay bool
// TCPKeepAlive enables OS-level TCP keepalive probes (SO_KEEPALIVE).
TCPKeepAlive bool
// KeepAliveInterval is the period between SSH-level "keepalive@openssh.com"
// heartbeats (the empty packets that keep a session alive through idle
// NAT/firewall timeouts). A value <= 0 disables the heartbeat.
KeepAliveInterval time.Duration
// DialTimeout caps the TCP connect phase. A value <= 0 means
// DefaultDialTimeout.
DialTimeout time.Duration
}
Settings is the connection tuning applied to outbound SSH connections.
func Default ¶
func Default() Settings
Default returns the built-in tuning used before the user configures anything.
func (Settings) ApplyTCPOptions ¶
ApplyTCPOptions sets TCP_NODELAY on conn per the tuning. It is a no-op for non-TCP connections (e.g. a SOCKS5-proxied or jump-host channel conn), where the option is not reachable. Returns the first error encountered, if any.
func (Settings) DialTimeoutOrDefault ¶
DialTimeoutOrDefault returns the configured dial timeout, falling back to DefaultDialTimeout when unset.