mirror of
https://codeberg.org/YGGverse/psocks.git
synced 2026-03-31 08:25:27 +00:00
minor logic optimization
This commit is contained in:
parent
239a85ca47
commit
82b09d74ae
3 changed files with 13 additions and 13 deletions
|
|
@ -4,7 +4,7 @@ Experimental async SOCKS5 (TCP/UDP) proxy server based on [fast-socks5](https://
|
||||||
|
|
||||||
## Goals
|
## Goals
|
||||||
|
|
||||||
* Ad/tracking protection
|
* Ad/tracking protection (before sending a DNS request)
|
||||||
* Reduce CPU usage by filtering extra SSL traffic on background
|
* Reduce CPU usage by filtering extra SSL traffic on background
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
|
||||||
11
src/list.rs
11
src/list.rs
|
|
@ -51,13 +51,10 @@ impl List {
|
||||||
cache,
|
cache,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub async fn any(&self, values: &[&str]) -> bool {
|
pub async fn any(&self, value: &str) -> bool {
|
||||||
let guard = self.index.read().await;
|
self.index.read().await.iter().any(|item| match item {
|
||||||
values.iter().any(|&value| {
|
Item::Exact(v) => v == value,
|
||||||
guard.iter().any(|item| match item {
|
Item::Ending(v) => value.ends_with(v),
|
||||||
Item::Exact(v) => v == value,
|
|
||||||
Item::Ending(v) => value.ends_with(v),
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub async fn entries(&self) -> u64 {
|
pub async fn entries(&self) -> u64 {
|
||||||
|
|
|
||||||
13
src/main.rs
13
src/main.rs
|
|
@ -120,7 +120,6 @@ async fn serve_socks5(
|
||||||
totals: Arc<Total>,
|
totals: Arc<Total>,
|
||||||
) -> Result<(), SocksError> {
|
) -> Result<(), SocksError> {
|
||||||
totals.increase_request();
|
totals.increase_request();
|
||||||
|
|
||||||
let request = match &opt.auth {
|
let request = match &opt.auth {
|
||||||
AuthMode::NoAuth if opt.skip_auth => {
|
AuthMode::NoAuth if opt.skip_auth => {
|
||||||
Socks5ServerProtocol::skip_auth_this_is_not_rfc_compliant(socket)
|
Socks5ServerProtocol::skip_auth_this_is_not_rfc_compliant(socket)
|
||||||
|
|
@ -137,16 +136,20 @@ async fn serve_socks5(
|
||||||
.read_command()
|
.read_command()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let (host, _) = request.2.clone().into_string_and_port(); // @TODO ref
|
let (host, _) = request.2.clone().into_string_and_port();
|
||||||
let (proto, cmd, addr) = request.resolve_dns().await?;
|
|
||||||
|
|
||||||
if !list.any(&[&host, &addr.to_string()]).await {
|
if !list.any(&host).await {
|
||||||
totals.increase_blocked();
|
totals.increase_blocked();
|
||||||
info!("Blocked connection attempt to: {host}");
|
info!("Blocked connection attempt to: {host}");
|
||||||
proto.reply_error(&ReplyError::ConnectionNotAllowed).await?;
|
request
|
||||||
|
.0
|
||||||
|
.reply_error(&ReplyError::ConnectionNotAllowed)
|
||||||
|
.await?;
|
||||||
return Err(ReplyError::ConnectionNotAllowed.into());
|
return Err(ReplyError::ConnectionNotAllowed.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let (proto, cmd, addr) = request.resolve_dns().await?;
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
Socks5Command::TCPConnect => {
|
Socks5Command::TCPConnect => {
|
||||||
run_tcp_proxy(proto, &addr, opt.request_timeout, false).await?;
|
run_tcp_proxy(proto, &addr, opt.request_timeout, false).await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue