Add more logging to better isolate lockup

pull/146/head
Chip Senkbeil 2 years ago
parent 56150af49e
commit 431949af50
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -57,7 +57,7 @@ impl<A: AuthHandler + Send> TcpClientBuilder<A> {
// Establish our framed transport, perform a handshake to set the codec, and do
// authentication to ensure the connection can be used
let mut transport = FramedTransport::<_>::plain(transport);
let mut transport = FramedTransport::plain(transport);
transport.client_handshake().await?;
transport.authenticate(auth_handler).await?;

@ -58,7 +58,7 @@ impl<A: AuthHandler + Send> UnixSocketClientBuilder<A> {
// Establish our framed transport, perform a handshake to set the codec, and do
// authentication to ensure the connection can be used
let mut transport = FramedTransport::<_>::plain(transport);
let mut transport = FramedTransport::plain(transport);
transport.client_handshake().await?;
transport.authenticate(auth_handler).await?;

@ -80,7 +80,7 @@ impl<A: AuthHandler + Send> WindowsPipeClientBuilder<A> {
// Establish our framed transport, perform a handshake to set the codec, and do
// authentication to ensure the connection can be used
let mut transport = FramedTransport::<_>::plain(transport);
let mut transport = FramedTransport::plain(transport);
transport.client_handshake().await?;
transport.authenticate(auth_handler).await?;

@ -84,6 +84,7 @@ mod tests {
};
use async_trait::async_trait;
use std::net::{Ipv6Addr, SocketAddr};
use test_log::test;
pub struct TestServerHandler;
@ -131,7 +132,7 @@ mod tests {
}
}
#[tokio::test]
#[test(tokio::test)]
async fn should_invoke_handler_upon_receiving_a_request() {
let server = Server::tcp()
.handler(TestServerHandler)

@ -86,6 +86,7 @@ mod tests {
};
use async_trait::async_trait;
use tempfile::NamedTempFile;
use test_log::test;
pub struct TestServerHandler;
@ -133,7 +134,7 @@ mod tests {
}
}
#[tokio::test]
#[test(tokio::test)]
async fn should_invoke_handler_upon_receiving_a_request() {
// Generate a socket path and delete the file after so there is nothing there
let path = NamedTempFile::new()

@ -100,6 +100,7 @@ mod tests {
Client, ConnectionCtx, Request, ServerCtx,
};
use async_trait::async_trait;
use test_log::test;
pub struct TestServerHandler;
@ -147,7 +148,7 @@ mod tests {
}
}
#[tokio::test]
#[test(tokio::test)]
async fn should_invoke_handler_upon_receiving_a_request() {
let server = Server::windows_pipe()
.handler(TestServerHandler)

@ -377,6 +377,13 @@ impl<T: Transport> FramedTransport<T> {
}};
}
// Define a label to distinguish log output for client and server
let log_label = if handshake.is_client() {
"Handshake | Client"
} else {
"Handshake | Server"
};
// Determine compression and encryption to apply to framed transport
let choice = match handshake {
Handshake::Client {
@ -385,11 +392,11 @@ impl<T: Transport> FramedTransport<T> {
preferred_encryption_type,
} => {
// Receive options from the server and pick one
debug!("[Handshake] Client waiting on server options");
debug!("[{log_label}] Waiting on options");
let options = next_frame_as!(Options);
// Choose a compression and encryption option from the options
debug!("[Handshake] Client selecting from server options: {options:#?}");
debug!("[{log_label}] Selecting from options: {options:#?}");
let choice = Choice {
// Use preferred compression if available, otherwise default to no compression
// to avoid choosing something poor
@ -413,7 +420,7 @@ impl<T: Transport> FramedTransport<T> {
};
// Report back to the server the choice
debug!("[Handshake] Client reporting choice: {choice:#?}");
debug!("[{log_label}] Reporting choice: {choice:#?}");
write_frame!(choice);
choice
@ -428,16 +435,16 @@ impl<T: Transport> FramedTransport<T> {
};
// Send options to the client
debug!("[Handshake] Server sending options: {options:#?}");
debug!("[{log_label}] Sending options: {options:#?}");
write_frame!(options);
// Get client's response with selected compression and encryption
debug!("[Handshake] Server waiting on client choice");
debug!("[{log_label}] Waiting on choice");
next_frame_as!(Choice)
}
};
debug!("[Handshake] Building compression & encryption codecs based on {choice:#?}");
debug!("[{log_label}] Building compression & encryption codecs based on {choice:#?}");
let compression_level = choice.compression_level.unwrap_or_default();
// Acquire a codec for the compression type
@ -461,6 +468,7 @@ impl<T: Transport> FramedTransport<T> {
salt: Salt,
}
debug!("[{log_label}] Exchanging public key and salt");
let exchange = KeyExchange::default();
write_frame!(KeyExchangeData {
public_key: exchange.pk_bytes(),
@ -471,7 +479,10 @@ impl<T: Transport> FramedTransport<T> {
// also wants a 32-byte key. Once we introduce new encryption algorithms that
// are not using 32-byte keys, the key exchange will need to support deriving
// other length keys.
trace!("[{log_label}] Waiting on public key and salt from other side");
let data = next_frame_as!(KeyExchangeData);
trace!("[{log_label}] Deriving shared secret key");
let key = exchange.derive_shared_secret(data.public_key, data.salt)?;
Some(ty.new_codec(key.unprotected_as_bytes())?)
}
@ -479,6 +490,7 @@ impl<T: Transport> FramedTransport<T> {
};
// Bundle our compression and encryption codecs into a single, chained codec
trace!("[{log_label}] Bundling codecs");
let codec: BoxedCodec = match (compression_codec, encryption_codec) {
// If we have both encryption and compression, do the encryption first and then
// compress in order to get smallest result

@ -44,4 +44,14 @@ impl Handshake {
encryption_types: EncryptionType::known_variants().to_vec(),
}
}
/// Returns true if handshake is from client-side
pub fn is_client(&self) -> bool {
matches!(self, Self::Client { .. })
}
/// Returns true if handshake is from server-side
pub fn is_server(&self) -> bool {
matches!(self, Self::Server { .. })
}
}

Loading…
Cancel
Save