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 derive_more::{Display, Error, From};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
@ -1,5 +1,5 @@
|
|||||||
use super::{RemoteProcess, RemoteProcessError, RemoteStderr, RemoteStdin, RemoteStdout};
|
use super::{RemoteProcess, RemoteProcessError, RemoteStderr, RemoteStdin, RemoteStdout};
|
||||||
use crate::core::{client::Session, net::DataStream};
|
use crate::{client::Session, net::DataStream};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Write,
|
fmt::Write,
|
||||||
io::{self, Cursor, Read},
|
io::{self, Cursor, Read},
|
@ -1,4 +1,4 @@
|
|||||||
use crate::core::{
|
use crate::{
|
||||||
client::Session,
|
client::Session,
|
||||||
constants::CLIENT_BROADCAST_CHANNEL_CAPACITY,
|
constants::CLIENT_BROADCAST_CHANNEL_CAPACITY,
|
||||||
data::{Request, RequestData, Response, ResponseData},
|
data::{Request, RequestData, Response, ResponseData},
|
@ -1,11 +1,6 @@
|
|||||||
use std::{future::Future, time::Duration};
|
use std::{future::Future, time::Duration};
|
||||||
use tokio::{io, time};
|
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
|
// Wraps a future in a tokio timeout call, transforming the error into
|
||||||
// an io error
|
// an io error
|
||||||
pub async fn timeout<T, F>(d: Duration, f: F) -> io::Result<T>
|
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},
|
constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_MILLIS},
|
||||||
data::{
|
data::{
|
||||||
self, DirEntry, FileType, Request, RequestData, Response, ResponseData, RunningProcess,
|
self, DirEntry, FileType, Request, RequestData, Response, ResponseData, RunningProcess,
|
@ -1,4 +1,4 @@
|
|||||||
use crate::core::{
|
use crate::{
|
||||||
client::Session,
|
client::Session,
|
||||||
constants::CLIENT_BROADCAST_CHANNEL_CAPACITY,
|
constants::CLIENT_BROADCAST_CHANNEL_CAPACITY,
|
||||||
data::{Request, RequestData, Response, ResponseData},
|
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};
|
use std::{io, sync::Arc};
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 100;
|
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};
|
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
|
/// Represents the maximum size (in bytes) that data will be read from pipes
|
||||||
/// per individual `read` call
|
/// per individual `read` call
|
||||||
///
|
///
|
||||||
/// Current setting is 16k size
|
/// Current setting is 16k size
|
||||||
pub const MAX_PIPE_CHUNK_SIZE: usize = 16384;
|
pub const MAX_PIPE_CHUNK_SIZE: usize = 16384;
|
||||||
|
|
||||||
/// Duration in milliseconds to sleep between reading stdout/stderr chunks
|
/// Capacity associated with a server receiving messages from a connection
|
||||||
/// to avoid sending many small messages to clients
|
/// with a client
|
||||||
pub const READ_PAUSE_MILLIS: u64 = 50;
|
pub const SERVER_CONN_MSG_CAPACITY: usize = 10000;
|
||||||
|
|
||||||
/// Represents the length of the salt to use for encryption
|
|
||||||
pub const SALT_LEN: usize = 16;
|
|
||||||
|
|
||||||
/// Test-only constants
|
/// Represents maximum time (in milliseconds) to wait on a network request
|
||||||
#[cfg(test)]
|
/// before failing (0 meaning indefinitely)
|
||||||
pub mod test {
|
pub const TIMEOUT: usize = 15000;
|
||||||
pub const BUFFER_SIZE: usize = 100;
|
|
||||||
pub const TENANT: &str = "test-tenant";
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
pub static ref TIMEOUT_STR: String = TIMEOUT.to_string();
|
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
|
/// Exit codes following https://www.freebsd.org/cgi/man.cgi?query=sysexits&sektion=3
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
@ -1,15 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
cli::{subcommand, ExitCodeError},
|
|
||||||
core::{
|
|
||||||
constants::{
|
constants::{
|
||||||
SERVER_CONN_MSG_CAPACITY_STR, SESSION_FILE_PATH_STR, SESSION_SOCKET_PATH_STR,
|
SERVER_CONN_MSG_CAPACITY_STR, SESSION_FILE_PATH_STR, SESSION_SOCKET_PATH_STR, TIMEOUT_STR,
|
||||||
TIMEOUT_STR,
|
|
||||||
},
|
|
||||||
data::RequestData,
|
|
||||||
server::PortRange,
|
|
||||||
},
|
},
|
||||||
|
exit::ExitCodeError,
|
||||||
|
subcommand,
|
||||||
};
|
};
|
||||||
use derive_more::{Display, Error, From, IsVariant};
|
use derive_more::{Display, Error, From, IsVariant};
|
||||||
|
use distant_core::{PortRange, RequestData};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
@ -1,7 +1,5 @@
|
|||||||
use crate::{
|
use crate::opt::Format;
|
||||||
cli::Format,
|
use distant_core::{data::Error, Response, ResponseData};
|
||||||
core::data::{Error, Response, ResponseData},
|
|
||||||
};
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
@ -1,11 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
cli::{
|
exit::{ExitCode, ExitCodeError},
|
||||||
opt::{CommonOpt, ConvertToIpAddrError, ListenSubcommand},
|
opt::{CommonOpt, ConvertToIpAddrError, ListenSubcommand},
|
||||||
ExitCode, ExitCodeError,
|
|
||||||
},
|
|
||||||
core::server::DistantServer,
|
|
||||||
};
|
};
|
||||||
use derive_more::{Display, Error, From};
|
use derive_more::{Display, Error, From};
|
||||||
|
use distant_core::DistantServer;
|
||||||
use fork::{daemon, Fork};
|
use fork::{daemon, Fork};
|
||||||
use log::*;
|
use log::*;
|
||||||
use tokio::{io, task::JoinError};
|
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