Skip to content

Commit cfe45e5

Browse files
authored
Support sending "[email protected]" requests (#527)
1 parent 04e529e commit cfe45e5

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

russh/src/client/encrypted.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ impl Session {
731731
Some(GlobalRequestResponse::Keepalive) => {
732732
// ignore keepalives
733733
}
734+
Some(GlobalRequestResponse::NoMoreSessions) => {
735+
debug!("[email protected] requests success");
736+
}
734737
Some(GlobalRequestResponse::TcpIpForward(return_channel)) => {
735738
let result = if r.is_empty() {
736739
// If a specific port was requested, the reply has no data
@@ -767,6 +770,9 @@ impl Session {
767770
Some(GlobalRequestResponse::Keepalive) => {
768771
// ignore keepalives
769772
}
773+
Some(GlobalRequestResponse::NoMoreSessions) => {
774+
warn!("[email protected] requests failure");
775+
}
770776
Some(GlobalRequestResponse::TcpIpForward(return_channel)) => {
771777
let _ = return_channel.send(None);
772778
}

russh/src/client/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ pub enum Msg {
200200
Keepalive {
201201
want_reply: bool,
202202
},
203+
NoMoreSessions {
204+
want_reply: bool,
205+
},
203206
}
204207

205208
impl From<(ChannelId, ChannelMsg)> for Msg {
@@ -834,6 +837,14 @@ impl<H: Handler> Handle<H> {
834837
.await
835838
.map_err(|_| Error::SendError)
836839
}
840+
841+
/// Send a no-more-sessions request to the remote peer.
842+
pub async fn no_more_sessions(&self, want_reply: bool) -> Result<(), Error> {
843+
self.sender
844+
.send(Msg::NoMoreSessions { want_reply })
845+
.await
846+
.map_err(|_| Error::SendError)
847+
}
837848
}
838849

839850
impl<H: Handler> Future for Handle<H> {
@@ -1376,6 +1387,9 @@ impl Session {
13761387
Msg::Keepalive { want_reply } => {
13771388
let _ = self.send_keepalive(want_reply);
13781389
}
1390+
Msg::NoMoreSessions { want_reply } => {
1391+
let _ = self.no_more_sessions(want_reply);
1392+
}
13791393
msg => {
13801394
// should be unreachable, since the receiver only gets
13811395
// messages from methods implemented within russh

russh/src/client/session.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,19 @@ impl Session {
414414
Ok(())
415415
}
416416

417+
pub fn no_more_sessions(&mut self, want_reply: bool) -> Result<(), crate::Error> {
418+
self.open_global_requests
419+
.push_back(crate::session::GlobalRequestResponse::NoMoreSessions);
420+
if let Some(ref mut enc) = self.common.encrypted {
421+
push_packet!(enc.write, {
422+
msg::GLOBAL_REQUEST.encode(&mut enc.write)?;
423+
"[email protected]".encode(&mut enc.write)?;
424+
(want_reply as u8).encode(&mut enc.write)?;
425+
});
426+
}
427+
Ok(())
428+
}
429+
417430
pub fn data(&mut self, channel: ChannelId, data: CryptoVec) -> Result<(), crate::Error> {
418431
if let Some(ref mut enc) = self.common.encrypted {
419432
enc.data(channel, data, self.kex.active())

russh/src/session.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ pub(crate) struct NewKeys {
585585
pub(crate) enum GlobalRequestResponse {
586586
/// request was for Keepalive, ignore result
587587
Keepalive,
588+
/// request was for NoMoreSessions, disallow additional sessions
589+
NoMoreSessions,
588590
/// request was for TcpIpForward, sends Some(port) for success or None for failure
589591
TcpIpForward(oneshot::Sender<Option<u32>>),
590592
/// request was for CancelTcpIpForward, sends true for success or false for failure

0 commit comments

Comments
 (0)