-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92ed15e
commit 45c041e
Showing
6 changed files
with
96 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "realm" | ||
version = "2.0.5" | ||
version = "2.1.0" | ||
authors = ["zhboner <[email protected]>"] | ||
edition = "2021" | ||
|
||
|
@@ -32,7 +32,7 @@ pin-project = "1" | |
lazy_static = "1" | ||
|
||
# transport | ||
kaminari = { version = "0.5.7", optional = true } | ||
kaminari = { version = "0.6.0", optional = true } | ||
|
||
|
||
# tfo | ||
|
@@ -65,12 +65,15 @@ panic = "abort" | |
opt-level = 0 | ||
|
||
[features] | ||
default = ["udp", "zero-copy", "trust-dns", "multi-thread", "proxy-protocol", "transport"] | ||
default = ["udp", "zero-copy", "trust-dns", "multi-thread", | ||
"proxy-protocol", "transport", "transport-boost" | ||
] | ||
udp = [] | ||
tfo = ["tokio-tfo"] | ||
zero-copy = [] | ||
trust-dns = ["trust-dns-resolver"] | ||
transport = ["kaminari"] | ||
transport-boost = [] | ||
proxy-protocol = ["haproxy"] | ||
multi-thread = ["tokio/rt-multi-thread"] | ||
jemalloc = ["jemallocator"] | ||
|
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::io::Result; | ||
use futures::try_join; | ||
use tokio::io::copy_bidirectional; | ||
use kaminari::{AsyncAccept, AsyncConnect, IOStream}; | ||
use kaminari::mix::{MixAccept, MixConnect}; | ||
|
||
pub async fn relay_transport<S: IOStream>( | ||
src: S, | ||
dst: S, | ||
ac: &MixAccept, | ||
cc: &MixConnect, | ||
) -> Result<()> { | ||
macro_rules! hs_relay { | ||
($ac: expr, $cc: expr) => { | ||
handshake_and_relay(src, dst, $ac, $cc).await | ||
}; | ||
} | ||
|
||
#[cfg(feature = "transport-boost")] | ||
{ | ||
use MixConnect::*; | ||
if let Some(ac) = ac.as_plain() { | ||
return match cc { | ||
Plain(cc) => hs_relay!(ac, cc), | ||
Ws(cc) => hs_relay!(ac, cc), | ||
Tls(cc) => hs_relay!(ac, cc), | ||
Wss(cc) => hs_relay!(ac, cc), | ||
}; | ||
} | ||
} | ||
|
||
#[cfg(feature = "transport-boost")] | ||
{ | ||
use MixAccept::*; | ||
if let Some(cc) = cc.as_plain() { | ||
return match ac { | ||
Plain(ac) => hs_relay!(ac, cc), | ||
Ws(ac) => hs_relay!(ac, cc), | ||
Tls(ac) => hs_relay!(ac, cc), | ||
Wss(ac) => hs_relay!(ac, cc), | ||
}; | ||
} | ||
} | ||
|
||
hs_relay!(ac, cc) | ||
} | ||
|
||
pub async fn handshake_and_relay<S, AC, CC>( | ||
src: S, | ||
dst: S, | ||
ac: &AC, | ||
cc: &CC, | ||
) -> Result<()> | ||
where | ||
S: IOStream, | ||
AC: AsyncAccept<S>, | ||
CC: AsyncConnect<S>, | ||
{ | ||
let (mut src, mut dst) = try_join!(ac.accept(src), cc.connect(dst))?; | ||
|
||
copy_bidirectional(&mut src, &mut dst).await.map(|_| ()) | ||
} |