Initial cut of integrating with tracing
This commit is contained in:
parent
6e98665d17
commit
558539332f
|
@ -13,3 +13,5 @@ rand_distr = "0.4.0"
|
||||||
hashbrown = "0.9.1"
|
hashbrown = "0.9.1"
|
||||||
termcolor = "1.1.2"
|
termcolor = "1.1.2"
|
||||||
clap = "3.0.0-beta.2"
|
clap = "3.0.0-beta.2"
|
||||||
|
tracing = "0.1.0"
|
||||||
|
tracing-subscriber = "0.2"
|
38
src/main.rs
38
src/main.rs
|
@ -5,8 +5,12 @@ use std::io::Write;
|
||||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
||||||
mod parties;
|
mod parties;
|
||||||
mod server;
|
mod server;
|
||||||
|
|
||||||
use clap::Clap;
|
use clap::Clap;
|
||||||
|
use tracing::event;
|
||||||
|
|
||||||
|
use tracing::Level;
|
||||||
|
use tracing_subscriber;
|
||||||
|
use tracing_subscriber::FmtSubscriber;
|
||||||
|
|
||||||
#[derive(Clap)]
|
#[derive(Clap)]
|
||||||
#[clap(version = "1.0", author = "Sarah Jamie Lewis <sarah@openprivacy.ca>")]
|
#[clap(version = "1.0", author = "Sarah Jamie Lewis <sarah@openprivacy.ca>")]
|
||||||
|
@ -29,31 +33,49 @@ struct Opts {
|
||||||
/// maximum false positive rate
|
/// maximum false positive rate
|
||||||
#[clap(short, long, default_value = "8")]
|
#[clap(short, long, default_value = "8")]
|
||||||
max_p: usize,
|
max_p: usize,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
trace: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let opts: Opts = Opts::parse();
|
let opts: Opts = Opts::parse();
|
||||||
|
let level = match opts.trace {
|
||||||
|
true => Level::TRACE,
|
||||||
|
_ => Level::INFO,
|
||||||
|
};
|
||||||
|
let subscriber = FmtSubscriber::builder().with_max_level(level).finish();
|
||||||
|
tracing::subscriber::with_default(subscriber, || {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let mut server = SimulatedServer::new();
|
let mut server = SimulatedServer::new();
|
||||||
|
|
||||||
println!("Generating {} Parties...", opts.num_parties);
|
|
||||||
let simulated_parties = SimulatedParties::new_simulation(opts.num_parties, opts.gamma);
|
let simulated_parties = SimulatedParties::new_simulation(opts.num_parties, opts.gamma);
|
||||||
|
{
|
||||||
|
event!(Level::INFO, "Generating {} Parties and registering them with the server", opts.num_parties);
|
||||||
simulated_parties.register_with_server(&mut server, &mut rng, opts.min_p, opts.max_p);
|
simulated_parties.register_with_server(&mut server, &mut rng, opts.min_p, opts.max_p);
|
||||||
|
}
|
||||||
|
|
||||||
let pareto = Pareto::new(1.0, 1.0).unwrap();
|
let pareto = Pareto::new(1.0, 1.0).unwrap();
|
||||||
|
|
||||||
println!("Simulating message sends using {} samples from a pareto distribution...", opts.samples_per_round);
|
{
|
||||||
|
event!(Level::INFO, "Simulating message sends using {} samples from a pareto distribution...", opts.samples_per_round);
|
||||||
(0..opts.samples_per_round).for_each(|_i| simulated_parties.sample_traffic(&mut server, &mut rng, pareto));
|
(0..opts.samples_per_round).for_each(|_i| simulated_parties.sample_traffic(&mut server, &mut rng, pareto));
|
||||||
|
}
|
||||||
|
|
||||||
println!("Simulating Adversarial Server Processing Messages..");
|
{
|
||||||
|
event!(Level::INFO, "Simulating Adversarial Server Processing Messages..");
|
||||||
server.test_messages();
|
server.test_messages();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
let (round_stats, party_stats) = server.statistics();
|
let (round_stats, party_stats) = server.statistics();
|
||||||
|
|
||||||
let if_uniform = (round_stats.num_messages as f64) / (round_stats.num_registered_parties as f64);
|
let if_uniform = (round_stats.num_messages as f64) / (round_stats.num_registered_parties as f64);
|
||||||
println!(
|
event!(
|
||||||
|
Level::INFO,
|
||||||
"Round had {} messages, send to {} parties ({:.2} is uniform distribution)",
|
"Round had {} messages, send to {} parties ({:.2} is uniform distribution)",
|
||||||
round_stats.num_messages, round_stats.num_registered_parties, if_uniform
|
round_stats.num_messages,
|
||||||
|
round_stats.num_registered_parties,
|
||||||
|
if_uniform
|
||||||
);
|
);
|
||||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||||
for (party, stats) in party_stats.iter() {
|
for (party, stats) in party_stats.iter() {
|
||||||
|
@ -77,3 +99,5 @@ fn main() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@ use fuzzytags::FuzzySecretKey;
|
||||||
use rand::distributions::Distribution;
|
use rand::distributions::Distribution;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand_distr::num_traits::ToPrimitive;
|
use rand_distr::num_traits::ToPrimitive;
|
||||||
|
use tracing::event;
|
||||||
|
use tracing::span;
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
pub struct SimulatedParties {
|
pub struct SimulatedParties {
|
||||||
parties: Vec<FuzzySecretKey>,
|
parties: Vec<FuzzySecretKey>,
|
||||||
|
@ -22,9 +25,15 @@ impl SimulatedParties {
|
||||||
where
|
where
|
||||||
R: Rng,
|
R: Rng,
|
||||||
{
|
{
|
||||||
|
let span = span!(Level::TRACE, "register_with_server");
|
||||||
|
let _enter = span.enter();
|
||||||
for party in self.parties.iter() {
|
for party in self.parties.iter() {
|
||||||
let n = rng.gen_range(min_p..max_p);
|
let n = rng.gen_range(min_p..max_p);
|
||||||
|
let span = span!(Level::TRACE, "{register}", party = party.public_key().id().as_str());
|
||||||
|
let _enter = span.enter();
|
||||||
let detection_key = party.extract(n);
|
let detection_key = party.extract(n);
|
||||||
|
event!(Level::TRACE, "create detection key {detection_key}", detection_key = detection_key.id().as_str());
|
||||||
|
event!(Level::TRACE, "register with server");
|
||||||
server.register_key(&detection_key, &party.public_key());
|
server.register_key(&detection_key, &party.public_key());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,14 +43,18 @@ impl SimulatedParties {
|
||||||
D: Distribution<f64>,
|
D: Distribution<f64>,
|
||||||
R: Rng,
|
R: Rng,
|
||||||
{
|
{
|
||||||
|
let span = span!(Level::TRACE, "sample_traffic");
|
||||||
|
let _enter = span.enter();
|
||||||
let v = distribution.sample(rng).to_u16().unwrap();
|
let v = distribution.sample(rng).to_u16().unwrap();
|
||||||
let receiver = rng.gen_range(0..self.parties.len());
|
let receiver = rng.gen_range(0..self.parties.len());
|
||||||
let receiver_public_key = self.parties.get(receiver).unwrap().public_key();
|
let receiver_public_key = self.parties.get(receiver).unwrap().public_key();
|
||||||
println!("[Oracle] {} received {} messages", receiver_public_key.id(), v);
|
|
||||||
|
let span = span!(Level::TRACE, "{party}", party = receiver_public_key.id().as_str());
|
||||||
|
let _enter = span.enter();
|
||||||
for _i in 0..v {
|
for _i in 0..v {
|
||||||
let tag = receiver_public_key.generate_tag();
|
let tag = receiver_public_key.generate_tag();
|
||||||
|
event!(Level::TRACE, "message sent to {tag}", tag = tag.to_string());
|
||||||
server.add_message(tag);
|
server.add_message(tag);
|
||||||
//message_oracle.push(receiver);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
use fuzzytags::{FuzzyDetectionKey, FuzzyPublicKey, FuzzyTag};
|
use fuzzytags::{FuzzyDetectionKey, FuzzyPublicKey, FuzzyTag};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
use tracing::event;
|
||||||
|
use tracing::span;
|
||||||
|
use tracing::Level;
|
||||||
|
|
||||||
pub struct SimulatedServer {
|
pub struct SimulatedServer {
|
||||||
keybase: Vec<(FuzzyDetectionKey, FuzzyPublicKey)>,
|
keybase: Vec<(FuzzyDetectionKey, FuzzyPublicKey)>,
|
||||||
|
@ -47,7 +50,10 @@ impl SimulatedServer {
|
||||||
pub fn test_messages(&mut self) {
|
pub fn test_messages(&mut self) {
|
||||||
for message in self.messages.iter() {
|
for message in self.messages.iter() {
|
||||||
for (detection_key, public_key) in self.keybase.iter() {
|
for (detection_key, public_key) in self.keybase.iter() {
|
||||||
|
let span = span!(Level::TRACE, "{detection}", party = public_key.id().as_str());
|
||||||
|
let _enter = span.enter();
|
||||||
if detection_key.test_tag(message) {
|
if detection_key.test_tag(message) {
|
||||||
|
event!(Level::TRACE, "Matched detection key for {key} to tag {tag} ", key = public_key.id(), tag = message.to_string());
|
||||||
self.tags_to_keys_cache.get_mut(message.to_string().as_str()).unwrap().push((*public_key).clone());
|
self.tags_to_keys_cache.get_mut(message.to_string().as_str()).unwrap().push((*public_key).clone());
|
||||||
|
|
||||||
self.keys_to_tags_cache.get_mut(public_key.id().as_str()).unwrap().push((*message).clone());
|
self.keys_to_tags_cache.get_mut(public_key.id().as_str()).unwrap().push((*message).clone());
|
||||||
|
|
Loading…
Reference in New Issue