Begin work on cleaning up old nonces

This commit is contained in:
Vecna 2024-04-12 12:50:40 -04:00
parent 158512f427
commit 5c6a076289
1 changed files with 35 additions and 21 deletions

View File

@ -321,6 +321,19 @@ pub async fn update_extra_infos(
/// We store to-be-processed negative reports as a vector. Add this NR
/// to that vector (or create a new vector if necessary)
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() {
Some(v) => bincode::deserialize(&v).unwrap(),
None => BTreeMap::<String, Vec<SerializableNegativeReport>>::new(),
@ -345,6 +358,7 @@ pub fn save_negative_report_to_process(db: &Db, nr: NegativeReport) {
// Commit changes to database
db.insert("nrs-to-process", bincode::serialize(&reports).unwrap())
.unwrap();
}
}
/// Sends a collection of negative reports to the Lox Authority and returns the