Still unfinished

pull/219/head
Chip Senkbeil 10 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",
"bytes",
"chacha20poly1305",
"const-str",
"derive_more",
"distant-auth",
"dyn-clone",

@ -15,6 +15,7 @@ license = "MIT OR Apache-2.0"
async-trait = "0.1.68"
bytes = "1.4.0"
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"] }
distant-auth = { version = "=0.20.0-alpha.12", path = "../distant-auth" }
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;
/// Represents a version and compatibility rules.
#[derive(Clone, Debug)]
pub struct Version {
inner: SemVer,
rules: VersionReq,
lower: Comparator,
upper: Comparator,
}
impl Version {
@ -44,38 +45,34 @@ impl Version {
/// assert!(!a.is_compatible_with(&b));
/// 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 {
inner: SemVer::new(major, minor, patch),
rules: VersionReq {
comparators: vec![
Comparator {
op: Op::GreaterEq,
major,
minor: Some(minor),
patch: Some(patch),
pre: Prerelease::EMPTY,
},
Comparator {
op: Op::Less,
major: if major == 0 { 0 } else { major + 1 },
minor: if major == 0 { Some(minor + 1) } else { None },
patch: None,
pre: Prerelease::EMPTY,
},
],
lower: Comparator {
op: Op::GreaterEq,
major,
minor: Some(minor),
patch: Some(patch),
pre: Prerelease::EMPTY,
},
upper: Comparator {
op: Op::Less,
major: if major == 0 { 0 } else { major + 1 },
minor: if major == 0 { Some(minor + 1) } else { None },
patch: None,
pre: Prerelease::EMPTY,
},
}
}
/// Returns true if this version is compatible with another version.
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
/// using big endian.
pub fn from_be_bytes(bytes: [u8; 24]) -> Self {
pub const fn from_be_bytes(bytes: [u8; 24]) -> Self {
Self::new(
u64::from_be_bytes([
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 data::*;
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)
.config(ClientConfig::default().with_maximum_silence_duration())
.connector(t1)
.version(Version::new(
PROTOCOL_VERSION.major,
PROTOCOL_VERSION.minor,
PROTOCOL_VERSION.patch,
))
.connect()
.await?;
Ok((client, server))

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

@ -7,7 +7,7 @@ use distant_core::net::auth::{
AuthHandler, AuthMethodHandler, PromptAuthMethodHandler, SingleAuthHandler,
};
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 crate::cli::common::{MsgReceiver, MsgSender};
@ -71,6 +71,7 @@ impl<T: AuthHandler + Clone> Client<T> {
},
..Default::default()
})
.version(PROTOCOL_VERSION)
.connect()
.await
{
@ -113,6 +114,7 @@ impl<T: AuthHandler + Clone> Client<T> {
},
..Default::default()
})
.version(PROTOCOL_VERSION)
.connect()
.await
{

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

Loading…
Cancel
Save