Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 148 additions & 67 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,31 @@ debug = 1
[patch.crates-io]
tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", rev = "6b9af8ac7bb5abc159d9a67e9ddbf84127559a4a"}
rustls = { git = "https://github.com/Watfaq/rustls.git", rev = "a7d217bf235aeb3ca8d123352d90a27c1ca0f41b"}

[workspace.metadata.cross.build]
pre-build = [
"apt update",
"apt install -y protobuf-compiler"
]

[workspace.metadata.cross.build.env]
volumes = ["/var/run/docker.sock=/var/run/docker.sock"] # Docker in docker
passthrough = ["CLASH_GIT_REF", "CLASH_GIT_SHA", "RUSTFLAGS", "RUST_LOG", "CLASH_DOCKER_TEST"]

[workspace.metadata.cross.target.x86_64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main"

[workspace.metadata.cross.target.i686-unknown-linux-gnu]
image = "ghcr.io/cross-rs/i686-unknown-linux-gnu:main"

[workspace.metadata.cross.target.aarch64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main"

workspace.metadata.cross.[target.armv7-unknown-linux-gnueabi]
image = "ghcr.io/cross-rs/armv7-unknown-linux-gnueabi:main"

[workspace.metadata.cross.target.armv7-unknown-linux-gnueabihf]
image = "ghcr.io/cross-rs/armv7-unknown-linux-gnueabihf:main"

[workspace.metadata.cross.target.armv7-unknown-linux-musleabihf]
image = "ghcr.io/cross-rs/armv7-unknown-linux-musleabihf:main"
27 changes: 0 additions & 27 deletions Cross.toml

This file was deleted.

6 changes: 3 additions & 3 deletions clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ hickory-proto = { version = "0.25.0-alpha.2", features = ["dns-over-rustls", "dn
dhcproto = "0.12"
ring-compat = { version = "0.8", features = ["aead"] }

rand = "0.8"
rand = "0.9"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2"
Expand All @@ -119,8 +119,8 @@ arti-client = { version = "0.26", optional = true, default-features = false, fea
tor-rtcompat = { version = "0.26", optional = true, default-features = false }

# tuic
tuic = { tag = "v1.4.3", optional = true, git = "https://github.com/Itsusinn/tuic.git" }
tuic-quinn = { tag = "v1.4.3", optional = true, git = "https://github.com/Itsusinn/tuic.git" }
tuic = { tag = "v1.4.5", optional = true, git = "https://github.com/Itsusinn/tuic.git" }
tuic-quinn = { tag = "v1.4.5", optional = true, git = "https://github.com/Itsusinn/tuic.git" }
register-count = { version = "0.1", optional = true }

quinn = { version = "0.11", default-features = false, features = ["futures-io", "runtime-tokio", "rustls"] }
Expand Down
6 changes: 3 additions & 3 deletions clash_lib/src/app/dns/resolver/enhanced.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use futures::{FutureExt, TryFutureExt};
use rand::prelude::SliceRandom;
use rand::seq::IndexedRandom;
use std::{
net,
sync::{
Expand Down Expand Up @@ -531,7 +531,7 @@ impl ClashResolver for EnhancedResolver {
}

match self.lookup_ip(host, rr::RecordType::A).await {
Ok(result) => match result.choose(&mut rand::thread_rng()).unwrap() {
Ok(result) => match result.choose(&mut rand::rng()).unwrap() {
net::IpAddr::V4(v4) => Ok(Some(*v4)),
_ => unreachable!("invalid IP family"),
},
Expand Down Expand Up @@ -564,7 +564,7 @@ impl ClashResolver for EnhancedResolver {
}

match self.lookup_ip(host, rr::RecordType::AAAA).await {
Ok(result) => match result.choose(&mut rand::thread_rng()).unwrap() {
Ok(result) => match result.choose(&mut rand::rng()).unwrap() {
net::IpAddr::V6(v6) => Ok(Some(*v6)),
_ => unreachable!("invalid IP family"),
},
Expand Down
6 changes: 3 additions & 3 deletions clash_lib/src/app/dns/resolver/system_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl ClashResolver for SystemResolver {
Ok(response
.iter()
.filter(|x| self.ipv6() || x.is_ipv4())
.choose(&mut rand::thread_rng()))
.choose(&mut rand::rng()))
}

async fn resolve_v4(
Expand All @@ -42,7 +42,7 @@ impl ClashResolver for SystemResolver {
_: bool,
) -> anyhow::Result<Option<std::net::Ipv4Addr>> {
let response = self.inner.ipv4_lookup(host).await?;
Ok(response.iter().map(|x| x.0).choose(&mut rand::thread_rng()))
Ok(response.iter().map(|x| x.0).choose(&mut rand::rng()))
}

async fn resolve_v6(
Expand All @@ -51,7 +51,7 @@ impl ClashResolver for SystemResolver {
_: bool,
) -> anyhow::Result<Option<std::net::Ipv6Addr>> {
let response = self.inner.ipv6_lookup(host).await?;
Ok(response.iter().map(|x| x.0).choose(&mut rand::thread_rng()))
Ok(response.iter().map(|x| x.0).choose(&mut rand::rng()))
}

async fn cached_for(&self, _: std::net::IpAddr) -> Option<String> {
Expand Down
6 changes: 3 additions & 3 deletions clash_lib/src/app/dns/resolver/system_non_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ClashResolver for SystemResolver {
}
})
.collect::<Vec<_>>();
Ok(response.into_iter().choose(&mut rand::thread_rng()))
Ok(response.into_iter().choose(&mut rand::rng()))
}

async fn resolve_v4(
Expand All @@ -54,7 +54,7 @@ impl ClashResolver for SystemResolver {
_ => None,
})
.collect::<Vec<_>>();
Ok(response.into_iter().choose(&mut rand::thread_rng()))
Ok(response.into_iter().choose(&mut rand::rng()))
}

async fn resolve_v6(
Expand All @@ -72,7 +72,7 @@ impl ClashResolver for SystemResolver {
_ => None,
})
.collect::<Vec<_>>();
Ok(response.into_iter().choose(&mut rand::thread_rng()))
Ok(response.into_iter().choose(&mut rand::rng()))
}

async fn cached_for(&self, _: std::net::IpAddr) -> Option<String> {
Expand Down
8 changes: 4 additions & 4 deletions clash_lib/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{fmt::Write, num::ParseIntError, path::Path};

use crate::{common::errors::new_io_error, Error};
use rand::{
distributions::uniform::{SampleRange, SampleUniform},
distr::uniform::{SampleRange, SampleUniform},
Fill, Rng,
};
use sha2::Digest;
Expand All @@ -16,15 +16,15 @@ where
T: SampleUniform,
R: SampleRange<T>,
{
let mut rng = rand::thread_rng();
rng.gen_range(range)
let mut rng = rand::rng();
rng.random_range(range)
}

pub fn rand_fill<T>(buf: &mut T)
where
T: Fill + ?Sized,
{
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
rng.fill(buf)
}

Expand Down
4 changes: 2 additions & 2 deletions clash_lib/src/proxy/converters/hysteria2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ impl PortGenrateor {
}

pub fn get(&self) -> u16 {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let len =
1 + self.ports.len() + self.range.iter().map(|r| r.len()).sum::<usize>();
let idx = rng.gen_range(0..len);
let idx = rng.random_range(0..len);
match idx {
0 => self.default,
idx if idx <= self.ports.len() => self.ports[idx - 1],
Expand Down
6 changes: 3 additions & 3 deletions clash_lib/src/proxy/hysteria2/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::ErrorKind;

use bytes::{Buf, BufMut, BytesMut};
use quinn_proto::{coding::Codec, VarInt};
use rand::distributions::Alphanumeric;
use rand::distr::Alphanumeric;
use tokio_util::codec::{Decoder, Encoder};

use crate::session::SocksAddr;
Expand Down Expand Up @@ -64,8 +64,8 @@ impl Decoder for Hy2TcpCodec {
#[inline]
pub fn padding(range: std::ops::RangeInclusive<u32>) -> Vec<u8> {
use rand::Rng;
let mut rng = rand::thread_rng();
let len = rng.gen_range(range) as usize;
let mut rng = rand::rng();
let len = rng.random_range(range) as usize;
rng.sample_iter(Alphanumeric).take(len).collect()
}

Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/hysteria2/salamander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl SalamanderObfs {
}

fn encrpyt(&self, data: &mut [u8]) -> Bytes {
let salt: [u8; 8] = rand::thread_rng().gen();
let salt: [u8; 8] = rand::rng().random();

let mut res = BytesMut::with_capacity(8 + data.len());
res.put_slice(&salt);
Expand Down
12 changes: 6 additions & 6 deletions clash_lib/src/proxy/shadowsocks/shadow_tls/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{io, ptr::copy_nonoverlapping, sync::Arc};

use rand::Rng;

use rand::distributions::Distribution;
use rand::distr::Distribution;
use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
use tokio_rustls::{client::TlsStream, TlsConnector};

Expand Down Expand Up @@ -119,7 +119,7 @@ fn generate_session_id(hmac: &Hmac, buf: &[u8]) -> [u8; TLS_SESSION_ID_SIZE] {
}

let mut session_id = [0; TLS_SESSION_ID_SIZE];
rand::thread_rng().fill(&mut session_id[..TLS_SESSION_ID_SIZE - HMAC_SIZE]);
rand::rng().fill(&mut session_id[..TLS_SESSION_ID_SIZE - HMAC_SIZE]);
let mut hmac = hmac.to_owned();
hmac.update(&buf[0..SESSION_ID_START]);
hmac.update(&session_id);
Expand All @@ -143,13 +143,13 @@ async fn fake_request<S: tokio::io::AsyncRead + AsyncWrite + Unpin>(
) -> std::io::Result<()> {
const HEADER: &[u8; 207] = b"GET / HTTP/1.1\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36\nAccept: gzip, deflate, br\nConnection: Close\nCookie: sessionid=";
const FAKE_REQUEST_LENGTH_RANGE: (usize, usize) = (16, 64);
let cnt = rand::thread_rng()
.gen_range(FAKE_REQUEST_LENGTH_RANGE.0..FAKE_REQUEST_LENGTH_RANGE.1);
let cnt = rand::rng()
.random_range(FAKE_REQUEST_LENGTH_RANGE.0..FAKE_REQUEST_LENGTH_RANGE.1);
let mut buffer = Vec::with_capacity(cnt + HEADER.len() + 1);

buffer.extend_from_slice(HEADER);
rand::distributions::Alphanumeric
.sample_iter(rand::thread_rng())
rand::distr::Alphanumeric
.sample_iter(rand::rng())
.take(cnt)
.for_each(|c| buffer.push(c));
buffer.push(b'\n');
Expand Down
5 changes: 3 additions & 2 deletions clash_lib/src/proxy/shadowsocks/simple_obfs/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::pin::Pin;
use crate::proxy::AnyStream;
use base64::Engine;
use bytes::{BufMut, BytesMut};
use rand::Rng;
use tokio::io::{AsyncRead, AsyncWrite};

#[derive(Debug)]
Expand Down Expand Up @@ -41,8 +42,8 @@ impl AsyncWrite for HTTPObfs {
buffer.put_slice(
format!(
"User-Agent: curl/7.{}.{}\r\n",
rand::random::<usize>() % 54,
rand::random::<usize>() % 2
rand::rng().random_range(0..54),
rand::rng().random_range(0..2),
)
.as_bytes(),
);
Expand Down
4 changes: 2 additions & 2 deletions clash_lib/src/proxy/transport/h2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bytes::{Bytes, BytesMut};
use futures::ready;
use h2::{RecvStream, SendStream};
use http::Request;
use rand::random;
use rand::Rng;
use tokio::io::{AsyncRead, AsyncWrite};
use tracing::error;

Expand All @@ -20,7 +20,7 @@ pub struct Http2Config {

impl Http2Config {
fn req(&self) -> std::io::Result<Request<()>> {
let uri_idx = random::<usize>() % self.hosts.len();
let uri_idx = rand::rng().random_range(0..self.hosts.len());
let uri = {
http::Uri::builder()
.scheme("https")
Expand Down
4 changes: 2 additions & 2 deletions clash_lib/src/proxy/wg/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use bytes::{BufMut, Bytes, BytesMut};
use futures::{SinkExt, StreamExt};

use rand::seq::SliceRandom;
use rand::seq::IndexedRandom;
use smoltcp::{
iface::{Config, Interface, SocketHandle, SocketSet},
phy::Device,
Expand Down Expand Up @@ -488,7 +488,7 @@ impl DeviceManager {
if let Ok(ip) = domain.parse::<IpAddr>() {
ip
} else {
let dns_server = self.dns_servers.choose(&mut rand::thread_rng());
let dns_server = self.dns_servers.choose(&mut rand::rng());
if let Some(dns_server) = dns_server {
let ip = self.look_up_dns(domain, *dns_server).await;
if let Some(ip) = ip {
Expand Down
4 changes: 2 additions & 2 deletions clash_lib/src/proxy/wg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use async_trait::async_trait;
use futures::TryFutureExt;

use ipnet::IpNet;
use rand::seq::SliceRandom;
use rand::seq::IndexedRandom;
use tokio::sync::OnceCell;
use tracing::debug;

Expand Down Expand Up @@ -268,7 +268,7 @@ impl OutboundHandler for Handler {
.dns
.as_ref()
.unwrap()
.choose(&mut rand::thread_rng())
.choose(&mut rand::rng())
.unwrap();

inner
Expand Down
4 changes: 2 additions & 2 deletions clash_lib/src/proxy/wg/ports.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::VecDeque, ops::Range, sync::Arc};

use anyhow::Context;
use rand::{seq::SliceRandom, thread_rng};
use rand::seq::SliceRandom;

const MIN_PORT: u16 = 1025;
const MAX_PORT: u16 = 60000;
Expand All @@ -24,7 +24,7 @@ impl PortPool {
pub fn new() -> Self {
let mut inner = TcpPortPoolInner::default();
let mut ports: Vec<u16> = PORT_RANGE.collect();
ports.shuffle(&mut thread_rng());
ports.shuffle(&mut rand::rng());
ports
.into_iter()
.for_each(|p| inner.queue.push_back(p) as ());
Expand Down
Loading