radicle/profile: Control socket path for Windows

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.
This commit is contained in:
Lorenz Leutgeb 2025-08-21 21:28:35 +02:00 committed by Fintan Halpenny
parent fd34b680b5
commit ce11f03fe6
3 changed files with 50 additions and 5 deletions

View File

@ -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

View File

@ -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.

View File

@ -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.