Compare commits

..

No commits in common. 'c88f96baba2a0ee813b19b42b80f9aebb07d4488' and '83bd62c8fb80236c0647910b57ae164017de23c1' have entirely different histories.

105
Cargo.lock generated

@ -773,7 +773,7 @@ dependencies = [
[[package]]
name = "distant"
version = "0.21.0"
version = "0.20.0"
dependencies = [
"anyhow",
"assert_cmd",
@ -786,8 +786,8 @@ dependencies = [
"dialoguer",
"directories",
"distant-core",
"distant-plugin-local",
"distant-plugin-ssh",
"distant-local",
"distant-ssh2",
"env_logger",
"file-mode",
"flexi_logger",
@ -817,17 +817,29 @@ dependencies = [
"winsplit",
]
[[package]]
name = "distant-auth"
version = "0.20.0"
dependencies = [
"async-trait",
"derive_more",
"env_logger",
"log",
"serde",
"test-log",
"tokio",
]
[[package]]
name = "distant-core"
version = "0.21.0"
version = "0.20.0"
dependencies = [
"async-trait",
"bitflags 2.4.0",
"bytes",
"derive_more",
"distant-core-net",
"distant-core-plugin",
"distant-core-protocol",
"distant-net",
"distant-protocol",
"env_logger",
"futures",
"hex",
@ -845,28 +857,43 @@ dependencies = [
]
[[package]]
name = "distant-core-auth"
version = "0.21.0"
name = "distant-local"
version = "0.20.0"
dependencies = [
"assert_fs",
"async-trait",
"derive_more",
"distant-core",
"env_logger",
"grep",
"ignore",
"indoc",
"log",
"serde",
"notify",
"notify-debouncer-full",
"num_cpus",
"once_cell",
"portable-pty",
"predicates",
"rand 0.8.5",
"rstest",
"shell-words",
"test-log",
"tokio",
"walkdir",
"whoami",
"winsplit",
]
[[package]]
name = "distant-core-net"
version = "0.21.0"
name = "distant-net"
version = "0.20.0"
dependencies = [
"async-trait",
"bytes",
"chacha20poly1305",
"const-str",
"derive_more",
"distant-core-auth",
"distant-auth",
"dyn-clone",
"env_logger",
"flate2",
@ -890,18 +917,8 @@ dependencies = [
]
[[package]]
name = "distant-core-plugin"
version = "0.21.0"
dependencies = [
"async-trait",
"distant-core-auth",
"distant-core-protocol",
"serde",
]
[[package]]
name = "distant-core-protocol"
version = "0.21.0"
name = "distant-protocol"
version = "0.20.0"
dependencies = [
"bitflags 2.4.0",
"const-str",
@ -917,36 +934,8 @@ dependencies = [
]
[[package]]
name = "distant-plugin-local"
version = "0.21.0"
dependencies = [
"assert_fs",
"async-trait",
"distant-core",
"env_logger",
"grep",
"ignore",
"indoc",
"log",
"notify",
"notify-debouncer-full",
"num_cpus",
"once_cell",
"portable-pty",
"predicates",
"rand 0.8.5",
"rstest",
"shell-words",
"test-log",
"tokio",
"walkdir",
"whoami",
"winsplit",
]
[[package]]
name = "distant-plugin-ssh"
version = "0.21.0"
name = "distant-ssh2"
version = "0.20.0"
dependencies = [
"anyhow",
"assert_fs",
@ -3504,9 +3493,9 @@ dependencies = [
[[package]]
name = "typed-path"
version = "0.6.0"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbb9d13b8242894ff21f9990082b90a6410a43dcc6029ac4227a1467853ba781"
checksum = "4b26db9a2991a51e1e805820c2cabfc974f625ad6457be8a3eaba4c78361484e"
[[package]]
name = "typenum"

@ -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.21.0"
version = "0.20.0"
authors = ["Chip Senkbeil <chip@senkbeil.org>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
@ -13,13 +13,12 @@ license = "MIT OR Apache-2.0"
[workspace]
members = [
"distant-auth",
"distant-core",
"distant-core-auth",
"distant-core-net",
"distant-core-plugin",
"distant-core-protocol",
"distant-plugin-local",
"distant-plugin-ssh",
"distant-local",
"distant-net",
"distant-protocol",
"distant-ssh2",
]
[profile.release]
@ -30,8 +29,8 @@ strip = true
[features]
default = ["vendored-openssl"]
openssl = ["distant-plugin-ssh/openssl"]
vendored-openssl = ["distant-plugin-ssh/vendored-openssl"]
openssl = ["distant-ssh2/openssl"]
vendored-openssl = ["distant-ssh2/vendored-openssl"]
[dependencies]
anyhow = "1.0.71"
@ -41,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.21.0", path = "distant-core" }
distant-plugin-local = { version = "=0.21.0", path = "distant-plugin-local" }
distant-core = { version = "=0.20.0", path = "distant-core" }
distant-local = { version = "=0.20.0", path = "distant-local" }
directories = "5.0.1"
file-mode = "0.1.2"
flexi_logger = "0.25.5"
@ -60,13 +59,13 @@ tokio = { version = "1.28.2", features = ["full"] }
toml_edit = { version = "0.19.10", features = ["serde"] }
terminal_size = "0.2.6"
termwiz = "0.20.0"
typed-path = "0.6.0"
typed-path = "0.3.2"
which = "4.4.0"
winsplit = "0.1.0"
whoami = "1.4.0"
# Optional native SSH functionality
distant-plugin-ssh = { version = "=0.21.0", path = "distant-plugin-ssh", optional = true }
distant-ssh2 = { version = "=0.20.0", path = "distant-ssh2", optional = true }
[target.'cfg(unix)'.dependencies]
fork = "0.1.21"

@ -1,9 +1,9 @@
[package]
name = "distant-core-auth"
description = "Core authentication library for distant, providing various implementations"
name = "distant-auth"
description = "Authentication library for distant, providing various implementations"
categories = ["authentication"]
keywords = ["auth", "authentication", "async"]
version = "0.21.0"
version = "0.20.0"
authors = ["Chip Senkbeil <chip@senkbeil.org>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"

@ -1,18 +0,0 @@
[package]
name = "distant-core-plugin"
description = "Core plugin library for distant that provides everything needed to build a plugin"
categories = []
keywords = []
version = "0.21.0"
authors = ["Chip Senkbeil <chip@senkbeil.org>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
repository = "https://github.com/chipsenkbeil/distant"
readme = "README.md"
license = "MIT OR Apache-2.0"
[dependencies]
async-trait = "0.1.68"
distant-core-auth = { version = "=0.21.0", path = "../distant-core-auth" }
distant-core-protocol = { version = "=0.21.0", path = "../distant-core-protocol" }
serde = { version = "1.0.163", features = ["derive"] }

@ -1,35 +0,0 @@
# distant auth
[![Crates.io][distant_crates_img]][distant_crates_lnk] [![Docs.rs][distant_doc_img]][distant_doc_lnk] [![Rustc 1.70.0][distant_rustc_img]][distant_rustc_lnk]
[distant_crates_img]: https://img.shields.io/crates/v/distant-auth.svg
[distant_crates_lnk]: https://crates.io/crates/distant-auth
[distant_doc_img]: https://docs.rs/distant-auth/badge.svg
[distant_doc_lnk]: https://docs.rs/distant-auth
[distant_rustc_img]: https://img.shields.io/badge/distant_auth-rustc_1.70+-lightgray.svg
[distant_rustc_lnk]: https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html
## Details
The `distant-auth` library supplies the authentication functionality for the
distant interfaces and distant cli.
## Installation
You can import the dependency by adding the following to your `Cargo.toml`:
```toml
[dependencies]
distant-auth = "0.20"
```
## License
This project is licensed under either of
Apache License, Version 2.0, (LICENSE-APACHE or
[apache-license][apache-license]) MIT license (LICENSE-MIT or
[mit-license][mit-license]) at your option.
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
[mit-license]: http://opensource.org/licenses/MIT

@ -1,29 +0,0 @@
/// Full API that represents a distant-compatible server.
pub trait Api {
type FileSystem: FileSystemApi;
type Process: ProcessApi;
type Search: SearchApi;
type SystemInfo: SystemInfoApi;
type Version: VersionApi;
}
/// API supporting filesystem operations.
pub trait FileSystemApi {}
/// API supporting process creation and manipulation.
pub trait ProcessApi {}
/// API supporting searching through the remote system.
pub trait SearchApi {}
/// API supporting retrieval of information about the remote system.
pub trait SystemInfoApi {}
/// API supporting retrieval of the server's version.
pub trait VersionApi {}
/// Generic struct that implements all APIs as unsupported.
pub struct Unsupported;
impl FileSystemApi for Unsupported {
}

@ -1,6 +0,0 @@
mod destination;
mod map;
mod utils;
pub use destination::{Destination, Host, HostParseError};
pub use map::{Map, MapParseError};

@ -1,46 +0,0 @@
use std::fmt;
use std::marker::PhantomData;
use std::str::FromStr;
use serde::de::{Deserializer, Error as SerdeError, Visitor};
use serde::ser::Serializer;
/// From https://docs.rs/serde_with/1.14.0/src/serde_with/rust.rs.html#90-118
pub fn deserialize_from_str<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: FromStr,
T::Err: fmt::Display,
{
struct Helper<S>(PhantomData<S>);
impl<'de, S> Visitor<'de> for Helper<S>
where
S: FromStr,
<S as FromStr>::Err: fmt::Display,
{
type Value = S;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "a string")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: SerdeError,
{
value.parse::<Self::Value>().map_err(SerdeError::custom)
}
}
deserializer.deserialize_str(Helper(PhantomData))
}
/// From https://docs.rs/serde_with/1.14.0/src/serde_with/rust.rs.html#121-127
pub fn serialize_to_str<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: fmt::Display,
S: Serializer,
{
serializer.collect_str(&value)
}

@ -1,312 +0,0 @@
use std::future::Future;
use std::io;
use async_trait::async_trait;
use distant_core_auth::Authenticator;
use crate::common::{Destination, Map};
/// Boxed [`LaunchHandler`].
pub type BoxedLaunchHandler = Box<dyn LaunchHandler>;
/// Boxed [`ConnectHandler`].
pub type BoxedConnectHandler = Box<dyn ConnectHandler>;
/// Interface for a handler to launch a server, returning the destination to the server.
#[async_trait]
pub trait LaunchHandler: Send + Sync {
/// Launches a server using the target `destination`. If the destination is unsupported, this
/// method will return an error.
///
/// * Takes `options` as additional parameters custom to the destination.
/// * Takes `authenticator` to handle any authentication needs.
async fn launch(
&self,
destination: &Destination,
options: &Map,
authenticator: &mut dyn Authenticator,
) -> io::Result<Destination>;
}
#[async_trait]
impl<F, R> LaunchHandler for F
where
F: Fn(&Destination, &Map, &mut dyn Authenticator) -> R + Send + Sync + 'static,
R: Future<Output = io::Result<Destination>> + Send + 'static,
{
async fn launch(
&self,
destination: &Destination,
options: &Map,
authenticator: &mut dyn Authenticator,
) -> io::Result<Destination> {
self(destination, options, authenticator).await
}
}
/// Generates a new [`LaunchHandler`] for the provided anonymous function.
///
/// ### Examples
///
/// ```
/// use distant_core_plugin::boxed_launch_handler;
///
/// let _handler = boxed_launch_handler!(|destination, options, authenticator| {
/// todo!("Implement handler logic.");
/// });
///
/// let _handler = boxed_launch_handler!(|destination, options, authenticator| async {
/// todo!("We support async within as well regardless of the keyword!");
/// });
///
/// let _handler = boxed_launch_handler!(move |destination, options, authenticator| {
/// todo!("You can also explicitly mark to move into the closure");
/// });
/// ```
#[macro_export]
macro_rules! boxed_launch_handler {
(|$destination:ident, $options:ident, $authenticator:ident| $(async)? $body:block) => {{
let x: $crate::handlers::BoxedLaunchHandler = Box::new(
|$destination: &$crate::common::Destination,
$options: &$crate::common::Map,
$authenticator: &mut dyn $crate::auth::Authenticator| async { $body },
);
x
}};
(move |$destination:ident, $options:ident, $authenticator:ident| $(async)? $body:block) => {{
let x: $crate::handlers::BoxedLaunchHandler = Box::new(
move |$destination: &$crate::common::Destination,
$options: &$crate::common::Map,
$authenticator: &mut dyn $crate::auth::Authenticator| async move { $body },
);
x
}};
}
/// Interface for a handler to connect to a server, returning a boxed client to the server.
#[async_trait]
pub trait ConnectHandler: Send + Sync {
/// Connects to a server at the specified `destination`. If the destination is unsupported,
/// this method will return an error.
///
/// * Takes `options` as additional parameters custom to the destination.
/// * Takes `authenticator` to handle any authentication needs.
async fn connect(
&self,
destination: &Destination,
options: &Map,
authenticator: &mut dyn Authenticator,
) -> io::Result<UntypedClient>;
}
#[async_trait]
impl<F, R> ConnectHandler for F
where
F: Fn(&Destination, &Map, &mut dyn Authenticator) -> R + Send + Sync + 'static,
R: Future<Output = io::Result<UntypedClient>> + Send + 'static,
{
async fn connect(
&self,
destination: &Destination,
options: &Map,
authenticator: &mut dyn Authenticator,
) -> io::Result<UntypedClient> {
self(destination, options, authenticator).await
}
}
/// Generates a new [`ConnectHandler`] for the provided anonymous function.
///
/// ### Examples
///
/// ```
/// use distant_core_plugin::boxed_connect_handler;
///
/// let _handler = boxed_connect_handler!(|destination, options, authenticator| {
/// todo!("Implement handler logic.");
/// });
///
/// let _handler = boxed_connect_handler!(|destination, options, authenticator| async {
/// todo!("We support async within as well regardless of the keyword!");
/// });
///
/// let _handler = boxed_connect_handler!(move |destination, options, authenticator| {
/// todo!("You can also explicitly mark to move into the closure");
/// });
/// ```
#[macro_export]
macro_rules! boxed_connect_handler {
(|$destination:ident, $options:ident, $authenticator:ident| $(async)? $body:block) => {{
let x: $crate::handlers::BoxedConnectHandler = Box::new(
|$destination: &$crate::common::Destination,
$options: &$crate::common::Map,
$authenticator: &mut dyn $crate::auth::Authenticator| async { $body },
);
x
}};
(move |$destination:ident, $options:ident, $authenticator:ident| $(async)? $body:block) => {{
let x: $crate::handlers::BoxedConnectHandler = Box::new(
move |$destination: &$crate::common::Destination,
$options: &$crate::common::Map,
$authenticator: &mut dyn $crate::auth::Authenticator| async move { $body },
);
x
}};
}
#[cfg(test)]
mod tests {
use test_log::test;
use super::*;
use crate::common::FramedTransport;
#[inline]
fn test_destination() -> Destination {
"scheme://host:1234".parse().unwrap()
}
#[inline]
fn test_options() -> Map {
Map::default()
}
#[inline]
fn test_authenticator() -> impl Authenticator {
FramedTransport::pair(1).0
}
#[test(tokio::test)]
async fn boxed_launch_handler_should_generate_valid_boxed_launch_handler() {
let handler = boxed_launch_handler!(|_destination, _options, _authenticator| {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.launch(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
let handler = boxed_launch_handler!(|_destination, _options, _authenticator| async {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.launch(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
let handler = boxed_launch_handler!(move |_destination, _options, _authenticator| {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.launch(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
let handler = boxed_launch_handler!(move |_destination, _options, _authenticator| async {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.launch(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
}
#[test(tokio::test)]
async fn boxed_connect_handler_should_generate_valid_boxed_connect_handler() {
let handler = boxed_connect_handler!(|_destination, _options, _authenticator| {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.connect(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
let handler = boxed_connect_handler!(|_destination, _options, _authenticator| async {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.connect(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
let handler = boxed_connect_handler!(move |_destination, _options, _authenticator| {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.connect(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
let handler = boxed_connect_handler!(move |_destination, _options, _authenticator| async {
Err(io::Error::from(io::ErrorKind::Other))
});
assert_eq!(
handler
.connect(
&test_destination(),
&test_options(),
&mut test_authenticator()
)
.await
.unwrap_err()
.kind(),
io::ErrorKind::Other
);
}
}

@ -1,12 +0,0 @@
#![doc = include_str!("../README.md")]
#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;
pub mod api;
pub mod common;
pub mod handlers;
pub use distant_core_auth as auth;
pub use distant_core_protocol as protocol;

@ -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.21.0"
version = "0.20.0"
authors = ["Chip Senkbeil <chip@senkbeil.org>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
@ -16,9 +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-core-net = { version = "=0.21.0", path = "../distant-core-net" }
distant-core-plugin = { version = "=0.21.0", path = "../distant-core-plugin" }
distant-core-protocol = { version = "=0.21.0", path = "../distant-core-protocol" }
distant-net = { version = "=0.20.0", path = "../distant-net" }
distant-protocol = { version = "=0.20.0", path = "../distant-protocol" }
futures = "0.3.28"
hex = "0.4.3"
log = "0.4.18"

@ -3,8 +3,8 @@ use std::path::PathBuf;
use std::sync::Arc;
use async_trait::async_trait;
use distant_core_net::common::ConnectionId;
use distant_core_net::server::{Reply, RequestCtx, ServerHandler};
use distant_net::common::ConnectionId;
use distant_net::server::{Reply, RequestCtx, ServerHandler};
use log::*;
use crate::protocol::{

@ -1,6 +1,6 @@
use std::io;
use distant_core_net::server::Reply;
use distant_net::server::Reply;
use crate::protocol;

@ -1,5 +1,5 @@
use distant_core_net::client::Channel;
use distant_core_net::Client;
use distant_net::client::Channel;
use distant_net::Client;
use crate::protocol;

@ -3,8 +3,8 @@ use std::io;
use std::path::PathBuf;
use std::pin::Pin;
use distant_core_net::client::Channel;
use distant_core_net::common::Request;
use distant_net::client::Channel;
use distant_net::common::Request;
use crate::client::{
RemoteCommand, RemoteLspCommand, RemoteLspProcess, RemoteOutput, RemoteProcess, Searcher,

@ -432,8 +432,8 @@ mod tests {
use std::future::Future;
use std::time::Duration;
use distant_core_net::common::{FramedTransport, InmemoryTransport, Request, Response};
use distant_core_net::Client;
use distant_net::common::{FramedTransport, InmemoryTransport, Request, Response};
use distant_net::Client;
use test_log::test;
use super::*;

@ -1,8 +1,8 @@
use std::path::PathBuf;
use std::sync::Arc;
use distant_core_net::client::Mailbox;
use distant_core_net::common::{Request, Response};
use distant_net::client::Mailbox;
use distant_net::common::{Request, Response};
use log::*;
use tokio::io;
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
@ -590,8 +590,8 @@ mod errors {
mod tests {
use std::time::Duration;
use distant_core_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_core_net::Client;
use distant_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_net::Client;
use test_log::test;
use super::*;

@ -1,6 +1,6 @@
use std::{fmt, io};
use distant_core_net::common::Request;
use distant_net::common::Request;
use log::*;
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
@ -193,8 +193,8 @@ mod tests {
use std::path::PathBuf;
use std::sync::Arc;
use distant_core_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_core_net::Client;
use distant_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_net::Client;
use test_log::test;
use tokio::sync::Mutex;

@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use std::{fmt, io};
use distant_core_net::common::Request;
use distant_net::common::Request;
use log::*;
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
@ -181,8 +181,8 @@ impl Watcher {
mod tests {
use std::sync::Arc;
use distant_core_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_core_net::Client;
use distant_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_net::Client;
use test_log::test;
use tokio::sync::Mutex;

@ -2,7 +2,7 @@ use std::convert::TryFrom;
use std::str::FromStr;
use std::{fmt, io};
use distant_core_net::common::{Destination, Host, SecretKey32};
use distant_net::common::{Destination, Host, SecretKey32};
use serde::de::Deserializer;
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};

@ -5,11 +5,11 @@ use async_trait::async_trait;
use distant_core::{
DistantApi, DistantApiServerHandler, DistantChannelExt, DistantClient, DistantCtx,
};
use distant_core_net::auth::{DummyAuthHandler, Verifier};
use distant_core_net::client::Client;
use distant_core_net::common::{InmemoryTransport, OneshotListener, Version};
use distant_core_net::server::{Server, ServerRef};
use distant_core_protocol::PROTOCOL_VERSION;
use distant_net::auth::{DummyAuthHandler, Verifier};
use distant_net::client::Client;
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) {
@ -85,8 +85,8 @@ mod single {
mod batch_parallel {
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use distant_core_net::common::Request;
use distant_core_protocol::{Msg, Request as RequestPayload};
use distant_net::common::Request;
use distant_protocol::{Msg, Request as RequestPayload};
use test_log::test;
use super::*;
@ -128,7 +128,7 @@ mod batch_parallel {
let mut times = Vec::new();
for payload in payloads {
match payload {
distant_core_protocol::Response::Blob { data } => {
distant_protocol::Response::Blob { data } => {
let mut buf = [0u8; 8];
buf.copy_from_slice(&data[..8]);
times.push(u64::from_be_bytes(buf));
@ -177,21 +177,21 @@ mod batch_parallel {
// Should be a success, error, and success
assert!(
matches!(payloads[0], distant_core_protocol::Response::Blob { .. }),
matches!(payloads[0], distant_protocol::Response::Blob { .. }),
"Unexpected payloads[0]: {:?}",
payloads[0]
);
assert!(
matches!(
&payloads[1],
distant_core_protocol::Response::Error(distant_core_protocol::Error { kind, description })
if matches!(kind, distant_core_protocol::ErrorKind::Other) && description == "test error"
distant_protocol::Response::Error(distant_protocol::Error { kind, description })
if matches!(kind, distant_protocol::ErrorKind::Other) && description == "test error"
),
"Unexpected payloads[1]: {:?}",
payloads[1]
);
assert!(
matches!(payloads[2], distant_core_protocol::Response::Blob { .. }),
matches!(payloads[2], distant_protocol::Response::Blob { .. }),
"Unexpected payloads[2]: {:?}",
payloads[2]
);
@ -201,8 +201,8 @@ mod batch_parallel {
mod batch_sequence {
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use distant_core_net::common::Request;
use distant_core_protocol::{Msg, Request as RequestPayload};
use distant_net::common::Request;
use distant_protocol::{Msg, Request as RequestPayload};
use test_log::test;
use super::*;
@ -247,7 +247,7 @@ mod batch_sequence {
let mut times = Vec::new();
for payload in payloads {
match payload {
distant_core_protocol::Response::Blob { data } => {
distant_protocol::Response::Blob { data } => {
let mut buf = [0u8; 8];
buf.copy_from_slice(&data[..8]);
times.push(u64::from_be_bytes(buf));
@ -299,15 +299,15 @@ mod batch_sequence {
// Should be a success, error, and interrupt
assert!(
matches!(payloads[0], distant_core_protocol::Response::Blob { .. }),
matches!(payloads[0], distant_protocol::Response::Blob { .. }),
"Unexpected payloads[0]: {:?}",
payloads[0]
);
assert!(
matches!(
&payloads[1],
distant_core_protocol::Response::Error(distant_core_protocol::Error { kind, description })
if matches!(kind, distant_core_protocol::ErrorKind::Other) && description == "test error"
distant_protocol::Response::Error(distant_protocol::Error { kind, description })
if matches!(kind, distant_protocol::ErrorKind::Other) && description == "test error"
),
"Unexpected payloads[1]: {:?}",
payloads[1]
@ -315,8 +315,8 @@ mod batch_sequence {
assert!(
matches!(
&payloads[2],
distant_core_protocol::Response::Error(distant_core_protocol::Error { kind, .. })
if matches!(kind, distant_core_protocol::ErrorKind::Interrupted)
distant_protocol::Response::Error(distant_protocol::Error { kind, .. })
if matches!(kind, distant_protocol::ErrorKind::Interrupted)
),
"Unexpected payloads[2]: {:?}",
payloads[2]

@ -1,8 +1,8 @@
[package]
name = "distant-plugin-local"
description = "Plugin library implementing distant API for local interactions"
name = "distant-local"
description = "Library implementing distant API for local interactions"
categories = ["network-programming"]
version = "0.21.0"
version = "0.20.0"
authors = ["Chip Senkbeil <chip@senkbeil.org>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
@ -21,7 +21,7 @@ macos-kqueue = ["notify/macos_kqueue"]
[dependencies]
async-trait = "0.1.68"
distant-core = { version = "=0.21.0", path = "../distant-core" }
distant-core = { version = "=0.20.0", path = "../distant-core" }
grep = "0.2.12"
ignore = "0.4.20"
log = "0.4.18"

@ -6,7 +6,7 @@ use distant_core::net::client::{Client, TcpConnector};
use distant_core::net::common::PortRange;
use distant_core::net::server::Server;
use distant_core::{DistantApiServerHandler, DistantClient};
use distant_plugin_local::Api;
use distant_local::Api;
use rstest::*;
use tokio::sync::mpsc;

@ -1,9 +1,9 @@
[package]
name = "distant-core-net"
description = "Core network library for distant, providing implementations to support client/server architecture"
name = "distant-net"
description = "Network library for distant, providing implementations to support client/server architecture"
categories = ["network-programming"]
keywords = ["api", "async"]
version = "0.21.0"
version = "0.20.0"
authors = ["Chip Senkbeil <chip@senkbeil.org>"]
edition = "2021"
homepage = "https://github.com/chipsenkbeil/distant"
@ -17,7 +17,7 @@ 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-core-auth = { version = "=0.21.0", path = "../distant-core-auth" }
distant-auth = { version = "=0.20.0", path = "../distant-auth" }
dyn-clone = "1.0.11"
flate2 = "1.0.26"
hex = "0.4.3"
@ -37,7 +37,7 @@ strum = { version = "0.24.1", features = ["derive"] }
tokio = { version = "1.28.2", features = ["full"] }
[dev-dependencies]
distant-core-auth = { version = "=0.21.0", path = "../distant-core-auth", features = ["tests"] }
distant-auth = { version = "=0.20.0", path = "../distant-auth", features = ["tests"] }
env_logger = "0.10.0"
serde_json = "1.0.96"
tempfile = "3.5.0"

@ -1,8 +1,8 @@
use std::io;
use async_trait::async_trait;
use distant_core_auth::msg::*;
use distant_core_auth::{AuthHandler, Authenticate, Authenticator};
use distant_auth::msg::*;
use distant_auth::{AuthHandler, Authenticate, Authenticator};
use log::*;
use crate::common::{utils, FramedTransport, Transport};
@ -165,7 +165,7 @@ where
#[cfg(test)]
mod tests {
use distant_core_auth::tests::TestAuthHandler;
use distant_auth::tests::TestAuthHandler;
use test_log::test;
use tokio::sync::mpsc;

@ -14,7 +14,7 @@ use std::time::Duration;
use std::{convert, io};
use async_trait::async_trait;
use distant_core_auth::AuthHandler;
use distant_auth::AuthHandler;
#[cfg(windows)]
pub use windows::*;

@ -2,7 +2,7 @@ use std::io;
use std::ops::{Deref, DerefMut};
use async_trait::async_trait;
use distant_core_auth::{AuthHandler, Authenticate, Verifier};
use distant_auth::{AuthHandler, Authenticate, Verifier};
use log::*;
use serde::{Deserialize, Serialize};
use tokio::sync::oneshot;
@ -506,8 +506,8 @@ impl<T: Transport> Connection<T> {
mod tests {
use std::sync::Arc;
use distant_core_auth::msg::Challenge;
use distant_core_auth::{Authenticator, DummyAuthHandler};
use distant_auth::msg::Challenge;
use distant_auth::{Authenticator, DummyAuthHandler};
use test_log::test;
use super::*;

@ -2,6 +2,7 @@ use std::fmt;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::str::FromStr;
use derive_more::{Display, Error, From};
use serde::de::Deserializer;
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
@ -9,7 +10,7 @@ use serde::{Deserialize, Serialize};
use super::{deserialize_from_str, serialize_to_str};
/// Represents the host of a destination
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, From, Display, Hash, PartialEq, Eq)]
pub enum Host {
Ipv4(Ipv4Addr),
Ipv6(Ipv6Addr),
@ -68,41 +69,7 @@ impl From<IpAddr> for Host {
}
}
impl From<Ipv4Addr> for Host {
fn from(addr: Ipv4Addr) -> Self {
Self::Ipv4(addr)
}
}
impl From<Ipv6Addr> for Host {
fn from(addr: Ipv6Addr) -> Self {
Self::Ipv6(addr)
}
}
impl<'a> From<&'a str> for Host {
fn from(name: &'a str) -> Self {
Self::Name(name.to_string())
}
}
impl From<String> for Host {
fn from(name: String) -> Self {
Self::Name(name)
}
}
impl fmt::Display for Host {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Ipv4(addr) => write!(f, "{addr}"),
Self::Ipv6(addr) => write!(f, "{addr}"),
Self::Name(name) => write!(f, "{name}"),
}
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, Error, Hash, PartialEq, Eq)]
pub enum HostParseError {
EmptyLabel,
EndsWithHyphen,
@ -136,8 +103,6 @@ impl fmt::Display for HostParseError {
}
}
impl std::error::Error for HostParseError {}
impl FromStr for Host {
type Err = HostParseError;
@ -146,7 +111,7 @@ impl FromStr for Host {
/// ### Examples
///
/// ```
/// # use distant_core_net::common::Host;
/// # use distant_net::common::Host;
/// # use std::net::{Ipv4Addr, Ipv6Addr};
/// // IPv4 address
/// assert_eq!("127.0.0.1".parse(), Ok(Host::Ipv4(Ipv4Addr::new(127, 0, 0, 1))));

@ -1,9 +1,10 @@
use std::collections::hash_map::{Entry, IntoIter, Iter, IterMut};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fmt;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use derive_more::{Display, Error, From, IntoIterator};
use serde::de::Deserializer;
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
@ -11,7 +12,7 @@ use serde::{Deserialize, Serialize};
use crate::common::utils::{deserialize_from_str, serialize_to_str};
/// Contains map information for connections and other use cases
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, From, IntoIterator, PartialEq, Eq)]
pub struct Map(HashMap<String, String>);
impl Map {
@ -33,7 +34,7 @@ impl Map {
/// Keeping the value will result in `x` retaining the `a` key's original value:
///
/// ```rust
/// use distant_core_net::map;
/// use distant_net::map;
///
/// let mut x = map!("a" -> "hello", "b" -> "world");
/// let y = map!("a" -> "foo", "c" -> "bar");
@ -46,7 +47,7 @@ impl Map {
/// Not keeping the value will result in `x` replacing the `a` key's value:
///
/// ```rust
/// use distant_core_net::map;
/// use distant_net::map;
///
/// let mut x = map!("a" -> "hello", "b" -> "world");
/// let y = map!("a" -> "foo", "c" -> "bar");
@ -111,64 +112,18 @@ impl fmt::Display for Map {
}
}
impl From<HashMap<String, String>> for Map {
fn from(map: HashMap<String, String>) -> Self {
Self(map)
}
}
impl<'a> IntoIterator for &'a Map {
type Item = (&'a String, &'a String);
type IntoIter = Iter<'a, String, String>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<'a> IntoIterator for &'a mut Map {
type Item = (&'a String, &'a mut String);
type IntoIter = IterMut<'a, String, String>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
}
}
impl IntoIterator for Map {
type Item = (String, String);
type IntoIter = IntoIter<String, String>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Display, Error)]
pub enum MapParseError {
#[display(fmt = "Missing = after key ('{key}')")]
MissingEqualsAfterKey { key: String },
#[display(fmt = "Key ('{key}') must start with alphabetic character")]
KeyMustStartWithAlphabeticCharacter { key: String },
MissingClosingQuoteForValue,
}
impl fmt::Display for MapParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::MissingEqualsAfterKey { key } => {
write!(f, "Missing = after key ('{key}')")
}
Self::KeyMustStartWithAlphabeticCharacter { key } => {
write!(f, "Key ('{key}') must start with alphabetic character")
}
Self::MissingClosingQuoteForValue => {
write!(f, "Missing closing \" for value")
}
}
}
#[display(fmt = "Missing closing \" for value")]
MissingClosingQuoteForValue,
}
impl std::error::Error for MapParseError {}
impl FromStr for Map {
type Err = MapParseError;
@ -292,7 +247,7 @@ impl<'de> Deserialize<'de> for Map {
/// Generates a new [`Map`] of key/value pairs based on literals.
///
/// ```
/// use distant_core_net::map;
/// use distant_net::map;
///
/// let _map = map!("key" -> "value", "key2" -> "value2");
/// ```

@ -11,7 +11,7 @@ use crate::common::{utils, Value};
/// Generates a new [`Header`] of key/value pairs based on literals.
///
/// ```
/// use distant_core_net::header;
/// use distant_net::header;
///
/// let _header = header!("key" -> "value", "key2" -> 123);
/// ```

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save