Skip to main content

SshConnection

Struct SshConnection 

Source
pub struct SshConnection { /* private fields */ }
Expand description

SSH connection to RIPE Atlas controller

Implementations§

Source§

impl SshConnection

Source

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.

Source

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

Source

pub async fn connect_to_servers( servers: &[&str], key: &PrivateKey, config: SshConfig, known_hosts: KnownHosts, ) -> Result<Self>

Try connecting to multiple servers in order

Source

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.

Source

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.

Source

pub async fn request_reverse_tunnel(&self, bind_port: u16) -> Result<()>

Request reverse port forwarding

Source

pub async fn cancel_reverse_tunnel(&self, bind_port: u16) -> Result<()>

Cancel reverse port forwarding

Source

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

Source

pub fn controller_host(&self) -> &str

Get the controller host we’re connected to

Source

pub fn controller_port(&self) -> u16

Get the controller port we’re connected to

Source

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.

Source

pub async fn execute(&self, command: &str) -> Result<String>

Execute a command and return output

Source

pub async fn execute_with_stdin( &self, command: &str, stdin_data: &str, ) -> Result<String>

Execute a command with stdin data and return output

Source

pub async fn is_connected(&self) -> bool

Check if connection is still alive

Source

pub fn host(&self) -> &str

Get the host we’re connected to

Source

pub fn port(&self) -> u16

Get the port we’re connected to

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more