mirror of https://github.com/chipsenkbeil/distant
Split distant into distant-core and distant (bin)
parent
156fe50423
commit
df81894785
@ -0,0 +1,35 @@
|
||||
[package]
|
||||
name = "distant-core"
|
||||
description = "Core library for distant, enabling operation on a remote computer through file and process manipulation"
|
||||
categories = ["network-programming"]
|
||||
version = "0.13.0"
|
||||
authors = ["Chip Senkbeil <chip@senkbeil.org>"]
|
||||
edition = "2018"
|
||||
homepage = "https://github.com/chipsenkbeil/distant"
|
||||
repository = "https://github.com/chipsenkbeil/distant"
|
||||
readme = "README.md"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
bytes = "1.0.1"
|
||||
derive_more = { version = "0.99.16", default-features = false, features = ["display", "from", "error", "is_variant"] }
|
||||
futures = "0.3.16"
|
||||
hex = "0.4.3"
|
||||
k256 = { version = "0.9.6", features = ["ecdh"] }
|
||||
lazy_static = "1.4.0"
|
||||
log = "0.4.14"
|
||||
orion = "0.16.0"
|
||||
rand = { version = "0.8.4", features = ["getrandom"] }
|
||||
serde = { version = "1.0.126", features = ["derive"] }
|
||||
serde_cbor = "0.11.1"
|
||||
serde_json = "1.0.64"
|
||||
strum = { version = "0.21.0", features = ["derive"] }
|
||||
tokio = { version = "1.9.0", features = ["full"] }
|
||||
tokio-util = { version = "0.6.7", features = ["codec"] }
|
||||
walkdir = "2.3.2"
|
||||
|
||||
# Optional dependencies based on features
|
||||
structopt = { version = "0.3.22", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.2.0"
|
@ -1,4 +1,4 @@
|
||||
use crate::core::client::{SessionInfo, SessionInfoParseError};
|
||||
use crate::client::{SessionInfo, SessionInfoParseError};
|
||||
use derive_more::{Display, Error, From};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
@ -1,5 +1,5 @@
|
||||
use super::{RemoteProcess, RemoteProcessError, RemoteStderr, RemoteStdin, RemoteStdout};
|
||||
use crate::core::{client::Session, net::DataStream};
|
||||
use crate::{client::Session, net::DataStream};
|
||||
use std::{
|
||||
fmt::Write,
|
||||
io::{self, Cursor, Read},
|
@ -1,4 +1,4 @@
|
||||
use crate::core::{
|
||||
use crate::{
|
||||
client::Session,
|
||||
constants::CLIENT_BROADCAST_CHANNEL_CAPACITY,
|
||||
data::{Request, RequestData, Response, ResponseData},
|
@ -1,11 +1,6 @@
|
||||
use std::{future::Future, time::Duration};
|
||||
use tokio::{io, time};
|
||||
|
||||
// Generates a new tenant name
|
||||
pub fn new_tenant() -> String {
|
||||
format!("tenant_{}{}", rand::random::<u16>(), rand::random::<u8>())
|
||||
}
|
||||
|
||||
// Wraps a future in a tokio timeout call, transforming the error into
|
||||
// an io error
|
||||
pub async fn timeout<T, F>(d: Duration, f: F) -> io::Result<T>
|
@ -0,0 +1,23 @@
|
||||
/// Capacity associated with a client broadcasting its received messages that
|
||||
/// do not have a callback associated
|
||||
pub const CLIENT_BROADCAST_CHANNEL_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_MILLIS: u64 = 50;
|
||||
|
||||
/// Represents the length of the salt to use for encryption
|
||||
pub const SALT_LEN: usize = 16;
|
||||
|
||||
/// Test-only constants
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
pub const BUFFER_SIZE: usize = 100;
|
||||
pub const TENANT: &str = "test-tenant";
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
mod client;
|
||||
pub use client::{
|
||||
LspContent, LspContentParseError, LspData, LspDataParseError, LspHeader, LspHeaderParseError,
|
||||
LspSessionInfoError, RemoteLspProcess, RemoteLspStderr, RemoteLspStdin, RemoteLspStdout,
|
||||
RemoteProcess, RemoteProcessError, RemoteStderr, RemoteStdin, RemoteStdout, Session,
|
||||
SessionInfo, SessionInfoFile, SessionInfoParseError,
|
||||
};
|
||||
|
||||
mod constants;
|
||||
|
||||
mod net;
|
||||
pub use net::{
|
||||
DataStream, InmemoryStream, InmemoryStreamReadHalf, InmemoryStreamWriteHalf, Listener,
|
||||
SecretKey, Transport, TransportError, TransportReadHalf, TransportWriteHalf,
|
||||
};
|
||||
|
||||
pub mod data;
|
||||
pub use data::{Request, RequestData, Response, ResponseData};
|
||||
|
||||
mod server;
|
||||
pub use server::{DistantServer, PortRange, RelayServer};
|
@ -1,4 +1,4 @@
|
||||
use crate::core::{
|
||||
use crate::{
|
||||
constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_MILLIS},
|
||||
data::{
|
||||
self, DirEntry, FileType, Request, RequestData, Response, ResponseData, RunningProcess,
|
@ -1,4 +1,4 @@
|
||||
use crate::core::{
|
||||
use crate::{
|
||||
client::Session,
|
||||
constants::CLIENT_BROADCAST_CHANNEL_CAPACITY,
|
||||
data::{Request, RequestData, Response, ResponseData},
|
@ -1,4 +1,4 @@
|
||||
use distant::net::{Transport, TransportError, InmemoryStream, SecretKey};
|
||||
use distant_core::{Transport, TransportError, InmemoryStream, SecretKey};
|
||||
use std::{io, sync::Arc};
|
||||
|
||||
const BUFFER_SIZE: usize = 100;
|
@ -1,13 +0,0 @@
|
||||
mod buf;
|
||||
mod exit;
|
||||
mod link;
|
||||
mod opt;
|
||||
mod output;
|
||||
mod session;
|
||||
mod stdin;
|
||||
mod subcommand;
|
||||
|
||||
pub use exit::{ExitCode, ExitCodeError};
|
||||
pub use opt::*;
|
||||
pub use output::ResponseOut;
|
||||
pub use session::CliSession;
|
@ -1,36 +1,18 @@
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
/// Represents maximum time (in milliseconds) to wait on a network request
|
||||
/// before failing (0 meaning indefinitely)
|
||||
pub const TIMEOUT: usize = 15000;
|
||||
|
||||
/// Capacity associated with a client broadcasting its received messages that
|
||||
/// do not have a callback associated
|
||||
pub const CLIENT_BROADCAST_CHANNEL_CAPACITY: usize = 10000;
|
||||
|
||||
/// Capacity associated with a server receiving messages from a connection
|
||||
/// with a client
|
||||
pub const SERVER_CONN_MSG_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_MILLIS: u64 = 50;
|
||||
|
||||
/// Represents the length of the salt to use for encryption
|
||||
pub const SALT_LEN: usize = 16;
|
||||
/// Capacity associated with a server receiving messages from a connection
|
||||
/// with a client
|
||||
pub const SERVER_CONN_MSG_CAPACITY: usize = 10000;
|
||||
|
||||
/// Test-only constants
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
pub const BUFFER_SIZE: usize = 100;
|
||||
pub const TENANT: &str = "test-tenant";
|
||||
}
|
||||
/// Represents maximum time (in milliseconds) to wait on a network request
|
||||
/// before failing (0 meaning indefinitely)
|
||||
pub const TIMEOUT: usize = 15000;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref TIMEOUT_STR: String = TIMEOUT.to_string();
|
@ -1,5 +0,0 @@
|
||||
pub mod client;
|
||||
pub mod constants;
|
||||
pub mod data;
|
||||
pub mod net;
|
||||
pub mod server;
|
@ -1,4 +1,4 @@
|
||||
use crate::core::{client::RemoteProcessError, net::TransportError};
|
||||
use distant_core::{RemoteProcessError, TransportError};
|
||||
|
||||
/// Exit codes following https://www.freebsd.org/cgi/man.cgi?query=sysexits&sektion=3
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
@ -1,15 +1,12 @@
|
||||
use crate::{
|
||||
cli::{subcommand, ExitCodeError},
|
||||
core::{
|
||||
constants::{
|
||||
SERVER_CONN_MSG_CAPACITY_STR, SESSION_FILE_PATH_STR, SESSION_SOCKET_PATH_STR,
|
||||
TIMEOUT_STR,
|
||||
},
|
||||
data::RequestData,
|
||||
server::PortRange,
|
||||
constants::{
|
||||
SERVER_CONN_MSG_CAPACITY_STR, SESSION_FILE_PATH_STR, SESSION_SOCKET_PATH_STR, TIMEOUT_STR,
|
||||
},
|
||||
exit::ExitCodeError,
|
||||
subcommand,
|
||||
};
|
||||
use derive_more::{Display, Error, From, IsVariant};
|
||||
use distant_core::{PortRange, RequestData};
|
||||
use lazy_static::lazy_static;
|
||||
use std::{
|
||||
env,
|
@ -1,7 +1,5 @@
|
||||
use crate::{
|
||||
cli::Format,
|
||||
core::data::{Error, Response, ResponseData},
|
||||
};
|
||||
use crate::opt::Format;
|
||||
use distant_core::{data::Error, Response, ResponseData};
|
||||
use log::*;
|
||||
use std::io;
|
||||
|
@ -1,11 +1,9 @@
|
||||
use crate::{
|
||||
cli::{
|
||||
opt::{CommonOpt, ConvertToIpAddrError, ListenSubcommand},
|
||||
ExitCode, ExitCodeError,
|
||||
},
|
||||
core::server::DistantServer,
|
||||
exit::{ExitCode, ExitCodeError},
|
||||
opt::{CommonOpt, ConvertToIpAddrError, ListenSubcommand},
|
||||
};
|
||||
use derive_more::{Display, Error, From};
|
||||
use distant_core::DistantServer;
|
||||
use fork::{daemon, Fork};
|
||||
use log::*;
|
||||
use tokio::{io, task::JoinError};
|
@ -0,0 +1,4 @@
|
||||
// Generates a new tenant name
|
||||
pub fn new_tenant() -> String {
|
||||
format!("tenant_{}{}", rand::random::<u16>(), rand::random::<u8>())
|
||||
}
|
Loading…
Reference in New Issue