Skip to content

Commit

Permalink
chore: release 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsusinn committed Dec 22, 2024
1 parent f615eff commit 6643ab0
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
env:
PACKAGE: "tuic-server"
PACKAGE2: "tuic-client"
RUST_TOOLCHAIN: "nightly-2024-11-26"
RUST_TOOLCHAIN: "nightly-2024-12-20"

jobs:
compile:
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
authors = ["EAimTY <[email protected]>", "Itsusinn <[email protected]>"]
version = "1.4.0"
version = "1.4.1"
rust-version = "1.80.0"
edition = "2021"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct Config {
pub max_external_packet_size: usize,

#[serde(with = "humantime_serde")]
#[educe(Default(expression = Duration::from_millis(10000)))]
#[educe(Default(expression = Duration::from_millis(60000)))]
pub stream_timeout: Duration,
}

Expand Down
5 changes: 3 additions & 2 deletions tuic-server/src/connection/handle_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Connection {
let target_addr = conn.addr().to_string();

info!(
"[{id:#010x}] [{addr}] [{user}] [TCP] {target_addr}",
"[{id:#010x}] [{addr}] [{user}] [TCP] {target_addr} ",
id = self.id(),
addr = self.inner.remote_address(),
user = self.auth,
Expand Down Expand Up @@ -63,6 +63,7 @@ impl Connection {
// a <- b rx
let (tx, rx, err) =
exchange_tcp(&mut conn, &mut stream, self.ctx.cfg.stream_timeout).await;
// let (tx, rx) = tokio::io::copy_bidirectional(&mut conn, &mut stream).await?;
_ = conn.reset(ERROR_CODE);
_ = stream.shutdown().await;

Expand All @@ -86,7 +87,7 @@ impl Connection {
match process.await {
Ok(()) => {}
Err(err) => warn!(
"[{id:#010x}] [{addr}] [{user}] [TCP] {target_addr}: {err:#?}",
"[{id:#010x}] [{addr}] [{user}] [TCP] {target_addr}: {err}",
id = self.id(),
addr = self.inner.remote_address(),
user = self.auth,
Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod handle_stream;
mod handle_task;
mod udp_session;

pub const ERROR_CODE: VarInt = VarInt::from_u32(0);
pub const ERROR_CODE: VarInt = VarInt::from_u32(6000);
pub const INIT_CONCURRENT_STREAMS: u32 = 32;

#[derive(Clone)]
Expand Down
8 changes: 5 additions & 3 deletions tuic-server/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ pub async fn exchange_tcp(
let mut last_err = None;
let mut timeout = tokio::time::interval(timeout);
timeout.reset();

loop {
tokio::select! {
_ = timeout.tick() => {
last_err = Some(eyre::eyre!("TCP stream timeout"));
break;
},

a2b_res = a.recv.read(&mut a2b) => match a2b_res {
Ok(Some(num)) => {
a2b_num += num;
if let Err(err) = b.write(&a2b).await {
timeout.reset();
if let Err(err) = b.write_all(&a2b[..num]).await {
last_err = Some(err.into());
break;
}
Expand All @@ -50,7 +51,8 @@ pub async fn exchange_tcp(
break;
}
b2a_num += num;
if let Err(err) = a.send.write(&b2a).await {
timeout.reset();
if let Err(err) = a.send.write_all(&b2a[..num]).await {
last_err = Some(err.into());
break;
}
Expand Down
3 changes: 1 addition & 2 deletions tuic-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(trivial_bounds)]
#![feature(let_chains, async_closure)]
#![feature(let_chains, trivial_bounds)]

use std::{env, process, sync::Arc};

Expand Down
23 changes: 9 additions & 14 deletions tuic-server/src/tls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
ops::Deref,
path::{Path, PathBuf},
sync::Arc,
sync::{Arc, RwLock},
};

use eyre::Context;
Expand All @@ -10,8 +11,7 @@ use rustls::{
server::{ClientHello, ResolvesServerCert},
sign::CertifiedKey,
};
use tokio::sync::RwLock;
use tracing::{error, warn};
use tracing::warn;

use crate::utils::{self, FutResultExt};

Expand Down Expand Up @@ -40,24 +40,19 @@ impl CertResolver {
let (mut watcher, mut rx) = utils::async_watcher().await?;

watcher.watch(self.cert_path.as_ref(), RecursiveMode::NonRecursive)?;

while let Some(res) = rx.recv().await {
match res {
Err(e) => error!("TLS cert-key reload watcher error: {:?}", e),
Ok(_) => {
warn!("TLS cert-key reload");
let cert_key = load_cert_key(&self.cert_path, &self.key_path).await?;
let mut guard = self.cert_key.write().await;
*guard = cert_key;
}
while (rx.recv().await).is_ok() {
warn!("TLS cert-key reload");
let cert_key = load_cert_key(&self.cert_path, &self.key_path).await?;
if let Ok(mut guard) = self.cert_key.write() {
*guard = cert_key;
}
}
Ok(())
}
}
impl ResolvesServerCert for CertResolver {
fn resolve(&self, _: ClientHello<'_>) -> Option<Arc<CertifiedKey>> {
Some(self.cert_key.blocking_read().clone())
Some(self.cert_key.read().ok()?.deref().clone())
}
}

Expand Down
24 changes: 13 additions & 11 deletions tuic-server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::{
};

use educe::Educe;
use notify::{Event, RecommendedWatcher, Watcher};
use notify::{EventKind, RecommendedWatcher, Watcher};
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::{Receiver, channel};
use tokio::sync::broadcast;

#[derive(Clone, Copy)]
pub enum UdpRelayMode {
Expand Down Expand Up @@ -70,16 +70,18 @@ where
}
}

pub async fn async_watcher() -> notify::Result<(RecommendedWatcher, Receiver<notify::Result<Event>>)>
{
let (tx, rx) = channel(1);

pub async fn async_watcher() -> eyre::Result<(RecommendedWatcher, broadcast::Receiver<()>)> {
let (tx, rx) = broadcast::channel(1);
let watcher = RecommendedWatcher::new(
move |res| {
let tx = tx.clone();
tokio::task::spawn(async move {
tx.send(res).await.unwrap();
});
move |res: Result<notify::Event, notify::Error>| {
if let Ok(event) = res {
match event.kind {
EventKind::Create(_) | EventKind::Modify(_) => {
tx.send(()).unwrap();
}
_ => {}
}
}
},
notify::Config::default(),
)?;
Expand Down

0 comments on commit 6643ab0

Please sign in to comment.