-
Notifications
You must be signed in to change notification settings - Fork 205
feat(dvc): make dvc named pipe proxy cross-platform #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Vladyslav Nikonov (pacmancoder)
merged 4 commits into
master
from
feat/dvc-proxy-cross-platform
Aug 4, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #[derive(Debug)] | ||
| pub(crate) enum DvcPipeProxyError { | ||
| Io(std::io::Error), | ||
| EncodeDvcMessage(ironrdp_core::EncodeError), | ||
| } | ||
|
|
||
| impl core::fmt::Display for DvcPipeProxyError { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| match self { | ||
| DvcPipeProxyError::Io(_) => write!(f, "IO error"), | ||
| DvcPipeProxyError::EncodeDvcMessage(_) => write!(f, "DVC message encoding error"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl core::error::Error for DvcPipeProxyError { | ||
| fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { | ||
| match self { | ||
| DvcPipeProxyError::Io(err) => Some(err), | ||
| DvcPipeProxyError::EncodeDvcMessage(src) => Some(src), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| use ironrdp_core::{ensure_size, Encode, EncodeResult}; | ||
| use ironrdp_dvc::DvcEncode; | ||
|
|
||
| pub(crate) struct RawDataDvcMessage(pub Vec<u8>); | ||
|
|
||
| impl Encode for RawDataDvcMessage { | ||
| fn encode(&self, dst: &mut ironrdp_core::WriteCursor<'_>) -> EncodeResult<()> { | ||
| ensure_size!(in: dst, size: self.size()); | ||
| dst.write_slice(&self.0); | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn name(&self) -> &'static str { | ||
| "RawDataDvcMessage" | ||
| } | ||
|
|
||
| fn size(&self) -> usize { | ||
| self.0.len() | ||
| } | ||
| } | ||
|
|
||
| impl DvcEncode for RawDataDvcMessage {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| use async_trait::async_trait; | ||
|
|
||
| use crate::error::DvcPipeProxyError; | ||
|
|
||
| #[async_trait] | ||
| pub(crate) trait OsPipe: Send + Sync { | ||
| /// Creates a new OS pipe and waits for the connection. | ||
| async fn connect(pipe_name: &str) -> Result<Self, DvcPipeProxyError> | ||
| where | ||
| Self: Sized; | ||
|
|
||
| /// Reads data from the pipe and returns the number of bytes read. | ||
| /// | ||
| /// Returned future should be stateless and can be polled multiple times. | ||
| async fn read(&mut self, buffer: &mut [u8]) -> Result<usize, DvcPipeProxyError>; | ||
|
|
||
| /// Writes data to the pipe and returns the number of bytes written. | ||
| async fn write_all(&mut self, buffer: &[u8]) -> Result<(), DvcPipeProxyError>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,5 @@ | ||
| #[cfg(target_os = "windows")] | ||
| mod windows; | ||
| #[cfg(target_os = "windows")] | ||
| pub use self::windows::DvcNamedPipeProxy; | ||
| pub(crate) mod windows; | ||
|
|
||
| #[cfg(not(target_os = "windows"))] | ||
| mod unix; | ||
| #[cfg(not(target_os = "windows"))] | ||
| pub use self::unix::DvcNamedPipeProxy; | ||
| pub(crate) mod unix; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,66 @@ | ||
| use ironrdp_core::impl_as_any; | ||
| use ironrdp_dvc::{DvcClientProcessor, DvcMessage, DvcProcessor}; | ||
| use ironrdp_pdu::{pdu_other_err, PduResult}; | ||
| use ironrdp_svc::SvcMessage; | ||
|
|
||
| /// A proxy DVC pipe client that forwards DVC messages to/from a named pipe server. | ||
| pub struct DvcNamedPipeProxy { | ||
| channel_name: String, | ||
| use async_trait::async_trait; | ||
| use tokio::fs; | ||
| use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _}; | ||
|
|
||
| use crate::error::DvcPipeProxyError; | ||
| use crate::os_pipe::OsPipe; | ||
|
|
||
| /// Unix-specific implementation of the OS pipe trait. | ||
| pub(crate) struct UnixPipe { | ||
| socket: tokio::net::UnixStream, | ||
| } | ||
|
|
||
| impl DvcNamedPipeProxy { | ||
| /// Creates a new DVC named pipe proxy. | ||
| /// `dvc_write_callback` is called when the proxy receives a DVC message from the | ||
| /// named pipe server and the SVC message is ready to be sent to the DVC channel in the main | ||
| /// IronRDP active session loop. | ||
| pub fn new<F>(channel_name: &str, _named_pipe_name: &str, _dvc_write_callback: F) -> Self | ||
| where | ||
| F: Fn(u32, Vec<SvcMessage>) -> PduResult<()> + Send + 'static, | ||
| { | ||
| error!("DvcNamedPipeProxy is not implemented on Unix-like systems, using a stub implementation"); | ||
|
|
||
| Self { | ||
| channel_name: channel_name.to_owned(), | ||
| #[async_trait] | ||
| impl OsPipe for UnixPipe { | ||
| async fn connect(pipe_name: &str) -> Result<Self, DvcPipeProxyError> { | ||
| // Domain socket file could already exist from a previous run. | ||
| match fs::metadata(&pipe_name).await { | ||
| Ok(metadata) => { | ||
| use std::os::unix::fs::FileTypeExt as _; | ||
|
|
||
| info!( | ||
| %pipe_name, | ||
| "DVC pipe already exists, removing stale file." | ||
| ); | ||
|
|
||
| // Just to be sure, check if it's indeed a socket - | ||
| // throw an error if calling code accidentally passed a regular file. | ||
| if !metadata.file_type().is_socket() { | ||
| return Err(DvcPipeProxyError::Io(std::io::Error::new( | ||
| std::io::ErrorKind::InvalidInput, | ||
| format!("Path {pipe_name} is not a socket"), | ||
| ))); | ||
| } | ||
|
|
||
| fs::remove_file(pipe_name).await.map_err(DvcPipeProxyError::Io)?; | ||
| } | ||
| Err(e) if e.kind() == std::io::ErrorKind::NotFound => { | ||
| trace!( | ||
| %pipe_name, | ||
| "DVC pipe does not exist, creating it." | ||
| ); | ||
| } | ||
| Err(e) => { | ||
| return Err(DvcPipeProxyError::Io(e)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl_as_any!(DvcNamedPipeProxy); | ||
| let listener = tokio::net::UnixListener::bind(pipe_name).map_err(DvcPipeProxyError::Io)?; | ||
|
|
||
| impl DvcProcessor for DvcNamedPipeProxy { | ||
| fn channel_name(&self) -> &str { | ||
| &self.channel_name | ||
| let (socket, _) = listener.accept().await.map_err(DvcPipeProxyError::Io)?; | ||
|
|
||
| Ok(Self { socket }) | ||
| } | ||
|
|
||
| fn start(&mut self, _channel_id: u32) -> PduResult<Vec<DvcMessage>> { | ||
| Err(pdu_other_err!( | ||
| "DvcNamedPipeProxy is not implemented on Unix-like systems" | ||
| )) | ||
| async fn read(&mut self, buffer: &mut [u8]) -> Result<usize, DvcPipeProxyError> { | ||
| self.socket.read(buffer).await.map_err(DvcPipeProxyError::Io) | ||
| } | ||
|
|
||
| fn process(&mut self, _channel_id: u32, _payload: &[u8]) -> PduResult<Vec<DvcMessage>> { | ||
| Err(pdu_other_err!( | ||
| "DvcNamedPipeProxy is not implemented on Unix-like systems" | ||
| )) | ||
| async fn write_all(&mut self, buffer: &[u8]) -> Result<(), DvcPipeProxyError> { | ||
| self.socket | ||
| .write_all(buffer) | ||
| .await | ||
| .map_err(DvcPipeProxyError::Io) | ||
| .map(|_| ()) | ||
| } | ||
| } | ||
|
|
||
| impl DvcClientProcessor for DvcNamedPipeProxy {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use async_trait::async_trait; | ||
| use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _}; | ||
| use tokio::net::windows::named_pipe; | ||
|
|
||
| use crate::error::DvcPipeProxyError; | ||
| use crate::os_pipe::OsPipe; | ||
|
|
||
| const PIPE_BUFFER_SIZE: u32 = 64 * 1024; | ||
|
|
||
| /// Unix-specific implementation of the OS pipe trait. | ||
| pub(crate) struct WindowsPipe { | ||
| pipe_server: named_pipe::NamedPipeServer, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl OsPipe for WindowsPipe { | ||
| async fn connect(pipe_name: &str) -> Result<Self, DvcPipeProxyError> { | ||
| let pipe_name = format!("\\\\.\\pipe\\{pipe_name}"); | ||
|
|
||
| let pipe_server = named_pipe::ServerOptions::new() | ||
| .first_pipe_instance(true) | ||
| .access_inbound(true) | ||
| .access_outbound(true) | ||
| .max_instances(2) | ||
| .in_buffer_size(PIPE_BUFFER_SIZE) | ||
| .out_buffer_size(PIPE_BUFFER_SIZE) | ||
| .pipe_mode(named_pipe::PipeMode::Message) | ||
| .create(pipe_name) | ||
| .map_err(DvcPipeProxyError::Io)?; | ||
|
|
||
| pipe_server.connect().await.map_err(DvcPipeProxyError::Io)?; | ||
|
|
||
| Ok(Self { pipe_server }) | ||
| } | ||
|
|
||
| async fn read(&mut self, buffer: &mut [u8]) -> Result<usize, DvcPipeProxyError> { | ||
| self.pipe_server.read(buffer).await.map_err(DvcPipeProxyError::Io) | ||
| } | ||
|
|
||
| async fn write_all(&mut self, buffer: &[u8]) -> Result<(), DvcPipeProxyError> { | ||
| self.pipe_server | ||
| .write_all(buffer) | ||
| .await | ||
| .map_err(DvcPipeProxyError::Io) | ||
| .map(|_| ()) | ||
| } | ||
| } |
37 changes: 0 additions & 37 deletions
37
crates/ironrdp-dvc-pipe-proxy/src/platform/windows/error.rs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: We loose the sync-friendly non-tokio-specific interface you made efforts to keep, but at the same time the tradeoff seems worth it.
question: Just to be on the safe side, can you double check you really enabled only the minimal amount of features?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, feature set is minimal