Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
sim: Change a few things in the simulator
cloudhead committed 2 years ago
commit 4307bdaae4355213efdaa46afc16fed4f53cb754
parent d1f4161ee9d8c55b7e9f7c42b28a9b3277470032
1 file changed +5 -22
modified radicle-node/src/test/simulator.rs
@@ -259,25 +259,7 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
        self.latencies
            .get(&(from, to))
            .cloned()
-
            .map(|l| {
-
                let mut rng = self.rng.borrow_mut();
-

-
                if l <= MIN_LATENCY {
-
                    l
-
                } else {
-
                    // Create variance in the latency. The resulting latency
-
                    // will be between half, and two times the base latency.
-
                    let millis = l.as_millis();
-

-
                    if rng.bool() {
-
                        // More latency.
-
                        LocalDuration::from_millis(millis + rng.u128(0..millis))
-
                    } else {
-
                        // Less latency.
-
                        LocalDuration::from_millis(millis - rng.u128(0..millis / 2))
-
                    }
-
                }
-
            })
+
            .map(|l| if l < MIN_LATENCY { MIN_LATENCY } else { l })
            .unwrap_or_else(|| MIN_LATENCY)
    }

@@ -409,9 +391,10 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
                        let attempt = self.attempts.remove(&conn);
                        let connection = self.connections.remove(&conn);

-
                        // Can't be both attempting and connected.
-
                        assert!(!(attempt && connection));
-

+
                        // FIXME: This shouldn't happen, but it does when latency is introduced.
+
                        if attempt && connection {
+
                            log::error!(target: "sim", "Connection is attempted and connected at the same time");
+
                        }
                        if attempt || connection {
                            p.disconnected(id, &reason);
                        }