-
Notifications
You must be signed in to change notification settings - Fork 125
feat(proxy): add shadowquic protocol #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+862
−119
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6aaae35
feat: imple shadowquic tcp proxy
spongebob888 e139202
chore: fix fmt
spongebob888 fcbd48c
feat: impl shadowquic udp proxy
spongebob888 8252fb7
chore: fix fmt
spongebob888 937d4c9
fix: impl handler name
spongebob888 d602c18
chore: fix clippy
spongebob888 8a33934
fix: ipv6 sever addr may failed
spongebob888 38ba428
test: adding tests for shadowquic
spongebob888 6e79787
fix: ipv6 server addr
spongebob888 cdc2660
chore: bump shadowquic version
spongebob888 4af800c
doc: update shadowquic document
spongebob888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,4 +12,6 @@ pub mod tuic; | |
| pub mod vmess; | ||
| pub mod wireguard; | ||
|
|
||
| #[cfg(feature = "shadowquic")] | ||
| pub mod shadowquic; | ||
| mod utils; | ||
This file contains hidden or 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,46 @@ | ||
| use shadowquic::config::{ | ||
| default_alpn, default_congestion_control, default_initial_mtu, default_min_mtu, | ||
| default_over_stream, default_zero_rtt, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| config::proxy::OutboundShadowQuic, | ||
| proxy::shadowquic::{Handler, HandlerOptions}, | ||
| }; | ||
|
|
||
| impl TryFrom<OutboundShadowQuic> for Handler { | ||
| type Error = crate::Error; | ||
|
|
||
| fn try_from(value: OutboundShadowQuic) -> Result<Self, Self::Error> { | ||
| (&value).try_into() | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&OutboundShadowQuic> for Handler { | ||
| type Error = crate::Error; | ||
|
|
||
| fn try_from(s: &OutboundShadowQuic) -> Result<Self, Self::Error> { | ||
| Ok(Handler::new( | ||
| s.common_opts.name.clone(), | ||
| HandlerOptions { | ||
| addr: format!( | ||
| "{}:{}", | ||
| s.common_opts.server.to_owned(), | ||
| s.common_opts.port | ||
| ), | ||
| jls_pwd: s.jls_pwd.clone(), | ||
| jls_iv: s.jls_iv.clone(), | ||
| server_name: s.server_name.clone(), | ||
| alpn: s.alpn.clone().unwrap_or(default_alpn()), | ||
| initial_mtu: s.initial_mtu.unwrap_or(default_initial_mtu()), | ||
| congestion_control: s | ||
| .congestion_control | ||
| .clone() | ||
| .unwrap_or(default_congestion_control()), | ||
| zero_rtt: s.zero_rtt.unwrap_or(default_zero_rtt()), | ||
| over_stream: s.over_stream.unwrap_or(default_over_stream()), | ||
| min_mtu: s.min_mtu.unwrap_or(default_min_mtu()), | ||
| }, | ||
| )) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,72 @@ | ||
| use std::io; | ||
|
|
||
| use bytes::Bytes; | ||
| use futures::{Sink, SinkExt, Stream}; | ||
| use shadowquic::msgs::socks5::SocksAddr as SQAddr; | ||
| use tokio::sync::mpsc::Receiver; | ||
| use tokio_util::sync::PollSender; | ||
|
|
||
| use crate::{ | ||
| common::errors::new_io_error, proxy::datagram::UdpPacket, session::SocksAddr, | ||
| }; | ||
|
|
||
| use super::{to_clash_socks_addr, to_sq_socks_addr}; | ||
|
|
||
| pub struct UdpSessionWrapper { | ||
| pub s: PollSender<(Bytes, SQAddr)>, | ||
| pub r: Receiver<(Bytes, SQAddr)>, | ||
| pub src_addr: SocksAddr, /* source addres of local socket, binded during | ||
| * associate task | ||
| * started */ | ||
| } | ||
| impl Sink<UdpPacket> for UdpSessionWrapper { | ||
| type Error = io::Error; | ||
|
|
||
| fn poll_ready( | ||
| self: std::pin::Pin<&mut Self>, | ||
| cx: &mut std::task::Context<'_>, | ||
| ) -> std::task::Poll<Result<(), Self::Error>> { | ||
| self.get_mut().s.poll_ready_unpin(cx).map_err(new_io_error) | ||
| } | ||
|
|
||
| fn start_send( | ||
| self: std::pin::Pin<&mut Self>, | ||
| item: UdpPacket, | ||
| ) -> Result<(), Self::Error> { | ||
| self.get_mut() | ||
| .s | ||
| .start_send_unpin((item.data.into(), to_sq_socks_addr(item.dst_addr))) | ||
| .map_err(new_io_error) | ||
| } | ||
|
|
||
| fn poll_flush( | ||
| self: std::pin::Pin<&mut Self>, | ||
| cx: &mut std::task::Context<'_>, | ||
| ) -> std::task::Poll<Result<(), Self::Error>> { | ||
| self.get_mut().s.poll_flush_unpin(cx).map_err(new_io_error) | ||
| } | ||
|
|
||
| fn poll_close( | ||
| self: std::pin::Pin<&mut Self>, | ||
| cx: &mut std::task::Context<'_>, | ||
| ) -> std::task::Poll<Result<(), Self::Error>> { | ||
| self.get_mut().s.poll_close_unpin(cx).map_err(new_io_error) | ||
| } | ||
| } | ||
|
|
||
| impl Stream for UdpSessionWrapper { | ||
| type Item = UdpPacket; | ||
|
|
||
| fn poll_next( | ||
| mut self: std::pin::Pin<&mut Self>, | ||
| cx: &mut std::task::Context<'_>, | ||
| ) -> std::task::Poll<Option<Self::Item>> { | ||
| self.r.poll_recv(cx).map(|x| { | ||
| x.map(|x| UdpPacket { | ||
| data: x.0.into(), | ||
| src_addr: self.src_addr.clone(), | ||
| dst_addr: to_clash_socks_addr(x.1), | ||
| }) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you may need to gate the feature here to pass the build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in latest commit