pub fn perform_random_operation(&self, group: &mut Group) -> Result<(), SetupError> {
        // Who's going to do it?
        let member_id = group.random_group_member();
        println!("Member performing the operation: {:?}", member_id);

        // TODO: Do both things.
        let action_type = match (OsRng.next_u32() as usize) % 2 {
            0 => ActionType::Proposal,
            1 => ActionType::Commit,
            _ => return Err(SetupError::Unknown),
        };

        // TODO: Do multiple things.
        let operation_type = (OsRng.next_u32() as usize) % 3;
        match operation_type {
            0 => {
                println!(
                    "Perfoming a self-update with action type: {:?}",
                    action_type
                );
                self.self_update(action_type, group, &member_id, None)?;
            }
            1 => {
                // If it's a single-member group, don't remove anyone.
                if group.members.len() > 1 {
                    // How many members?
                    let number_of_removals =
                        (((OsRng.next_u32() as usize) % group.members.len()) % 5) + 1;

                    let (own_index, _) = group
                        .members
                        .iter()
                        .find(|(_, identity)| identity == &member_id)
                        .unwrap()
                        .clone();
                    println!(
                        "Index of the member performing the {:?}: {:?}",
                        action_type, own_index
                    );

                    let mut target_member_ids = Vec::new();
                    // Get the client references, as opposed to just the member indices.
                    println!("Removing members:");
                    for _ in 0..number_of_removals {
                        // Get a random index.
                        let mut member_list_index =
                            (OsRng.next_u32() as usize) % group.members.len();
                        // Re-sample until the index is not our own index and
                        // not one that is not already being removed.
                        let (mut leaf_index, mut identity) =
                            group.members[member_list_index].clone();
                        while leaf_index == own_index || target_member_ids.contains(&identity) {
                            member_list_index = (OsRng.next_u32() as usize) % group.members.len();
                            let (new_leaf_index, new_identity) =
                                group.members[member_list_index].clone();
                            leaf_index = new_leaf_index;
                            identity = new_identity;
                        }
                        target_member_ids.push(identity);
                    }
                    self.remove_clients(action_type, group, &member_id, target_member_ids)?
                };
            }
            2 => {
                // First, figure out if there are clients left to add.
                let clients_left = self.clients.borrow().len() - group.members.len();
                if clients_left > 0 {
                    let number_of_adds = (((OsRng.next_u32() as usize) % clients_left) % 5) + 1;
                    let new_member_ids = self
                        .random_new_members_for_group(group, number_of_adds)
                        .unwrap();
                    println!(
                        "{:?}: Adding new clients: {:?}",
                        action_type, new_member_ids
                    );
                    // Have the adder add them to the group.
                    self.add_clients(action_type, group, &member_id, new_member_ids)?;
                }
            }
            _ => return Err(SetupError::Unknown),
        };
        Ok(())
    }
/// This function picks a random member of group `group` and has them
/// perform a random commit- or proposal action. TODO #133: This won't work
/// yet due to the missing proposal validation.
This function picks a random member of group `group` and has them
perform a random commit- or proposal action. TODO #133: This won't work
yet due to the missing proposal validation.
This function picks a random member of group ` group ` and has them perform a random commit - or proposal action . TODO #133 : This won ' t work yet due to the missing proposal validation .
pub fn perform_random_operation(&self, group: &mut Group) -> Result<(), SetupError> {
        // Who's going to do it?
        let member_id = group.random_group_member();
        println!("Member performing the operation: {:?}", member_id);
        // TODO: Do both things.
        let action_type = match (OsRng.next_u32() as usize) % 2 {
            0 => ActionType::Proposal,
            1 => ActionType::Commit,
            _ => return Err(SetupError::Unknown),
        };
        // TODO: Do multiple things.
        let operation_type = (OsRng.next_u32() as usize) % 3;
        match operation_type {
            0 => {
                println!(
                    "Perfoming a self-update with action type: {:?}",
                    action_type
                );
                self.self_update(action_type, group, &member_id, None)?;
            }
            1 => {
                // If it's a single-member group, don't remove anyone.
                if group.members.len() > 1 {
                    // How many members?
                    let number_of_removals =
                        (((OsRng.next_u32() as usize) % group.members.len()) % 5) + 1;
                    let (own_index, _) = group
                        .members
                        .iter()
                        .find(|(_, identity)| identity == &member_id)
                        .unwrap()
                        .clone();
                    println!(
                        "Index of the member performing the {:?}: {:?}",
                        action_type, own_index
                    );
                    let mut target_member_ids = Vec::new();
                    // Get the client references, as opposed to just the member indices.
                    println!("Removing members:");
                    for _ in 0..number_of_removals {
                        // Get a random index.
                        let mut member_list_index =
                            (OsRng.next_u32() as usize) % group.members.len();
                        // Re-sample until the index is not our own index and
                        // not one that is not already being removed.
                        let (mut leaf_index, mut identity) =
                            group.members[member_list_index].clone();
                        while leaf_index == own_index || target_member_ids.contains(&identity) {
                            member_list_index = (OsRng.next_u32() as usize) % group.members.len();
                            let (new_leaf_index, new_identity) =
                                group.members[member_list_index].clone();
                            leaf_index = new_leaf_index;
                            identity = new_identity;
                        }
                        target_member_ids.push(identity);
                    }
                    self.remove_clients(action_type, group, &member_id, target_member_ids)?
                };
            }
            2 => {
                // First, figure out if there are clients left to add.
                let clients_left = self.clients.borrow().len() - group.members.len();
                if clients_left > 0 {
                    let number_of_adds = (((OsRng.next_u32() as usize) % clients_left) % 5) + 1;
                    let new_member_ids = self
                        .random_new_members_for_group(group, number_of_adds)
                        .unwrap();
                    println!(
                        "{:?}: Adding new clients: {:?}",
                        action_type, new_member_ids
                    );
                    // Have the adder add them to the group.
                    self.add_clients(action_type, group, &member_id, new_member_ids)?;
                }
            }
            _ => return Err(SetupError::Unknown),
        };
        Ok(())
    }
pub fn perform_random_operation ( & self , group : & mut Group ) -> Result < ( ) , SetupError > { // Who's going to do it? let member_id = group . random_group_member ( ) ; println ! ( " " member_id ) ; // TODO: Do both things. let action_type = match ( OsRng . next_u32 ( ) as usize ) % 2 { 0 => ActionType :: Proposal , 1 => ActionType :: Commit , _ => return Err ( SetupError :: Unknown ) , } ; // TODO: Do multiple things. let operation_type = ( OsRng . next_u32 ( ) as usize ) % 3 ; match operation_type { 0 => { println ! ( " " action_type ) ; self . self_update ( action_type , group , & member_id , None ) ? ; } 1 => { // If it's a single-member group, don't remove anyone. if group . members . len ( ) > 1 { // How many members? let number_of_removals = ( ( ( OsRng . next_u32 ( ) as usize ) % group . members . len ( ) ) % 5 ) + 1 ; let ( own_index , _ ) = group . members . iter ( ) . find ( | ( _ , identity ) | identity == & member_id ) . unwrap ( ) . clone ( ) ; println ! ( " " action_type own_index ) ; let mut target_member_ids = Vec :: new ( ) ; // Get the client references, as opposed to just the member indices. println ! ( " " ) ; for _ in 0 .. number_of_removals { // Get a random index. let mut member_list_index = ( OsRng . next_u32 ( ) as usize ) % group . members . len ( ) ; // Re-sample until the index is not our own index and // not one that is not already being removed. let ( mut leaf_index , mut identity ) = group . members [ member_list_index ] . clone ( ) ; while leaf_index == own_index || target_member_ids . contains ( & identity ) { member_list_index = ( OsRng . next_u32 ( ) as usize ) % group . members . len ( ) ; let ( new_leaf_index , new_identity ) = group . members [ member_list_index ] . clone ( ) ; leaf_index = new_leaf_index ; identity = new_identity ; } target_member_ids . push ( identity ) ; } self . remove_clients ( action_type , group , & member_id , target_member_ids ) ? } ; } 2 => { // First, figure out if there are clients left to add. let clients_left = self . clients . borrow ( ) . len ( ) - group . members . len ( ) ; if clients_left > 0 { let number_of_adds = ( ( ( OsRng . next_u32 ( ) as usize ) % clients_left ) % 5 ) + 1 ; let new_member_ids = self . random_new_members_for_group ( group , number_of_adds ) . unwrap ( ) ; println ! ( " " action_type new_member_ids ) ; // Have the adder add them to the group. self . add_clients ( action_type , group , & member_id , new_member_ids ) ? ; } } _ => return Err ( SetupError :: Unknown ) , } ; Ok ( ( ) ) }
This function picks a random member of group `group` and has them
perform a random commit- or proposal action.
This function picks a random member of group ` group ` and has them perform a random commit - or proposal action .
&self
group
&mut Group
&self
group
&mut Group