Quellcode durchsuchen

Allow users to migrate from level 0 to 1

Vecna vor 4 Monaten
Ursprung
Commit
33070b62f1
1 geänderte Dateien mit 53 neuen und 53 gelöschten Zeilen
  1. 53 53
      src/user.rs

+ 53 - 53
src/user.rs

@@ -449,11 +449,11 @@ impl User {
             };
 
             // Can we level up the main credential?
-            let can_level_up = reachcred.is_some()
-                && (level == 0
-                    && eligible_for_trust_promotion(&config.la_net, &self.primary_cred).await
-                    || level > 0
-                        && eligible_for_level_up(&config.la_net, &self.primary_cred).await);
+            let can_level_up = level == 0
+                && eligible_for_trust_promotion(&config.la_net, &self.primary_cred).await
+                || reachcred.is_some()
+                    && level > 0
+                    && eligible_for_level_up(&config.la_net, &self.primary_cred).await;
 
             // Can we migrate the main credential?
             let can_migrate = reachcred.is_none() && level >= MIN_TRUST_LEVEL;
@@ -608,8 +608,6 @@ impl User {
             // let's just allow it.
 
             if can_level_up {
-                // If we can level up/trust migrate, do so
-
                 // Trust migration from level 0 to level 1
                 let cred = if level == 0 {
                     trust_migration(
@@ -653,6 +651,7 @@ impl User {
                     get_migration_pub(&config.la_pubkeys),
                 )
                 .await?;
+
                 self.primary_cred = cred;
                 self.secondary_cred = None;
             } else if second_level_up {
@@ -672,6 +671,7 @@ impl User {
                     get_migration_pub(&config.la_pubkeys),
                 )
                 .await?;
+
                 self.primary_cred = cred;
                 self.secondary_cred = None;
             } else if second_cred.is_some() {
@@ -783,56 +783,56 @@ impl User {
         }
 
         // Censor user tries to level up their primary credential
-        if reachcred.is_some() {
-            if level == 0 && eligible_for_trust_promotion(&config.la_net, &self.primary_cred).await
-                || level > 0 && eligible_for_level_up(&config.la_net, &self.primary_cred).await
-            {
-                let new_cred = if level == 0 {
-                    trust_migration(
-                        &config.la_net,
-                        &self.primary_cred,
-                        &trust_promotion(
-                            &config.la_net,
-                            &self.primary_cred,
-                            get_lox_pub(&config.la_pubkeys),
-                        )
-                        .await?,
-                        get_lox_pub(&config.la_pubkeys),
-                        get_migration_pub(&config.la_pubkeys),
-                    )
-                    .await?
-                } else {
-                    level_up(
+        if level == 0 && eligible_for_trust_promotion(&config.la_net, &self.primary_cred).await
+            || reachcred.is_some()
+                && level > 0
+                && eligible_for_level_up(&config.la_net, &self.primary_cred).await
+        {
+            let new_cred = if level == 0 {
+                trust_migration(
+                    &config.la_net,
+                    &self.primary_cred,
+                    &trust_promotion(
                         &config.la_net,
                         &self.primary_cred,
-                        &reachcred.unwrap(),
                         get_lox_pub(&config.la_pubkeys),
-                        get_reachability_pub(&config.la_pubkeys),
                     )
-                    .await?
-                };
-                self.primary_cred = new_cred;
-                let (bucket, _reachcred) = get_bucket(&config.la_net, &self.primary_cred).await?;
-                // Make sure each bridge is in global bridges set and
-                // known by censor
-                for bl in bucket {
-                    let fingerprint = bl.get_hashed_fingerprint();
-                    if !bridges.contains_key(&fingerprint) {
-                        let bridge = Bridge::from_bridge_line(&bl);
-                        bridges.insert(fingerprint, bridge);
-                    }
-                    censor.learn_bridge(&fingerprint);
-                    if level == 2 {
-                        // level up to 3
-                        // Give censor an additional credential
-                        censor.give_lox_cred(&fingerprint, &self.primary_cred, true);
-                    } else if level > 2 {
-                        // level up to 4
-                        // Replace censor's credential with newer one,
-                        // but don't add to count of censor's
-                        // credentials
-                        censor.give_lox_cred(&fingerprint, &self.primary_cred, false);
-                    }
+                    .await?,
+                    get_lox_pub(&config.la_pubkeys),
+                    get_migration_pub(&config.la_pubkeys),
+                )
+                .await?
+            } else {
+                level_up(
+                    &config.la_net,
+                    &self.primary_cred,
+                    &reachcred.unwrap(),
+                    get_lox_pub(&config.la_pubkeys),
+                    get_reachability_pub(&config.la_pubkeys),
+                )
+                .await?
+            };
+            self.primary_cred = new_cred;
+            let (bucket, _reachcred) = get_bucket(&config.la_net, &self.primary_cred).await?;
+            // Make sure each bridge is in global bridges set and
+            // known by censor
+            for bl in bucket {
+                let fingerprint = bl.get_hashed_fingerprint();
+                if !bridges.contains_key(&fingerprint) {
+                    let bridge = Bridge::from_bridge_line(&bl);
+                    bridges.insert(fingerprint, bridge);
+                }
+                censor.learn_bridge(&fingerprint);
+                if level == 2 {
+                    // level up to 3
+                    // Give censor an additional credential
+                    censor.give_lox_cred(&fingerprint, &self.primary_cred, true);
+                } else if level > 2 {
+                    // level up to 4
+                    // Replace censor's credential with newer one,
+                    // but don't add to count of censor's
+                    // credentials
+                    censor.give_lox_cred(&fingerprint, &self.primary_cred, false);
                 }
             }
         } else {