pub fn collect_garbage(&mut self) {
		use std::collections::hash_map::Entry;

		self.live_message_sinks.retain(|_, sinks| {
			sinks.retain(|sink| !sink.is_closed());
			!sinks.is_empty()
		});

		let known_messages = &mut self.known_messages;
		let before = self.messages.len();
		let validators = &self.validators;

		let mut check_fns = HashMap::new();
		let mut message_expired = move |entry: &MessageEntry<B>| {
			let engine_id = entry.message.engine_id;
			let check_fn = match check_fns.entry(engine_id) {
				Entry::Occupied(entry) => entry.into_mut(),
				Entry::Vacant(vacant) => match validators.get(&engine_id) {
					None => return true, // treat all messages with no validator as expired
					Some(validator) => vacant.insert(validator.message_expired()),
				}
			};

			(check_fn)(entry.topic, &entry.message.data)
		};

		self.messages.retain(|entry| !message_expired(entry));

		trace!(target: "gossip", "Cleaned up {} stale messages, {} left ({} known)",
			before - self.messages.len(),
			self.messages.len(),
			known_messages.len(),
		);

		for (_, ref mut peer) in self.peers.iter_mut() {
			peer.known_messages.retain(|h| known_messages.contains_key(h));
		}
	}
/// Prune old or no longer relevant consensus messages. Provide a predicate
/// for pruning, which returns `false` when the items with a given topic should be pruned.
Prune old or no longer relevant consensus messages. Provide a predicate
for pruning, which returns `false` when the items with a given topic should be pruned.
Prune old or no longer relevant consensus messages . Provide a predicate for pruning which returns ` false ` when the items with a given topic should be pruned .
pub fn collect_garbage(&mut self) {
		use std::collections::hash_map::Entry;
		self.live_message_sinks.retain(|_, sinks| {
			sinks.retain(|sink| !sink.is_closed());
			!sinks.is_empty()
		});
		let known_messages = &mut self.known_messages;
		let before = self.messages.len();
		let validators = &self.validators;
		let mut check_fns = HashMap::new();
		let mut message_expired = move |entry: &MessageEntry<B>| {
			let engine_id = entry.message.engine_id;
			let check_fn = match check_fns.entry(engine_id) {
				Entry::Occupied(entry) => entry.into_mut(),
				Entry::Vacant(vacant) => match validators.get(&engine_id) {
					None => return true, // treat all messages with no validator as expired
					Some(validator) => vacant.insert(validator.message_expired()),
				}
			};
			(check_fn)(entry.topic, &entry.message.data)
		};
		self.messages.retain(|entry| !message_expired(entry));
		trace!(target: "gossip", "Cleaned up {} stale messages, {} left ({} known)",
			before - self.messages.len(),
			self.messages.len(),
			known_messages.len(),
		);
		for (_, ref mut peer) in self.peers.iter_mut() {
			peer.known_messages.retain(|h| known_messages.contains_key(h));
		}
	}
pub fn collect_garbage ( & mut self ) { use std :: collections :: hash_map :: Entry ; self . live_message_sinks . retain ( | _ , sinks | { sinks . retain ( | sink | ! sink . is_closed ( ) ) ; ! sinks . is_empty ( ) } ) ; let known_messages = & mut self . known_messages ; let before = self . messages . len ( ) ; let validators = & self . validators ; let mut check_fns = HashMap :: new ( ) ; let mut message_expired = move | entry : & MessageEntry < B > | { let engine_id = entry . message . engine_id ; let check_fn = match check_fns . entry ( engine_id ) { Entry :: Occupied ( entry ) => entry . into_mut ( ) , Entry :: Vacant ( vacant ) => match validators . get ( & engine_id ) { None => return true , // treat all messages with no validator as expired Some ( validator ) => vacant . insert ( validator . message_expired ( ) ) , } } ; ( check_fn ) ( entry . topic , & entry . message . data ) } ; self . messages . retain ( | entry | ! message_expired ( entry ) ) ; trace ! ( target " " " " before self messages len ( ) self messages len ( ) known_messages len ( ) ) ; for ( _ , ref mut peer ) in self . peers . iter_mut ( ) { peer . known_messages . retain ( | h | known_messages . contains_key ( h ) ) ; } }
Prune old or no longer relevant consensus messages.
Prune old or no longer relevant consensus messages .
&mut self
&mut self