Apply nightly formatting to reorder imports and use module-level import granularity

pull/184/head
Chip Senkbeil 12 months ago
parent 5b19870b98
commit b8fecaacc0
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -1,15 +1,17 @@
use crate::{
data::{
Capabilities, ChangeKind, DirEntry, Environment, Error, Metadata, ProcessId, PtySize,
SearchId, SearchQuery, SystemInfo,
},
DistantMsg, DistantRequestData, DistantResponseData,
};
use std::io;
use std::path::PathBuf;
use std::sync::Arc;
use async_trait::async_trait;
use distant_net::common::ConnectionId;
use distant_net::server::{ConnectionCtx, Reply, ServerCtx, ServerHandler};
use log::*;
use std::{io, path::PathBuf, sync::Arc};
use crate::data::{
Capabilities, ChangeKind, DirEntry, Environment, Error, Metadata, ProcessId, PtySize, SearchId,
SearchQuery, SystemInfo,
};
use crate::{DistantMsg, DistantRequestData, DistantResponseData};
mod local;
pub use local::LocalDistantApi;
@ -420,9 +422,9 @@ where
T: DistantApi<LocalData = D> + Send + Sync,
D: Send + Sync,
{
type LocalData = D;
type Request = DistantMsg<DistantRequestData>;
type Response = DistantMsg<DistantResponseData>;
type LocalData = D;
/// Overridden to leverage [`DistantApi`] implementation of `on_accept`
async fn on_accept(&self, ctx: ConnectionCtx<'_, Self::LocalData>) -> io::Result<()> {

@ -1,19 +1,17 @@
use crate::{
data::{
Capabilities, ChangeKind, ChangeKindSet, DirEntry, Environment, FileType, Metadata,
ProcessId, PtySize, SearchId, SearchQuery, SystemInfo,
},
DistantApi, DistantCtx,
};
use std::io;
use std::path::{Path, PathBuf};
use async_trait::async_trait;
use log::*;
use std::{
io,
path::{Path, PathBuf},
};
use tokio::io::AsyncWriteExt;
use walkdir::WalkDir;
use crate::data::{
Capabilities, ChangeKind, ChangeKindSet, DirEntry, Environment, FileType, Metadata, ProcessId,
PtySize, SearchId, SearchQuery, SystemInfo,
};
use crate::{DistantApi, DistantCtx};
mod process;
mod state;
@ -493,17 +491,20 @@ impl DistantApi for LocalDistantApi {
#[cfg(test)]
mod tests {
use super::*;
use crate::api::ConnectionCtx;
use crate::data::DistantResponseData;
use std::sync::Arc;
use std::time::Duration;
use assert_fs::prelude::*;
use distant_net::server::Reply;
use once_cell::sync::Lazy;
use predicates::prelude::*;
use std::{sync::Arc, time::Duration};
use test_log::test;
use tokio::sync::mpsc;
use super::*;
use crate::api::ConnectionCtx;
use crate::data::DistantResponseData;
static TEMP_SCRIPT_DIR: Lazy<assert_fs::TempDir> =
Lazy::new(|| assert_fs::TempDir::new().unwrap());
static SCRIPT_RUNNER: Lazy<String> = Lazy::new(|| String::from("bash"));

@ -1,6 +1,10 @@
use std::future::Future;
use std::pin::Pin;
use tokio::io;
use tokio::sync::mpsc;
use crate::data::{ProcessId, PtySize};
use std::{future::Future, pin::Pin};
use tokio::{io, sync::mpsc};
mod pty;
pub use pty::*;

@ -1,20 +1,19 @@
use std::ffi::OsStr;
use std::io::{self, Read, Write};
use std::path::PathBuf;
use std::sync::{Arc, Mutex, Weak};
use log::*;
use portable_pty::{CommandBuilder, MasterPty, PtySize as PortablePtySize};
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use super::{
wait, ExitStatus, FutureReturn, InputChannel, OutputChannel, Process, ProcessId, ProcessKiller,
ProcessPty, PtySize, WaitRx,
};
use crate::{
constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_DURATION},
data::Environment,
};
use log::*;
use portable_pty::{CommandBuilder, MasterPty, PtySize as PortablePtySize};
use std::{
ffi::OsStr,
io::{self, Read, Write},
path::PathBuf,
sync::{Arc, Mutex, Weak},
};
use tokio::{sync::mpsc, task::JoinHandle};
use crate::constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_DURATION};
use crate::data::Environment;
/// Represents a process that is associated with a pty
pub struct PtyProcess {

@ -1,11 +1,18 @@
use std::ffi::OsStr;
use std::path::PathBuf;
use std::process::Stdio;
use log::*;
use tokio::io;
use tokio::process::Command;
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use super::{
wait, ExitStatus, FutureReturn, InputChannel, NoProcessPty, OutputChannel, Process, ProcessId,
ProcessKiller, WaitRx,
};
use crate::data::Environment;
use log::*;
use std::{ffi::OsStr, path::PathBuf, process::Stdio};
use tokio::{io, process::Command, sync::mpsc, task::JoinHandle};
mod tasks;

@ -1,10 +1,10 @@
use crate::constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_DURATION};
use std::io;
use tokio::{
io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt},
sync::mpsc,
task::JoinHandle,
};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use crate::constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_DURATION};
pub fn spawn_read_task<R>(
reader: R,

@ -1,4 +1,5 @@
use tokio::{io, sync::mpsc};
use tokio::io;
use tokio::sync::mpsc;
/// Exit status of a remote process
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

@ -1,10 +1,13 @@
use crate::data::{DistantResponseData, Environment, ProcessId, PtySize};
use std::collections::HashMap;
use std::io;
use std::ops::Deref;
use std::path::PathBuf;
use distant_net::server::Reply;
use std::{collections::HashMap, io, ops::Deref, path::PathBuf};
use tokio::{
sync::{mpsc, oneshot},
task::JoinHandle,
};
use tokio::sync::{mpsc, oneshot};
use tokio::task::JoinHandle;
use crate::data::{DistantResponseData, Environment, ProcessId, PtySize};
mod instance;
pub use instance::*;

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

@ -1,24 +1,23 @@
use std::collections::HashMap;
use std::ops::Deref;
use std::path::Path;
use std::{cmp, io};
use distant_net::server::Reply;
use grep::matcher::Matcher;
use grep::regex::{RegexMatcher, RegexMatcherBuilder};
use grep::searcher::{BinaryDetection, Searcher, SearcherBuilder, Sink, SinkMatch};
use ignore::types::TypesBuilder;
use ignore::{DirEntry, ParallelVisitor, ParallelVisitorBuilder, WalkBuilder, WalkParallel};
use log::*;
use tokio::sync::{broadcast, mpsc, oneshot};
use tokio::task::JoinHandle;
use crate::data::{
DistantResponseData, SearchId, SearchQuery, SearchQueryContentsMatch, SearchQueryMatch,
SearchQueryMatchData, SearchQueryOptions, SearchQueryPathMatch, SearchQuerySubmatch,
SearchQueryTarget,
};
use distant_net::server::Reply;
use grep::{
matcher::Matcher,
regex::{RegexMatcher, RegexMatcherBuilder},
searcher::{BinaryDetection, Searcher, SearcherBuilder, Sink, SinkMatch},
};
use ignore::{
types::TypesBuilder, DirEntry, ParallelVisitor, ParallelVisitorBuilder, WalkBuilder,
WalkParallel,
};
use log::*;
use std::{cmp, collections::HashMap, io, ops::Deref, path::Path};
use tokio::{
sync::{broadcast, mpsc, oneshot},
task::JoinHandle,
};
const MAXIMUM_SEARCH_THREADS: usize = 12;
@ -808,12 +807,14 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::data::{FileType, SearchQueryCondition, SearchQueryMatchData};
use assert_fs::prelude::*;
use std::path::PathBuf;
use assert_fs::prelude::*;
use test_log::test;
use super::*;
use crate::data::{FileType, SearchQueryCondition, SearchQueryMatchData};
fn make_path(path: &str) -> PathBuf {
use std::path::MAIN_SEPARATOR;

@ -1,23 +1,21 @@
use crate::{constants::SERVER_WATCHER_CAPACITY, data::ChangeKind};
use std::collections::HashMap;
use std::io;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use distant_net::common::ConnectionId;
use log::*;
use notify::{
Config as WatcherConfig, Error as WatcherError, ErrorKind as WatcherErrorKind,
Event as WatcherEvent, PollWatcher, RecursiveMode, Watcher,
};
use std::{
collections::HashMap,
io,
ops::Deref,
path::{Path, PathBuf},
};
use tokio::{
sync::{
mpsc::{self, error::TrySendError},
oneshot,
},
task::JoinHandle,
};
use tokio::sync::mpsc::error::TrySendError;
use tokio::sync::mpsc::{self};
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use crate::constants::SERVER_WATCHER_CAPACITY;
use crate::data::ChangeKind;
mod path;
pub use path::*;

@ -1,12 +1,11 @@
use crate::data::{Change, ChangeKind, ChangeKindSet, DistantResponseData, Error};
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 std::{
fmt,
hash::{Hash, Hasher},
io,
path::{Path, PathBuf},
};
use crate::data::{Change, ChangeKind, ChangeKindSet, DistantResponseData, Error};
/// Represents a path registered with a watcher that includes relevant state including
/// the ability to reply with

@ -1,6 +1,11 @@
use crate::{api::DistantMsg, data::DistantResponseData};
use std::future::Future;
use std::io;
use std::pin::Pin;
use distant_net::server::Reply;
use std::{future::Future, io, pin::Pin};
use crate::api::DistantMsg;
use crate::data::DistantResponseData;
/// Wrapper around a reply that can be batch or single, converting
/// a single data into the wrapped type

@ -1,5 +1,7 @@
use distant_net::client::Channel;
use distant_net::Client;
use crate::{DistantMsg, DistantRequestData, DistantResponseData};
use distant_net::{client::Channel, Client};
mod ext;
mod lsp;

@ -1,16 +1,20 @@
use crate::{
client::{
RemoteCommand, RemoteLspCommand, RemoteLspProcess, RemoteOutput, RemoteProcess, Searcher,
Watcher,
},
data::{
Capabilities, ChangeKindSet, DirEntry, DistantRequestData, DistantResponseData,
Environment, Error as Failure, Metadata, PtySize, SearchId, SearchQuery, SystemInfo,
},
DistantMsg,
use std::future::Future;
use std::io;
use std::path::PathBuf;
use std::pin::Pin;
use distant_net::client::Channel;
use distant_net::common::Request;
use crate::client::{
RemoteCommand, RemoteLspCommand, RemoteLspProcess, RemoteOutput, RemoteProcess, Searcher,
Watcher,
};
use crate::data::{
Capabilities, ChangeKindSet, DirEntry, DistantRequestData, DistantResponseData, Environment,
Error as Failure, Metadata, PtySize, SearchId, SearchQuery, SystemInfo,
};
use distant_net::{client::Channel, common::Request};
use std::{future::Future, io, path::PathBuf, pin::Pin};
use crate::DistantMsg;
pub type AsyncReturn<'a, T, E = io::Error> =
Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>;

@ -1,20 +1,17 @@
use crate::{
client::{
DistantChannel, RemoteCommand, RemoteProcess, RemoteStatus, RemoteStderr, RemoteStdin,
RemoteStdout,
},
data::{Environment, PtySize},
};
use std::io::{self, Cursor, Read};
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use futures::stream::{Stream, StreamExt};
use std::{
io::{self, Cursor, Read},
ops::{Deref, DerefMut},
path::PathBuf,
};
use tokio::{
sync::mpsc::{self, error::TryRecvError},
task::JoinHandle,
use tokio::sync::mpsc::error::TryRecvError;
use tokio::sync::mpsc::{self};
use tokio::task::JoinHandle;
use crate::client::{
DistantChannel, RemoteCommand, RemoteProcess, RemoteStatus, RemoteStderr, RemoteStdin,
RemoteStdout,
};
use crate::data::{Environment, PtySize};
mod msg;
pub use msg::*;
@ -397,14 +394,15 @@ fn read_lsp_messages(input: &[u8]) -> io::Result<(Option<Vec<u8>>, Vec<LspMsg>)>
#[cfg(test)]
mod tests {
use std::future::Future;
use std::time::Duration;
use distant_net::common::{FramedTransport, InmemoryTransport, Request, Response};
use distant_net::Client;
use test_log::test;
use super::*;
use crate::data::{DistantRequestData, DistantResponseData};
use distant_net::{
common::{FramedTransport, InmemoryTransport, Request, Response},
Client,
};
use std::{future::Future, time::Duration};
use test_log::test;
/// Timeout used with timeout function
const TIMEOUT: Duration = Duration::from_millis(50);

@ -1,13 +1,12 @@
use std::fmt;
use std::io::{self, BufRead};
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
use std::string::FromUtf8Error;
use derive_more::{Display, Error, From};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use std::{
fmt,
io::{self, BufRead},
ops::{Deref, DerefMut},
str::FromStr,
string::FromUtf8Error,
};
/// Represents some data being communicated to/from an LSP consisting of a header and content part
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@ -61,6 +60,7 @@ impl LspMsg {
pub fn header(&self) -> &LspHeader {
&self.header
}
/// Returns a mutable reference to the header part
pub fn mut_header(&mut self) -> &mut LspHeader {
&mut self.header
@ -395,9 +395,10 @@ impl FromStr for LspContent {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
macro_rules! make_obj {
($($tail:tt)*) => {
match serde_json::json!($($tail)*) {

@ -1,26 +1,19 @@
use crate::{
client::DistantChannel,
constants::CLIENT_PIPE_CAPACITY,
data::{Cmd, DistantRequestData, DistantResponseData, Environment, ProcessId, PtySize},
DistantMsg,
};
use distant_net::{
client::Mailbox,
common::{Request, Response},
};
use std::path::PathBuf;
use std::sync::Arc;
use distant_net::client::Mailbox;
use distant_net::common::{Request, Response};
use log::*;
use std::{path::PathBuf, sync::Arc};
use tokio::{
io,
sync::{
mpsc::{
self,
error::{TryRecvError, TrySendError},
},
RwLock,
},
task::JoinHandle,
};
use tokio::io;
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
use tokio::sync::mpsc::{self};
use tokio::sync::RwLock;
use tokio::task::JoinHandle;
use crate::client::DistantChannel;
use crate::constants::CLIENT_PIPE_CAPACITY;
use crate::data::{Cmd, DistantRequestData, DistantResponseData, Environment, ProcessId, PtySize};
use crate::DistantMsg;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RemoteOutput {
@ -595,18 +588,16 @@ mod errors {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
client::DistantClient,
data::{Error, ErrorKind},
};
use distant_net::{
common::{FramedTransport, InmemoryTransport, Response},
Client,
};
use std::time::Duration;
use distant_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_net::Client;
use test_log::test;
use super::*;
use crate::client::DistantClient;
use crate::data::{Error, ErrorKind};
fn make_session() -> (FramedTransport<InmemoryTransport>, DistantClient) {
let (t1, t2) = FramedTransport::pair(100);
(t1, Client::spawn_inmemory(t2, Default::default()))

@ -1,13 +1,16 @@
use crate::{
client::{DistantChannel, DistantChannelExt},
constants::CLIENT_SEARCHER_CAPACITY,
data::{DistantRequestData, DistantResponseData, SearchId, SearchQuery, SearchQueryMatch},
DistantMsg,
};
use std::{fmt, io};
use distant_net::common::Request;
use log::*;
use std::{fmt, io};
use tokio::{sync::mpsc, task::JoinHandle};
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use crate::client::{DistantChannel, DistantChannelExt};
use crate::constants::CLIENT_SEARCHER_CAPACITY;
use crate::data::{
DistantRequestData, DistantResponseData, SearchId, SearchQuery, SearchQueryMatch,
};
use crate::DistantMsg;
/// Represents a searcher for files, directories, and symlinks on the filesystem
pub struct Searcher {
@ -190,19 +193,20 @@ impl Searcher {
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use std::sync::Arc;
use distant_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_net::Client;
use test_log::test;
use tokio::sync::Mutex;
use super::*;
use crate::data::{
SearchQueryCondition, SearchQueryMatchData, SearchQueryOptions, SearchQueryPathMatch,
SearchQuerySubmatch, SearchQueryTarget,
};
use crate::DistantClient;
use distant_net::{
common::{FramedTransport, InmemoryTransport, Response},
Client,
};
use std::{path::PathBuf, sync::Arc};
use test_log::test;
use tokio::sync::Mutex;
fn make_session() -> (FramedTransport<InmemoryTransport>, DistantClient) {
let (t1, t2) = FramedTransport::pair(100);

@ -1,16 +1,15 @@
use crate::{
client::{DistantChannel, DistantChannelExt},
constants::CLIENT_WATCHER_CAPACITY,
data::{Change, ChangeKindSet, DistantRequestData, DistantResponseData},
DistantMsg,
};
use std::path::{Path, PathBuf};
use std::{fmt, io};
use distant_net::common::Request;
use log::*;
use std::{
fmt, io,
path::{Path, PathBuf},
};
use tokio::{sync::mpsc, task::JoinHandle};
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use crate::client::{DistantChannel, DistantChannelExt};
use crate::constants::CLIENT_WATCHER_CAPACITY;
use crate::data::{Change, ChangeKindSet, DistantRequestData, DistantResponseData};
use crate::DistantMsg;
/// Represents a watcher of some path on a remote machine
pub struct Watcher {
@ -181,17 +180,17 @@ impl Watcher {
#[cfg(test)]
mod tests {
use super::*;
use crate::data::ChangeKind;
use crate::DistantClient;
use distant_net::{
common::{FramedTransport, InmemoryTransport, Response},
Client,
};
use std::sync::Arc;
use distant_net::common::{FramedTransport, InmemoryTransport, Response};
use distant_net::Client;
use test_log::test;
use tokio::sync::Mutex;
use super::*;
use crate::data::ChangeKind;
use crate::DistantClient;
fn make_session() -> (FramedTransport<InmemoryTransport>, DistantClient) {
let (t1, t2) = FramedTransport::pair(100);
(t1, Client::spawn_inmemory(t2, Default::default()))

@ -1,7 +1,13 @@
use crate::serde_str::{deserialize_from_str, serialize_to_str};
use std::convert::TryFrom;
use std::str::FromStr;
use std::{fmt, io};
use distant_net::common::{Destination, Host, SecretKey32};
use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize};
use std::{convert::TryFrom, fmt, io, str::FromStr};
use serde::de::Deserializer;
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
use crate::serde_str::{deserialize_from_str, serialize_to_str};
const SCHEME: &str = "distant";
const SCHEME_WITH_SEP: &str = "distant://";
@ -167,11 +173,13 @@ impl TryFrom<DistantSingleKeyCredentials> for Destination {
#[cfg(test)]
mod tests {
use super::*;
use once_cell::sync::Lazy;
use std::net::{Ipv4Addr, Ipv6Addr};
use once_cell::sync::Lazy;
use test_log::test;
use super::*;
const HOST: &str = "testhost";
const PORT: u16 = 12345;

@ -1,6 +1,8 @@
use std::io;
use std::path::PathBuf;
use derive_more::{From, IsVariant};
use serde::{Deserialize, Serialize};
use std::{io, path::PathBuf};
use strum::{AsRefStr, EnumDiscriminants, EnumIter, EnumMessage, EnumString};
mod capabilities;

@ -1,15 +1,15 @@
use super::CapabilityKind;
use std::cmp::Ordering;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::ops::{BitAnd, BitOr, BitXor};
use std::str::FromStr;
use derive_more::{From, Into, IntoIterator};
use serde::{Deserialize, Serialize};
use std::{
cmp::Ordering,
collections::HashSet,
hash::{Hash, Hasher},
ops::{BitAnd, BitOr, BitXor},
str::FromStr,
};
use strum::{EnumMessage, IntoEnumIterator};
use super::CapabilityKind;
/// Set of supported capabilities for a server
#[derive(Clone, Debug, From, Into, PartialEq, Eq, IntoIterator, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]

@ -1,15 +1,15 @@
use std::collections::HashSet;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::iter::FromIterator;
use std::ops::{BitOr, Sub};
use std::path::PathBuf;
use std::str::FromStr;
use derive_more::{Deref, DerefMut, IntoIterator};
use notify::{event::Event as NotifyEvent, EventKind as NotifyEventKind};
use notify::event::Event as NotifyEvent;
use notify::EventKind as NotifyEventKind;
use serde::{Deserialize, Serialize};
use std::{
collections::HashSet,
fmt,
hash::{Hash, Hasher},
iter::FromIterator,
ops::{BitOr, Sub},
path::PathBuf,
str::FromStr,
};
use strum::{EnumString, EnumVariantNames, VariantNames};
/// Change to one or more paths on the filesystem

@ -1,6 +1,7 @@
use std::ops::{Deref, DerefMut};
use derive_more::{Display, From, Into};
use serde::{Deserialize, Serialize};
use std::ops::{Deref, DerefMut};
/// Represents some command with arguments to execute
#[derive(Clone, Debug, Display, From, Into, Hash, PartialEq, Eq, Serialize, Deserialize)]

@ -1,7 +1,8 @@
use std::io;
use derive_more::Display;
use notify::ErrorKind as NotifyErrorKind;
use serde::{Deserialize, Serialize};
use std::io;
/// General purpose error type that can be sent across the wire
#[derive(Clone, Debug, Display, PartialEq, Eq, Serialize, Deserialize)]

@ -1,6 +1,8 @@
use std::fs::FileType as StdFileType;
use std::path::PathBuf;
use derive_more::IsVariant;
use serde::{Deserialize, Serialize};
use std::{fs::FileType as StdFileType, path::PathBuf};
use strum::AsRefStr;
/// Represents information about a single entry within a directory

@ -1,11 +1,11 @@
use super::{deserialize_u128_option, serialize_u128_option, FileType};
use std::io;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
use bitflags::bitflags;
use serde::{Deserialize, Serialize};
use std::{
io,
path::{Path, PathBuf},
time::SystemTime,
};
use super::{deserialize_u128_option, serialize_u128_option, FileType};
/// Represents metadata about some path on a remote machine
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]

@ -1,7 +1,10 @@
use std::fmt;
use std::num::ParseIntError;
use std::str::FromStr;
use derive_more::{Display, Error};
use portable_pty::PtySize as PortablePtySize;
use serde::{Deserialize, Serialize};
use std::{fmt, num::ParseIntError, str::FromStr};
/// Represents the size associated with a remote PTY
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]

@ -1,6 +1,11 @@
use super::FileType;
use std::borrow::Cow;
use std::collections::HashSet;
use std::path::PathBuf;
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, collections::HashSet, path::PathBuf, str::FromStr};
use super::FileType;
/// Id associated with a search
pub type SearchId = u32;
@ -380,9 +385,10 @@ mod tests {
use super::*;
mod search_query_condition {
use super::*;
use test_log::test;
use super::*;
#[test]
fn to_regex_string_should_convert_to_appropriate_regex_and_escape_as_needed() {
assert_eq!(

@ -1,5 +1,7 @@
use std::env;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use std::{env, path::PathBuf};
/// Represents information about a system
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]

@ -1,8 +1,9 @@
use serde::{
de::{Deserializer, Error as SerdeError, Visitor},
ser::Serializer,
};
use std::{fmt, marker::PhantomData, str::FromStr};
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>

@ -1,9 +1,10 @@
use crate::stress::fixtures::*;
use assert_fs::prelude::*;
use distant_core::DistantChannelExt;
use rstest::*;
use test_log::test;
use crate::stress::fixtures::*;
// 64KB is maximum TCP packet size
const MAX_TCP_PACKET_BYTES: usize = 65535;

@ -1,9 +1,11 @@
use crate::stress::fixtures::*;
use assert_fs::prelude::*;
use distant_core::{data::ChangeKindSet, DistantChannelExt};
use distant_core::data::ChangeKindSet;
use distant_core::DistantChannelExt;
use rstest::*;
use test_log::test;
use crate::stress::fixtures::*;
const MAX_FILES: usize = 500;
#[rstest]

@ -1,11 +1,12 @@
use std::net::SocketAddr;
use std::time::Duration;
use distant_core::net::client::{Client, TcpConnector};
use distant_core::net::common::authentication::{DummyAuthHandler, Verifier};
use distant_core::net::common::PortRange;
use distant_core::net::server::Server;
use distant_core::{DistantApiServerHandler, DistantClient, LocalDistantApi};
use rstest::*;
use std::net::SocketAddr;
use std::time::Duration;
use tokio::sync::mpsc;
pub struct DistantClientCtx {

@ -1,19 +1,18 @@
use std::ops::{Deref, DerefMut};
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::{fmt, io};
use log::*;
use serde::de::DeserializeOwned;
use serde::Serialize;
use tokio::sync::{mpsc, oneshot, watch};
use tokio::task::JoinHandle;
use crate::common::{
Connection, FramedTransport, HeapSecretKey, InmemoryTransport, Interest, Reconnectable,
Transport, UntypedRequest, UntypedResponse,
};
use log::*;
use serde::{de::DeserializeOwned, Serialize};
use std::{
fmt, io,
ops::{Deref, DerefMut},
sync::Arc,
time::{Duration, Instant},
};
use tokio::{
sync::{mpsc, oneshot, watch},
task::JoinHandle,
};
mod builder;
pub use builder::*;
@ -644,8 +643,9 @@ mod tests {
use crate::common::{Ready, Request, Response, TestTransport};
mod typed {
use super::*;
use test_log::test;
use super::*;
type TestClient = Client<u8, u8>;
fn spawn_test_client<T>(
@ -962,8 +962,9 @@ mod tests {
}
mod untyped {
use super::*;
use test_log::test;
use super::*;
type TestClient = UntypedClient;
/// Creates a new test transport whose operations do not panic, but do nothing.

@ -10,14 +10,17 @@ pub use unix::*;
#[cfg(windows)]
mod windows;
use std::time::Duration;
use std::{convert, io};
use async_trait::async_trait;
#[cfg(windows)]
pub use windows::*;
use super::ClientConfig;
use crate::client::{Client, UntypedClient};
use crate::common::{authentication::AuthHandler, Connection, Transport};
use async_trait::async_trait;
use std::{convert, io, time::Duration};
use crate::common::authentication::AuthHandler;
use crate::common::{Connection, Transport};
/// Interface that performs the connection to produce a [`Transport`] for use by the [`Client`].
#[async_trait]

@ -1,9 +1,11 @@
use super::Connector;
use crate::common::TcpTransport;
use async_trait::async_trait;
use std::io;
use async_trait::async_trait;
use tokio::net::ToSocketAddrs;
use super::Connector;
use crate::common::TcpTransport;
/// Implementation of [`Connector`] to support connecting via TCP.
pub struct TcpConnector<T> {
addr: T,

@ -1,7 +1,10 @@
use std::io;
use std::path::PathBuf;
use async_trait::async_trait;
use super::Connector;
use crate::common::UnixSocketTransport;
use async_trait::async_trait;
use std::{io, path::PathBuf};
/// Implementation of [`Connector`] to support connecting via a Unix socket.
pub struct UnixSocketConnector {

@ -1,9 +1,11 @@
use super::Connector;
use crate::common::WindowsPipeTransport;
use async_trait::async_trait;
use std::ffi::OsString;
use std::io;
use async_trait::async_trait;
use super::Connector;
use crate::common::WindowsPipeTransport;
/// Implementation of [`Connector`] to support connecting via a Windows named pipe.
pub struct WindowsPipeConnector {
addr: OsString,

@ -1,8 +1,14 @@
use crate::common::{Request, Response, UntypedRequest, UntypedResponse};
use std::marker::PhantomData;
use std::sync::Weak;
use std::{convert, fmt, io};
use log::*;
use serde::{de::DeserializeOwned, Serialize};
use std::{convert, fmt, io, marker::PhantomData, sync::Weak};
use tokio::{sync::mpsc, time::Duration};
use serde::de::DeserializeOwned;
use serde::Serialize;
use tokio::sync::mpsc;
use tokio::time::Duration;
use crate::common::{Request, Response, UntypedRequest, UntypedResponse};
mod mailbox;
pub use mailbox::*;
@ -336,11 +342,13 @@ mod tests {
use super::*;
mod typed {
use super::*;
use std::sync::Arc;
use std::time::Duration;
use test_log::test;
use super::*;
type TestChannel = Channel<u8, u8>;
type Setup = (
TestChannel,
@ -446,11 +454,13 @@ mod tests {
}
mod untyped {
use super::*;
use std::sync::Arc;
use std::time::Duration;
use test_log::test;
use super::*;
type TestChannel = UntypedChannel;
type Setup = (
TestChannel,

@ -1,15 +1,12 @@
use crate::common::{Id, Response, UntypedResponse};
use std::collections::HashMap;
use std::sync::{Arc, Weak};
use std::time::Duration;
use async_trait::async_trait;
use std::{
collections::HashMap,
sync::{Arc, Weak},
time::Duration,
};
use tokio::{
io,
sync::{mpsc, Mutex, RwLock},
time,
};
use tokio::sync::{mpsc, Mutex, RwLock};
use tokio::{io, time};
use crate::common::{Id, Response, UntypedResponse};
#[derive(Clone, Debug)]
pub struct PostOffice<T> {

@ -1,6 +1,7 @@
use super::ReconnectStrategy;
use std::time::Duration;
use super::ReconnectStrategy;
const DEFAULT_SILENCE_DURATION: Duration = Duration::from_secs(20);
const MAXIMUM_SILENCE_DURATION: Duration = Duration::from_millis(68719476734);

@ -1,11 +1,13 @@
use super::Reconnectable;
use log::*;
use std::io;
use std::time::Duration;
use log::*;
use strum::Display;
use tokio::sync::watch;
use tokio::task::JoinHandle;
use super::Reconnectable;
/// Represents a watcher over a [`ConnectionState`].
#[derive(Clone)]
pub struct ConnectionWatcher(pub(super) watch::Receiver<ConnectionState>);

@ -1,6 +1,7 @@
use std::io;
use async_trait::async_trait;
use dyn_clone::DynClone;
use std::io;
use tokio::sync::{mpsc, oneshot};
/// Interface representing functionality to shut down an active client.

@ -1,8 +1,11 @@
use super::{msg::*, AuthHandler};
use crate::common::{utils, FramedTransport, Transport};
use std::io;
use async_trait::async_trait;
use log::*;
use std::io;
use super::msg::*;
use super::AuthHandler;
use crate::common::{utils, FramedTransport, Transport};
/// Represents an interface for authenticating with a server.
#[async_trait]
@ -200,11 +203,12 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::common::authentication::AuthMethodHandler;
use test_log::test;
use tokio::sync::mpsc;
use super::*;
use crate::common::authentication::AuthMethodHandler;
#[async_trait]
trait TestAuthHandler {
async fn on_initialization(

@ -1,9 +1,11 @@
use std::collections::HashMap;
use std::io;
use async_trait::async_trait;
use super::msg::*;
use crate::common::authentication::Authenticator;
use crate::common::HeapSecretKey;
use async_trait::async_trait;
use std::collections::HashMap;
use std::io;
mod methods;
pub use methods::*;

@ -1,8 +1,10 @@
use std::io;
use async_trait::async_trait;
use super::{
Challenge, ChallengeResponse, Error, Info, Verification, VerificationKind, VerificationResponse,
};
use async_trait::async_trait;
use std::io;
/// Interface for a handler of authentication requests for a specific authentication method.
#[async_trait]

@ -1,10 +1,12 @@
use std::io;
use async_trait::async_trait;
use log::*;
use super::{
AuthMethodHandler, Challenge, ChallengeResponse, Error, Info, Verification, VerificationKind,
VerificationResponse,
};
use async_trait::async_trait;
use log::*;
use std::io;
/// Blocking implementation of [`AuthMethodHandler`] that uses prompts to communicate challenge &
/// verification requests, receiving responses to relay back.

@ -1,11 +1,13 @@
use std::io;
use async_trait::async_trait;
use log::*;
use super::{
AuthMethodHandler, Challenge, ChallengeResponse, Error, Info, Verification,
VerificationResponse,
};
use crate::common::HeapSecretKey;
use async_trait::async_trait;
use log::*;
use std::io;
/// Implementation of [`AuthMethodHandler`] that answers challenge requests using a static
/// [`HeapSecretKey`]. All other portions of method authentication are handled by another
@ -98,9 +100,10 @@ impl AuthMethodHandler for StaticKeyAuthMethodHandler {
#[cfg(test)]
mod tests {
use test_log::test;
use super::*;
use crate::common::authentication::msg::{ErrorKind, Question, VerificationKind};
use test_log::test;
#[test(tokio::test)]
async fn on_challenge_should_fail_if_non_key_question_received() {

@ -1,8 +1,10 @@
use crate::common::HeapSecretKey;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::common::HeapSecretKey;
/// Represents the result of a request to the database.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum KeychainResult<T> {

@ -1,9 +1,13 @@
use super::{super::HeapSecretKey, msg::*, Authenticator};
use async_trait::async_trait;
use log::*;
use std::collections::HashMap;
use std::io;
use async_trait::async_trait;
use log::*;
use super::super::HeapSecretKey;
use super::msg::*;
use super::Authenticator;
mod none;
mod static_key;
@ -113,9 +117,10 @@ pub trait AuthenticationMethod: Send + Sync {
#[cfg(test)]
mod tests {
use test_log::test;
use super::*;
use crate::common::FramedTransport;
use test_log::test;
struct SuccessAuthenticationMethod;

@ -1,7 +1,9 @@
use super::{AuthenticationMethod, Authenticator};
use async_trait::async_trait;
use std::io;
use async_trait::async_trait;
use super::{AuthenticationMethod, Authenticator};
/// Authenticaton method for a static secret key
#[derive(Clone, Debug)]
pub struct NoneAuthenticationMethod;

@ -1,7 +1,9 @@
use std::io;
use async_trait::async_trait;
use super::{AuthenticationMethod, Authenticator, Challenge, Error, Question};
use crate::common::HeapSecretKey;
use async_trait::async_trait;
use std::io;
/// Authenticaton method for a static secret key
#[derive(Clone, Debug)]
@ -53,13 +55,12 @@ impl AuthenticationMethod for StaticKeyAuthenticationMethod {
#[cfg(test)]
mod tests {
use super::*;
use crate::common::{
authentication::msg::{AuthenticationResponse, ChallengeResponse},
FramedTransport,
};
use test_log::test;
use super::*;
use crate::common::authentication::msg::{AuthenticationResponse, ChallengeResponse};
use crate::common::FramedTransport;
#[test(tokio::test)]
async fn authenticate_should_fail_if_key_challenge_fails() {
let method = StaticKeyAuthenticationMethod::new(b"".to_vec());

@ -1,6 +1,7 @@
use std::collections::HashMap;
use derive_more::{Display, Error, From};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Represents messages from an authenticator that act as initiators such as providing
/// a challenge, verifying information, presenting information, or highlighting an error

@ -1,16 +1,15 @@
use super::{
authentication::{AuthHandler, Authenticate, Keychain, KeychainResult, Verifier},
Backup, FramedTransport, HeapSecretKey, Reconnectable, Transport,
};
use std::io;
use std::ops::{Deref, DerefMut};
use async_trait::async_trait;
use log::*;
use serde::{Deserialize, Serialize};
use std::io;
use std::ops::{Deref, DerefMut};
use tokio::sync::oneshot;
use super::authentication::{AuthHandler, Authenticate, Keychain, KeychainResult, Verifier};
#[cfg(test)]
use super::InmemoryTransport;
use super::{Backup, FramedTransport, HeapSecretKey, Reconnectable, Transport};
/// Id of the connection
pub type ConnectionId = u32;
@ -454,14 +453,15 @@ impl<T: Transport> Connection<T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::common::{
authentication::{msg::Challenge, Authenticator, DummyAuthHandler},
Frame,
};
use std::sync::Arc;
use test_log::test;
use super::*;
use crate::common::authentication::msg::Challenge;
use crate::common::authentication::{Authenticator, DummyAuthHandler};
use crate::common::Frame;
#[test(tokio::test)]
async fn client_should_fail_if_codec_handshake_fails() {
let (mut t1, t2) = FramedTransport::pair(100);

@ -1,6 +1,12 @@
use std::fmt;
use std::hash::Hash;
use std::str::FromStr;
use serde::de::Deserializer;
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
use super::utils::{deserialize_from_str, serialize_to_str};
use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize};
use std::{fmt, hash::Hash, str::FromStr};
mod host;
mod parser;

@ -1,11 +1,13 @@
use super::{deserialize_from_str, serialize_to_str};
use std::fmt;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::str::FromStr;
use derive_more::{Display, Error, From};
use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize};
use std::{
fmt,
net::{IpAddr, Ipv4Addr, Ipv6Addr},
str::FromStr,
};
use serde::de::Deserializer;
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
use super::{deserialize_from_str, serialize_to_str};
/// Represents the host of a destination
#[derive(Clone, Debug, From, Display, Hash, PartialEq, Eq)]

@ -342,9 +342,10 @@ mod tests {
}
mod parse_host {
use super::*;
use std::net::{Ipv4Addr, Ipv6Addr};
use super::*;
#[test]
fn should_fail_if_domain_name_is_invalid() {
let _ = parse_host("").unwrap_err();

@ -1,6 +1,7 @@
use async_trait::async_trait;
use std::io;
use async_trait::async_trait;
mod mapped;
pub use mapped::*;

@ -1,7 +1,9 @@
use super::Listener;
use async_trait::async_trait;
use std::io;
use async_trait::async_trait;
use super::Listener;
/// Represents a [`Listener`] that wraps a different [`Listener`],
/// mapping the received connection to something else using the map function
pub struct MappedListener<L, F, T, U>

@ -1,9 +1,11 @@
use super::Listener;
use std::io;
use async_trait::async_trait;
use derive_more::From;
use std::io;
use tokio::sync::mpsc;
use super::Listener;
/// Represents a [`Listener`] that uses an [`mpsc::Receiver`] to
/// accept new connections
#[derive(From)]

@ -1,9 +1,11 @@
use super::Listener;
use std::io;
use async_trait::async_trait;
use derive_more::From;
use std::io;
use tokio::sync::oneshot;
use super::Listener;
/// Represents a [`Listener`] that only has a single connection
#[derive(From)]
pub struct OneshotListener<T: Send> {
@ -47,10 +49,11 @@ impl<T: Send> Listener for OneshotListener<T> {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use tokio::task::JoinHandle;
use super::*;
#[test(tokio::test)]
async fn from_value_should_return_value_on_first_call_to_accept() {
let mut listener = OneshotListener::from_value("hello world");

@ -1,9 +1,12 @@
use super::Listener;
use crate::common::{PortRange, TcpTransport};
use std::net::IpAddr;
use std::{fmt, io};
use async_trait::async_trait;
use std::{fmt, io, net::IpAddr};
use tokio::net::TcpListener as TokioTcpListener;
use super::Listener;
use crate::common::{PortRange, TcpTransport};
/// Represents a [`Listener`] for incoming connections over TCP
pub struct TcpListener {
addr: IpAddr,
@ -64,11 +67,14 @@ impl Listener for TcpListener {
#[cfg(test)]
mod tests {
use super::*;
use crate::common::TransportExt;
use std::net::{Ipv6Addr, SocketAddr};
use test_log::test;
use tokio::{sync::oneshot, task::JoinHandle};
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use super::*;
use crate::common::TransportExt;
#[test(tokio::test)]
async fn should_fail_to_bind_if_port_already_bound() {

@ -1,13 +1,13 @@
use super::Listener;
use crate::common::UnixSocketTransport;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use std::{fmt, io};
use async_trait::async_trait;
use std::{
fmt, io,
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
};
use tokio::net::{UnixListener, UnixStream};
use super::Listener;
use crate::common::UnixSocketTransport;
/// Represents a [`Listener`] for incoming connections over a Unix socket
pub struct UnixSocketListener {
path: PathBuf,
@ -94,11 +94,13 @@ impl Listener for UnixSocketListener {
#[cfg(test)]
mod tests {
use super::*;
use crate::common::TransportExt;
use tempfile::NamedTempFile;
use test_log::test;
use tokio::{sync::oneshot, task::JoinHandle};
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use super::*;
use crate::common::TransportExt;
#[test(tokio::test)]
async fn should_succeed_to_bind_if_file_exists_at_path_but_nothing_listening() {

@ -1,12 +1,12 @@
use super::Listener;
use crate::common::{NamedPipe, WindowsPipeTransport};
use std::ffi::{OsStr, OsString};
use std::{fmt, io, mem};
use async_trait::async_trait;
use std::{
ffi::{OsStr, OsString},
fmt, io, mem,
};
use tokio::net::windows::named_pipe::{NamedPipeServer, ServerOptions};
use super::Listener;
use crate::common::{NamedPipe, WindowsPipeTransport};
/// Represents a [`Listener`] for incoming connections over a named windows pipe
pub struct WindowsPipeListener {
addr: OsString,
@ -66,10 +66,12 @@ impl Listener for WindowsPipeListener {
#[cfg(test)]
mod tests {
use test_log::test;
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use super::*;
use crate::common::TransportExt;
use test_log::test;
use tokio::{sync::oneshot, task::JoinHandle};
#[test(tokio::test)]
async fn should_fail_to_bind_if_pipe_already_bound() {

@ -1,13 +1,15 @@
use crate::common::utils::{deserialize_from_str, serialize_to_str};
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, ser::Serializer, Deserialize, Serialize};
use std::{
collections::hash_map::Entry,
collections::HashMap,
fmt,
ops::{Deref, DerefMut},
str::FromStr,
};
use serde::de::Deserializer;
use serde::ser::Serializer;
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, From, IntoIterator, PartialEq, Eq)]

@ -1,8 +1,12 @@
use std::borrow::Cow;
use std::{io, str};
use derive_more::{Display, Error};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use super::{parse_msg_pack_str, write_str_msg_pack, Id};
use crate::common::utils;
use derive_more::{Display, Error};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{borrow::Cow, io, str};
/// Represents a request to send
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
@ -195,9 +199,10 @@ impl<'a> UntypedRequest<'a> {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
const TRUE_BYTE: u8 = 0xc3;
const NEVER_USED_BYTE: u8 = 0xc1;

@ -1,8 +1,12 @@
use std::borrow::Cow;
use std::io;
use derive_more::{Display, Error};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use super::{parse_msg_pack_str, write_str_msg_pack, Id};
use crate::common::utils;
use derive_more::{Display, Error};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{borrow::Cow, io};
/// Represents a response received related to some response
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
@ -233,9 +237,10 @@ impl<'a> UntypedResponse<'a> {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
const TRUE_BYTE: u8 = 0xc3;
const NEVER_USED_BYTE: u8 = 0xc1;

@ -1,11 +1,10 @@
use std::fmt;
use std::net::{IpAddr, SocketAddr};
use std::ops::RangeInclusive;
use std::str::FromStr;
use derive_more::Display;
use serde::{de, Deserialize, Serialize};
use std::{
fmt,
net::{IpAddr, SocketAddr},
ops::RangeInclusive,
str::FromStr,
};
/// Represents some range of ports
#[derive(Copy, Clone, Debug, Display, PartialEq, Eq)]
@ -71,8 +70,8 @@ impl From<RangeInclusive<u16>> for PortRange {
}
impl<'a> IntoIterator for &'a PortRange {
type Item = u16;
type IntoIter = RangeInclusive<u16>;
type Item = u16;
fn into_iter(self) -> Self::IntoIter {
self.start..=self.end.unwrap_or(self.start)
@ -80,8 +79,8 @@ impl<'a> IntoIterator for &'a PortRange {
}
impl IntoIterator for PortRange {
type Item = u16;
type IntoIter = RangeInclusive<u16>;
type Item = u16;
fn into_iter(self) -> Self::IntoIter {
self.start..=self.end.unwrap_or(self.start)

@ -1,5 +1,7 @@
use std::time::Duration;
use std::{fmt, io};
use async_trait::async_trait;
use std::{fmt, io, time::Duration};
mod framed;
pub use framed::*;
@ -25,11 +27,10 @@ pub use unix::*;
#[cfg(windows)]
mod windows;
pub use tokio::io::{Interest, Ready};
#[cfg(windows)]
pub use windows::*;
pub use tokio::io::{Interest, Ready};
/// Duration to wait after WouldBlock received during looping operations like `read_exact`.
const SLEEP_DURATION: Duration = Duration::from_millis(1);
@ -270,9 +271,10 @@ impl<T: Transport> TransportExt for T {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
#[test(tokio::test)]
async fn read_exact_should_fail_if_try_read_encounters_error_other_than_would_block() {
let transport = TestTransport {

@ -1,10 +1,15 @@
use super::{InmemoryTransport, Interest, Ready, Reconnectable, Transport};
use crate::common::utils;
use std::future::Future;
use std::time::Duration;
use std::{fmt, io};
use async_trait::async_trait;
use bytes::{Buf, BytesMut};
use log::*;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{fmt, future::Future, io, time::Duration};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use super::{InmemoryTransport, Interest, Ready, Reconnectable, Transport};
use crate::common::utils;
mod backup;
mod codec;
@ -585,6 +590,7 @@ impl<T: Transport> FramedTransport<T> {
pub async fn client_handshake(&mut self) -> io::Result<()> {
self.handshake(Handshake::client()).await
}
/// Shorthand for creating a [`FramedTransport`] with a [`PlainCodec`] and then immediately
/// performing a [`server_handshake`], returning the updated [`FramedTransport`] on success.
///
@ -905,11 +911,12 @@ impl FramedTransport<InmemoryTransport> {
#[cfg(test)]
mod tests {
use super::*;
use crate::common::TestTransport;
use bytes::BufMut;
use test_log::test;
use super::*;
use crate::common::TestTransport;
/// Codec that always succeeds without altering the frame
#[derive(Clone, Debug, PartialEq, Eq)]
struct OkCodec;

@ -1,6 +1,7 @@
use super::{Frame, OwnedFrame};
use std::collections::VecDeque;
use super::{Frame, OwnedFrame};
/// Maximum size (in bytes) for saved frames (256MiB)
const MAX_BACKUP_SIZE: usize = 256 * 1024 * 1024;

@ -1,7 +1,9 @@
use super::Frame;
use dyn_clone::DynClone;
use std::io;
use dyn_clone::DynClone;
use super::Frame;
mod chain;
mod compression;
mod encryption;

@ -1,6 +1,7 @@
use super::{Codec, Frame};
use std::io;
use super::{Codec, Frame};
/// Represents a codec that chains together other codecs such that encoding will call the encode
/// methods of the underlying, chained codecs from left-to-right and decoding will call the decode
/// methods in reverse order
@ -59,9 +60,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
#[derive(Copy, Clone)]
struct TestCodec<'a> {
msg: &'a str,

@ -1,10 +1,12 @@
use super::{Codec, Frame};
use flate2::{
bufread::{DeflateDecoder, DeflateEncoder, GzDecoder, GzEncoder, ZlibDecoder, ZlibEncoder},
Compression,
use std::io::{self, Read};
use flate2::bufread::{
DeflateDecoder, DeflateEncoder, GzDecoder, GzEncoder, ZlibDecoder, ZlibEncoder,
};
use flate2::Compression;
use serde::{Deserialize, Serialize};
use std::io::{self, Read};
use super::{Codec, Frame};
/// Represents the level of compression to apply to data
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
@ -28,14 +30,12 @@ pub enum CompressionLevel {
}
impl CompressionLevel {
/// Applies no compression
pub const NONE: Self = Self::Zero;
/// Applies fastest compression
pub const FAST: Self = Self::One;
/// Applies best compression to reduce size (slowest)
pub const BEST: Self = Self::Nine;
/// Applies fastest compression
pub const FAST: Self = Self::One;
/// Applies no compression
pub const NONE: Self = Self::Zero;
}
impl Default for CompressionLevel {
@ -186,9 +186,10 @@ impl Codec for CompressionCodec {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
#[test]
fn encode_should_apply_appropriate_compression_algorithm() {
// Encode using DEFLATE and verify that the compression was as expected by decompressing

@ -1,7 +1,9 @@
use super::{Codec, Frame};
use derive_more::Display;
use std::{fmt, io};
use derive_more::Display;
use super::{Codec, Frame};
mod key;
pub use key::*;
@ -134,7 +136,8 @@ impl Codec for EncryptionCodec {
Ok(match self {
Self::XChaCha20Poly1305 { cipher } => {
use chacha20poly1305::{aead::Aead, XNonce};
use chacha20poly1305::aead::Aead;
use chacha20poly1305::XNonce;
let item = frame.into_item();
let nonce = XNonce::from_slice(&nonce_bytes);
@ -165,7 +168,8 @@ impl Codec for EncryptionCodec {
// of the frame to tease out the decrypted frame item
let item = match self {
Self::XChaCha20Poly1305 { cipher } => {
use chacha20poly1305::{aead::Aead, XNonce};
use chacha20poly1305::aead::Aead;
use chacha20poly1305::XNonce;
let nonce = XNonce::from_slice(&frame.as_item()[..nonce_size]);
cipher
.decrypt(nonce, &frame.as_item()[nonce_size..])
@ -179,9 +183,10 @@ impl Codec for EncryptionCodec {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
#[test]
fn encode_should_build_a_frame_containing_a_length_nonce_and_ciphertext() {
let ty = EncryptionType::XChaCha20Poly1305;
@ -198,7 +203,8 @@ mod tests {
// Manually build our key & cipher so we can decrypt the frame manually to ensure it is
// correct
let item = {
use chacha20poly1305::{aead::Aead, KeyInit, XChaCha20Poly1305, XNonce};
use chacha20poly1305::aead::Aead;
use chacha20poly1305::{KeyInit, XChaCha20Poly1305, XNonce};
let cipher = XChaCha20Poly1305::new_from_slice(&key).unwrap();
cipher
.decrypt(XNonce::from_slice(nonce), ciphertext)

@ -1,6 +1,9 @@
use std::fmt;
use std::str::FromStr;
use derive_more::{Display, Error};
use rand::{rngs::OsRng, RngCore};
use std::{fmt, str::FromStr};
use rand::rngs::OsRng;
use rand::RngCore;
#[derive(Debug, Display, Error)]
pub struct SecretKeyError;
@ -287,9 +290,10 @@ impl PartialEq<HeapSecretKey> for &str {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
#[test]
fn secret_key_should_be_able_to_be_generated() {
SecretKey::<0>::generate().unwrap_err();

@ -1,6 +1,7 @@
use super::{Codec, Frame};
use std::io;
use super::{Codec, Frame};
/// Represents a codec that does not alter the frame (synonymous with "plain text")
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct PlainCodec;

@ -1,5 +1,7 @@
use std::io;
use std::sync::Arc;
use super::{Codec, Frame};
use std::{io, sync::Arc};
/// Represents a codec that invokes one of two codecs based on the given predicate
#[derive(Debug, Default, PartialEq, Eq)]
@ -85,9 +87,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
#[derive(Copy, Clone)]
struct TestCodec<'a> {
msg: &'a str,

@ -1,8 +1,12 @@
use super::SecretKey32;
use p256::{ecdh::EphemeralSecret, PublicKey};
use std::convert::TryFrom;
use std::io;
use p256::ecdh::EphemeralSecret;
use p256::PublicKey;
use rand::rngs::OsRng;
use sha2::Sha256;
use std::{convert::TryFrom, io};
use super::SecretKey32;
mod pkb;
pub use pkb::PublicKeyBytes;

@ -1,6 +1,8 @@
use std::convert::TryFrom;
use std::io;
use p256::{EncodedPoint, PublicKey};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{convert::TryFrom, io};
/// Represents a wrapper around [`EncodedPoint`], and exists to
/// fix an issue with [`serde`] deserialization failing when

@ -1,11 +1,11 @@
use rand::{rngs::OsRng, RngCore};
use std::convert::{TryFrom, TryInto};
use std::ops::BitXor;
use std::str::FromStr;
use std::{fmt, io};
use rand::rngs::OsRng;
use rand::RngCore;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{
convert::{TryFrom, TryInto},
fmt, io,
ops::BitXor,
str::FromStr,
};
/// Friendly wrapper around a 32-byte array representing a salt
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]

@ -1,6 +1,7 @@
use bytes::{Buf, BufMut, BytesMut};
use std::borrow::Cow;
use bytes::{Buf, BufMut, BytesMut};
/// Represents a frame whose lifetime is static
pub type OwnedFrame = Frame<'static>;
@ -226,9 +227,10 @@ impl<'a, const N: usize> PartialEq<&'a [u8; N]> for Frame<'_> {
#[cfg(test)]
mod tests {
use super::*;
use test_log::test;
use super::*;
#[test]
fn write_should_succeed_when_item_is_zero_bytes() {
let frame = Frame::new(&[]);

@ -1,13 +1,11 @@
use super::{Interest, Ready, Reconnectable, Transport};
use std::io;
use std::sync::{Mutex, MutexGuard};
use async_trait::async_trait;
use std::{
io,
sync::{Mutex, MutexGuard},
};
use tokio::sync::mpsc::{
self,
error::{TryRecvError, TrySendError},
};
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
use tokio::sync::mpsc::{self};
use super::{Interest, Ready, Reconnectable, Transport};
/// Represents a [`Transport`] comprised of two inmemory channels
#[derive(Debug)]
@ -202,9 +200,10 @@ fn copy_and_store(
#[cfg(test)]
mod tests {
use test_log::test;
use super::*;
use crate::common::TransportExt;
use test_log::test;
#[test]
fn is_rx_closed_should_properly_reflect_if_internal_rx_channel_is_closed() {

@ -1,8 +1,11 @@
use super::{Interest, Ready, Reconnectable, Transport};
use std::net::IpAddr;
use std::{fmt, io};
use async_trait::async_trait;
use std::{fmt, io, net::IpAddr};
use tokio::net::{TcpStream, ToSocketAddrs};
use super::{Interest, Ready, Reconnectable, Transport};
/// Represents a [`Transport`] that leverages a TCP stream
pub struct TcpTransport {
pub(crate) addr: IpAddr,
@ -68,11 +71,15 @@ impl Transport for TcpTransport {
#[cfg(test)]
mod tests {
use super::*;
use crate::common::TransportExt;
use std::net::{Ipv6Addr, SocketAddr};
use test_log::test;
use tokio::{net::TcpListener, sync::oneshot, task::JoinHandle};
use tokio::net::TcpListener;
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use super::*;
use crate::common::TransportExt;
async fn find_ephemeral_addr() -> SocketAddr {
// Start a listener on a distinct port, get its port, and kill it

@ -1,7 +1,9 @@
use super::{Interest, Ready, Reconnectable, Transport};
use async_trait::async_trait;
use std::{fmt, io};
use async_trait::async_trait;
use super::{Interest, Ready, Reconnectable, Transport};
pub type TryReadFn = Box<dyn Fn(&mut [u8]) -> io::Result<usize> + Send + Sync>;
pub type TryWriteFn = Box<dyn Fn(&[u8]) -> io::Result<usize> + Send + Sync>;
pub type ReadyFn = Box<dyn Fn(Interest) -> io::Result<Ready> + Send + Sync>;

@ -1,11 +1,11 @@
use super::{Interest, Ready, Reconnectable, Transport};
use std::path::{Path, PathBuf};
use std::{fmt, io};
use async_trait::async_trait;
use std::{
fmt, io,
path::{Path, PathBuf},
};
use tokio::net::UnixStream;
use super::{Interest, Ready, Reconnectable, Transport};
/// Represents a [`Transport`] that leverages a Unix socket
pub struct UnixSocketTransport {
pub(crate) path: PathBuf,
@ -61,16 +61,15 @@ impl Transport for UnixSocketTransport {
#[cfg(test)]
mod tests {
use super::*;
use crate::common::TransportExt;
use tempfile::NamedTempFile;
use test_log::test;
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::UnixListener,
sync::oneshot,
task::JoinHandle,
};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::UnixListener;
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use super::*;
use crate::common::TransportExt;
async fn start_and_run_server(tx: oneshot::Sender<PathBuf>) -> io::Result<()> {
// Generate a socket path and delete the file after so there is nothing there

@ -1,9 +1,9 @@
use super::{Interest, Ready, Reconnectable, Transport};
use std::ffi::{OsStr, OsString};
use std::{fmt, io};
use async_trait::async_trait;
use std::{
ffi::{OsStr, OsString},
fmt, io,
};
use super::{Interest, Ready, Reconnectable, Transport};
mod pipe;
pub use pipe::NamedPipe;
@ -87,14 +87,13 @@ impl Transport for WindowsPipeTransport {
#[cfg(test)]
mod tests {
use test_log::test;
use tokio::net::windows::named_pipe::{NamedPipeServer, ServerOptions};
use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use super::*;
use crate::common::TransportExt;
use test_log::test;
use tokio::{
net::windows::named_pipe::{NamedPipeServer, ServerOptions},
sync::oneshot,
task::JoinHandle,
};
async fn start_and_run_server(tx: oneshot::Sender<String>) -> io::Result<()> {
let pipe = start_server(tx).await?;

@ -1,5 +1,8 @@
use std::ffi::OsStr;
use std::io;
use std::time::Duration;
use derive_more::{From, TryInto};
use std::{ffi::OsStr, io, time::Duration};
use tokio::net::windows::named_pipe::{ClientOptions, NamedPipeClient, NamedPipeServer};
// Equivalent to winapi::shared::winerror::ERROR_PIPE_BUSY

@ -1,10 +1,14 @@
use serde::{
de::{DeserializeOwned, Deserializer, Error as SerdeError, Visitor},
ser::Serializer,
Serialize,
};
use std::{fmt, future::Future, io, marker::PhantomData, str::FromStr, time::Duration};
use tokio::{sync::mpsc, task::JoinHandle};
use std::future::Future;
use std::marker::PhantomData;
use std::str::FromStr;
use std::time::Duration;
use std::{fmt, io};
use serde::de::{DeserializeOwned, Deserializer, Error as SerdeError, Visitor};
use serde::ser::Serializer;
use serde::Serialize;
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
pub fn serialize_to_vec<T: Serialize>(value: &T) -> io::Result<Vec<u8>> {
rmp_serde::encode::to_vec_named(value)
@ -142,9 +146,10 @@ mod tests {
use super::*;
mod timer {
use super::*;
use test_log::test;
use super::*;
#[test(tokio::test)]
async fn should_not_invoke_callback_regardless_of_time_if_not_started() {
let timer = Timer::new(Duration::default(), async {});

@ -5,6 +5,4 @@ pub mod server;
pub use client::{Client, ReconnectStrategy};
pub use server::Server;
pub use log;
pub use paste;
pub use {log, paste};

@ -1,19 +1,15 @@
use crate::{
client::Client,
common::{
authentication::{
msg::{Authentication, AuthenticationResponse},
AuthHandler,
},
ConnectionId, Destination, Map, Request,
},
manager::data::{
ConnectionInfo, ConnectionList, ManagerCapabilities, ManagerRequest, ManagerResponse,
},
};
use log::*;
use std::io;
use log::*;
use crate::client::Client;
use crate::common::authentication::msg::{Authentication, AuthenticationResponse};
use crate::common::authentication::AuthHandler;
use crate::common::{ConnectionId, Destination, Map, Request};
use crate::manager::data::{
ConnectionInfo, ConnectionList, ManagerCapabilities, ManagerRequest, ManagerResponse,
};
mod channel;
pub use channel::*;

@ -1,16 +1,15 @@
use crate::{
client::{Client, ClientConfig, UntypedClient},
common::{ConnectionId, FramedTransport, InmemoryTransport, UntypedRequest},
manager::data::{ManagerRequest, ManagerResponse},
};
use std::io;
use std::ops::{Deref, DerefMut};
use log::*;
use serde::{de::DeserializeOwned, Serialize};
use std::{
io,
ops::{Deref, DerefMut},
};
use serde::de::DeserializeOwned;
use serde::Serialize;
use tokio::task::JoinHandle;
use crate::client::{Client, ClientConfig, UntypedClient};
use crate::common::{ConnectionId, FramedTransport, InmemoryTransport, UntypedRequest};
use crate::manager::data::{ManagerRequest, ManagerResponse};
/// Represents a raw channel between a manager client and server. Underneath, this routes incoming
/// and outgoing data from a proxied server to an inmemory transport.
pub struct RawChannel {

@ -1,15 +1,15 @@
use super::ManagerCapabilityKind;
use std::cmp::Ordering;
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::ops::{BitAnd, BitOr, BitXor};
use std::str::FromStr;
use derive_more::{From, Into, IntoIterator};
use serde::{Deserialize, Serialize};
use std::{
cmp::Ordering,
collections::HashSet,
hash::{Hash, Hasher},
ops::{BitAnd, BitOr, BitXor},
str::FromStr,
};
use strum::{EnumMessage, IntoEnumIterator};
use super::ManagerCapabilityKind;
/// Set of supported capabilities for a manager
#[derive(Clone, Debug, From, Into, PartialEq, Eq, IntoIterator, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]

@ -1,6 +1,7 @@
use crate::common::{ConnectionId, Destination, Map};
use serde::{Deserialize, Serialize};
use crate::common::{ConnectionId, Destination, Map};
/// Information about a specific connection
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ConnectionInfo {

@ -1,10 +1,10 @@
use crate::common::{ConnectionId, Destination};
use std::collections::HashMap;
use std::ops::{Deref, DerefMut, Index, IndexMut};
use derive_more::IntoIterator;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
ops::{Deref, DerefMut, Index, IndexMut},
};
use crate::common::{ConnectionId, Destination};
/// Represents a list of information about active connections
#[derive(Clone, Debug, PartialEq, Eq, IntoIterator, Serialize, Deserialize)]

@ -1,11 +1,11 @@
use super::{ManagerAuthenticationId, ManagerChannelId};
use crate::common::{
authentication::msg::AuthenticationResponse, ConnectionId, Destination, Map, UntypedRequest,
};
use derive_more::IsVariant;
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumDiscriminants, EnumIter, EnumMessage, EnumString};
use super::{ManagerAuthenticationId, ManagerChannelId};
use crate::common::authentication::msg::AuthenticationResponse;
use crate::common::{ConnectionId, Destination, Map, UntypedRequest};
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, EnumDiscriminants, Serialize, Deserialize)]
#[strum_discriminants(derive(

@ -1,10 +1,10 @@
use serde::{Deserialize, Serialize};
use super::{
ConnectionInfo, ConnectionList, ManagerAuthenticationId, ManagerCapabilities, ManagerChannelId,
};
use crate::common::{
authentication::msg::Authentication, ConnectionId, Destination, UntypedResponse,
};
use serde::{Deserialize, Serialize};
use crate::common::authentication::msg::Authentication;
use crate::common::{ConnectionId, Destination, UntypedResponse};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", deny_unknown_fields, tag = "type")]

@ -1,16 +1,19 @@
use crate::{
common::{authentication::msg::AuthenticationResponse, ConnectionId, Destination, Map},
manager::{
ConnectionInfo, ConnectionList, ManagerAuthenticationId, ManagerCapabilities,
ManagerChannelId, ManagerRequest, ManagerResponse,
},
server::{Server, ServerCtx, ServerHandler},
};
use std::collections::HashMap;
use std::io;
use std::sync::Arc;
use async_trait::async_trait;
use log::*;
use std::{collections::HashMap, io, sync::Arc};
use tokio::sync::{oneshot, RwLock};
use crate::common::authentication::msg::AuthenticationResponse;
use crate::common::{ConnectionId, Destination, Map};
use crate::manager::{
ConnectionInfo, ConnectionList, ManagerAuthenticationId, ManagerCapabilities, ManagerChannelId,
ManagerRequest, ManagerResponse,
};
use crate::server::{Server, ServerCtx, ServerHandler};
mod authentication;
pub use authentication::*;
@ -183,9 +186,9 @@ pub struct DistantManagerServerConnection {
#[async_trait]
impl ServerHandler for ManagerServer {
type LocalData = DistantManagerServerConnection;
type Request = ManagerRequest;
type Response = ManagerResponse;
type LocalData = DistantManagerServerConnection;
async fn on_request(&self, ctx: ServerCtx<Self::Request, Self::Response, Self::LocalData>) {
let ServerCtx {
@ -315,12 +318,13 @@ impl ServerHandler for ManagerServer {
#[cfg(test)]
mod tests {
use tokio::sync::mpsc;
use super::*;
use crate::client::UntypedClient;
use crate::common::FramedTransport;
use crate::server::ServerReply;
use crate::{boxed_connect_handler, boxed_launch_handler};
use tokio::sync::mpsc;
fn test_config() -> Config {
Config {

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

Loading…
Cancel
Save