Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle/profile: Control socket path for Windows
Merged lorenz opened 8 months ago

The winpipe crate which is our current best bet for support on Windows requires that named pipes are at the magical location \\.pipe\.

Provide a default on Windows that matches this, and use our freshly assigned IANA service name for it.

This is a breaking change, as we remove a pub const, it should be reasonably easy to fix by dependents, and probably it was a mistake to make the default pub const as dependents should call Home::socket anyway.

3 files changed +50 -5 fd34b680 ce11f03f
added crates/radicle/CHANGELOG.md
@@ -0,0 +1,24 @@
+
# Changelog
+

+
All notable changes to this project will be documented in this file.
+

+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+

+
## [Unreleased]
+

+
### Added
+

+
### Changed
+

+
- `radicle::profile::Home::socket` defaults to the path `\\.\pipe\radicle-node`
+
  on Windows. The behavior on Unix-like systems has *not* changed.
+

+
### Deprecated
+

+
### Removed
+

+
- `radicle::node::DEFAULT_SOCKET_NAME`, use `radicle::profile::Home::socket`
+
  instead.
+

+
### Security
modified crates/radicle/src/node.rs
@@ -53,8 +53,6 @@ pub use timestamp::Timestamp;

/// Peer-to-peer protocol version.
pub const PROTOCOL_VERSION: u8 = 1;
-
/// Default name for control socket file.
-
pub const DEFAULT_SOCKET_NAME: &str = "control.sock";
/// Default radicle protocol port.
pub const DEFAULT_PORT: u16 = 8776;
/// Default timeout when waiting for the node to respond with data.
modified crates/radicle/src/profile.rs
@@ -578,9 +578,32 @@ impl Home {
    }

    pub fn socket(&self) -> PathBuf {
-
        env::var_os(env::RAD_SOCKET)
-
            .map(PathBuf::from)
-
            .unwrap_or_else(|| self.node().join(node::DEFAULT_SOCKET_NAME))
+
        use env::RAD_SOCKET;
+

+
        #[cfg(unix)]
+
        const DEFAULT_SOCKET_NAME: &str = "control.sock";
+

+
        #[cfg(windows)]
+
        const DEFAULT_SOCKET_NAME: &str = r#"\\.\pipe\radicle-node"#;
+

+
        match env::var_os(RAD_SOCKET).map(PathBuf::from) {
+
            None => {
+
                #[cfg(unix)]
+
                return self.node().join(DEFAULT_SOCKET_NAME);
+

+
                #[cfg(windows)]
+
                return PathBuf::from(DEFAULT_SOCKET_NAME);
+
            }
+
            Some(path) => {
+
                #[cfg(windows)]
+
                {
+
                    const PIPE_PREFIX: &str = r#"\\.\pipe\"#;
+
                    assert!(path.starts_with(PIPE_PREFIX), "The value of the environment variable {RAD_SOCKET} ('{}') must start with {PIPE_PREFIX}. This restriction might be relaxed in the future.", path.display());
+
                }
+

+
                path
+
            }
+
        }
    }

    /// Return a read-write handle to the notifications database.