Refactor local crate & update/clean dependencies (#191)

pull/195/head
Chip Senkbeil 11 months ago committed by GitHub
parent 40c265e35b
commit e99329d9a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,18 +38,12 @@ jobs:
toolchain: stable
components: clippy
- uses: Swatinem/rust-cache@v2
with:
key: "ci-clippy-${{ matrix.os }}"
- name: Check Cargo availability
run: cargo --version
- name: distant-auth (all features)
run: cargo clippy -p distant-auth --all-targets --verbose --all-features
- name: distant-net (all features)
run: cargo clippy -p distant-net --all-targets --verbose --all-features
- name: distant-core (all features)
run: cargo clippy -p distant-core --all-targets --verbose --all-features
- name: distant-ssh2 (all features)
run: cargo clippy -p distant-ssh2 --all-targets --verbose --all-features
- name: distant (all features)
run: cargo clippy --all-targets --verbose --all-features
- name: Run clippy (all features)
run: cargo clippy --workspace --all-targets --verbose --all-features
rustfmt:
name: "Verify code formatting (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
@ -73,6 +67,8 @@ jobs:
toolchain: stable
components: rustfmt
- uses: Swatinem/rust-cache@v2
with:
key: "ci-rustfmt-${{ matrix.os }}"
- name: Check Cargo availability
run: cargo --version
- run: cargo fmt --all -- --check
@ -102,6 +98,8 @@ jobs:
with:
tool: cargo-nextest@0.9.45
- uses: Swatinem/rust-cache@v2
with:
key: "ci-tests-${{ matrix.os }}-${{ matrix.rust }}-${{ matrix.target }}"
- name: Check Cargo availability
run: cargo --version
- uses: nick-fields/retry@v2
@ -157,58 +155,13 @@ jobs:
New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType String -Force
}
- name: Extend Windows retry count to be more resilient
if: matrix.os == 'windows-latest'
run: echo "NEXTEST_RETRIES=9" >> $GITHUB_ENV
shell: bash
- name: Run auth tests (all features)
run: cargo nextest run --profile ci --release --all-features -p distant-auth
- name: Run net tests (default features)
run: cargo nextest run --profile ci --release -p distant-net
- name: Build core (default features)
run: cargo build --release -p distant-core
- name: Run core tests (all features)
run: cargo nextest run --profile ci --release --all-features -p distant-core
if: matrix.os == 'windows-latest'
- name: Ensure /run/sshd exists on Unix
run: mkdir -p /run/sshd
if: matrix.os == 'ubuntu-latest'
- name: Build ssh2 (default features)
run: cargo build --release -p distant-ssh2
- name: Run ssh2 client tests (all features)
run: cargo nextest run --profile ci --release --all-features -p distant-ssh2 ssh2::client
- name: Build CLI (no default features)
run: cargo build --release --no-default-features
- name: Build CLI (default features)
run: cargo build --release
- name: Run CLI tests (all features)
run: cargo nextest run --profile ci --release --all-features
ssh-launch-tests:
name: "Test ssh launch using Rust ${{ matrix.rust }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
env:
RUSTFLAGS: --cfg ci
RUST_LOG: trace
strategy:
fail-fast: false
matrix:
include:
- { rust: stable, os: macos-latest }
- { rust: stable, os: ubuntu-latest }
steps:
- uses: actions/checkout@v3
- name: Install Rust ${{ matrix.rust }}
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
- uses: taiki-e/install-action@v1
with:
tool: cargo-nextest@0.9.45
- uses: Swatinem/rust-cache@v2
- name: Check Cargo availability
run: cargo --version
- name: Install distant cli for use in launch tests
run: |
cargo install --path .
echo "DISTANT_PATH=$HOME/.cargo/bin/distant" >> $GITHUB_ENV
- name: Run ssh2 launch tests (all features)
run: cargo nextest run --profile ci --release --all-features -p distant-ssh2 ssh2::launched
- name: Run all workspace tests (all features)
run: cargo nextest run --profile ci --release --all-features --workspace
- name: Run all doc tests (all features)
run: cargo test --release --all-features --workspace --doc

@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Capabilities` message type has been changed to `Version` with new struct to
report the version information that includes a server version string,
protocol version tuple, and capabilities
- `distant_core::api::local` moved to `distant_local`
### Removed

159
Cargo.lock generated

@ -223,9 +223,9 @@ dependencies = [
[[package]]
name = "async-once-cell"
version = "0.4.4"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b49bd4c5b769125ea6323601c39815848972880efd33ffb2d01f9f909adc699"
checksum = "fddec5f567375e0a634f94bc8dab1059b9d59a8aba12134c32f5ee21ce3f5f89"
[[package]]
name = "async-process"
@ -474,9 +474,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.2.7"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938"
checksum = "93aae7a4192245f70fe75dd9157fc7b4a5bf53e88d30bd4396f7d8f9284d5acc"
dependencies = [
"clap_builder",
"clap_derive",
@ -485,9 +485,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.2.7"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd"
checksum = "4f423e341edefb78c9caba2d9c7f7687d0e72e89df3ce3394554754393ac3990"
dependencies = [
"anstream",
"anstyle",
@ -498,18 +498,18 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.2.3"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1594fe2312ec4abf402076e407628f5c313e54c32ade058521df4ee34ecac8a8"
checksum = "a04ddfaacc3bc9e6ea67d024575fafc2a813027cf374b8f24f7bc233c6b6be12"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "4.2.0"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4"
checksum = "191d9573962933b4027f932c600cd252ce27a8ad5979418fe78e43c07996f27b"
dependencies = [
"heck",
"proc-macro2",
@ -519,9 +519,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.4.1"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "colorchoice"
@ -820,6 +820,7 @@ dependencies = [
"dialoguer",
"directories",
"distant-core",
"distant-local",
"distant-ssh2",
"env_logger",
"file-mode",
@ -866,7 +867,6 @@ dependencies = [
name = "distant-core"
version = "0.20.0-alpha.7"
dependencies = [
"assert_fs",
"async-trait",
"bitflags 2.3.1",
"bytes",
@ -875,8 +875,29 @@ dependencies = [
"distant-protocol",
"env_logger",
"futures",
"grep",
"hex",
"log",
"num_cpus",
"once_cell",
"rand",
"regex",
"serde",
"serde_bytes",
"serde_json",
"strum",
"test-log",
"tokio",
]
[[package]]
name = "distant-local"
version = "0.20.0-alpha.7"
dependencies = [
"assert_fs",
"async-trait",
"distant-core",
"env_logger",
"grep",
"ignore",
"indoc",
"log",
@ -886,16 +907,10 @@ dependencies = [
"portable-pty 0.8.1",
"predicates",
"rand",
"regex",
"rstest",
"serde",
"serde_bytes",
"serde_json",
"shell-words",
"strum",
"test-log",
"tokio",
"tokio-util",
"walkdir",
"whoami",
"winsplit",
@ -1195,9 +1210,9 @@ dependencies = [
[[package]]
name = "flexi_logger"
version = "0.25.4"
version = "0.25.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "611de758a8869ffffa7524aafdb48658c64dae95cdce49654d68a8442e500d89"
checksum = "37e7b68b1f7ce9c62856598e99cd6742b9cedb6186b47aa989a82640f20bfa9b"
dependencies = [
"chrono",
"glob",
@ -1821,12 +1836,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.17"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de"
[[package]]
name = "memchr"
@ -1976,12 +1988,11 @@ dependencies = [
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
version = "0.47.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
checksum = "1df031e117bca634c262e9bd3173776844b6c17a90b3741c9163663b4385af76"
dependencies = [
"overload",
"winapi",
"windows-sys 0.45.0",
]
[[package]]
@ -2026,9 +2037,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.17.1"
version = "1.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
[[package]]
name = "opaque-debug"
@ -2074,12 +2085,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "p256"
version = "0.13.2"
@ -2094,9 +2099,9 @@ dependencies = [
[[package]]
name = "papergrid"
version = "0.7.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1526bb6aa9f10ec339fb10360f22c57edf81d5678d0278e93bc12a47ffbe4b01"
checksum = "1fdfe703c51ddc52887ad78fc69cd2ea78d895ffcd6e955c9d03566db8ab5bb1"
dependencies = [
"bytecount",
"fnv",
@ -2557,13 +2562,13 @@ dependencies = [
[[package]]
name = "regex"
version = "1.8.1"
version = "1.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370"
checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390"
dependencies = [
"aho-corasick 1.0.1",
"memchr",
"regex-syntax 0.7.1",
"regex-syntax 0.7.2",
]
[[package]]
@ -2580,9 +2585,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rfc6979"
@ -2793,9 +2798,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
checksum = "93107647184f6027e3b7dcb2e11034cf95ffa1e3a682c67951963ac69c1c007d"
dependencies = [
"serde",
]
@ -3061,9 +3066,9 @@ dependencies = [
[[package]]
name = "sysinfo"
version = "0.28.4"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4c2f3ca6693feb29a89724516f016488e9aafc7f37264f898593ee4b942f31b"
checksum = "02f1dc6930a439cc5d154221b5387d153f8183529b07c19aca24ea31e0a167e1"
dependencies = [
"cfg-if",
"core-foundation-sys",
@ -3076,9 +3081,9 @@ dependencies = [
[[package]]
name = "tabled"
version = "0.10.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c3ee73732ffceaea7b8f6b719ce3bb17f253fa27461ffeaf568ebd0cdb4b85"
checksum = "da1a2e56bbf7bfdd08aaa7592157a742205459eff774b73bc01809ae2d99dc2a"
dependencies = [
"papergrid",
"tabled_derive",
@ -3087,9 +3092,9 @@ dependencies = [
[[package]]
name = "tabled_derive"
version = "0.5.0"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "beca1b4eaceb4f2755df858b88d9b9315b7ccfd1ffd0d7a48a52602301f01a57"
checksum = "99f688a08b54f4f02f0a3c382aefdb7884d3d69609f785bd253dc033243e3fe4"
dependencies = [
"heck",
"proc-macro-error",
@ -3251,9 +3256,9 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.28.1"
version = "1.28.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105"
checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2"
dependencies = [
"autocfg",
"bytes",
@ -3279,20 +3284,6 @@ dependencies = [
"syn 2.0.16",
]
[[package]]
name = "tokio-util"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]]
name = "toml"
version = "0.5.11"
@ -3304,18 +3295,18 @@ dependencies = [
[[package]]
name = "toml_datetime"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.19.8"
version = "0.19.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739"
dependencies = [
"indexmap",
"serde",
@ -3324,26 +3315,6 @@ dependencies = [
"winnow",
]
[[package]]
name = "tracing"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"
dependencies = [
"once_cell",
]
[[package]]
name = "typed-path"
version = "0.3.2"

@ -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'
@ -25,30 +32,31 @@ libssh = ["distant-ssh2/libssh"]
ssh2 = ["distant-ssh2/ssh2"]
[dependencies]
anyhow = "1.0.70"
anyhow = "1.0.71"
async-trait = "0.1.68"
clap = { version = "4.2.1", features = ["derive"] }
clap_complete = "4.2.0"
clap = { version = "4.3.0", features = ["derive"] }
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.3", default-features = false }
dialoguer = { version = "0.10.4", default-features = false }
distant-core = { version = "=0.20.0-alpha.7", path = "distant-core" }
directories = "5.0.0"
distant-local = { version = "=0.20.0-alpha.7", path = "distant-local" }
directories = "5.0.1"
file-mode = "0.1.2"
flexi_logger = "0.25.3"
flexi_logger = "0.25.5"
indoc = "2.0.1"
log = "0.4.17"
once_cell = "1.17.1"
log = "0.4.18"
once_cell = "1.17.2"
rand = { version = "0.8.5", features = ["getrandom"] }
rpassword = "7.2.0"
serde = { version = "1.0.159", features = ["derive"] }
serde_json = "1.0.95"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
shell-words = "1.1.0"
service-manager = { version = "0.2.0", features = ["clap", "serde"] }
tabled = "0.10.0"
tokio = { version = "1.27.0", features = ["full"] }
toml_edit = { version = "0.19.8", features = ["serde"] }
terminal_size = "0.2.5"
tabled = "0.12.0"
tokio = { version = "1.28.2", features = ["full"] }
toml_edit = { version = "0.19.10", features = ["serde"] }
terminal_size = "0.2.6"
termwiz = "0.20.0"
which = "4.4.0"
winsplit = "0.1.0"
@ -61,14 +69,14 @@ distant-ssh2 = { version = "=0.20.0-alpha.7", path = "distant-ssh2", default-fea
fork = "0.1.21"
[target.'cfg(windows)'.dependencies]
sysinfo = "0.28.4"
sysinfo = "0.29.0"
windows-service = "0.6.0"
[dev-dependencies]
assert_cmd = "2.0.10"
assert_fs = "1.0.12"
assert_cmd = "2.0.11"
assert_fs = "1.0.13"
env_logger = "0.10.0"
indoc = "2.0.1"
predicates = "3.0.2"
predicates = "3.0.3"
rstest = "0.17.0"
test-log = "0.2.11"

@ -18,10 +18,10 @@ tests = []
[dependencies]
async-trait = "0.1.68"
derive_more = { version = "0.99.17", default-features = false, features = ["display", "from", "error"] }
log = "0.4.17"
serde = { version = "1.0.159", features = ["derive"] }
log = "0.4.18"
serde = { version = "1.0.163", features = ["derive"] }
[dev-dependencies]
env_logger = "0.10.0"
test-log = "0.2.11"
tokio = { version = "1.27.0", features = ["full"] }
tokio = { version = "1.28.2", features = ["full"] }

@ -9,6 +9,5 @@ pub use methods::*;
#[cfg(any(test, feature = "tests"))]
pub mod tests {
pub use crate::TestAuthHandler;
pub use crate::TestAuthenticator;
pub use crate::{TestAuthHandler, TestAuthenticator};
}

@ -121,10 +121,10 @@ pub trait AuthenticationMethod: Send + Sync {
#[cfg(test)]
mod tests {
use std::sync::mpsc;
use test_log::test;
use super::*;
use crate::authenticator::TestAuthenticator;
struct SuccessAuthenticationMethod;

@ -13,37 +13,24 @@ license = "MIT OR Apache-2.0"
[dependencies]
async-trait = "0.1.68"
bitflags = "2.0.2"
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.7", path = "../distant-net" }
distant-protocol = { version = "=0.20.0-alpha.7", path = "../distant-protocol" }
futures = "0.3.28"
grep = "0.2.11"
hex = "0.4.3"
ignore = "0.4.20"
log = "0.4.17"
notify = { version = "6.0.0", features = ["serde"] }
log = "0.4.18"
num_cpus = "1.15.0"
once_cell = "1.17.1"
portable-pty = "0.8.1"
once_cell = "1.17.2"
rand = { version = "0.8.5", features = ["getrandom"] }
regex = "1.7.3"
serde = { version = "1.0.159", features = ["derive"] }
regex = "1.8.3"
serde = { version = "1.0.163", features = ["derive"] }
serde_bytes = "0.11.9"
serde_json = "1.0.95"
shell-words = "1.1.0"
serde_json = "1.0.96"
strum = { version = "0.24.1", features = ["derive"] }
tokio = { version = "1.27.0", features = ["full"] }
tokio-util = { version = "0.7.7", features = ["codec"] }
walkdir = "2.3.3"
whoami = "1.4.0"
winsplit = "0.1.0"
tokio = { version = "1.28.2", features = ["full"] }
[dev-dependencies]
assert_fs = "1.0.12"
env_logger = "0.10.0"
indoc = "2.0.1"
predicates = "3.0.2"
rstest = "0.17.0"
test-log = "0.2.11"

@ -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(

@ -5,9 +5,8 @@ use distant_net::client::Mailbox;
use distant_net::common::{Request, Response};
use log::*;
use tokio::io;
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
use tokio::sync::RwLock;
use tokio::sync::{mpsc, RwLock};
use tokio::task::JoinHandle;
use crate::client::DistantChannel;

@ -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);

@ -12,6 +12,5 @@ mod serde_str;
/// Network functionality.
pub use distant_net as net;
/// Protocol structures.
pub use distant_protocol as protocol;

@ -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.12"
ignore = "0.4.20"
log = "0.4.18"
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.28.2", features = ["full"] }
walkdir = "2.3.3"
whoami = "1.4.0"
winsplit = "0.1.0"
[dev-dependencies]
assert_fs = "1.0.13"
env_logger = "0.10.0"
indoc = "2.0.1"
once_cell = "1.17.2"
predicates = "3.0.3"
rstest = "0.17.0"
test-log = "0.2.11"

@ -3,17 +3,16 @@ use std::time::SystemTime;
use std::{env, io};
use async_trait::async_trait;
use ignore::{DirEntry as WalkDirEntry, WalkBuilder};
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};
use ignore::{DirEntry as WalkDirEntry, WalkBuilder};
use log::*;
use tokio::io::AsyncWriteExt;
use walkdir::WalkDir;
mod process;
@ -23,7 +22,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 +450,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 +459,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 +701,14 @@ mod tests {
use std::time::Duration;
use assert_fs::prelude::*;
use distant_net::server::Reply;
use distant_core::net::server::{ConnectionCtx, Reply};
use distant_core::protocol::Response;
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;
static TEMP_SCRIPT_DIR: Lazy<assert_fs::TempDir> =
Lazy::new(|| assert_fs::TempDir::new().unwrap());

@ -1,11 +1,10 @@
use std::future::Future;
use std::pin::Pin;
use distant_core::protocol::{ProcessId, PtySize};
use tokio::io;
use tokio::sync::mpsc;
use crate::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 {

@ -2,6 +2,7 @@ use std::ffi::OsStr;
use std::path::PathBuf;
use std::process::Stdio;
use distant_core::protocol::Environment;
use log::*;
use tokio::io;
use tokio::process::Command;
@ -12,7 +13,6 @@ use super::{
wait, ExitStatus, FutureReturn, InputChannel, NoProcessPty, OutputChannel, Process, ProcessId,
ProcessKiller, WaitRx,
};
use crate::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
@ -807,10 +806,10 @@ mod tests {
use std::path::PathBuf;
use assert_fs::prelude::*;
use distant_core::protocol::{FileType, SearchQueryCondition, SearchQueryMatchData};
use test_log::test;
use super::*;
use crate::protocol::{FileType, SearchQueryCondition, SearchQueryMatchData};
fn make_path(path: &str) -> PathBuf {
use std::path::MAIN_SEPARATOR;

@ -3,20 +3,19 @@ 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::{
Config as WatcherConfig, Error as WatcherError, ErrorKind as WatcherErrorKind,
Event as WatcherEvent, EventKind, PollWatcher, RecursiveMode, Watcher,
};
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::TrySendError;
use tokio::sync::oneshot;
use tokio::sync::{mpsc, 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,15 @@
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;

@ -18,23 +18,23 @@ chacha20poly1305 = "0.10.1"
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.7", path = "../distant-auth" }
dyn-clone = "1.0.11"
flate2 = "1.0.25"
flate2 = "1.0.26"
hex = "0.4.3"
hkdf = "0.12.3"
log = "0.4.17"
log = "0.4.18"
paste = "1.0.12"
p256 = { version = "0.13.0", features = ["ecdh", "pem"] }
p256 = { version = "0.13.2", features = ["ecdh", "pem"] }
rand = { version = "0.8.5", features = ["getrandom"] }
rmp-serde = "1.1.1"
sha2 = "0.10.6"
serde = { version = "1.0.159", features = ["derive"] }
serde = { version = "1.0.163", features = ["derive"] }
serde_bytes = "0.11.9"
strum = { version = "0.24.1", features = ["derive"] }
tokio = { version = "1.27.0", features = ["full"] }
tokio = { version = "1.28.2", features = ["full"] }
[dev-dependencies]
distant-auth = { version = "=0.20.0-alpha.7", path = "../distant-auth", features = ["tests"] }
env_logger = "0.10.0"
serde_json = "1.0.95"
serde_json = "1.0.96"
tempfile = "3.5.0"
test-log = "0.2.11"

@ -1,10 +1,11 @@
use crate::common::utils;
use crate::common::{FramedTransport, Transport};
use std::io;
use async_trait::async_trait;
use distant_auth::msg::*;
use distant_auth::{AuthHandler, Authenticate, Authenticator};
use log::*;
use std::io;
use crate::common::{utils, FramedTransport, Transport};
macro_rules! write_frame {
($transport:expr, $data:expr) => {{

@ -9,8 +9,7 @@ use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use super::{InmemoryTransport, Interest, Ready, Reconnectable, Transport};
use crate::common::utils;
use crate::common::SecretKey32;
use crate::common::{utils, SecretKey32};
mod backup;
mod codec;

@ -5,8 +5,7 @@ pub mod manager;
pub mod server;
pub use client::{Client, ReconnectStrategy};
pub use server::Server;
pub use {log, paste};
/// Authentication functionality tied to network operations.
pub use distant_auth as auth;
pub use server::Server;
pub use {log, paste};

@ -16,10 +16,10 @@ default = []
tests = []
[dependencies]
bitflags = "2.0.2"
bitflags = "2.3.1"
derive_more = { version = "0.99.17", default-features = false, features = ["deref", "deref_mut", "display", "from", "error", "into", "into_iterator", "is_variant"] }
regex = "1.7.3"
serde = { version = "1.0.159", features = ["derive"] }
regex = "1.8.3"
serde = { version = "1.0.163", features = ["derive"] }
serde_bytes = "0.11.9"
strum = { version = "0.24.1", features = ["derive"] }

@ -96,6 +96,7 @@ impl Permissions {
other_exec: None,
}
}
/// Creates a set of [`Permissions`] that indicate globally writable status.
///
/// ```

@ -612,9 +612,10 @@ mod tests {
}
mod changed {
use std::path::PathBuf;
use super::*;
use crate::common::ChangeKind;
use std::path::PathBuf;
#[test]
fn should_be_able_to_serialize_to_json() {
@ -742,9 +743,10 @@ mod tests {
}
mod metadata {
use std::path::PathBuf;
use super::*;
use crate::common::{FileType, UnixMetadata, WindowsMetadata};
use std::path::PathBuf;
#[test]
fn should_be_able_to_serialize_minimal_payload_to_json() {
@ -1219,9 +1221,10 @@ mod tests {
}
mod search_results {
use std::path::PathBuf;
use super::*;
use crate::common::{SearchQueryContentsMatch, SearchQueryMatch, SearchQuerySubmatch};
use std::path::PathBuf;
#[test]
fn should_be_able_to_serialize_to_json() {
@ -1768,9 +1771,10 @@ mod tests {
}
mod system_info {
use super::*;
use std::path::PathBuf;
use super::*;
#[test]
fn should_be_able_to_serialize_to_json() {
let payload = Response::SystemInfo(SystemInfo {

@ -17,33 +17,33 @@ ssh2 = ["wezterm-ssh/ssh2", "wezterm-ssh/vendored-openssl-ssh2"]
[dependencies]
async-compat = "0.2.1"
async-once-cell = "0.4.4"
async-once-cell = "0.5.2"
async-trait = "0.1.68"
derive_more = { version = "0.99.17", default-features = false, features = ["display", "error"] }
distant-core = { version = "=0.20.0-alpha.7", path = "../distant-core" }
futures = "0.3.28"
hex = "0.4.3"
log = "0.4.17"
log = "0.4.18"
rand = { version = "0.8.5", features = ["getrandom"] }
rpassword = "7.2.0"
shell-words = "1.1.0"
smol = "1.3.0"
tokio = { version = "1.27.0", features = ["full"] }
tokio = { version = "1.28.2", features = ["full"] }
typed-path = "0.3.2"
wezterm-ssh = { version = "0.4.0", default-features = false }
winsplit = "0.1.0"
# Optional serde support for data structures
serde = { version = "1.0.159", features = ["derive"], optional = true }
serde = { version = "1.0.163", features = ["derive"], optional = true }
[dev-dependencies]
anyhow = "1.0.70"
assert_fs = "1.0.12"
dunce = "1.0.3"
anyhow = "1.0.71"
assert_fs = "1.0.13"
dunce = "1.0.4"
env_logger = "0.10.0"
indoc = "2.0.1"
once_cell = "1.17.1"
predicates = "3.0.2"
once_cell = "1.17.2"
predicates = "3.0.3"
rstest = "0.17.0"
test-log = "0.2.11"
which = "4.4.0"

File diff suppressed because it is too large Load Diff

@ -1,3 +1,2 @@
mod client;
mod launched;
mod ssh;

@ -15,7 +15,7 @@ use assert_fs::TempDir;
use async_trait::async_trait;
use derive_more::{Deref, DerefMut, Display};
use distant_core::DistantClient;
use distant_ssh2::{DistantLaunchOpts, Ssh, SshAuthEvent, SshAuthHandler, SshOpts};
use distant_ssh2::{Ssh, SshAuthEvent, SshAuthHandler, SshOpts};
use log::*;
use once_cell::sync::Lazy;
use rstest::*;
@ -638,38 +638,6 @@ pub async fn client(sshd: Sshd) -> Ctx<DistantClient> {
}
}
/// Fixture to establish a client to a launched server
#[fixture]
pub async fn launched_client(sshd: Sshd) -> Ctx<DistantClient> {
let binary = std::env::var("DISTANT_PATH").unwrap_or_else(|_| String::from("distant"));
debug!("Setting path to distant binary as {binary}");
// Attempt to launch the server and connect to it, using $DISTANT_PATH as the path to the
// binary if provided, defaulting to assuming the binary is on our ssh path otherwise
//
// NOTE: Wrapping in ctx does not fully clean up the test as the launched distant server
// is not cleaned up during drop. We don't know what the server's pid is, so our
// only option would be to look up all running distant servers and kill them on drop,
// but that would cause other tests to fail.
//
// Setting an expiration of 1s would clean up running servers and possibly be good enough
let ssh_client = load_ssh_client(&sshd).await;
let mut client = ssh_client
.launch_and_connect(DistantLaunchOpts {
binary,
args: "--shutdown lonely=10".to_string(),
..Default::default()
})
.await
.context("Failed to launch and connect to distant server")
.unwrap();
client.shutdown_on_drop(true);
Ctx {
sshd,
value: client,
}
}
/// Access to raw [`Ssh`] client
#[fixture]
pub async fn ssh(sshd: Sshd) -> Ctx<Ssh> {

@ -13,9 +13,10 @@ use distant_core::protocol::{
use distant_core::{DistantChannel, DistantChannelExt, RemoteCommand, Searcher, Watcher};
use log::*;
use serde_json::json;
use tabled::object::Rows;
use tabled::style::Style;
use tabled::{Alignment, Disable, Modify, Table, Tabled};
use tabled::settings::object::Rows;
use tabled::settings::style::Style;
use tabled::settings::{Alignment, Disable, Modify};
use tabled::{Table, Tabled};
use tokio::sync::mpsc;
use crate::cli::common::{

@ -8,9 +8,10 @@ use distant_core::protocol::{
SearchQueryPathMatch, SystemInfo,
};
use log::*;
use tabled::object::Rows;
use tabled::style::Style;
use tabled::{Alignment, Disable, Modify, Table, Tabled};
use tabled::settings::object::Rows;
use tabled::settings::style::Style;
use tabled::settings::{Alignment, Disable, Modify};
use tabled::{Table, Tabled};
use crate::options::Format;

@ -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;

@ -3,9 +3,10 @@ use ::predicates::prelude::*;
mod predicates;
mod reader;
pub use self::predicates::TrimmedLinesMatchPredicate;
pub use reader::ThreadedReader;
pub use self::predicates::TrimmedLinesMatchPredicate;
/// Produces a regex predicate using the given string
pub fn regex_pred(s: &str) -> ::predicates::str::RegexPredicate {
predicate::str::is_match(s).unwrap()

@ -1,6 +1,7 @@
use std::fmt;
use predicates::reflection::PredicateReflection;
use predicates::Predicate;
use std::fmt;
/// Checks if lines of text match the provided, trimming each line
/// of both before comparing.

Loading…
Cancel
Save