fn network_is_complete(
    blocklist: &HashSet<NodeId>,
    nodes: &HashMap<NodeId, Runner<ConditionCheckReactor<TestReactor>>>,
) -> bool {
    // Collect expected nodes.
    let expected: HashSet<_> = nodes
        .keys()
        .filter(|&node_id| !blocklist.contains(node_id))
        .copied()
        .collect();

    for (node_id, node) in nodes {
        let net = &node.reactor().inner().net;
        // TODO: Ensure the connections are symmetrical.
        let peers: HashSet<_> = net.peers().into_iter().map(|(k, _)| k).collect();

        let mut missing = expected.difference(&peers);

        if let Some(first_missing) = missing.next() {
            // We only allow loopbacks to be missing.
            if first_missing != node_id {
                return false;
            }
        }

        if missing.next().is_some() {
            // We have at least two missing, which cannot be.
            return false;
        }
    }
    true
}
/// Checks whether or not a given network with potentially blocked nodes is completely connected.
Checks whether or not a given network with potentially blocked nodes is completely connected.
Checks whether or not a given network with potentially blocked nodes is completely connected .
fn network_is_complete(
    blocklist: &HashSet<NodeId>,
    nodes: &HashMap<NodeId, Runner<ConditionCheckReactor<TestReactor>>>,
) -> bool {
    // Collect expected nodes.
    let expected: HashSet<_> = nodes
        .keys()
        .filter(|&node_id| !blocklist.contains(node_id))
        .copied()
        .collect();
    for (node_id, node) in nodes {
        let net = &node.reactor().inner().net;
        // TODO: Ensure the connections are symmetrical.
        let peers: HashSet<_> = net.peers().into_iter().map(|(k, _)| k).collect();
        let mut missing = expected.difference(&peers);
        if let Some(first_missing) = missing.next() {
            // We only allow loopbacks to be missing.
            if first_missing != node_id {
                return false;
            }
        }
        if missing.next().is_some() {
            // We have at least two missing, which cannot be.
            return false;
        }
    }
    true
}
fn network_is_complete ( blocklist : & HashSet < NodeId > , nodes : & HashMap < NodeId , Runner < ConditionCheckReactor < TestReactor > > > , ) -> bool { // Collect expected nodes. let expected : HashSet < _ > = nodes . keys ( ) . filter ( | & node_id | ! blocklist . contains ( node_id ) ) . copied ( ) . collect ( ) ; for ( node_id , node ) in nodes { let net = & node . reactor ( ) . inner ( ) . net ; // TODO: Ensure the connections are symmetrical. let peers : HashSet < _ > = net . peers ( ) . into_iter ( ) . map ( | ( k , _ ) | k ) . collect ( ) ; let mut missing = expected . difference ( & peers ) ; if let Some ( first_missing ) = missing . next ( ) { // We only allow loopbacks to be missing. if first_missing != node_id { return false ; } } if missing . next ( ) . is_some ( ) { // We have at least two missing, which cannot be. return false ; } } true }
Checks whether or not a given network with potentially blocked nodes is completely connected.
Checks whether or not a given network with potentially blocked nodes is completely connected .
blocklist
&HashSet<NodeId>
nodes
&HashMap<NodeId, Runner<ConditionCheckReactor<TestReactor>>>
blocklist
&HashSet<NodeId>
nodes
&HashMap<NodeId, Runner<ConditionCheckReactor<TestReactor>>>