Initial commit

pull/191/head
Chip Senkbeil 1 year ago
parent 40c265e35b
commit 505b3a83e8
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

28
Cargo.lock generated

@ -820,6 +820,7 @@ dependencies = [
"dialoguer",
"directories",
"distant-core",
"distant-local",
"distant-ssh2",
"env_logger",
"file-mode",
@ -901,6 +902,33 @@ dependencies = [
"winsplit",
]
[[package]]
name = "distant-local"
version = "0.20.0-alpha.7"
dependencies = [
"assert_fs",
"async-trait",
"distant-core",
"env_logger",
"grep",
"ignore",
"indoc",
"log",
"notify",
"num_cpus",
"once_cell",
"portable-pty 0.8.1",
"predicates",
"rand",
"rstest",
"shell-words",
"test-log",
"tokio",
"walkdir",
"whoami",
"winsplit",
]
[[package]]
name = "distant-net"
version = "0.20.0-alpha.7"

@ -12,7 +12,14 @@ readme = "README.md"
license = "MIT OR Apache-2.0"
[workspace]
members = ["distant-auth", "distant-core", "distant-net", "distant-protocol", "distant-ssh2"]
members = [
"distant-auth",
"distant-core",
"distant-local",
"distant-net",
"distant-protocol",
"distant-ssh2",
]
[profile.release]
opt-level = 'z'
@ -33,6 +40,7 @@ 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.3", default-features = false }
distant-core = { version = "=0.20.0-alpha.7", path = "distant-core" }
distant-local = { version = "=0.20.0-alpha.7", path = "distant-local" }
directories = "5.0.0"
file-mode = "0.1.2"
flexi_logger = "0.25.3"

@ -12,9 +12,6 @@ use crate::protocol::{
SearchId, SearchQuery, SetPermissionsOptions, SystemInfo, Version,
};
mod local;
pub use local::LocalDistantApi;
mod reply;
use reply::DistantSingleReply;
@ -42,15 +39,6 @@ where
}
}
impl DistantApiServerHandler<LocalDistantApi, <LocalDistantApi as DistantApi>::LocalData> {
/// Creates a new server using the [`LocalDistantApi`] implementation
pub fn local() -> io::Result<Self> {
Ok(Self {
api: LocalDistantApi::initialize()?,
})
}
}
#[inline]
fn unsupported<T>(label: &str) -> io::Result<T> {
Err(io::Error::new(

@ -1,5 +1,3 @@
use std::time::Duration;
/// Capacity associated stdin, stdout, and stderr pipes receiving data from remote server
pub const CLIENT_PIPE_CAPACITY: usize = 10000;
@ -8,16 +6,3 @@ pub const CLIENT_WATCHER_CAPACITY: usize = 100;
/// Capacity associated with a client searcher receiving matches
pub const CLIENT_SEARCHER_CAPACITY: usize = 10000;
/// Capacity associated with the server's file watcher to pass events outbound
pub const SERVER_WATCHER_CAPACITY: usize = 10000;
/// Represents the maximum size (in bytes) that data will be read from pipes
/// per individual `read` call
///
/// Current setting is 16k size
pub const MAX_PIPE_CHUNK_SIZE: usize = 16384;
/// Duration in milliseconds to sleep between reading stdout/stderr chunks
/// to avoid sending many small messages to clients
pub const READ_PAUSE_DURATION: Duration = Duration::from_millis(1);

@ -0,0 +1,36 @@
[package]
name = "distant-local"
description = "Library implementing distant API for local interactions"
categories = ["network-programming"]
version = "0.20.0-alpha.7"
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 = { version = "=0.20.0-alpha.7", path = "../distant-core" }
grep = "0.2.11"
ignore = "0.4.20"
log = "0.4.17"
notify = { version = "6.0.0", features = ["serde"] }
num_cpus = "1.15.0"
portable-pty = "0.8.1"
rand = { version = "0.8.5", features = ["getrandom"] }
shell-words = "1.1.0"
tokio = { version = "1.27.0", features = ["full"] }
walkdir = "2.3.3"
whoami = "1.4.0"
winsplit = "0.1.0"
[dev-dependencies]
assert_fs = "1.0.12"
env_logger = "0.10.0"
indoc = "2.0.1"
once_cell = "1.17.1"
predicates = "3.0.2"
rstest = "0.17.0"
test-log = "0.2.11"

@ -8,12 +8,12 @@ use log::*;
use tokio::io::AsyncWriteExt;
use walkdir::WalkDir;
use crate::protocol::{
use distant_core::protocol::{
Capabilities, ChangeKind, ChangeKindSet, DirEntry, Environment, FileType, Metadata,
Permissions, ProcessId, PtySize, SearchId, SearchQuery, SetPermissionsOptions, SystemInfo,
Version, PROTOCOL_VERSION,
};
use crate::{DistantApi, DistantCtx};
use distant_core::{DistantApi, DistantCtx};
mod process;
@ -23,7 +23,7 @@ use state::*;
/// Represents an implementation of [`DistantApi`] that works with the local machine
/// where the server using this api is running. In other words, this is a direct
/// impementation of the API instead of a proxy to another machine as seen with
/// implementations on top of SSH and other protocol
/// implementations on top of SSH and other protocol.
pub struct LocalDistantApi {
state: GlobalState,
}
@ -451,7 +451,7 @@ impl DistantApi for LocalDistantApi {
unix: Some({
use std::os::unix::prelude::*;
let mode = metadata.mode();
crate::protocol::UnixMetadata::from(mode)
distant_core::protocol::UnixMetadata::from(mode)
}),
#[cfg(not(unix))]
unix: None,
@ -460,7 +460,7 @@ impl DistantApi for LocalDistantApi {
windows: Some({
use std::os::windows::prelude::*;
let attributes = metadata.file_attributes();
crate::protocol::WindowsMetadata::from(attributes)
distant_core::protocol::WindowsMetadata::from(attributes)
}),
#[cfg(not(windows))]
windows: None,
@ -702,15 +702,15 @@ mod tests {
use std::time::Duration;
use assert_fs::prelude::*;
use distant_net::server::Reply;
use distant_core::net::server::Reply;
use once_cell::sync::Lazy;
use predicates::prelude::*;
use test_log::test;
use tokio::sync::mpsc;
use super::*;
use crate::api::ConnectionCtx;
use crate::protocol::Response;
use distant_core::net::server::ConnectionCtx;
use distant_core::protocol::Response;
static TEMP_SCRIPT_DIR: Lazy<assert_fs::TempDir> =
Lazy::new(|| assert_fs::TempDir::new().unwrap());

@ -4,7 +4,7 @@ use std::pin::Pin;
use tokio::io;
use tokio::sync::mpsc;
use crate::protocol::{ProcessId, PtySize};
use distant_core::protocol::{ProcessId, PtySize};
mod pty;
pub use pty::*;

@ -3,6 +3,7 @@ use std::io::{self, Read, Write};
use std::path::PathBuf;
use std::sync::{Arc, Mutex, Weak};
use distant_core::protocol::Environment;
use log::*;
use portable_pty::{CommandBuilder, MasterPty, PtySize as PortablePtySize};
use tokio::sync::mpsc;
@ -13,7 +14,6 @@ use super::{
ProcessPty, PtySize, WaitRx,
};
use crate::constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_DURATION};
use crate::protocol::Environment;
/// Represents a process that is associated with a pty
pub struct PtyProcess {

@ -12,7 +12,7 @@ use super::{
wait, ExitStatus, FutureReturn, InputChannel, NoProcessPty, OutputChannel, Process, ProcessId,
ProcessKiller, WaitRx,
};
use crate::protocol::Environment;
use distant_core::protocol::Environment;
mod tasks;

@ -3,12 +3,11 @@ use std::io;
use std::ops::Deref;
use std::path::PathBuf;
use distant_net::server::Reply;
use distant_core::net::server::Reply;
use distant_core::protocol::{Environment, ProcessId, PtySize, Response};
use tokio::sync::{mpsc, oneshot};
use tokio::task::JoinHandle;
use crate::protocol::{Environment, ProcessId, PtySize, Response};
mod instance;
pub use instance::*;

@ -2,14 +2,14 @@ use std::future::Future;
use std::io;
use std::path::PathBuf;
use distant_net::server::Reply;
use distant_core::net::server::Reply;
use distant_core::protocol::{Environment, ProcessId, PtySize, Response};
use log::*;
use tokio::task::JoinHandle;
use crate::api::local::process::{
use crate::api::process::{
InputChannel, OutputChannel, Process, ProcessKiller, ProcessPty, PtyProcess, SimpleProcess,
};
use crate::protocol::{Environment, ProcessId, PtySize, Response};
/// Holds information related to a spawned process on the server
pub struct ProcessInstance {

@ -3,7 +3,12 @@ use std::ops::Deref;
use std::path::Path;
use std::{cmp, io};
use distant_net::server::Reply;
use distant_core::net::server::Reply;
use distant_core::protocol::{
Response, SearchId, SearchQuery, SearchQueryContentsMatch, SearchQueryMatch,
SearchQueryMatchData, SearchQueryOptions, SearchQueryPathMatch, SearchQuerySubmatch,
SearchQueryTarget,
};
use grep::matcher::Matcher;
use grep::regex::{RegexMatcher, RegexMatcherBuilder};
use grep::searcher::{BinaryDetection, Searcher, SearcherBuilder, Sink, SinkMatch};
@ -13,12 +18,6 @@ use log::*;
use tokio::sync::{broadcast, mpsc, oneshot};
use tokio::task::JoinHandle;
use crate::protocol::{
Response, SearchId, SearchQuery, SearchQueryContentsMatch, SearchQueryMatch,
SearchQueryMatchData, SearchQueryOptions, SearchQueryPathMatch, SearchQuerySubmatch,
SearchQueryTarget,
};
const MAXIMUM_SEARCH_THREADS: usize = 12;
/// Holds information related to active searches on the server
@ -810,7 +809,7 @@ mod tests {
use test_log::test;
use super::*;
use crate::protocol::{FileType, SearchQueryCondition, SearchQueryMatchData};
use distant_core::protocol::{FileType, SearchQueryCondition, SearchQueryMatchData};
fn make_path(path: &str) -> PathBuf {
use std::path::MAIN_SEPARATOR;

@ -3,7 +3,8 @@ use std::io;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use distant_net::common::ConnectionId;
use distant_core::net::common::ConnectionId;
use distant_core::protocol::ChangeKind;
use log::*;
use notify::event::{AccessKind, AccessMode, ModifyKind};
use notify::{
@ -16,7 +17,6 @@ use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use crate::constants::SERVER_WATCHER_CAPACITY;
use crate::protocol::ChangeKind;
mod path;
pub use path::*;

@ -2,10 +2,9 @@ use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::{fmt, io};
use distant_net::common::ConnectionId;
use distant_net::server::Reply;
use crate::protocol::{Change, ChangeKind, ChangeKindSet, Error, Response};
use distant_core::net::common::ConnectionId;
use distant_core::net::server::Reply;
use distant_core::protocol::{Change, ChangeKind, ChangeKindSet, Error, Response};
/// Represents a path registered with a watcher that includes relevant state including
/// the ability to reply with

@ -0,0 +1,14 @@
use std::time::Duration;
/// Capacity associated with the server's file watcher to pass events outbound
pub const SERVER_WATCHER_CAPACITY: usize = 10000;
/// Represents the maximum size (in bytes) that data will be read from pipes
/// per individual `read` call
///
/// Current setting is 16k size
pub const MAX_PIPE_CHUNK_SIZE: usize = 16384;
/// Duration in milliseconds to sleep between reading stdout/stderr chunks
/// to avoid sending many small messages to clients
pub const READ_PAUSE_DURATION: Duration = Duration::from_millis(1);

@ -0,0 +1,17 @@
mod api;
mod constants;
pub use api::LocalDistantApi;
use distant_core::{DistantApi, DistantApiServerHandler};
/// Implementation of [`DistantApiServerHandler`] using [`LocalDistantApi`].
pub type LocalDistantApiServerHandler =
DistantApiServerHandler<LocalDistantApi, <LocalDistantApi as DistantApi>::LocalData>;
/// Initializes a new [`LocalDistantApiServerHandler`].
pub fn initialize_handler() -> std::io::Result<LocalDistantApiServerHandler> {
Ok(LocalDistantApiServerHandler::new(
LocalDistantApi::initialize()?,
))
}

@ -5,7 +5,8 @@ use distant_core::net::auth::{DummyAuthHandler, Verifier};
use distant_core::net::client::{Client, TcpConnector};
use distant_core::net::common::PortRange;
use distant_core::net::server::Server;
use distant_core::{DistantApiServerHandler, DistantClient, LocalDistantApi};
use distant_core::{DistantApiServerHandler, DistantClient};
use distant_local::LocalDistantApi;
use rstest::*;
use tokio::sync::mpsc;

@ -4,7 +4,7 @@ use anyhow::Context;
use distant_core::net::auth::Verifier;
use distant_core::net::common::{Host, SecretKey32};
use distant_core::net::server::{Server, ServerConfig as NetServerConfig, ServerRef};
use distant_core::{DistantApiServerHandler, DistantSingleKeyCredentials};
use distant_core::DistantSingleKeyCredentials;
use log::*;
use crate::options::ServerSubcommand;
@ -140,8 +140,8 @@ async fn async_run(cmd: ServerSubcommand, _is_forked: bool) -> CliResult {
"using an ephemeral port".to_string()
}
);
let handler =
DistantApiServerHandler::local().context("Failed to create local distant api")?;
let handler = distant_local::initialize_handler()
.context("Failed to create local distant api")?;
let server = Server::tcp()
.config(NetServerConfig {
shutdown: shutdown.into_inner(),

@ -3981,6 +3981,7 @@ mod tests {
ManagerServiceSubcommand::Install {
kind: None,
user: false,
args: Vec::new(),
},
)),
};
@ -4008,6 +4009,7 @@ mod tests {
ManagerServiceSubcommand::Install {
kind: None,
user: false,
args: Vec::new(),
},
)),
}
@ -4026,6 +4028,7 @@ mod tests {
ManagerServiceSubcommand::Install {
kind: None,
user: false,
args: Vec::new(),
},
)),
};
@ -4053,6 +4056,7 @@ mod tests {
ManagerServiceSubcommand::Install {
kind: None,
user: false,
args: Vec::new(),
},
)),
}

@ -8,7 +8,7 @@ use crate::cli::utils::TrimmedLinesMatchPredicate;
#[test_log::test]
fn should_output_capabilities(ctx: DistantManagerCtx) {
// Because all of our crates have the same version, we can expect it to match
let package_name = "distant-core";
let package_name = "distant-local";
let package_version = env!("CARGO_PKG_VERSION");
let (major, minor, patch) = PROTOCOL_VERSION;

Loading…
Cancel
Save