Add Windows named-pipe local control

This commit is contained in:
Eric Wendland 2026-07-18 17:05:38 +02:00
commit 3c84713472
9 changed files with 338 additions and 72 deletions

View file

@ -87,7 +87,23 @@ impl GethPaths {
#[must_use]
pub fn socket_path(&self) -> PathBuf {
self.run_dir().join("geth.sock")
PathBuf::from(self.control_endpoint())
}
#[must_use]
pub fn control_endpoint(&self) -> String {
#[cfg(unix)]
{
self.run_dir().join("geth.sock").display().to_string()
}
#[cfg(windows)]
{
let home = self.home.display().to_string().to_ascii_lowercase();
format!(
r"\\.\pipe\geth-{:016x}",
stable_control_endpoint_suffix(home.as_bytes())
)
}
}
pub fn ensure_base_dirs(&self) -> Result<(), ConfigError> {
@ -98,6 +114,16 @@ impl GethPaths {
}
}
#[cfg(any(windows, test))]
fn stable_control_endpoint_suffix(bytes: &[u8]) -> u64 {
let mut hash = 0xcbf2_9ce4_8422_2325_u64;
for byte in bytes {
hash ^= u64::from(*byte);
hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
}
hash
}
#[derive(Debug, thiserror::Error)]
pub enum ConfigError {
#[error("could not determine OS data directory and GETH_HOME is unset")]
@ -603,6 +629,18 @@ mod tests {
assert!(matches!(error, ConfigError::InvalidLocalDiscovery(_)));
}
#[test]
fn control_endpoint_suffix_is_stable_and_home_scoped() {
assert_eq!(
stable_control_endpoint_suffix(b"C:/Users/Eric/geth"),
stable_control_endpoint_suffix(b"C:/Users/Eric/geth")
);
assert_ne!(
stable_control_endpoint_suffix(b"C:/Users/Eric/geth"),
stable_control_endpoint_suffix(b"C:/Users/Eric/other")
);
}
#[test]
fn config_set_preserves_comments_and_validates_the_result() {
let home = tempfile::tempdir().expect("tempdir");