Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 16 additions & 4 deletions crates/chaff-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
#![cfg(not(tarpaulin_include))]

use borsh::BorshDeserialize as _;
use std::{fs::File, path::PathBuf};
use std::{fs::File, path::PathBuf, time::Duration};

use bpaf::Bpaf;
use chaff::machine::Machine;
use chaff::{
distr::{Distr, DistrKind},
machine::Machine,
};
use chaff_cli::{
errors::CliError,
subcommands::{cap_convert, capture, dataset_convert, dataset_stats, simulate, trace_stats},
utils::parse_dataset,
};
use chaff_machines::constant;
use chaff_machines::wtf_pad_lite;

/// Command-line interface options
#[derive(Debug, Clone, Bpaf)]
Expand Down Expand Up @@ -147,11 +150,20 @@ fn run() -> Result<(), CliError> {
CliOptions::TraceStats { input } => trace_stats::run(&input),
CliOptions::DatasetStats { dataset_type, path } => dataset_stats::run(&dataset_type, &path),
CliOptions::Simulate { action, machine } => {
#[expect(clippy::unwrap_used)]
let machine = if let Some(path) = machine {
let mut file = File::open(path)?;
Machine::deserialize_reader(&mut file)?
} else {
constant::construct()
// constant::construct()
let delay_distr: Distr = DistrKind::Normal {
mean: 0.015,
std_dev: 0.05,
}
.try_into()
.unwrap();
let timeout: Distr = Duration::from_secs_f64(1.0).try_into().unwrap();
wtf_pad_lite::construct(delay_distr, timeout)
};

match action {
Expand Down
3 changes: 2 additions & 1 deletion crates/chaff-machines/src/wtf_pad_lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use chaff::{
///
/// This defence does not do both burst and gap level padding, has different stop conditions, and a
/// different way of sampling distributions.
///
/// # Panics
///
/// Shouldn't panic unless modified.
Expand Down Expand Up @@ -96,5 +97,5 @@ pub fn construct(
actions: [FrameworkAction::CancelAll],
}
}
.expect("preconstructed machine should be valid")
.expect("premade machine with valid distrs was invalid")
}
111 changes: 65 additions & 46 deletions crates/chaff-sim/benches/tiktok_undefended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,93 @@

#![expect(clippy::unwrap_used)]

use ::chaff::{action::IntegratorAction, event::Event, machine};
use ::chaff::{
action::IntegratorAction,
distr::{Distr, DistrKind},
event::Event,
machine,
};
use chaff_cli::subcommands::simulate;
use chaff_datasets::parsers::chaff;
use chaff_machines::constant;
use chaff_machines::{constant, wtf_pad_lite};
use criterion::{Criterion, criterion_group, criterion_main};
use std::{hint::black_box, path::Path};
use std::{hint::black_box, path::Path, time::Duration};

fn constant(c: &mut Criterion) {
fn machines(c: &mut Criterion) {
let workspace_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let dataset_dir = workspace_dir
.parent()
.and_then(Path::parent)
.unwrap()
.join("data/tik_tok_undefended.chaff");
let dataset = chaff::try_parse(dataset_dir).unwrap();
let machine = constant::construct();

c.bench_function("tiktok undefended const", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
}
{
let delay_distr: Distr = DistrKind::Normal {
mean: 0.015,
std_dev: 0.05,
}
.try_into()
.unwrap();
let timeout: Distr = Duration::from_secs(1).try_into().unwrap();
let machine = wtf_pad_lite::construct(delay_distr, timeout);

fn no_op(c: &mut Criterion) {
let workspace_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let dataset_dir = workspace_dir
.parent()
.and_then(Path::parent)
.unwrap()
.join("data/tik_tok_undefended.chaff");
let dataset = chaff::try_parse(dataset_dir).unwrap();
let machine = machine! {
queues: [],
state init {},
c.bench_function("tiktok undefended wtf_pad_lite normal", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
}
.unwrap();

c.bench_function("tiktok undefended no_op", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
}
{
let delay_distr: Distr = Duration::from_secs_f64(0.015).try_into().unwrap();
let timeout: Distr = Duration::from_secs(1).try_into().unwrap();
let machine = wtf_pad_lite::construct(delay_distr, timeout);

fn double(c: &mut Criterion) {
let workspace_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let dataset_dir = workspace_dir
.parent()
.and_then(Path::parent)
.unwrap()
.join("data/tik_tok_undefended.chaff");
let dataset = chaff::try_parse(dataset_dir).unwrap();
let machine = machine! {
queues: [],
state double {
action: IntegratorAction::SendDecoy,
transitions: [
Event::SendNormal => double,
],
},
c.bench_function("tiktok undefended wtf_pad_lite constant", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
}

{
let machine = constant::construct();

c.bench_function("tiktok undefended const", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
}

{
let machine = machine! {
queues: [],
state double {
actions: [IntegratorAction::SendDecoy],
transitions: [
Event::SendNormal => double,
],
},
}
.unwrap();

c.bench_function("tiktok undefended double", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
}
.unwrap();

c.bench_function("tiktok undefended double", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
{
let machine = machine! {
queues: [],
state init {},
}
.unwrap();

c.bench_function("tiktok undefended no_op", |b| {
b.iter(|| simulate::run_dataset(black_box(&dataset), &None, black_box(&machine)));
});
}
}

criterion_group!(
name = tiktok_undefended;
config = Criterion::default().sample_size(20);
targets = constant, no_op, double
targets = machines
);
criterion_main!(tiktok_undefended);
Loading