// Tries to populate a `NetworkTopology` from the registry.
Tries to populate a `NetworkTopology` from the registry.
Tries to populate a ` NetworkTopology ` from the registry .
fn try_to_populate_network_topology(
        &self,
        registry_version: RegistryVersion,
    ) -> Result<NetworkTopology, RegistryClientError> {
        // Return the list of subnets present in the registry. If no subnet list is
        // defined, as could be the case in tests, an empty `Vec` is returned.
        let subnet_ids_record = self.registry.get_subnet_ids(registry_version)?;
        let subnet_ids = subnet_ids_record.unwrap_or_default();
        // Populate subnet topologies.
        let mut subnets: BTreeMap<SubnetId, SubnetTopology> = BTreeMap::new();
        for subnet_id in &subnet_ids {
            let mut nodes: BTreeMap<NodeId, NodeTopology> = BTreeMap::new();
            // Return the list of nodes present in the registry. If no nodes are
            // defined, as could be the case in tests, an empty `Vec` is returned.
            let node_ids_record = self
                .registry
                .get_node_ids_on_subnet(*subnet_id, registry_version)?;
            let node_ids = node_ids_record.unwrap_or_default();
            for node_id in node_ids {
                // Get the node
                let node_record = match self
                    .registry
                    .get_transport_info(node_id, registry_version)?
                {
                    Some(node_record) => node_record,
                    None => {
                        warn!(
                            self.log,
                            "No NodeRecord found for node {}. Skipping...", node_id
                        );
                        continue;
                    }
                };
                let http_info = match node_record.http {
                    Some(http_info) => http_info,
                    None => {
                        warn!(
                            self.log,
                            "NodeRecord for node {} does not contain an http connection endpoint. Skipping...",
                            node_id
                        );
                        continue;
                    }
                };
                let http_port = match u16::try_from(http_info.port) {
                    Ok(http_port) => http_port,
                    _ => {
                        warn!(
                            self.log,
                            "Invalid HTTP port {} defined for node {}. Skipping...",
                            http_info.port,
                            node_id,
                        );
                        continue;
                    }
                };
                nodes.insert(
                    node_id,
                    NodeTopology {
                        ip_address: http_info.ip_addr,
                        http_port,
                    },
                );
            }
            let public_key =
                get_subnet_public_key(Arc::clone(&self.registry), *subnet_id, registry_version)?;
            let subnet_type = self.get_subnet_type(*subnet_id, registry_version);
            subnets.insert(
                *subnet_id,
                SubnetTopology {
                    public_key,
                    nodes,
                    subnet_type,
                },
            );
        }
        let routing_table_record = self.registry.get_routing_table(registry_version)?;
        let routing_table = routing_table_record.unwrap_or_default();
        let nns_subnet_id = self.get_nns_subnet_id(registry_version);
        Ok(NetworkTopology {
            subnets,
            routing_table: Arc::new(routing_table),
            nns_subnet_id,
        })
    }
fn try_to_populate_network_topology ( & self , registry_version : RegistryVersion , ) -> Result < NetworkTopology , RegistryClientError > { // Return the list of subnets present in the registry. If no subnet list is // defined, as could be the case in tests, an empty `Vec` is returned. let subnet_ids_record = self . registry . get_subnet_ids ( registry_version ) ? ; let subnet_ids = subnet_ids_record . unwrap_or_default ( ) ; // Populate subnet topologies. let mut subnets : BTreeMap < SubnetId , SubnetTopology > = BTreeMap :: new ( ) ; for subnet_id in & subnet_ids { let mut nodes : BTreeMap < NodeId , NodeTopology > = BTreeMap :: new ( ) ; // Return the list of nodes present in the registry. If no nodes are // defined, as could be the case in tests, an empty `Vec` is returned. let node_ids_record = self . registry . get_node_ids_on_subnet ( * subnet_id , registry_version ) ? ; let node_ids = node_ids_record . unwrap_or_default ( ) ; for node_id in node_ids { // Get the node let node_record = match self . registry . get_transport_info ( node_id , registry_version ) ? { Some ( node_record ) => node_record , None => { warn ! ( self log " " node_id ) ; continue ; } } ; let http_info = match node_record . http { Some ( http_info ) => http_info , None => { warn ! ( self log " " node_id ) ; continue ; } } ; let http_port = match u16 :: try_from ( http_info . port ) { Ok ( http_port ) => http_port , _ => { warn ! ( self log " " http_info port node_id ) ; continue ; } } ; nodes . insert ( node_id , NodeTopology { ip_address : http_info . ip_addr , http_port , } , ) ; } let public_key = get_subnet_public_key ( Arc :: clone ( & self . registry ) , * subnet_id , registry_version ) ? ; let subnet_type = self . get_subnet_type ( * subnet_id , registry_version ) ; subnets . insert ( * subnet_id , SubnetTopology { public_key , nodes , subnet_type , } , ) ; } let routing_table_record = self . registry . get_routing_table ( registry_version ) ? ; let routing_table = routing_table_record . unwrap_or_default ( ) ; let nns_subnet_id = self . get_nns_subnet_id ( registry_version ) ; Ok ( NetworkTopology { subnets , routing_table : Arc :: new ( routing_table ) , nns_subnet_id , } ) }
Tries to populate a `NetworkTopology` from the registry.
Tries to populate a ` NetworkTopology ` from the registry .
&self
registry_version
RegistryVersion