Still unfinished

pull/219/head
Chip Senkbeil 11 months ago
parent cf2c5c700e
commit fc932346a2
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

1
Cargo.lock generated

@ -931,6 +931,7 @@ dependencies = [
"async-trait", "async-trait",
"bytes", "bytes",
"chacha20poly1305", "chacha20poly1305",
"const-str",
"derive_more", "derive_more",
"distant-auth", "distant-auth",
"dyn-clone", "dyn-clone",

@ -15,6 +15,7 @@ license = "MIT OR Apache-2.0"
async-trait = "0.1.68" async-trait = "0.1.68"
bytes = "1.4.0" bytes = "1.4.0"
chacha20poly1305 = "0.10.1" chacha20poly1305 = "0.10.1"
const-str = "0.5.6"
derive_more = { version = "0.99.17", default-features = false, features = ["as_mut", "as_ref", "deref", "deref_mut", "display", "from", "error", "into", "into_iterator", "is_variant", "try_into"] } derive_more = { version = "0.99.17", default-features = false, features = ["as_mut", "as_ref", "deref", "deref_mut", "display", "from", "error", "into", "into_iterator", "is_variant", "try_into"] }
distant-auth = { version = "=0.20.0-alpha.12", path = "../distant-auth" } distant-auth = { version = "=0.20.0-alpha.12", path = "../distant-auth" }
dyn-clone = "1.0.11" dyn-clone = "1.0.11"

@ -1,11 +1,12 @@
use semver::{Comparator, Op, Prerelease, Version as SemVer, VersionReq}; use semver::{Comparator, Op, Prerelease, Version as SemVer};
use std::fmt; use std::fmt;
/// Represents a version and compatibility rules. /// Represents a version and compatibility rules.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Version { pub struct Version {
inner: SemVer, inner: SemVer,
rules: VersionReq, lower: Comparator,
upper: Comparator,
} }
impl Version { impl Version {
@ -44,38 +45,34 @@ impl Version {
/// assert!(!a.is_compatible_with(&b)); /// assert!(!a.is_compatible_with(&b));
/// assert!(!b.is_compatible_with(&a)); /// assert!(!b.is_compatible_with(&a));
/// ``` /// ```
pub fn new(major: u64, minor: u64, patch: u64) -> Self { pub const fn new(major: u64, minor: u64, patch: u64) -> Self {
Self { Self {
inner: SemVer::new(major, minor, patch), inner: SemVer::new(major, minor, patch),
rules: VersionReq { lower: Comparator {
comparators: vec![ op: Op::GreaterEq,
Comparator { major,
op: Op::GreaterEq, minor: Some(minor),
major, patch: Some(patch),
minor: Some(minor), pre: Prerelease::EMPTY,
patch: Some(patch), },
pre: Prerelease::EMPTY, upper: Comparator {
}, op: Op::Less,
Comparator { major: if major == 0 { 0 } else { major + 1 },
op: Op::Less, minor: if major == 0 { Some(minor + 1) } else { None },
major: if major == 0 { 0 } else { major + 1 }, patch: None,
minor: if major == 0 { Some(minor + 1) } else { None }, pre: Prerelease::EMPTY,
patch: None,
pre: Prerelease::EMPTY,
},
],
}, },
} }
} }
/// Returns true if this version is compatible with another version. /// Returns true if this version is compatible with another version.
pub fn is_compatible_with(&self, other: &Self) -> bool { pub fn is_compatible_with(&self, other: &Self) -> bool {
self.rules.matches(&other.inner) self.lower.matches(&other.inner) && self.upper.matches(&other.inner)
} }
/// Converts from a collection of bytes into a version using the byte form major/minor/patch /// Converts from a collection of bytes into a version using the byte form major/minor/patch
/// using big endian. /// using big endian.
pub fn from_be_bytes(bytes: [u8; 24]) -> Self { pub const fn from_be_bytes(bytes: [u8; 24]) -> Self {
Self::new( Self::new(
u64::from_be_bytes([ u64::from_be_bytes([
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],

@ -5,3 +5,12 @@ mod server;
pub use client::*; pub use client::*;
pub use data::*; pub use data::*;
pub use server::*; pub use server::*;
use crate::common::Version;
/// Represents the version associated with the manager's protocol.
pub const PROTOCOL_VERSION: Version = Version::new(
const_str::parse!(env!("CARGO_PKG_VERSION_MAJOR"), u64),
const_str::parse!(env!("CARGO_PKG_VERSION_MINOR"), u64),
const_str::parse!(env!("CARGO_PKG_VERSION_PATCH"), u64),
);

@ -762,11 +762,6 @@ impl Ssh {
.auth_handler(DummyAuthHandler) .auth_handler(DummyAuthHandler)
.config(ClientConfig::default().with_maximum_silence_duration()) .config(ClientConfig::default().with_maximum_silence_duration())
.connector(t1) .connector(t1)
.version(Version::new(
PROTOCOL_VERSION.major,
PROTOCOL_VERSION.minor,
PROTOCOL_VERSION.patch,
))
.connect() .connect()
.await?; .await?;
Ok((client, server)) Ok((client, server))

@ -2,8 +2,9 @@ use std::io::{self, Read, Write};
use anyhow::Context; use anyhow::Context;
use distant_core::net::auth::Verifier; use distant_core::net::auth::Verifier;
use distant_core::net::common::{Host, SecretKey32}; use distant_core::net::common::{Host, SecretKey32, Version};
use distant_core::net::server::{Server, ServerConfig as NetServerConfig}; use distant_core::net::server::{Server, ServerConfig as NetServerConfig};
use distant_core::protocol::PROTOCOL_VERSION;
use distant_core::DistantSingleKeyCredentials; use distant_core::DistantSingleKeyCredentials;
use distant_local::{Config as LocalConfig, WatchConfig as LocalWatchConfig}; use distant_local::{Config as LocalConfig, WatchConfig as LocalWatchConfig};
use log::*; use log::*;
@ -159,6 +160,11 @@ async fn async_run(cmd: ServerSubcommand, _is_forked: bool) -> CliResult {
}) })
.handler(handler) .handler(handler)
.verifier(Verifier::static_key(key.clone())) .verifier(Verifier::static_key(key.clone()))
.version(Version::new(
PROTOCOL_VERSION.major,
PROTOCOL_VERSION.minor,
PROTOCOL_VERSION.patch,
))
.start(addr, port) .start(addr, port)
.await .await
.with_context(|| format!("Failed to start server @ {addr} with {port}"))?; .with_context(|| format!("Failed to start server @ {addr} with {port}"))?;

@ -7,7 +7,7 @@ use distant_core::net::auth::{
AuthHandler, AuthMethodHandler, PromptAuthMethodHandler, SingleAuthHandler, AuthHandler, AuthMethodHandler, PromptAuthMethodHandler, SingleAuthHandler,
}; };
use distant_core::net::client::{Client as NetClient, ClientConfig, ReconnectStrategy}; use distant_core::net::client::{Client as NetClient, ClientConfig, ReconnectStrategy};
use distant_core::net::manager::ManagerClient; use distant_core::net::manager::{ManagerClient, PROTOCOL_VERSION};
use log::*; use log::*;
use crate::cli::common::{MsgReceiver, MsgSender}; use crate::cli::common::{MsgReceiver, MsgSender};
@ -71,6 +71,7 @@ impl<T: AuthHandler + Clone> Client<T> {
}, },
..Default::default() ..Default::default()
}) })
.version(PROTOCOL_VERSION)
.connect() .connect()
.await .await
{ {
@ -113,6 +114,7 @@ impl<T: AuthHandler + Clone> Client<T> {
}, },
..Default::default() ..Default::default()
}) })
.version(PROTOCOL_VERSION)
.connect() .connect()
.await .await
{ {

@ -1,6 +1,6 @@
use anyhow::Context; use anyhow::Context;
use distant_core::net::auth::Verifier; use distant_core::net::auth::Verifier;
use distant_core::net::manager::{Config as ManagerConfig, ManagerServer}; use distant_core::net::manager::{Config as ManagerConfig, ManagerServer, PROTOCOL_VERSION};
use distant_core::net::server::ServerRef; use distant_core::net::server::ServerRef;
use log::*; use log::*;
@ -18,6 +18,9 @@ impl Manager {
pub async fn listen(self) -> anyhow::Result<ServerRef> { pub async fn listen(self) -> anyhow::Result<ServerRef> {
let user = self.config.user; let user = self.config.user;
// Version we'll use to report compatibility in talking to the manager
let version = PROTOCOL_VERSION;
#[cfg(unix)] #[cfg(unix)]
{ {
use distant_core::net::common::UnixSocketListener; use distant_core::net::common::UnixSocketListener;
@ -38,6 +41,7 @@ impl Manager {
let server = ManagerServer::new(self.config) let server = ManagerServer::new(self.config)
.verifier(Verifier::none()) .verifier(Verifier::none())
.version(version)
.start( .start(
UnixSocketListener::bind_with_permissions(socket_path, self.access.into_mode()) UnixSocketListener::bind_with_permissions(socket_path, self.access.into_mode())
.await?, .await?,
@ -59,6 +63,7 @@ impl Manager {
let server = ManagerServer::new(self.config) let server = ManagerServer::new(self.config)
.verifier(Verifier::none()) .verifier(Verifier::none())
.version(version)
.start(WindowsPipeListener::bind_local(pipe_name)?) .start(WindowsPipeListener::bind_local(pipe_name)?)
.with_context(|| format!("Failed to start manager at pipe {pipe_name:?}"))?; .with_context(|| format!("Failed to start manager at pipe {pipe_name:?}"))?;

Loading…
Cancel
Save