Make partial blocking per-user, use bridges immediately
This commit is contained in:
parent
ebc508b64f
commit
fcbffdc53e
111
src/user.rs
111
src/user.rs
|
@ -40,6 +40,13 @@ pub struct User {
|
||||||
|
|
||||||
// How likely is this user to use bridges on a given day?
|
// How likely is this user to use bridges on a given day?
|
||||||
prob_use_bridges: f64,
|
prob_use_bridges: f64,
|
||||||
|
|
||||||
|
// If the censor implements partial blocking, is the user blocked?
|
||||||
|
in_censorship_range: bool,
|
||||||
|
|
||||||
|
// Track date the user joined and whether they're able to connect
|
||||||
|
pub join_date: u32,
|
||||||
|
pub able_to_connect: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
|
@ -51,21 +58,26 @@ impl User {
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let cred = Self::get_new_credential(&config).await?.0;
|
let cred = Self::get_new_credential(&config).await?.0;
|
||||||
|
|
||||||
// Probabilistically decide whether this user submits reports
|
// Decide how likely this user is to use bridges on a given day
|
||||||
let submits_reports = if is_censor {
|
// and whether they submit reports
|
||||||
false
|
let (prob_use_bridges, submits_reports) = if is_censor {
|
||||||
|
(0.0, false)
|
||||||
} else {
|
} else {
|
||||||
event_happens(config.prob_user_submits_reports)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Randomly determine how likely this user is to use bridges on
|
|
||||||
// a given day
|
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let prob_use_bridges = rng.gen_range(0.0..=1.0);
|
let prob_use_bridges = rng.gen_range(0.0..=1.0);
|
||||||
|
let submits_reports = event_happens(config.prob_user_submits_reports);
|
||||||
|
(prob_use_bridges, submits_reports)
|
||||||
|
};
|
||||||
|
|
||||||
// If the user cooperates with the censor, immediately tell the
|
let in_censorship_range = if config.censor_totality == Partial {
|
||||||
// censor about all the bridges
|
event_happens(config.censor_partial_blocking_percent)
|
||||||
if is_censor {
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut able_to_connect = false;
|
||||||
|
|
||||||
|
// Immediately download and try to use our bridges, or report them to the censor.
|
||||||
let (bucket, _reachcred) = get_bucket(&config.la_net, &cred).await?;
|
let (bucket, _reachcred) = get_bucket(&config.la_net, &cred).await?;
|
||||||
for bridgeline in bucket {
|
for bridgeline in bucket {
|
||||||
if bridgeline != BridgeLine::default() {
|
if bridgeline != BridgeLine::default() {
|
||||||
|
@ -73,7 +85,24 @@ impl User {
|
||||||
let bridge = Bridge::from_bridge_line(&bridgeline);
|
let bridge = Bridge::from_bridge_line(&bridgeline);
|
||||||
bridges.insert(bridgeline.get_hashed_fingerprint(), bridge);
|
bridges.insert(bridgeline.get_hashed_fingerprint(), bridge);
|
||||||
}
|
}
|
||||||
|
let bridge = bridges
|
||||||
|
.get_mut(&bridgeline.get_hashed_fingerprint())
|
||||||
|
.unwrap();
|
||||||
|
if is_censor {
|
||||||
censor.learn_bridge(&bridgeline.get_hashed_fingerprint());
|
censor.learn_bridge(&bridgeline.get_hashed_fingerprint());
|
||||||
|
} else if Self::connect(in_censorship_range, config, bridge, censor) {
|
||||||
|
able_to_connect = true;
|
||||||
|
} else if submits_reports {
|
||||||
|
// New user only has one bridge, so no need
|
||||||
|
// to collect the negative reports before
|
||||||
|
// sending. Just send one now.
|
||||||
|
let mut negative_reports = Vec::<NegativeReport>::new();
|
||||||
|
negative_reports.push(NegativeReport::from_bridgeline(
|
||||||
|
bridgeline,
|
||||||
|
config.country.to_string(),
|
||||||
|
BridgeDistributor::Lox,
|
||||||
|
));
|
||||||
|
Self::send_negative_reports(&config, negative_reports).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +113,9 @@ impl User {
|
||||||
secondary_cred: None,
|
secondary_cred: None,
|
||||||
submits_reports: submits_reports,
|
submits_reports: submits_reports,
|
||||||
prob_use_bridges: prob_use_bridges,
|
prob_use_bridges: prob_use_bridges,
|
||||||
|
in_censorship_range,
|
||||||
|
join_date: get_date(),
|
||||||
|
able_to_connect,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,20 +171,50 @@ impl User {
|
||||||
(prob_use_bridges, submits_reports)
|
(prob_use_bridges, submits_reports)
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the user cooperates with the censor, immediately tell the
|
let in_censorship_range = if config.censor_totality == Partial {
|
||||||
// censor about all the bridges
|
event_happens(config.censor_partial_blocking_percent)
|
||||||
if is_censor {
|
} else {
|
||||||
let (bucket, _reachcred) = get_bucket(&config.la_net, &self.primary_cred).await?;
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut able_to_connect = false;
|
||||||
|
|
||||||
|
// Immediately download bucket and test bridges or give them to
|
||||||
|
// the censor
|
||||||
|
let mut negative_reports = Vec::<NegativeReport>::new();
|
||||||
|
let (bucket, _reachcred) = get_bucket(&config.la_net, &friend_cred).await?;
|
||||||
for bridgeline in bucket {
|
for bridgeline in bucket {
|
||||||
if bridgeline != BridgeLine::default() {
|
if bridgeline != BridgeLine::default() {
|
||||||
if !bridges.contains_key(&bridgeline.get_hashed_fingerprint()) {
|
if !bridges.contains_key(&bridgeline.get_hashed_fingerprint()) {
|
||||||
let bridge = Bridge::from_bridge_line(&bridgeline);
|
let bridge = Bridge::from_bridge_line(&bridgeline);
|
||||||
bridges.insert(bridgeline.get_hashed_fingerprint(), bridge);
|
bridges.insert(bridgeline.get_hashed_fingerprint(), bridge);
|
||||||
}
|
}
|
||||||
|
let bridge = bridges
|
||||||
|
.get_mut(&bridgeline.get_hashed_fingerprint())
|
||||||
|
.unwrap();
|
||||||
|
if is_censor {
|
||||||
censor.learn_bridge(&bridgeline.get_hashed_fingerprint());
|
censor.learn_bridge(&bridgeline.get_hashed_fingerprint());
|
||||||
|
} else if Self::connect(in_censorship_range, config, bridge, censor) {
|
||||||
|
able_to_connect = true;
|
||||||
|
} else if submits_reports {
|
||||||
|
negative_reports.push(NegativeReport::from_bridgeline(
|
||||||
|
bridgeline,
|
||||||
|
config.country.to_string(),
|
||||||
|
BridgeDistributor::Lox,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Submit reports if we have them
|
||||||
|
if negative_reports.len() > 0 {
|
||||||
|
Self::send_negative_reports(&config, negative_reports).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let in_censorship_range = if config.censor_totality == Partial {
|
||||||
|
event_happens(config.censor_partial_blocking_percent)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
is_censor,
|
is_censor,
|
||||||
|
@ -160,17 +222,24 @@ impl User {
|
||||||
secondary_cred: None,
|
secondary_cred: None,
|
||||||
submits_reports: submits_reports,
|
submits_reports: submits_reports,
|
||||||
prob_use_bridges: prob_use_bridges,
|
prob_use_bridges: prob_use_bridges,
|
||||||
|
in_censorship_range,
|
||||||
|
join_date: get_date(),
|
||||||
|
able_to_connect,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to "connect" to the bridge, returns true if successful.
|
// Attempt to "connect" to the bridge, returns true if successful.
|
||||||
// Note that this does not involve making a real connection to a
|
// Note that this does not involve making a real connection to a
|
||||||
// real bridge.
|
// real bridge.
|
||||||
pub fn connect(&self, config: &Config, bridge: &mut Bridge, censor: &Censor) -> bool {
|
pub fn connect(
|
||||||
|
in_censorship_range: bool,
|
||||||
|
config: &Config,
|
||||||
|
bridge: &mut Bridge,
|
||||||
|
censor: &Censor,
|
||||||
|
) -> bool {
|
||||||
if censor.blocks_bridge(config, &bridge.fingerprint) {
|
if censor.blocks_bridge(config, &bridge.fingerprint) {
|
||||||
if config.censor_totality == Full
|
if config.censor_totality == Full
|
||||||
|| config.censor_totality == Partial
|
|| config.censor_totality == Partial && in_censorship_range
|
||||||
&& event_happens(censor.partial_blocking_percent)
|
|
||||||
{
|
{
|
||||||
// If censor tries to hide its censorship, record a
|
// If censor tries to hide its censorship, record a
|
||||||
// false connection
|
// false connection
|
||||||
|
@ -327,7 +396,8 @@ impl User {
|
||||||
for i in 0..bucket.len() {
|
for i in 0..bucket.len() {
|
||||||
// At level 0, we only have 1 bridge
|
// At level 0, we only have 1 bridge
|
||||||
if bucket[i] != BridgeLine::default() {
|
if bucket[i] != BridgeLine::default() {
|
||||||
if self.connect(
|
if Self::connect(
|
||||||
|
self.in_censorship_range,
|
||||||
&config,
|
&config,
|
||||||
bridges
|
bridges
|
||||||
.get_mut(&bucket[i].get_hashed_fingerprint())
|
.get_mut(&bucket[i].get_hashed_fingerprint())
|
||||||
|
@ -374,7 +444,8 @@ impl User {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Attempt to connect to second cred's bridge
|
// Attempt to connect to second cred's bridge
|
||||||
if self.connect(
|
if Self::connect(
|
||||||
|
self.in_censorship_range,
|
||||||
&config,
|
&config,
|
||||||
bridges
|
bridges
|
||||||
.get_mut(&bridgeline.get_hashed_fingerprint())
|
.get_mut(&bridgeline.get_hashed_fingerprint())
|
||||||
|
|
Loading…
Reference in New Issue