pub struct SshConnection { /* private fields */ }Expand description
SSH connection to RIPE Atlas controller
Implementations§
Source§impl SshConnection
impl SshConnection
Sourcepub async fn connect(
host: &str,
port: u16,
key: &PrivateKey,
config: SshConfig,
known_hosts: KnownHosts,
telnet_state: Option<TelnetState>,
) -> Result<Self>
pub async fn connect( host: &str, port: u16, key: &PrivateKey, config: SshConfig, known_hosts: KnownHosts, telnet_state: Option<TelnetState>, ) -> Result<Self>
Connect to a controller server
If telnet_state is provided, forwarded SSH connections (reverse
tunnel) will be handled directly by the telnet command parser
without a local TCP listener.
Sourcepub async fn connect_with_retry(
host: &str,
port: u16,
key: &PrivateKey,
config: SshConfig,
known_hosts: KnownHosts,
telnet_state: Option<TelnetState>,
) -> Result<Self>
pub async fn connect_with_retry( host: &str, port: u16, key: &PrivateKey, config: SshConfig, known_hosts: KnownHosts, telnet_state: Option<TelnetState>, ) -> Result<Self>
Connect with automatic retry
Sourcepub async fn connect_to_servers(
servers: &[&str],
key: &PrivateKey,
config: SshConfig,
known_hosts: KnownHosts,
) -> Result<Self>
pub async fn connect_to_servers( servers: &[&str], key: &PrivateKey, config: SshConfig, known_hosts: KnownHosts, ) -> Result<Self>
Try connecting to multiple servers in order
Sourcepub async fn init(
&self,
probe_info: Option<&ProbeInitInfo>,
) -> Result<InitResponse>
pub async fn init( &self, probe_info: Option<&ProbeInitInfo>, ) -> Result<InitResponse>
Execute the INIT command and parse response
The RIPE Atlas protocol requires sending probe identification data to the server when running INIT on a registration server.
Sourcepub async fn run_keep_session(&self) -> Result<()>
pub async fn run_keep_session(&self) -> Result<()>
Start the KEEP session and monitor it.
Opens a channel with the KEEP command and blocks until the channel closes (which means the controller disconnected). Returns when the connection is lost. The caller should use this as the connection health signal.
Sourcepub async fn request_reverse_tunnel(&self, bind_port: u16) -> Result<()>
pub async fn request_reverse_tunnel(&self, bind_port: u16) -> Result<()>
Request reverse port forwarding
Sourcepub async fn cancel_reverse_tunnel(&self, bind_port: u16) -> Result<()>
pub async fn cancel_reverse_tunnel(&self, bind_port: u16) -> Result<()>
Cancel reverse port forwarding
Sourcepub async fn open_direct_tcpip(
&self,
remote_host: &str,
remote_port: u16,
) -> Result<Channel<Msg>>
pub async fn open_direct_tcpip( &self, remote_host: &str, remote_port: u16, ) -> Result<Channel<Msg>>
Create a direct-tcpip channel to forward data to the controller This opens an SSH channel that connects to the specified host:port on the server side
Sourcepub fn controller_host(&self) -> &str
pub fn controller_host(&self) -> &str
Get the controller host we’re connected to
Sourcepub fn controller_port(&self) -> u16
pub fn controller_port(&self) -> u16
Get the controller port we’re connected to
Sourcepub async fn start_http_proxy(
&self,
local_port: u16,
remote_port: u16,
reconnect_signal: CancellationToken,
) -> Result<()>
pub async fn start_http_proxy( &self, local_port: u16, remote_port: u16, reconnect_signal: CancellationToken, ) -> Result<()>
Start a local HTTP proxy that forwards to the controller via SSH direct-tcpip
This sets up a local TCP listener on the specified port. When connections come in, they are forwarded through the SSH connection to the controller’s HTTP endpoint.
This mimics the behavior of ssh -L local_port:127.0.0.1:remote_port
The Atlas protocol uses: -L 8080:127.0.0.1:8080 to forward local:8080
to controller’s 127.0.0.1:8080
The reconnect_signal token will be cancelled if the proxy detects the
SSH session is dead (e.g., consecutive channel open failures or
timeouts). The caller should watch this token and reconnect when
it’s cancelled.
Sourcepub async fn execute(&self, command: &str) -> Result<String>
pub async fn execute(&self, command: &str) -> Result<String>
Execute a command and return output
Sourcepub async fn execute_with_stdin(
&self,
command: &str,
stdin_data: &str,
) -> Result<String>
pub async fn execute_with_stdin( &self, command: &str, stdin_data: &str, ) -> Result<String>
Execute a command with stdin data and return output
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if connection is still alive