-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: ignore nix direnv files * build: add tuic related deps * feat: support parse tuic configuration * fix(logging): shutdown should be logged after receiving signal * feat: support TUIC TCP relay * feat(tuic): allow more configuration and remove hardcode vars * chore: clean logging and error handling * feat(tuic): support UDP relay * chore(tuic): rename symbols * build: change tuic into git deps * style: cargo fmt * build: update tuic * refactor: reduce spawn task * refactor: use Arc<TuicConnection> * style: make clippy happy * fix: handle UDP dissociate * refactor: remove redundant fast open and fix typo
- Loading branch information
iHsin
authored
Mar 25, 2024
1 parent
ef2b845
commit bfddc52
Showing
15 changed files
with
1,087 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod shadowsocks; | ||
pub mod tor; | ||
pub mod trojan; | ||
pub mod tuic; | ||
pub mod vmess; | ||
pub mod wireguard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::time::Duration; | ||
|
||
use quinn::VarInt; | ||
|
||
use crate::{ | ||
config::internal::proxy::OutboundTuic, | ||
proxy::{ | ||
tuic::{types::CongestionControl, Handler, HandlerOptions}, | ||
AnyOutboundHandler, | ||
}, | ||
}; | ||
|
||
impl TryFrom<OutboundTuic> for AnyOutboundHandler { | ||
type Error = crate::Error; | ||
|
||
fn try_from(value: OutboundTuic) -> Result<Self, Self::Error> { | ||
(&value).try_into() | ||
} | ||
} | ||
|
||
impl TryFrom<&OutboundTuic> for AnyOutboundHandler { | ||
type Error = crate::Error; | ||
|
||
fn try_from(s: &OutboundTuic) -> Result<Self, Self::Error> { | ||
Handler::new(HandlerOptions { | ||
name: s.name.to_owned(), | ||
server: s.server.to_owned(), | ||
port: s.port, | ||
uuid: s.uuid.to_owned(), | ||
password: s.password.to_owned(), | ||
udp_relay_mode: s.udp_relay_mode.to_owned().unwrap_or("native".to_string()), | ||
disable_sni: s.disable_sni.unwrap_or(false), | ||
alpn: s | ||
.alpn | ||
.clone() | ||
.map(|v| v.into_iter().map(|alpn| alpn.into_bytes()).collect()) | ||
.unwrap_or_default(), | ||
heartbeat_interval: Duration::from_millis(s.heartbeat_interval.unwrap_or(3000)), | ||
reduce_rtt: s.reduce_rtt.unwrap_or(false) || s.fast_open.unwrap_or(false), | ||
request_timeout: Duration::from_millis(s.request_timeout.unwrap_or(8000)), | ||
congestion_controller: s | ||
.congestion_controller | ||
.clone() | ||
.map(|v| CongestionControl::from(v.as_str())) | ||
.unwrap_or_default(), | ||
max_udp_relay_packet_size: s.max_udp_relay_packet_size.unwrap_or(1500), | ||
max_open_stream: VarInt::from_u64(s.max_open_stream.unwrap_or(32)) | ||
.unwrap_or(VarInt::MAX), | ||
ip: s.ip.clone(), | ||
skip_cert_verify: s.skip_cert_verify.unwrap_or(false), | ||
sni: s.sni.clone(), | ||
gc_interval: Duration::from_millis(s.gc_interval.unwrap_or(3000)), | ||
gc_lifetime: Duration::from_millis(s.gc_lifetime.unwrap_or(15000)), | ||
send_window: s.send_window.unwrap_or(8 * 1024 * 1024 * 2), | ||
receive_window: VarInt::from_u64(s.receive_window.unwrap_or(8 * 1024 * 1024)) | ||
.unwrap_or(VarInt::MAX), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::{ | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
use futures::{Sink, SinkExt, Stream}; | ||
|
||
use crate::{common::errors::new_io_error, proxy::datagram::UdpPacket}; | ||
|
||
use super::TuicDatagramOutbound; | ||
|
||
impl Sink<UdpPacket> for TuicDatagramOutbound { | ||
type Error = std::io::Error; | ||
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.send_tx | ||
.poll_ready_unpin(cx) | ||
.map_err(|v| new_io_error(&format!("{v:?}"))) | ||
} | ||
fn start_send(mut self: Pin<&mut Self>, item: UdpPacket) -> Result<(), Self::Error> { | ||
self.send_tx | ||
.start_send_unpin(item) | ||
.map_err(|v| new_io_error(&format!("{v:?}"))) | ||
} | ||
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.send_tx | ||
.poll_flush_unpin(cx) | ||
.map_err(|v| new_io_error(&format!("{v:?}"))) | ||
} | ||
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.send_tx | ||
.poll_close_unpin(cx) | ||
.map_err(|v| new_io_error(&format!("{v:?}"))) | ||
} | ||
} | ||
|
||
impl Stream for TuicDatagramOutbound { | ||
type Item = UdpPacket; | ||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
self.recv_rx.poll_recv(cx) | ||
} | ||
} |
Oops, something went wrong.