Skip to main content

ChaiServer

Struct ChaiServer 

Source
pub struct ChaiServer<T: ChaiApp + Send + 'static> { /* private fields */ }

Implementations§

Source§

impl<T: ChaiApp + Send + 'static> ChaiServer<T>

Source

pub fn new(port: u16) -> Self

Examples found in repository?
examples/counter.rs (line 69)
54async fn main() {
55    let host_key =
56        load_host_keys("./examples/host_keys/id_ed25519").expect("Failed to load host keys");
57    let mut methods = MethodSet::empty();
58    methods.push(MethodKind::None);
59
60    let config = Config {
61        inactivity_timeout: Some(std::time::Duration::from_secs(3600)),
62        auth_rejection_time: std::time::Duration::from_secs(3),
63        auth_rejection_time_initial: Some(std::time::Duration::from_secs(0)),
64        keys: vec![host_key],
65        methods,
66        ..Default::default()
67    };
68
69    let mut server = ChaiServer::<MyApp>::new(2222);
70    server.run(config).await.expect("Failed running server");
71}
Source

pub fn with_max_connections(self, max: usize) -> Self

Set the maximum number of concurrent SSH connections. Default: 100.

Source

pub fn with_channel_buffer(self, size: usize) -> Self

Set the per-connection terminal output channel buffer size. Frames are dropped (not buffered) when the buffer is full. Default: 64.

Source

pub async fn run(&mut self, config: Config) -> Result<(), Error>

Examples found in repository?
examples/counter.rs (line 70)
54async fn main() {
55    let host_key =
56        load_host_keys("./examples/host_keys/id_ed25519").expect("Failed to load host keys");
57    let mut methods = MethodSet::empty();
58    methods.push(MethodKind::None);
59
60    let config = Config {
61        inactivity_timeout: Some(std::time::Duration::from_secs(3600)),
62        auth_rejection_time: std::time::Duration::from_secs(3),
63        auth_rejection_time_initial: Some(std::time::Duration::from_secs(0)),
64        keys: vec![host_key],
65        methods,
66        ..Default::default()
67    };
68
69    let mut server = ChaiServer::<MyApp>::new(2222);
70    server.run(config).await.expect("Failed running server");
71}

Trait Implementations§

Source§

impl<T: ChaiApp + Send + 'static> Clone for ChaiServer<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ChaiApp + Send + 'static> Drop for ChaiServer<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: ChaiApp + Send + 'static> Handler for ChaiServer<T>

Source§

type Error = Error

Source§

async fn channel_open_session( &mut self, _channel: Channel<Msg>, _session: &mut Session, ) -> Result<bool, Self::Error>

Called when a new session channel is created. Return value indicates whether the channel request should be granted.
Source§

async fn auth_publickey( &mut self, user: &str, _: &PublicKey, ) -> Result<Auth, Self::Error>

Check authentication using the “publickey” method. This method is called after the signature has been verified and key ownership has been confirmed. Russh guarantees that rejection happens in constant time config.auth_rejection_time, except if this method takes more time than that.
Source§

async fn auth_none(&mut self, user: &str) -> Result<Auth, Self::Error>

Check authentication using the “none” method. Russh makes sure rejection happens in time config.auth_rejection_time, except if this method takes more than that.
Source§

async fn data( &mut self, channel: ChannelId, data: &[u8], session: &mut Session, ) -> Result<(), Self::Error>

Called when a data packet is received. A response can be written to the response argument.
Source§

async fn window_change_request( &mut self, channel: ChannelId, col_width: u32, row_height: u32, _: u32, _: u32, session: &mut Session, ) -> Result<(), Self::Error>

The client’s pseudo-terminal window size has changed. Read more
Source§

async fn pty_request( &mut self, _channel: ChannelId, _: &str, col_width: u32, row_height: u32, _: u32, _: u32, _: &[(Pty, u32)], _session: &mut Session, ) -> Result<(), Self::Error>

The client requests a pseudo-terminal with the given specifications. Read more
Source§

async fn shell_request( &mut self, channel: ChannelId, session: &mut Session, ) -> Result<(), Self::Error>

The client requests a shell. Read more
Source§

async fn channel_close( &mut self, channel: ChannelId, session: &mut Session, ) -> Result<(), Self::Error>

Called when the client closes a channel.
Source§

fn auth_password( &mut self, user: &str, password: &str, ) -> impl Future<Output = Result<Auth, Self::Error>> + Send

Check authentication using the “password” method. Russh makes sure rejection happens in time config.auth_rejection_time, except if this method takes more than that.
Source§

fn auth_publickey_offered( &mut self, user: &str, public_key: &PublicKey, ) -> impl Future<Output = Result<Auth, Self::Error>> + Send

Check authentication using the “publickey” method. This method should just check whether the public key matches the authorized ones. Russh then checks the signature. If the key is unknown, or the signature is invalid, Russh guarantees that rejection happens in constant time config.auth_rejection_time, except if this method takes more time than that.
Source§

fn auth_openssh_certificate( &mut self, user: &str, certificate: &Certificate, ) -> impl Future<Output = Result<Auth, Self::Error>> + Send

Check authentication using an OpenSSH certificate. This method is called after the signature has been verified and key ownership has been confirmed. Russh guarantees that rejection happens in constant time config.auth_rejection_time, except if this method takes more time than that.
Source§

fn auth_keyboard_interactive<'a>( &'a mut self, user: &str, submethods: &str, response: Option<Response<'a>>, ) -> impl Future<Output = Result<Auth, Self::Error>> + Send

Check authentication using the “keyboard-interactive” method. Russh makes sure rejection happens in time config.auth_rejection_time, except if this method takes more than that.
Source§

fn auth_succeeded( &mut self, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Called when authentication succeeds for a session.
Source§

fn authentication_banner( &mut self, ) -> impl Future<Output = Result<Option<String>, Self::Error>> + Send

Called when authentication starts but before it is successful. Return value is an authentication banner, usually a warning message shown to the client.
Source§

fn channel_eof( &mut self, channel: ChannelId, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Called when the client sends EOF to a channel.
Source§

fn channel_open_x11( &mut self, channel: Channel<Msg>, originator_address: &str, originator_port: u32, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Called when a new X11 channel is created. Return value indicates whether the channel request should be granted.
Source§

fn channel_open_direct_tcpip( &mut self, channel: Channel<Msg>, host_to_connect: &str, port_to_connect: u32, originator_address: &str, originator_port: u32, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Called when a new direct TCP/IP (“local TCP forwarding”) channel is opened. Return value indicates whether the channel request should be granted.
Source§

fn channel_open_forwarded_tcpip( &mut self, channel: Channel<Msg>, host_to_connect: &str, port_to_connect: u32, originator_address: &str, originator_port: u32, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Called when a new remote forwarded TCP connection comes in. https://www.rfc-editor.org/rfc/rfc4254#section-7
Source§

fn channel_open_direct_streamlocal( &mut self, channel: Channel<Msg>, socket_path: &str, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Called when a new direct-streamlocal (“local UNIX socket forwarding”) channel is created. Return value indicates whether the channel request should be granted.
Source§

fn channel_open_confirmation( &mut self, id: ChannelId, max_packet_size: u32, window_size: u32, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Called when the client confirmed our request to open a channel. A channel can only be written to after receiving this message (this library panics otherwise).
Source§

fn extended_data( &mut self, channel: ChannelId, code: u32, data: &[u8], session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Called when an extended data packet is received. Code 1 means that this packet comes from stderr, other codes are not defined (see RFC4254).
Source§

fn window_adjusted( &mut self, channel: ChannelId, new_size: u32, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Called when the network window is adjusted, meaning that we can send more bytes.
Source§

fn adjust_window(&mut self, channel: ChannelId, current: u32) -> u32

Called when this server adjusts the network window. Return the next target window.
Source§

fn x11_request( &mut self, channel: ChannelId, single_connection: bool, x11_auth_protocol: &str, x11_auth_cookie: &str, x11_screen_number: u32, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

The client requests an X11 connection. Read more
Source§

fn env_request( &mut self, channel: ChannelId, variable_name: &str, variable_value: &str, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

The client wants to set the given environment variable. Check these carefully, as it is dangerous to allow any variable environment to be set. Read more
Source§

fn exec_request( &mut self, channel: ChannelId, data: &[u8], session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

The client sends a command to execute, to be passed to a shell. Make sure to check the command before doing so. Read more
Source§

fn subsystem_request( &mut self, channel: ChannelId, name: &str, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

The client asks to start the subsystem with the given name (such as sftp). Read more
Source§

fn agent_request( &mut self, channel: ChannelId, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

The client requests OpenSSH agent forwarding Read more
Source§

fn signal( &mut self, channel: ChannelId, signal: Sig, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send

The client is sending a signal (usually to pass to the currently running process).
Source§

fn tcpip_forward( &mut self, address: &str, port: &mut u32, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Used for reverse-forwarding ports, see RFC4254. If port is 0, you should set it to the allocated port number.
Source§

fn cancel_tcpip_forward( &mut self, address: &str, port: u32, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Used to stop the reverse-forwarding of a port, see RFC4254.
Source§

fn streamlocal_forward( &mut self, socket_path: &str, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Source§

fn cancel_streamlocal_forward( &mut self, socket_path: &str, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Source§

fn lookup_dh_gex_group( &mut self, gex_params: &GexParams, ) -> impl Future<Output = Result<Option<DhGroup>, Self::Error>> + Send

Override when enabling the diffie-hellman-group-exchange-* key exchange methods. Should return a Diffie-Hellman group with a safe prime whose length is between gex_params.min_group_size and gex_params.max_group_size and (if possible) over and as close as possible to gex_params.preferred_group_size. Read more
Source§

impl<T: ChaiApp + Send + 'static> Server for ChaiServer<T>

Source§

type Handler = ChaiServer<T>

The type of handlers.
Source§

fn new_client(&mut self, _: Option<SocketAddr>) -> Self

Called when a new client connects.
Source§

fn handle_session_error(&mut self, _error: <Self::Handler as Handler>::Error)

Called when an active connection fails.
Source§

fn run_on_socket( &mut self, config: Arc<Config>, socket: &TcpListener, ) -> RunningServer<impl Future<Output = Result<(), Error>> + Unpin + Send>
where Self: Send,

Run a server on a specified tokio::net::TcpListener. Useful when dropping privileges immediately after socket binding, for example.
Source§

fn run_on_address<A>( &mut self, config: Arc<Config>, addrs: A, ) -> impl Future<Output = Result<(), Error>> + Send
where A: ToSocketAddrs + Send, Self: Send,

Run a server. This is a convenience function; consider using run_on_socket for more control.

Auto Trait Implementations§

§

impl<T> Freeze for ChaiServer<T>

§

impl<T> !RefUnwindSafe for ChaiServer<T>

§

impl<T> Send for ChaiServer<T>

§

impl<T> Sync for ChaiServer<T>

§

impl<T> Unpin for ChaiServer<T>

§

impl<T> UnsafeUnpin for ChaiServer<T>

§

impl<T> !UnwindSafe for ChaiServer<T>

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> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Declassify for T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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