pub(crate) fn synthesize_ic_commands<P: AsRef<Path>>(
        logger: &Logger,
        ic: &InternetComputer,
        prep_dir: P,
    ) -> Vec<NodeCommand> {
        let initialize_ic = |addr_allocator: &mut dyn TcpAddrAllocator| {
            Self::initialize_ic(logger, ic, prep_dir, addr_allocator)
        };
        if ic.experimental_vm_test {
            // XXX: This will be replaced with actual addresses
            let num_addrs = ic.subnets.iter().map(|s| s.nodes.len()).sum();
            let addrs: Vec<IpAddr> = (0..num_addrs)
                .map(|i| IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, i as u16)))
                .collect();
            let mut addr_allocator = VmAddrAllocator::new(addrs);
            let (initialized_ic, malicious_nodes) = initialize_ic(&mut addr_allocator);

            // assemble target path
            let cfg_img_dir = tempfile::tempdir().expect("Could not create temporary directory");
            // for each node, run create-config-image.
            for (subnet_idx, subnet) in initialized_ic.initialized_topology {
                for (node_idx, node) in subnet.initialized_nodes {
                    let ip_addr = addr_allocator
                        .get_addr(subnet_idx as usize, node_idx as usize, AddrType::P2P)
                        .ip();

                    let mut cmd = Command::new("build-bootstrap-config-image.sh");
                    let target_file = PathBuf::from(cfg_img_dir.path())
                        .join(format!("node_{}_{}", subnet_idx, node_idx,));

                    cmd.arg(target_file.clone())
                        .arg("--ipv6_address")
                        .arg(ip_addr.to_string()) //
                        .arg("--ipv6_gateway")
                        .arg(ip_addr.to_string()) // XXX: need to change this to the correct setting
                        .arg("--ic_registry_local_store")
                        .arg(initialized_ic.target_dir.join("ic_registry_local_store"))
                        .arg("--ic_crypto")
                        .arg(node.crypto_path());

                    let output = cmd
                        .output()
                        .expect("could not spawn image creation process");

                    println!("status: {}", output.status);
                    std::io::stdout().write_all(&output.stdout).unwrap();
                    std::io::stderr().write_all(&output.stderr).unwrap();

                    let mut cmd = Command::new("sha256sum");
                    cmd.arg(target_file);

                    let output = cmd
                        .output()
                        .expect("could not spawn image creation process");

                    println!("status: {}", output.status);
                    std::io::stdout().write_all(&output.stdout).unwrap();
                    std::io::stderr().write_all(&output.stderr).unwrap();
                }
            }
            let mut cmd = Command::new("ls");
            cmd.arg("-lah").arg(cfg_img_dir.path());
            let output = cmd
                .output()
                .expect("could not spawn image creation process");

            println!("status: {}", output.status);
            std::io::stdout().write_all(&output.stdout).unwrap();
            std::io::stderr().write_all(&output.stderr).unwrap();
            vec![]
        } else {
            // System Tests
            let mut addr_allocator = EphemeralPortAllocator::new();
            let (initialized_ic, malicious_nodes) = initialize_ic(&mut addr_allocator);

            // All replicas read the registry content from the local store that is on disk.
            let data_provider_config = DataProviderConfig::LocalStore(
                initialized_ic.target_dir.join("ic_registry_local_store"),
            );

            initialized_ic
                .initialized_topology
                .iter()
                .flat_map(|(idx, init_subnet)| {
                    let is_root_subnet = *idx == 0;

                    debug!(
                        logger,
                        "Synthesizing commands for subnet {}", init_subnet.subnet_id
                    );
                    Self::synthesize_subnet_commands(
                        logger,
                        init_subnet,
                        data_provider_config.clone(),
                        &malicious_nodes,
                        is_root_subnet,
                        init_subnet.subnet_config.subnet_type,
                        ic.subnets[(*idx as usize)].node_config.clone(),
                        &mut addr_allocator,
                    )
                })
                .collect()
        }
    }
/// Initialize an Internet Computer: Bootstrap the Internet Computer
/// described by `ic` using `prep_dir` as the working_dir (containing crypto
/// state of the nodes and the initial registry).
///
/// Returns a vector of NodeCommands that can be run by the
Initialize an Internet Computer: Bootstrap the Internet Computer
described by `ic` using `prep_dir` as the working_dir (containing crypto
state of the nodes and the initial registry).

Returns a vector of NodeCommands that can be run by the
Initialize an Internet Computer : Bootstrap the Internet Computer described by ` ic ` using ` prep_dir ` as the working_dir ( containing crypto state of the nodes and the initial registry ) . Returns a vector of NodeCommands that can be run by the
pub(crate) fn synthesize_ic_commands<P: AsRef<Path>>(
        logger: &Logger,
        ic: &InternetComputer,
        prep_dir: P,
    ) -> Vec<NodeCommand> {
        let initialize_ic = |addr_allocator: &mut dyn TcpAddrAllocator| {
            Self::initialize_ic(logger, ic, prep_dir, addr_allocator)
        };
        if ic.experimental_vm_test {
            // XXX: This will be replaced with actual addresses
            let num_addrs = ic.subnets.iter().map(|s| s.nodes.len()).sum();
            let addrs: Vec<IpAddr> = (0..num_addrs)
                .map(|i| IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, i as u16)))
                .collect();
            let mut addr_allocator = VmAddrAllocator::new(addrs);
            let (initialized_ic, malicious_nodes) = initialize_ic(&mut addr_allocator);
            // assemble target path
            let cfg_img_dir = tempfile::tempdir().expect("Could not create temporary directory");
            // for each node, run create-config-image.
            for (subnet_idx, subnet) in initialized_ic.initialized_topology {
                for (node_idx, node) in subnet.initialized_nodes {
                    let ip_addr = addr_allocator
                        .get_addr(subnet_idx as usize, node_idx as usize, AddrType::P2P)
                        .ip();
                    let mut cmd = Command::new("build-bootstrap-config-image.sh");
                    let target_file = PathBuf::from(cfg_img_dir.path())
                        .join(format!("node_{}_{}", subnet_idx, node_idx,));
                    cmd.arg(target_file.clone())
                        .arg("--ipv6_address")
                        .arg(ip_addr.to_string()) //
                        .arg("--ipv6_gateway")
                        .arg(ip_addr.to_string()) // XXX: need to change this to the correct setting
                        .arg("--ic_registry_local_store")
                        .arg(initialized_ic.target_dir.join("ic_registry_local_store"))
                        .arg("--ic_crypto")
                        .arg(node.crypto_path());
                    let output = cmd
                        .output()
                        .expect("could not spawn image creation process");
                    println!("status: {}", output.status);
                    std::io::stdout().write_all(&output.stdout).unwrap();
                    std::io::stderr().write_all(&output.stderr).unwrap();
                    let mut cmd = Command::new("sha256sum");
                    cmd.arg(target_file);
                    let output = cmd
                        .output()
                        .expect("could not spawn image creation process");
                    println!("status: {}", output.status);
                    std::io::stdout().write_all(&output.stdout).unwrap();
                    std::io::stderr().write_all(&output.stderr).unwrap();
                }
            }
            let mut cmd = Command::new("ls");
            cmd.arg("-lah").arg(cfg_img_dir.path());
            let output = cmd
                .output()
                .expect("could not spawn image creation process");
            println!("status: {}", output.status);
            std::io::stdout().write_all(&output.stdout).unwrap();
            std::io::stderr().write_all(&output.stderr).unwrap();
            vec![]
        } else {
            // System Tests
            let mut addr_allocator = EphemeralPortAllocator::new();
            let (initialized_ic, malicious_nodes) = initialize_ic(&mut addr_allocator);
            // All replicas read the registry content from the local store that is on disk.
            let data_provider_config = DataProviderConfig::LocalStore(
                initialized_ic.target_dir.join("ic_registry_local_store"),
            );
            initialized_ic
                .initialized_topology
                .iter()
                .flat_map(|(idx, init_subnet)| {
                    let is_root_subnet = *idx == 0;
                    debug!(
                        logger,
                        "Synthesizing commands for subnet {}", init_subnet.subnet_id
                    );
                    Self::synthesize_subnet_commands(
                        logger,
                        init_subnet,
                        data_provider_config.clone(),
                        &malicious_nodes,
                        is_root_subnet,
                        init_subnet.subnet_config.subnet_type,
                        ic.subnets[(*idx as usize)].node_config.clone(),
                        &mut addr_allocator,
                    )
                })
                .collect()
        }
    }
pub ( crate ) fn synthesize_ic_commands < P : AsRef < Path > > ( logger : & Logger , ic : & InternetComputer , prep_dir : P , ) -> Vec < NodeCommand > { let initialize_ic = | addr_allocator : & mut dyn TcpAddrAllocator | { Self :: initialize_ic ( logger , ic , prep_dir , addr_allocator ) } ; if ic . experimental_vm_test { // XXX: This will be replaced with actual addresses let num_addrs = ic . subnets . iter ( ) . map ( | s | s . nodes . len ( ) ) . sum ( ) ; let addrs : Vec < IpAddr > = ( 0 .. num_addrs ) . map ( | i | IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , i as u16 ) ) ) . collect ( ) ; let mut addr_allocator = VmAddrAllocator :: new ( addrs ) ; let ( initialized_ic , malicious_nodes ) = initialize_ic ( & mut addr_allocator ) ; // assemble target path let cfg_img_dir = tempfile :: tempdir ( ) . expect ( " " ) ; // for each node, run create-config-image. for ( subnet_idx , subnet ) in initialized_ic . initialized_topology { for ( node_idx , node ) in subnet . initialized_nodes { let ip_addr = addr_allocator . get_addr ( subnet_idx as usize , node_idx as usize , AddrType :: P2P ) . ip ( ) ; let mut cmd = Command :: new ( " " ) ; let target_file = PathBuf :: from ( cfg_img_dir . path ( ) ) . join ( format ! ( " " subnet_idx node_idx ) ) ; cmd . arg ( target_file . clone ( ) ) . arg ( " " ) . arg ( ip_addr . to_string ( ) ) // . arg ( " " ) . arg ( ip_addr . to_string ( ) ) // XXX: need to change this to the correct setting . arg ( " " ) . arg ( initialized_ic . target_dir . join ( " " ) ) . arg ( " " ) . arg ( node . crypto_path ( ) ) ; let output = cmd . output ( ) . expect ( " " ) ; println ! ( " " output status ) ; std :: io :: stdout ( ) . write_all ( & output . stdout ) . unwrap ( ) ; std :: io :: stderr ( ) . write_all ( & output . stderr ) . unwrap ( ) ; let mut cmd = Command :: new ( " " ) ; cmd . arg ( target_file ) ; let output = cmd . output ( ) . expect ( " " ) ; println ! ( " " output status ) ; std :: io :: stdout ( ) . write_all ( & output . stdout ) . unwrap ( ) ; std :: io :: stderr ( ) . write_all ( & output . stderr ) . unwrap ( ) ; } } let mut cmd = Command :: new ( " " ) ; cmd . arg ( " " ) . arg ( cfg_img_dir . path ( ) ) ; let output = cmd . output ( ) . expect ( " " ) ; println ! ( " " output status ) ; std :: io :: stdout ( ) . write_all ( & output . stdout ) . unwrap ( ) ; std :: io :: stderr ( ) . write_all ( & output . stderr ) . unwrap ( ) ; vec ! [ ] } else { // System Tests let mut addr_allocator = EphemeralPortAllocator :: new ( ) ; let ( initialized_ic , malicious_nodes ) = initialize_ic ( & mut addr_allocator ) ; // All replicas read the registry content from the local store that is on disk. let data_provider_config = DataProviderConfig :: LocalStore ( initialized_ic . target_dir . join ( " " ) , ) ; initialized_ic . initialized_topology . iter ( ) . flat_map ( | ( idx , init_subnet ) | { let is_root_subnet = * idx == 0 ; debug ! ( logger " " init_subnet subnet_id ) ; Self :: synthesize_subnet_commands ( logger , init_subnet , data_provider_config . clone ( ) , & malicious_nodes , is_root_subnet , init_subnet . subnet_config . subnet_type , ic . subnets [ ( * idx as usize ) ] . node_config . clone ( ) , & mut addr_allocator , ) } ) . collect ( ) } }
Initialize an Internet Computer: Bootstrap the Internet Computer
described by `ic` using `prep_dir` as the working_dir (containing crypto
state of the nodes and the initial registry).
Initialize an Internet Computer : Bootstrap the Internet Computer described by ` ic ` using ` prep_dir ` as the working_dir ( containing crypto state of the nodes and the initial registry ) .
logger
&Logger
ic
&InternetComputer
prep_dir
P
logger
&Logger
ic
&InternetComputer
prep_dir
P