mirror of https://github.com/rapiz1/rathole.git
refactor: improve log
This commit is contained in:
parent
9b3d2eb79a
commit
07cd606b63
|
@ -364,12 +364,14 @@ impl<T: 'static + Transport> ControlChannel<T> {
|
|||
.with_context(|| format!("Failed to connect to the server: {}", &self.remote_addr))?;
|
||||
|
||||
// Send hello
|
||||
debug!("Sending hello");
|
||||
let hello_send =
|
||||
Hello::ControlChannelHello(CURRENT_PROTO_VRESION, self.digest[..].try_into().unwrap());
|
||||
conn.write_all(&bincode::serialize(&hello_send).unwrap())
|
||||
.await?;
|
||||
|
||||
// Read hello))
|
||||
debug!("Reading hello");
|
||||
let nonce = match read_hello(&mut conn)
|
||||
.await
|
||||
.with_context(|| "Failed to read hello from the server")?
|
||||
|
@ -381,6 +383,7 @@ impl<T: 'static + Transport> ControlChannel<T> {
|
|||
};
|
||||
|
||||
// Send auth
|
||||
debug!("Sending auth");
|
||||
let mut concat = Vec::from(self.service.token.as_ref().unwrap().as_bytes());
|
||||
concat.extend_from_slice(&nonce);
|
||||
|
||||
|
@ -389,6 +392,7 @@ impl<T: 'static + Transport> ControlChannel<T> {
|
|||
conn.write_all(&bincode::serialize(&auth).unwrap()).await?;
|
||||
|
||||
// Read ack
|
||||
debug!("Reading ack");
|
||||
match read_ack(&mut conn).await? {
|
||||
Ack::Ok => {}
|
||||
v => {
|
||||
|
@ -444,6 +448,8 @@ impl ControlChannelHandle {
|
|||
transport: Arc<T>,
|
||||
) -> ControlChannelHandle {
|
||||
let digest = protocol::digest(service.name.as_bytes());
|
||||
|
||||
info!("Starting {}", hex::encode(digest));
|
||||
let (shutdown_tx, shutdown_rx) = oneshot::channel();
|
||||
let mut s = ControlChannel {
|
||||
digest,
|
||||
|
|
|
@ -353,9 +353,6 @@ where
|
|||
// and the connection pool task are created.
|
||||
#[instrument(skip_all, fields(service = %service.name))]
|
||||
fn new(conn: T::Stream, service: ServerServiceConfig) -> ControlChannelHandle<T> {
|
||||
// Save the name string for logging
|
||||
let name = service.name.clone();
|
||||
|
||||
// Create a shutdown channel
|
||||
let (shutdown_tx, shutdown_rx) = broadcast::channel::<bool>(1);
|
||||
|
||||
|
@ -407,11 +404,14 @@ where
|
|||
};
|
||||
|
||||
// Run the control channel
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = ch.run().await {
|
||||
error!(%name, "{}", err);
|
||||
tokio::spawn(
|
||||
async move {
|
||||
if let Err(err) = ch.run().await {
|
||||
error!("{:?}", err);
|
||||
}
|
||||
}
|
||||
});
|
||||
.instrument(Span::current()),
|
||||
);
|
||||
|
||||
ControlChannelHandle {
|
||||
_shutdown_tx: shutdown_tx,
|
||||
|
@ -513,10 +513,10 @@ fn tcp_listen_and_send(
|
|||
}
|
||||
Ok((incoming, addr)) => {
|
||||
// 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
|
||||
// So break the loop
|
||||
error!("{}", e);
|
||||
error!("{:?}", e);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -534,7 +534,7 @@ fn tcp_listen_and_send(
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}.instrument(Span::current()));
|
||||
|
||||
rx
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue