ssh_muxcontrol/commands/
mod.rs1use bytes::{BufMut, BytesMut};
2use std::{error::Error, fmt};
3
4#[derive(Debug)]
6pub struct CommandError {
7 details: String,
8}
9
10impl CommandError {
11 fn new(details: String) -> Self {
12 Self { details }
13 }
14}
15
16impl fmt::Display for CommandError {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 write!(f, "{}", self.details)
19 }
20}
21
22impl Error for CommandError {}
23
24pub trait MuxCmd {
25 fn serialize(&self, buffer: &mut BytesMut);
26 fn length(&self) -> usize;
27}
28
29mod new_session;
30pub use new_session::{MuxCmdNewSession, MuxRespNewSession};
31mod hello;
32pub use hello::{MuxCmdHello, MuxRespHello};
33mod exit;
34pub use exit::MuxRespExit;
35mod check_alive;
36pub use check_alive::{MuxCmdCheckAlive, MuxRespCheckAlive};
37
38#[derive(Debug)]
39pub struct MuxCmdMessage {
40 pub request: u32,
41 pub param: u32,
42}
43
44pub const MUX_VERSION: u32 = 4;
46pub const MUX_MSG_HELLO: u32 = 1;
47pub const MUX_NEW_SESSION: u32 = 0x10000002;
48pub const MUX_ALIVE_CHECK: u32 = 0x10000004;
49
50pub const MUX_IS_ALIVE: u32 = 0x80000005;
51pub const MUX_SESSION_OPENED: u32 = 0x80000006;
52pub const MUX_EXIT_MESSAGE: u32 = 0x80000004;
53
54impl MuxCmd for MuxCmdMessage {
55 fn serialize(&self, buffer: &mut BytesMut) {
56 buffer.put_u32(self.request);
57 buffer.put_u32(self.param);
58 }
59
60 fn length(&self) -> usize {
61 8
62 }
63}