Begin work on cleaning up old nonces
This commit is contained in:
parent
158512f427
commit
5c6a076289
14
src/lib.rs
14
src/lib.rs
|
@ -321,6 +321,19 @@ pub async fn update_extra_infos(
|
||||||
/// We store to-be-processed negative reports as a vector. Add this NR
|
/// We store to-be-processed negative reports as a vector. Add this NR
|
||||||
/// to that vector (or create a new vector if necessary)
|
/// to that vector (or create a new vector if necessary)
|
||||||
pub fn save_negative_report_to_process(db: &Db, nr: NegativeReport) {
|
pub fn save_negative_report_to_process(db: &Db, nr: NegativeReport) {
|
||||||
|
// TODO: Purge these database entries sometimes
|
||||||
|
let mut nonces = match db.get(format!("nonces_{}", &nr.date)).unwrap() {
|
||||||
|
Some(v) => bincode::deserialize(&v).unwrap(),
|
||||||
|
None => HashSet::<[u8; 32]>::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Just ignore the report if we've seen the nonce before
|
||||||
|
if nonces.insert(nr.nonce) {
|
||||||
|
db.insert(
|
||||||
|
format!("nonces_{}", &nr.date),
|
||||||
|
bincode::serialize(&nonces).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let mut reports = match db.get("nrs-to-process").unwrap() {
|
let mut reports = match db.get("nrs-to-process").unwrap() {
|
||||||
Some(v) => bincode::deserialize(&v).unwrap(),
|
Some(v) => bincode::deserialize(&v).unwrap(),
|
||||||
None => BTreeMap::<String, Vec<SerializableNegativeReport>>::new(),
|
None => BTreeMap::<String, Vec<SerializableNegativeReport>>::new(),
|
||||||
|
@ -346,6 +359,7 @@ pub fn save_negative_report_to_process(db: &Db, nr: NegativeReport) {
|
||||||
db.insert("nrs-to-process", bincode::serialize(&reports).unwrap())
|
db.insert("nrs-to-process", bincode::serialize(&reports).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Sends a collection of negative reports to the Lox Authority and returns the
|
/// Sends a collection of negative reports to the Lox Authority and returns the
|
||||||
/// number of valid reports returned by the server. The negative reports in the
|
/// number of valid reports returned by the server. The negative reports in the
|
||||||
|
|
Loading…
Reference in New Issue