Skip to content

Commit

Permalink
Refactor capabilities to version for manager, integrate version check…
Browse files Browse the repository at this point in the history
…ing for client/server/manager, and define protocol version (#219)
  • Loading branch information
chipsenkbeil authored Jul 14, 2023
1 parent 0efb5ae commit 8972013
Show file tree
Hide file tree
Showing 50 changed files with 955 additions and 977 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.20.0-alpha.13]

### Added

- Support for `--shell` with optional path to an explicit shell as an option
when executing `distant spawn` in order to run the command within a shell
rather than directly
- `semver` crate to be used for version information in protocol and manager
- `is_compatible_with` function to root of `distant-protocol` crate that checks
if a provided version is compatible with the protocol

### Changed

- `distant_protocol::PROTOCOL_VERSION` now uses the crate's major, minor, and
patch version at compile-time (parsed via `const-str` crate) to streamline
version handling between crate and protocol
- Protocol and manager now supply a version request instead of capabilities and
the capabilities of protocol are now a `Vec<String>` to contain a set of more
broad capabilities instead of every possible request type

### Fixed

Expand All @@ -30,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `Cmd::program` and `Cmd::arguments` functions as they were misleading (didn't
do what `distant-local` or `distant-ssh2` do)
- Removed `Capability` and `Capabilities` from protocol and manager

## [0.20.0-alpha.12]

Expand Down Expand Up @@ -600,7 +609,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
pending upon full channel and no longer locks up
- stdout, stderr, and stdin of `RemoteProcess` no longer cause deadlock

[Unreleased]: https://github.com/chipsenkbeil/distant/compare/v0.20.0-alpha.12...HEAD
[Unreleased]: https://github.com/chipsenkbeil/distant/compare/v0.20.0-alpha.13...HEAD
[0.20.0-alpha.13]: https://github.com/chipsenkbeil/distant/compare/v0.20.0-alpha.12...v0.20.0-alpha.13
[0.20.0-alpha.12]: https://github.com/chipsenkbeil/distant/compare/v0.20.0-alpha.11...v0.20.0-alpha.12
[0.20.0-alpha.11]: https://github.com/chipsenkbeil/distant/compare/v0.20.0-alpha.10...v0.20.0-alpha.11
[0.20.0-alpha.10]: https://github.com/chipsenkbeil/distant/compare/v0.20.0-alpha.9...v0.20.0-alpha.10
Expand Down
20 changes: 13 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "distant"
description = "Operate on a remote computer through file and process manipulation"
categories = ["command-line-utilities"]
keywords = ["cli"]
version = "0.20.0-alpha.12"
version = "0.20.0-alpha.13"
authors = ["Chip Senkbeil <[email protected]>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
Expand Down Expand Up @@ -40,8 +40,8 @@ clap_complete = "4.3.0"
config = { version = "0.13.3", default-features = false, features = ["toml"] }
derive_more = { version = "0.99.17", default-features = false, features = ["display", "from", "error", "is_variant"] }
dialoguer = { version = "0.10.4", default-features = false }
distant-core = { version = "=0.20.0-alpha.12", path = "distant-core" }
distant-local = { version = "=0.20.0-alpha.12", path = "distant-local" }
distant-core = { version = "=0.20.0-alpha.13", path = "distant-core" }
distant-local = { version = "=0.20.0-alpha.13", path = "distant-local" }
directories = "5.0.1"
file-mode = "0.1.2"
flexi_logger = "0.25.5"
Expand All @@ -65,7 +65,7 @@ winsplit = "0.1.0"
whoami = "1.4.0"

# Optional native SSH functionality
distant-ssh2 = { version = "=0.20.0-alpha.12", path = "distant-ssh2", default-features = false, features = ["serde"], optional = true }
distant-ssh2 = { version = "=0.20.0-alpha.13", path = "distant-ssh2", default-features = false, features = ["serde"], optional = true }

[target.'cfg(unix)'.dependencies]
fork = "0.1.21"
Expand Down
2 changes: 1 addition & 1 deletion distant-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "distant-auth"
description = "Authentication library for distant, providing various implementations"
categories = ["authentication"]
keywords = ["auth", "authentication", "async"]
version = "0.20.0-alpha.12"
version = "0.20.0-alpha.13"
authors = ["Chip Senkbeil <[email protected]>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
Expand Down
6 changes: 3 additions & 3 deletions distant-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "distant-core"
description = "Core library for distant, enabling operation on a remote computer through file and process manipulation"
categories = ["network-programming"]
keywords = ["api", "async"]
version = "0.20.0-alpha.12"
version = "0.20.0-alpha.13"
authors = ["Chip Senkbeil <[email protected]>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
Expand All @@ -16,8 +16,8 @@ async-trait = "0.1.68"
bitflags = "2.3.1"
bytes = "1.4.0"
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-net = { version = "=0.20.0-alpha.12", path = "../distant-net" }
distant-protocol = { version = "=0.20.0-alpha.12", path = "../distant-protocol" }
distant-net = { version = "=0.20.0-alpha.13", path = "../distant-net" }
distant-protocol = { version = "=0.20.0-alpha.13", path = "../distant-protocol" }
futures = "0.3.28"
hex = "0.4.3"
log = "0.4.18"
Expand Down
20 changes: 20 additions & 0 deletions distant-core/src/client/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ pub trait DistantChannelExt {
/// Creates a remote directory, optionally creating all parent components if specified
fn create_dir(&mut self, path: impl Into<PathBuf>, all: bool) -> AsyncReturn<'_, ()>;

/// Checks whether the `path` exists on the remote machine
fn exists(&mut self, path: impl Into<PathBuf>) -> AsyncReturn<'_, bool>;

/// Checks whether this client is compatible with the remote server
fn is_compatible(&mut self) -> AsyncReturn<'_, bool>;

/// Retrieves metadata about a path on a remote machine
fn metadata(
&mut self,
Expand Down Expand Up @@ -136,6 +140,9 @@ pub trait DistantChannelExt {
/// Retrieves server version information
fn version(&mut self) -> AsyncReturn<'_, Version>;

/// Returns version of protocol that the client uses
fn protocol_version(&self) -> protocol::semver::Version;

/// Writes a remote file with the data from a collection of bytes
fn write_file(
&mut self,
Expand Down Expand Up @@ -232,6 +239,15 @@ impl DistantChannelExt
)
}

fn is_compatible(&mut self) -> AsyncReturn<'_, bool> {
make_body!(self, protocol::Request::Version {}, |data| match data {
protocol::Response::Version(version) =>
Ok(protocol::is_compatible_with(&version.protocol_version)),
protocol::Response::Error(x) => Err(io::Error::from(x)),
_ => Err(mismatched_response()),
})
}

fn metadata(
&mut self,
path: impl Into<PathBuf>,
Expand Down Expand Up @@ -453,6 +469,10 @@ impl DistantChannelExt
})
}

fn protocol_version(&self) -> protocol::semver::Version {
protocol::PROTOCOL_VERSION
}

fn write_file(
&mut self,
path: impl Into<PathBuf>,
Expand Down
13 changes: 12 additions & 1 deletion distant-core/tests/api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use distant_core::{
};
use distant_net::auth::{DummyAuthHandler, Verifier};
use distant_net::client::Client;
use distant_net::common::{InmemoryTransport, OneshotListener};
use distant_net::common::{InmemoryTransport, OneshotListener, Version};
use distant_net::server::{Server, ServerRef};
use distant_protocol::PROTOCOL_VERSION;

/// Stands up an inmemory client and server using the given api.
async fn setup(api: impl DistantApi + Send + Sync + 'static) -> (DistantClient, ServerRef) {
Expand All @@ -17,12 +18,22 @@ async fn setup(api: impl DistantApi + Send + Sync + 'static) -> (DistantClient,
let server = Server::new()
.handler(DistantApiServerHandler::new(api))
.verifier(Verifier::none())
.version(Version::new(
PROTOCOL_VERSION.major,
PROTOCOL_VERSION.minor,
PROTOCOL_VERSION.patch,
))
.start(OneshotListener::from_value(t2))
.expect("Failed to start server");

let client: DistantClient = Client::build()
.auth_handler(DummyAuthHandler)
.connector(t1)
.version(Version::new(
PROTOCOL_VERSION.major,
PROTOCOL_VERSION.minor,
PROTOCOL_VERSION.patch,
))
.connect()
.await
.expect("Failed to connect to server");
Expand Down
4 changes: 2 additions & 2 deletions distant-local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "distant-local"
description = "Library implementing distant API for local interactions"
categories = ["network-programming"]
version = "0.20.0-alpha.12"
version = "0.20.0-alpha.13"
authors = ["Chip Senkbeil <[email protected]>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
Expand All @@ -21,7 +21,7 @@ macos-kqueue = ["notify/macos_kqueue"]

[dependencies]
async-trait = "0.1.68"
distant-core = { version = "=0.20.0-alpha.12", path = "../distant-core" }
distant-core = { version = "=0.20.0-alpha.13", path = "../distant-core" }
grep = "0.2.12"
ignore = "0.4.20"
log = "0.4.18"
Expand Down
32 changes: 27 additions & 5 deletions distant-local/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::time::SystemTime;
use std::{env, io};

use async_trait::async_trait;
use distant_core::protocol::semver;
use distant_core::protocol::{
Capabilities, ChangeKind, ChangeKindSet, DirEntry, Environment, FileType, Metadata,
Permissions, ProcessId, PtySize, SearchId, SearchQuery, SetPermissionsOptions, SystemInfo,
Version, PROTOCOL_VERSION,
ChangeKind, ChangeKindSet, DirEntry, Environment, FileType, Metadata, Permissions, ProcessId,
PtySize, SearchId, SearchQuery, SetPermissionsOptions, SystemInfo, Version, PROTOCOL_VERSION,
};
use distant_core::{DistantApi, DistantCtx};
use ignore::{DirEntry as WalkDirEntry, WalkBuilder};
Expand Down Expand Up @@ -635,10 +635,32 @@ impl DistantApi for Api {
async fn version(&self, ctx: DistantCtx) -> io::Result<Version> {
debug!("[Conn {}] Querying version", ctx.connection_id);

// Parse our server's version
let mut server_version: semver::Version = env!("CARGO_PKG_VERSION")
.parse()
.map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;

// Add the package name to the version information
if server_version.build.is_empty() {
server_version.build = semver::BuildMetadata::new(env!("CARGO_PKG_NAME"))
.map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;
} else {
let raw_build_str = format!(
"{}.{}",
server_version.build.as_str(),
env!("CARGO_PKG_NAME")
);
server_version.build = semver::BuildMetadata::new(&raw_build_str)
.map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;
}

Ok(Version {
server_version: format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
server_version,
protocol_version: PROTOCOL_VERSION,
capabilities: Capabilities::all(),
capabilities: Version::capabilities()
.iter()
.map(ToString::to_string)
.collect(),
})
}
}
Expand Down
8 changes: 5 additions & 3 deletions distant-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "distant-net"
description = "Network library for distant, providing implementations to support client/server architecture"
categories = ["network-programming"]
keywords = ["api", "async"]
version = "0.20.0-alpha.12"
version = "0.20.0-alpha.13"
authors = ["Chip Senkbeil <[email protected]>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
Expand All @@ -15,8 +15,9 @@ 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" }
distant-auth = { version = "=0.20.0-alpha.13", path = "../distant-auth" }
dyn-clone = "1.0.11"
flate2 = "1.0.26"
hex = "0.4.3"
Expand All @@ -28,14 +29,15 @@ rand = { version = "0.8.5", features = ["getrandom"] }
rmp = "0.8.11"
rmp-serde = "1.1.1"
sha2 = "0.10.6"
semver = { version = "1.0.17", features = ["serde"] }
serde = { version = "1.0.163", features = ["derive"] }
serde_bytes = "0.11.9"
serde_json = "1.0.96"
strum = { version = "0.24.1", features = ["derive"] }
tokio = { version = "1.28.2", features = ["full"] }

[dev-dependencies]
distant-auth = { version = "=0.20.0-alpha.12", path = "../distant-auth", features = ["tests"] }
distant-auth = { version = "=0.20.0-alpha.13", path = "../distant-auth", features = ["tests"] }
env_logger = "0.10.0"
serde_json = "1.0.96"
tempfile = "3.5.0"
Expand Down
Loading

0 comments on commit 8972013

Please sign in to comment.