refactor: improve log

This commit is contained in:
Yujia Qiao 2022-01-01 23:52:59 +08:00
parent 9b3d2eb79a
commit 07cd606b63
No known key found for this signature in database
GPG Key ID: DC129173B148701B
2 changed files with 16 additions and 10 deletions

View File

@ -364,12 +364,14 @@ impl<T: 'static + Transport> ControlChannel<T> {
.with_context(|| format!("Failed to connect to the server: {}", &self.remote_addr))?; .with_context(|| format!("Failed to connect to the server: {}", &self.remote_addr))?;
// Send hello // Send hello
debug!("Sending hello");
let hello_send = let hello_send =
Hello::ControlChannelHello(CURRENT_PROTO_VRESION, self.digest[..].try_into().unwrap()); Hello::ControlChannelHello(CURRENT_PROTO_VRESION, self.digest[..].try_into().unwrap());
conn.write_all(&bincode::serialize(&hello_send).unwrap()) conn.write_all(&bincode::serialize(&hello_send).unwrap())
.await?; .await?;
// Read hello)) // Read hello))
debug!("Reading hello");
let nonce = match read_hello(&mut conn) let nonce = match read_hello(&mut conn)
.await .await
.with_context(|| "Failed to read hello from the server")? .with_context(|| "Failed to read hello from the server")?
@ -381,6 +383,7 @@ impl<T: 'static + Transport> ControlChannel<T> {
}; };
// Send auth // Send auth
debug!("Sending auth");
let mut concat = Vec::from(self.service.token.as_ref().unwrap().as_bytes()); let mut concat = Vec::from(self.service.token.as_ref().unwrap().as_bytes());
concat.extend_from_slice(&nonce); concat.extend_from_slice(&nonce);
@ -389,6 +392,7 @@ impl<T: 'static + Transport> ControlChannel<T> {
conn.write_all(&bincode::serialize(&auth).unwrap()).await?; conn.write_all(&bincode::serialize(&auth).unwrap()).await?;
// Read ack // Read ack
debug!("Reading ack");
match read_ack(&mut conn).await? { match read_ack(&mut conn).await? {
Ack::Ok => {} Ack::Ok => {}
v => { v => {
@ -444,6 +448,8 @@ impl ControlChannelHandle {
transport: Arc<T>, transport: Arc<T>,
) -> ControlChannelHandle { ) -> ControlChannelHandle {
let digest = protocol::digest(service.name.as_bytes()); let digest = protocol::digest(service.name.as_bytes());
info!("Starting {}", hex::encode(digest));
let (shutdown_tx, shutdown_rx) = oneshot::channel(); let (shutdown_tx, shutdown_rx) = oneshot::channel();
let mut s = ControlChannel { let mut s = ControlChannel {
digest, digest,

View File

@ -353,9 +353,6 @@ where
// and the connection pool task are created. // and the connection pool task are created.
#[instrument(skip_all, fields(service = %service.name))] #[instrument(skip_all, fields(service = %service.name))]
fn new(conn: T::Stream, service: ServerServiceConfig) -> ControlChannelHandle<T> { fn new(conn: T::Stream, service: ServerServiceConfig) -> ControlChannelHandle<T> {
// Save the name string for logging
let name = service.name.clone();
// Create a shutdown channel // Create a shutdown channel
let (shutdown_tx, shutdown_rx) = broadcast::channel::<bool>(1); let (shutdown_tx, shutdown_rx) = broadcast::channel::<bool>(1);
@ -407,11 +404,14 @@ where
}; };
// Run the control channel // Run the control channel
tokio::spawn(async move { tokio::spawn(
if let Err(err) = ch.run().await { async move {
error!(%name, "{}", err); if let Err(err) = ch.run().await {
error!("{:?}", err);
}
} }
}); .instrument(Span::current()),
);
ControlChannelHandle { ControlChannelHandle {
_shutdown_tx: shutdown_tx, _shutdown_tx: shutdown_tx,
@ -513,10 +513,10 @@ fn tcp_listen_and_send(
} }
Ok((incoming, addr)) => { Ok((incoming, addr)) => {
// For every visitor, request to create a data channel // For every visitor, request to create a data channel
if let Err(e) = data_ch_req_tx.send(true) { if let Err(e) = data_ch_req_tx.send(true).with_context(|| "Failed to send data chan create request") {
// An error indicates the control channel is broken // An error indicates the control channel is broken
// So break the loop // So break the loop
error!("{}", e); error!("{:?}", e);
break; break;
} }
@ -534,7 +534,7 @@ fn tcp_listen_and_send(
} }
} }
} }
}); }.instrument(Span::current()));
rx rx
} }