Browse Source

Have Troll Patrol generate new negative report key if necessary

Vecna 9 months ago
parent
commit
d32c352ccc
2 changed files with 8 additions and 5 deletions
  1. 0 4
      src/bin/simulation.rs
  2. 8 1
      src/request_handler.rs

+ 0 - 4
src/bin/simulation.rs

@@ -199,10 +199,6 @@ pub async fn main() {
             }
         }
 
-        // Have Troll Patrol run its update process so we have a negative
-        // report key for tomorrow
-        tp_net_test.request("/update".to_string(), vec![]).await;
-
         // Advance LA's time to tomorrow
         la_net_test
             .request(

+ 8 - 1
src/request_handler.rs

@@ -33,7 +33,14 @@ pub async fn handle(db: &Db, req: Request<Body>) -> Result<Response<Body>, Infal
                         return Ok(prepare_header(val));
                     }
                 };
-                let pubkey = get_negative_report_public_key(&db, date);
+                // Get the current key or generate a new one. Note that
+                // this code is only called in simulation. In
+                // production, users should not be able to induce Troll
+                // Patrol to generate new keys.
+                let pubkey = match get_negative_report_public_key(&db, date) {
+                    Some(k) => Some(k),
+                    None => new_negative_report_key(&db, date),
+                };
                 prepare_header(serde_json::to_string(&pubkey).unwrap())
             }),
             (&Method::POST, "/negativereport") => Ok::<_, Infallible>({