Bladeren bron

Handle errors sending positive reports

Vecna 4 maanden geleden
bovenliggende
commit
135d2c6b02
2 gewijzigde bestanden met toevoegingen van 22 en 23 verwijderingen
  1. 11 11
      src/censor.rs
  2. 11 12
      src/user.rs

+ 11 - 11
src/censor.rs

@@ -126,22 +126,22 @@ impl Censor {
         }
 
         let (cred, _) = &self.lox_credentials.get(fingerprint).unwrap();
-        let pr = PositiveReport::from_lox_credential(
+        if let Ok(pr) = PositiveReport::from_lox_credential(
             *fingerprint,
             None,
             cred,
             get_lox_pub(&config.la_pubkeys),
             config.country.clone(),
-        )
-        .unwrap();
-        if config
-            .tp_net
-            .request("/positivereport".to_string(), pr.to_json().into_bytes())
-            .await
-            .is_err()
-        {
-            // failed to send positive report
-            return false;
+        ) {
+            if config
+                .tp_net
+                .request("/positivereport".to_string(), pr.to_json().into_bytes())
+                .await
+                .is_err()
+            {
+                // failed to send positive report
+                return false;
+            }
         }
         true
     }

+ 11 - 12
src/user.rs

@@ -589,16 +589,15 @@ impl User {
                             bridge.first_positive_report = get_date();
                         }
 
-                        positive_reports.push(
-                            PositiveReport::from_lox_credential(
-                                fingerprint,
-                                None,
-                                &self.primary_cred,
-                                get_lox_pub(&config.la_pubkeys),
-                                config.country.to_string(),
-                            )
-                            .unwrap(),
-                        );
+                        if let Ok(pr) = PositiveReport::from_lox_credential(
+                            fingerprint,
+                            None,
+                            &self.primary_cred,
+                            get_lox_pub(&config.la_pubkeys),
+                            config.country.to_string(),
+                        ) {
+                            positive_reports.push(pr)
+                        }
                     }
                 }
             }
@@ -628,7 +627,7 @@ impl User {
                     level_up(
                         &config.la_net,
                         &self.primary_cred,
-                        &reachcred.unwrap(),
+                        &reachcred.unwrap(), // must be Some
                         get_lox_pub(&config.la_pubkeys),
                         get_reachability_pub(&config.la_pubkeys),
                     )
@@ -806,7 +805,7 @@ impl User {
                 level_up(
                     &config.la_net,
                     &self.primary_cred,
-                    &reachcred.unwrap(),
+                    &reachcred.unwrap(), // must be Some
                     get_lox_pub(&config.la_pubkeys),
                     get_reachability_pub(&config.la_pubkeys),
                 )