Skip to content

Commit

Permalink
initial client support for unix sockets (direct-streamlocal)
Browse files Browse the repository at this point in the history
  • Loading branch information
mllken authored and Eugeny committed Feb 19, 2023
1 parent a80fdba commit 56c8ff6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions russh/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ pub enum Msg {
originator_port: u32,
sender: UnboundedSender<ChannelMsg>,
},
ChannelOpenDirectStream {
socket_path: String,
sender: UnboundedSender<ChannelMsg>,
},
TcpIpForward {
want_reply: bool,
address: String,
Expand Down Expand Up @@ -416,6 +420,21 @@ impl<H: Handler> Handle<H> {
self.wait_channel_confirmation(receiver).await
}

pub async fn channel_open_direct_stream<S: Into<String>>(
&self,
socket_path: S,
) -> Result<Channel<Msg>, crate::Error> {
let (sender, receiver) = unbounded_channel();
self.sender
.send(Msg::ChannelOpenDirectStream {
socket_path: socket_path.into(),
sender,
})
.await
.map_err(|_| crate::Error::SendError)?;
self.wait_channel_confirmation(receiver).await
}

pub async fn tcpip_forward<A: Into<String>>(
&mut self,
address: A,
Expand Down Expand Up @@ -779,6 +798,15 @@ impl Session {
)?;
self.channels.insert(id, sender);
}
Msg::ChannelOpenDirectStream {
socket_path,
sender,
} => {
let id = self.channel_open_direct_stream(
&socket_path,
)?;
self.channels.insert(id, sender);
}
Msg::TcpIpForward {
want_reply,
address,
Expand Down
11 changes: 11 additions & 0 deletions russh/src/client/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ impl Session {
})
}

pub fn channel_open_direct_stream(
&mut self,
socket_path: &str
) -> Result<ChannelId, crate::Error> {
self.channel_open_generic(b"[email protected]", |write| {
write.extend_ssh_string(socket_path.as_bytes());
write.extend_ssh_string("".as_bytes()); // reserved
write.push_u32_be(0); // reserved
})
}

#[allow(clippy::too_many_arguments)]
pub fn request_pty(
&mut self,
Expand Down

0 comments on commit 56c8ff6

Please sign in to comment.