Skip to content

Commit

Permalink
🎨 reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Reverier-Xu committed Dec 18, 2024
1 parent 54311c8 commit a9f193c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
6 changes: 5 additions & 1 deletion wsrx/src/cli/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ async fn heartbeat_watchdog(interval: u64) {
continue;
}
let last_heartbeat = last_heartbeat.unwrap();
if Utc::now().signed_duration_since(*last_heartbeat).num_seconds() > interval as i64 {
if Utc::now()
.signed_duration_since(*last_heartbeat)
.num_seconds()
> interval as i64
{
error!("Heartbeat timeout, last active at {last_heartbeat}, exiting.");
std::process::exit(0);
} else {
Expand Down
33 changes: 17 additions & 16 deletions wsrx/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::process;

use clap::{command, Parser};
use rustls::crypto;
use std::process;
use tracing::{error, info, warn};

mod cli;

/// wsrx is a controlled WS-TCP tunnel for Ret2Shell platform.
#[derive(Parser)]
#[command(name = "wsrx")]
#[command(bin_name = "wsrx")]
#[command(name = "wsrx", bin_name = "wsrx", version, about)]
enum WsrxCli {
#[clap(alias("d"))]
/// Launch wsrx daemon.
Expand All @@ -25,7 +25,8 @@ enum WsrxCli {
#[clap(short, long)]
log_json: Option<bool>,
/// The heartbeat interval in seconds.
/// If not set, the daemon will not automatically exit when heartbeat timeout.
/// If not set, the daemon will not automatically exit when heartbeat
/// timeout.
#[clap(long)]
heartbeat: Option<u64>,
},
Expand Down Expand Up @@ -67,19 +68,19 @@ async fn main() {
match crypto::aws_lc_rs::default_provider().install_default() {
Ok(_) => info!("using `AWS Libcrypto` as default crypto backend."),
Err(err) => {
error!("`AWS Libcrypto` is not available: {:?}", err);
warn!("try to use `ring` as default crypto backend.");
crypto::ring::default_provider()
.install_default()
.inspect_err(|err| {
error!("`ring` is not available: {:?}", err);
error!("All crypto backend are not available, exiting...");
process::exit(1);
})
.ok();
info!("using `ring` as default crypto backend.");
error!("`AWS Libcrypto` is not available: {:?}", err);
warn!("try to use `ring` as default crypto backend.");
crypto::ring::default_provider()
.install_default()
.inspect_err(|err| {
error!("`ring` is not available: {:?}", err);
error!("All crypto backend are not available, exiting...");
process::exit(1);
})
.ok();
info!("using `ring` as default crypto backend.");
}
}
}
match cli {
WsrxCli::Daemon {
host,
Expand Down
3 changes: 1 addition & 2 deletions wsrx/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ impl Sink<Message> for WrappedWsStream {
pub async fn proxy_stream<S, T>(s1: S, s2: T) -> Result<(), Error>
where
S: Sink<Message, Error = Error> + Stream<Item = Result<Message, Error>> + Unpin,
T: Sink<Message, Error = Error> + Stream<Item = Result<Message, Error>> + Unpin,
{
T: Sink<Message, Error = Error> + Stream<Item = Result<Message, Error>> + Unpin, {
let (s1sink, s1stream) = s1.split();
let (s2sink, s2stream) = s2.split();
let f1 = s1stream.forward(s2sink);
Expand Down

0 comments on commit a9f193c

Please sign in to comment.