Add spacing and change to DISTANT CONNECT from DISTANT DATA

pull/96/head
Chip Senkbeil 3 years ago
parent d4312649e6
commit 4050a421bc
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -397,7 +397,7 @@ impl LspContent {
let key = key let key = key
.as_str() .as_str()
.ok_or(LspSessionInfoError::InvalidSessionInfoParams)?; .ok_or(LspSessionInfoError::InvalidSessionInfoParams)?;
Ok(format!("DISTANT DATA {} {} {}", host, port, key).parse()?) Ok(format!("DISTANT CONNECT {} {} {}", host, port, key).parse()?)
} }
_ => Err(LspSessionInfoError::MissingSessionInfoParams), _ => Err(LspSessionInfoError::MissingSessionInfoParams),
} }

@ -50,13 +50,13 @@ impl FromStr for SessionInfo {
type Err = SessionInfoParseError; type Err = SessionInfoParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut tokens = s.split(' ').take(5); let mut tokens = s.trim().split(' ').take(5);
// First, validate that we have the appropriate prefix // First, validate that we have the appropriate prefix
if tokens.next().ok_or(SessionInfoParseError::BadPrefix)? != "DISTANT" { if tokens.next().ok_or(SessionInfoParseError::BadPrefix)? != "DISTANT" {
return Err(SessionInfoParseError::BadPrefix); return Err(SessionInfoParseError::BadPrefix);
} }
if tokens.next().ok_or(SessionInfoParseError::BadPrefix)? != "DATA" { if tokens.next().ok_or(SessionInfoParseError::BadPrefix)? != "CONNECT" {
return Err(SessionInfoParseError::BadPrefix); return Err(SessionInfoParseError::BadPrefix);
} }
@ -101,7 +101,7 @@ impl SessionInfo {
let host = env::var("DISTANT_HOST").map_err(to_err)?; let host = env::var("DISTANT_HOST").map_err(to_err)?;
let port = env::var("DISTANT_PORT").map_err(to_err)?; let port = env::var("DISTANT_PORT").map_err(to_err)?;
let key = env::var("DISTANT_KEY").map_err(to_err)?; let key = env::var("DISTANT_KEY").map_err(to_err)?;
Ok(format!("DISTANT DATA {} {} {}", host, port, key).parse()?) Ok(format!("DISTANT CONNECT {} {} {}", host, port, key).parse()?)
} }
/// Loads session from the next line available in this program's stdin /// Loads session from the next line available in this program's stdin
@ -138,10 +138,10 @@ impl SessionInfo {
} }
/// Converts to unprotected string that exposes the key in the form of /// Converts to unprotected string that exposes the key in the form of
/// `DISTANT DATA <host> <port> <key>` /// `DISTANT CONNECT <host> <port> <key>`
pub fn to_unprotected_string(&self) -> String { pub fn to_unprotected_string(&self) -> String {
format!( format!(
"DISTANT DATA {} {} {}", "DISTANT CONNECT {} {} {}",
self.host, self.host,
self.port, self.port,
self.key.unprotected_to_hex_key() self.key.unprotected_to_hex_key()

@ -355,7 +355,7 @@ impl FromStr for BindAddress {
)] )]
#[strum(serialize_all = "snake_case")] #[strum(serialize_all = "snake_case")]
pub enum SessionOutput { pub enum SessionOutput {
/// Session is in a file in the form of `DISTANT DATA <host> <port> <key>` /// Session is in a file in the form of `DISTANT CONNECT <host> <port> <key>`
File, File,
/// Special scenario where the session is not shared but is instead kept within the /// Special scenario where the session is not shared but is instead kept within the
@ -364,7 +364,7 @@ pub enum SessionOutput {
Keep, Keep,
/// Session is stored and retrieved over anonymous pipes (stdout/stdin) /// Session is stored and retrieved over anonymous pipes (stdout/stdin)
/// in form of `DISTANT DATA <host> <port> <key>` /// in form of `DISTANT CONNECT <host> <port> <key>`
Pipe, Pipe,
/// Special scenario where the session is not shared but is instead kept within the /// Special scenario where the session is not shared but is instead kept within the
@ -409,11 +409,11 @@ pub enum SessionInput {
/// * `DISTANT_KEY=<key>` /// * `DISTANT_KEY=<key>`
Environment, Environment,
/// Session is in a file in the form of `DISTANT DATA <host> <port> <key>` /// Session is in a file in the form of `DISTANT CONNECT <host> <port> <key>`
File, File,
/// Session is stored and retrieved over anonymous pipes (stdout/stdin) /// Session is stored and retrieved over anonymous pipes (stdout/stdin)
/// in form of `DISTANT DATA <host> <port> <key>` /// in form of `DISTANT CONNECT <host> <port> <key>`
Pipe, Pipe,
/// Session is stored and retrieved from the initializeOptions of the initialize request /// Session is stored and retrieved from the initializeOptions of the initialize request

@ -7,7 +7,10 @@ use distant_core::{
DistantServer, DistantServerOptions, SecretKey32, UnprotectedToHexKey, XChaCha20Poly1305Codec, DistantServer, DistantServerOptions, SecretKey32, UnprotectedToHexKey, XChaCha20Poly1305Codec,
}; };
use log::*; use log::*;
use tokio::{io, task::JoinError}; use tokio::{
io::{self, AsyncWriteExt},
task::JoinError,
};
#[derive(Debug, Display, Error, From)] #[derive(Debug, Display, Error, From)]
pub enum Error { pub enum Error {
@ -105,7 +108,11 @@ async fn run_async(cmd: ListenSubcommand, _opt: CommonOpt, is_forked: bool) -> R
.await?; .await?;
// Print information about port, key, etc. // Print information about port, key, etc.
println!("DISTANT DATA -- {} {}", port, key_hex_string); // NOTE: Following mosh approach of printing to make sure there's no garbage floating around
println!("\r");
println!("DISTANT CONNECT -- {} {}", port, key_hex_string);
println!("\r");
io::stdout().flush().await?;
// For the child, we want to fully disconnect it from pipes, which we do now // For the child, we want to fully disconnect it from pipes, which we do now
#[cfg(unix)] #[cfg(unix)]

Loading…
Cancel
Save