Skip to content

Commit

Permalink
Merge branch 'ios-wip' of github.com:geph-official/geph5 into ios-wip
Browse files Browse the repository at this point in the history
  • Loading branch information
thisbefruit committed Dec 30, 2024
2 parents 812a2e6 + ac1ac50 commit e98add1
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 37 deletions.
23 changes: 15 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions binaries/geph5-client/src/vpn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ static VPN_CAPTURE: CtxField<ArrayQueue<(Bytes, Instant)>> = |_| ArrayQueue::new
static VPN_INJECT: CtxField<ArrayQueue<Bytes>> = |_| ArrayQueue::new(100);

pub async fn vpn_loop(ctx: &AnyCtx<Config>) -> anyhow::Result<()> {
let (send_captured, recv_captured) = smol::channel::unbounded();
let (send_injected, recv_injected) = smol::channel::unbounded();
let (send_captured, recv_captured) = smol::channel::bounded(100);
let (send_injected, recv_injected) = smol::channel::bounded(100);

let ipstack = IpStack::new(
#[cfg(target_os = "ios")]
Expand Down Expand Up @@ -115,8 +115,6 @@ pub async fn vpn_loop(ctx: &AnyCtx<Config>) -> anyhow::Result<()> {
tracing::trace!(len = bts.len(), "vpn shuffling down");
ctx.get(VPN_INJECT).push(bts);
ctx.get(VPN_EVENT).notify_all();

smol::future::yield_now().await;
}
};
up_loop.race(dn_loop).await
Expand Down
7 changes: 7 additions & 0 deletions binaries/geph5-exit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ bytes = "1.8.0"
simple-dns = "0.9.0"
dashmap = "6.1.0"
globset = "0.4.15"
crossbeam-queue = "0.3.12"
scopeguard = "1.2.0"
async-event = "0.2.1"
ipnet = "2.10.1"
socket2 = "0.5.8"
serde_with = "3.12.0"
futures-concurrency = "7.6.2"
48 changes: 30 additions & 18 deletions binaries/geph5-exit/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use simple_dns::Packet;
use smol::{
channel::{Receiver, Sender},
future::FutureExt as _,
lock::Semaphore,
net::UdpSocket,
};

Expand All @@ -40,26 +41,31 @@ impl FilterOptions {
.time_to_live(Duration::from_secs(86400))
.build()
});
let nsfw_list = NSFW_LIST
.try_get_with((), async move {
anyhow::Ok(Arc::new(
parse_oisd("https://nsfw.oisd.nl/domainswild").await?,
))
})
.await
.map_err(|e| anyhow::anyhow!(e))?;
let ads_list = ADS_LIST
.try_get_with((), async move {
anyhow::Ok(Arc::new(
parse_oisd("https://big.oisd.nl/domainswild").await?,
))
})
.await
.map_err(|e| anyhow::anyhow!(e))?;
if self.nsfw && nsfw_list.is_match(name) {

if self.nsfw
&& NSFW_LIST
.try_get_with((), async move {
anyhow::Ok(Arc::new(
parse_oisd("https://nsfw.oisd.nl/domainswild").await?,
))
})
.await
.map_err(|e| anyhow::anyhow!(e))?
.is_match(name)
{
anyhow::bail!("blocking NSFW domain")
}
if self.ads && ads_list.is_match(name) {
if self.ads
&& ADS_LIST
.try_get_with((), async move {
anyhow::Ok(Arc::new(
parse_oisd("https://small.oisd.nl/domainswild").await?,
))
})
.await
.map_err(|e| anyhow::anyhow!(e))?
.is_match(name)
{
anyhow::bail!("blocking ads domain")
}
Ok(())
Expand All @@ -68,6 +74,8 @@ impl FilterOptions {

async fn parse_oisd(url: &str) -> anyhow::Result<GlobSet> {
let raw = reqwest::get(url).await?.bytes().await?;
tracing::info!(url, "STARTING TO BUILD an oisd blocklist");

let mut builder = GlobSet::builder();
let mut count = 0;
for line in String::from_utf8_lossy(&raw)
Expand All @@ -77,6 +85,10 @@ async fn parse_oisd(url: &str) -> anyhow::Result<GlobSet> {
builder.add(Glob::from_str(line)?);
builder.add(Glob::from_str(&line.replace("*.", ""))?);
count += 1;
if fastrand::f32() < 0.01 {
tracing::info!(url, count, "LOADING an oisd blocklist");
smol::future::yield_now().await;
}
}
tracing::info!(url, count, "LOADED an oisd blocklist");
Ok(builder.build()?)
Expand Down
Loading

0 comments on commit e98add1

Please sign in to comment.