Lines
97.44 %
Functions
100 %
Branches
//! Client data on the channels that buffer it: ssh-copy-id uploads and TUI input.
use super::{Session_, upload};
use crate::key_decoder::feed_shared;
use crate::tui_transport::restore;
use russh::ChannelId;
use russh::server::Session;
use tui::transport::warn_failed;
/// Sent after the terminal restore when a TUI channel is closed for overflowing its queue.
const OVERFLOW_REPLY: &[u8] = b"input overflow; session closed\r\n";
impl Session_ {
/// Appends to an upload; one over the cap is dropped with its channel.
/// False when `channel` is not an upload.
pub(super) fn feed_upload(
&mut self,
channel: ChannelId,
data: &[u8],
session: &mut Session,
) -> Result<bool, russh::Error> {
let Some(buf) = self.pubkey_uploads.get_mut(&channel) else {
return Ok(false);
};
if !upload::append_upload(buf, data) {
tracing::warn!(
"ssh-copy-id upload over {} bytes; closing",
upload::MAX_UPLOAD_BYTES
);
self.pubkey_uploads.remove(&channel);
session.close(channel)?;
}
Ok(true)
/// Decodes TUI input; a full queue closes the channel. False when `channel`
/// is not a TUI channel.
pub(super) fn feed_tui(
let Some(state) = self.tui_channels.get_mut(&channel) else {
let overflowed = state
.input_tx
.as_ref()
.is_some_and(|tx| feed_shared(&state.decoder, data, tx).is_err());
if overflowed {
tracing::warn!("tui input backlog on channel {channel:?}; closing it");
state.input_tx = None;
let mut farewell = Vec::new();
warn_failed(restore(&mut farewell));
farewell.extend_from_slice(OVERFLOW_REPLY);
session.data(channel, farewell)?;