pub struct ChaiServer<T: ChaiApp + Send + 'static> { /* private fields */ }Implementations§
Source§impl<T: ChaiApp + Send + 'static> ChaiServer<T>
impl<T: ChaiApp + Send + 'static> ChaiServer<T>
Sourcepub fn new(port: u16) -> Self
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}Sourcepub fn with_max_connections(self, max: usize) -> Self
pub fn with_max_connections(self, max: usize) -> Self
Set the maximum number of concurrent SSH connections. Default: 100.
Sourcepub fn with_channel_buffer(self, size: usize) -> Self
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.
Sourcepub async fn run(&mut self, config: Config) -> Result<(), Error>
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> Handler for ChaiServer<T>
impl<T: ChaiApp + Send + 'static> Handler for ChaiServer<T>
type Error = Error
Source§async fn channel_open_session(
&mut self,
_channel: Channel<Msg>,
_session: &mut Session,
) -> Result<bool, Self::Error>
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>
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>
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>
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>
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>
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>
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>
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
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
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
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
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
fn auth_succeeded( &mut self, session: &mut Session, ) -> impl Future<Output = Result<(), Self::Error>> + Send
Called when authentication succeeds for a session.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
fn streamlocal_forward( &mut self, socket_path: &str, session: &mut Session, ) -> impl Future<Output = Result<bool, Self::Error>> + Send
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
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 moreSource§impl<T: ChaiApp + Send + 'static> Server for ChaiServer<T>
impl<T: ChaiApp + Send + 'static> Server for ChaiServer<T>
Source§type Handler = ChaiServer<T>
type Handler = ChaiServer<T>
The type of handlers.
Source§fn new_client(&mut self, _: Option<SocketAddr>) -> Self
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)
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,
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.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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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