Compare commits

...

3 commits

Author SHA1 Message Date
Conrad Kramer
2d74945303 Cancel in-progress runs when pushing new code 2024-01-20 11:36:44 -08:00
Conrad Kramer
5da92148b7 Update macOS build machine
also skip macro validation, needed for SwiftLint's  macros.
2024-01-20 11:27:24 -08:00
Jett Chen
e85b32d9aa Wireguard Timer Support
Adds Wireguard Timer Support
2024-01-21 02:25:16 +08:00
10 changed files with 70 additions and 8 deletions

View file

@ -43,6 +43,7 @@ runs:
-clonedSourcePackagesDirPath SourcePackages \ -clonedSourcePackagesDirPath SourcePackages \
-packageCachePath $PWD/PackageCache \ -packageCachePath $PWD/PackageCache \
-skipPackagePluginValidation \ -skipPackagePluginValidation \
-skipMacroValidation \
-scheme '${{ inputs.scheme }}' \ -scheme '${{ inputs.scheme }}' \
-destination '${{ inputs.destination }}' \ -destination '${{ inputs.destination }}' \
-resultBundlePath BuildResults.xcresult -resultBundlePath BuildResults.xcresult

View file

@ -6,10 +6,13 @@ on:
pull_request: pull_request:
branches: branches:
- "*" - "*"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
name: Build App (${{ matrix.platform }}) name: Build App (${{ matrix.platform }})
runs-on: macos-14 runs-on: macos-13
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View file

@ -6,7 +6,7 @@ on:
jobs: jobs:
build: build:
name: Build ${{ matrix.configuration['platform'] }} Release name: Build ${{ matrix.configuration['platform'] }} Release
runs-on: macos-14 runs-on: macos-13
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:

View file

@ -16,3 +16,13 @@ test-dns:
@sudo route delete 8.8.8.8 @sudo route delete 8.8.8.8
@sudo route add 8.8.8.8 -interface utun$(tun_num) @sudo route add 8.8.8.8 -interface utun$(tun_num)
@dig @8.8.8.8 hackclub.com @dig @8.8.8.8 hackclub.com
test-https:
@sudo route delete 193.183.0.162
@sudo route add 193.183.0.162 -interface utun$(tun_num)
@curl -vv https://search.marginalia.nu
test-http:
@sudo route delete 146.190.62.39
@sudo route add 146.190.62.39 -interface utun$(tun_num)
@curl -vv 146.190.62.39:80

View file

@ -10,4 +10,4 @@ pub extern "C" fn initialize_oslog() {
tracing_subscriber::registry().with(OsLogger::new("com.hackclub.burrow", "backend")); tracing_subscriber::registry().with(OsLogger::new("com.hackclub.burrow", "backend"));
tracing::subscriber::set_global_default(collector).unwrap(); tracing::subscriber::set_global_default(collector).unwrap();
debug!("Initialized oslog tracing in libburrow rust FFI"); debug!("Initialized oslog tracing in libburrow rust FFI");
} }

View file

@ -101,7 +101,7 @@ impl Default for Config {
}, },
peers: vec![Peer { peers: vec![Peer {
endpoint: "wg.burrow.rs:51820".into(), endpoint: "wg.burrow.rs:51820".into(),
allowed_ips: vec!["8.8.8.8/32".into()], allowed_ips: vec!["8.8.8.8/32".into(), "0.0.0.0/0".into()],
public_key: "uy75leriJay0+oHLhRMpV+A5xAQ0hCJ+q7Ww81AOvT4=".into(), public_key: "uy75leriJay0+oHLhRMpV+A5xAQ0hCJ+q7Ww81AOvT4=".into(),
preshared_key: Some("s7lx/mg+reVEMnGnqeyYOQkzD86n2+gYnx1M9ygi08k=".into()), preshared_key: Some("s7lx/mg+reVEMnGnqeyYOQkzD86n2+gYnx1M9ygi08k=".into()),
persistent_keepalive: Default::default(), persistent_keepalive: Default::default(),

View file

@ -135,7 +135,7 @@ impl Interface {
debug!("spawning read task for peer {}", i); debug!("spawning read task for peer {}", i);
let pcb = pcbs.pcbs[i].clone(); let pcb = pcbs.pcbs[i].clone();
let tun = tun.clone(); let tun = tun.clone();
let tsk = async move { let main_tsk = async move {
if let Err(e) = pcb.open_if_closed().await { if let Err(e) = pcb.open_if_closed().await {
log::error!("failed to open pcb: {}", e); log::error!("failed to open pcb: {}", e);
return return
@ -147,8 +147,29 @@ impl Interface {
debug!("pcb ran successfully"); debug!("pcb ran successfully");
} }
}; };
let pcb = pcbs.pcbs[i].clone();
let update_timers_tsk = async move {
let mut buf = [0u8; 65535];
loop {
tokio::time::sleep(tokio::time::Duration::from_millis(250)).await;
pcb.update_timers(&mut buf).await;
}
};
let pcb = pcbs.pcbs[i].clone();
let reset_rate_limiter_tsk = async move {
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
pcb.reset_rate_limiter().await;
}
};
tsks.extend(vec![
tokio::spawn(main_tsk),
tokio::spawn(update_timers_tsk),
tokio::spawn(reset_rate_limiter_tsk)
]);
debug!("task made.."); debug!("task made..");
tsks.push(tokio::spawn(tsk));
} }
debug!("spawned read tasks"); debug!("spawned read tasks");
} }

View file

@ -346,6 +346,10 @@ impl Tunnel {
self.handle_verified_packet(packet, dst) self.handle_verified_packet(packet, dst)
} }
pub fn reset_rate_limiter(&self) {
self.rate_limiter.reset_count();
}
pub(crate) fn handle_verified_packet<'a>( pub(crate) fn handle_verified_packet<'a>(
&mut self, &mut self,
packet: Packet, packet: Packet,

View file

@ -1,6 +1,6 @@
use std::{net::SocketAddr, sync::Arc}; use std::{net::SocketAddr, sync::Arc};
use anyhow::Error; use anyhow::{Error, Result};
use fehler::throws; use fehler::throws;
use ip_network::IpNetwork; use ip_network::IpNetwork;
use rand::random; use rand::random;
@ -132,4 +132,28 @@ impl PeerPcb {
}; };
Ok(()) Ok(())
} }
pub async fn update_timers(&self, dst: &mut [u8]) -> Result<(), Error> {
match self.tunnel.write().await.update_timers(dst) {
TunnResult::Done => {}
TunnResult::Err(e) => {
tracing::error!(message = "Update timers error", error = ?e)
}
TunnResult::WriteToNetwork(packet) => {
self.open_if_closed().await?;
let handle = self.socket.read().await;
let Some(socket) = handle.as_ref() else {
tracing::error!("No socket for peer");
return Ok(())
};
socket.send(packet).await?;
}
_ => panic!("Unexpected result from update_timers"),
};
Ok(())
}
pub async fn reset_rate_limiter(&self) {
self.tunnel.read().await.reset_rate_limiter();
}
} }

View file

@ -26,7 +26,6 @@ impl TunInterface {
} }
} }
#[instrument]
pub async fn recv(&self, buf: &mut [u8]) -> io::Result<usize> { pub async fn recv(&self, buf: &mut [u8]) -> io::Result<usize> {
loop { loop {
let mut guard = self.inner.readable().await?; let mut guard = self.inner.readable().await?;