pub fn refresh_registry(&self, event_handler: &Arc<dyn P2PEventHandlerControl>) {
        let latest_registry_version = self.registry_client.get_latest_version();
        self.metrics
            .registry_version_used
            .set(latest_registry_version.get() as i64);

        let subnet_nodes = self.merge_subnet_membership(latest_registry_version);
        let self_not_in_subnet = !subnet_nodes.contains_key(&self.node_id);

        // If a peer is not in the nodes within this subnet, remove.
        // If self is not in the subnet, remove all peers.
        for peer in self.peer_manager.get_current_peer_ids().into_iter() {
            if !subnet_nodes.contains_key(&peer) || self_not_in_subnet {
                self.remove_node(peer, latest_registry_version);
                self.metrics.nodes_removed.inc();
            }
        }
        // If self is not subnet, exit early to avoid adding nodes to peer_manager.
        if self_not_in_subnet {
            return;
        }
        // Add in nodes to peer manager.
        for (node_id, node_record) in subnet_nodes.iter() {
            if self
                .peer_manager
                .add_peer(
                    *node_id,
                    node_record,
                    latest_registry_version,
                    event_handler,
                )
                .is_ok()
            {
                self.receive_check_caches.write().unwrap().insert(
                    *node_id,
                    ReceiveCheckCache::new(self.gossip_config.receive_check_cache_size as usize),
                );
            }
        }
    }
// Update the peer manager state based on the latest registry value.
Update the peer manager state based on the latest registry value.
Update the peer manager state based on the latest registry value .
pub fn refresh_registry(&self, event_handler: &Arc<dyn P2PEventHandlerControl>) {
        let latest_registry_version = self.registry_client.get_latest_version();
        self.metrics
            .registry_version_used
            .set(latest_registry_version.get() as i64);
        let subnet_nodes = self.merge_subnet_membership(latest_registry_version);
        let self_not_in_subnet = !subnet_nodes.contains_key(&self.node_id);
        // If a peer is not in the nodes within this subnet, remove.
        // If self is not in the subnet, remove all peers.
        for peer in self.peer_manager.get_current_peer_ids().into_iter() {
            if !subnet_nodes.contains_key(&peer) || self_not_in_subnet {
                self.remove_node(peer, latest_registry_version);
                self.metrics.nodes_removed.inc();
            }
        }
        // If self is not subnet, exit early to avoid adding nodes to peer_manager.
        if self_not_in_subnet {
            return;
        }
        // Add in nodes to peer manager.
        for (node_id, node_record) in subnet_nodes.iter() {
            if self
                .peer_manager
                .add_peer(
                    *node_id,
                    node_record,
                    latest_registry_version,
                    event_handler,
                )
                .is_ok()
            {
                self.receive_check_caches.write().unwrap().insert(
                    *node_id,
                    ReceiveCheckCache::new(self.gossip_config.receive_check_cache_size as usize),
                );
            }
        }
    }
pub fn refresh_registry ( & self , event_handler : & Arc < dyn P2PEventHandlerControl > ) { let latest_registry_version = self . registry_client . get_latest_version ( ) ; self . metrics . registry_version_used . set ( latest_registry_version . get ( ) as i64 ) ; let subnet_nodes = self . merge_subnet_membership ( latest_registry_version ) ; let self_not_in_subnet = ! subnet_nodes . contains_key ( & self . node_id ) ; // If a peer is not in the nodes within this subnet, remove. // If self is not in the subnet, remove all peers. for peer in self . peer_manager . get_current_peer_ids ( ) . into_iter ( ) { if ! subnet_nodes . contains_key ( & peer ) || self_not_in_subnet { self . remove_node ( peer , latest_registry_version ) ; self . metrics . nodes_removed . inc ( ) ; } } // If self is not subnet, exit early to avoid adding nodes to peer_manager. if self_not_in_subnet { return ; } // Add in nodes to peer manager. for ( node_id , node_record ) in subnet_nodes . iter ( ) { if self . peer_manager . add_peer ( * node_id , node_record , latest_registry_version , event_handler , ) . is_ok ( ) { self . receive_check_caches . write ( ) . unwrap ( ) . insert ( * node_id , ReceiveCheckCache :: new ( self . gossip_config . receive_check_cache_size as usize ) , ) ; } } }
Update the peer manager state based on the latest registry value.
Update the peer manager state based on the latest registry value .
&self
event_handler
&Arc<dyn P2PEventHandlerControl>
&self
event_handler
&Arc<dyn P2PEventHandlerControl>