fn route_single(
		&mut self,
		disconnect: bool,
		disconnected: Option<HashSet<usize>>,
		message_filter: &MessageFilter,
	) -> bool {
		let mut had_messages = false;
		let mut to_disconnect = HashSet::new();
		let peers = self.peers();
		for peer in peers {
			if let Some(message) = peer.pending_message(message_filter) {
				match message {
					NetworkMsg::Outgoing(recipient_id, packet) => {
						had_messages = true;

						let sender_pos = peers.iter().position(|p| p.peer_id == peer.peer_id).unwrap();
						let recipient_pos = peers.iter().position(|p| p.peer_id == recipient_id).unwrap();
						if disconnect {
							if let Some(ref disconnected) = disconnected {
								let mut current = HashSet::new();
								current.insert(sender_pos);
								current.insert(recipient_pos);
								// Not routing message between "disconnected" nodes.
								if disconnected.is_subset(&current) {
									continue;
								}
							}
						}

						peers[recipient_pos].receive_message(&peer.peer_id, packet);
					},
					NetworkMsg::ReportPeer(who, _) => {
						if disconnect {
							to_disconnect.insert(who);
						}
					},
					_ => (),
				}
			}
		}

		for d in to_disconnect {
			if let Some(d) = peers.iter().find(|p| p.peer_id == d) {
				for peer in 0..peers.len() {
					peers[peer].on_disconnect(d);
				}
			}
		}

		// make sure that the protocol(s) has processed all messages that have been queued
		self.peers().iter().for_each(|peer| peer.import_queue_sync());

		had_messages
	}
/// Do single round of message routing: single message from every peer is routed.
Do single round of message routing: single message from every peer is routed.
Do single round of message routing : single message from every peer is routed .
fn route_single(
		&mut self,
		disconnect: bool,
		disconnected: Option<HashSet<usize>>,
		message_filter: &MessageFilter,
	) -> bool {
		let mut had_messages = false;
		let mut to_disconnect = HashSet::new();
		let peers = self.peers();
		for peer in peers {
			if let Some(message) = peer.pending_message(message_filter) {
				match message {
					NetworkMsg::Outgoing(recipient_id, packet) => {
						had_messages = true;
						let sender_pos = peers.iter().position(|p| p.peer_id == peer.peer_id).unwrap();
						let recipient_pos = peers.iter().position(|p| p.peer_id == recipient_id).unwrap();
						if disconnect {
							if let Some(ref disconnected) = disconnected {
								let mut current = HashSet::new();
								current.insert(sender_pos);
								current.insert(recipient_pos);
								// Not routing message between "disconnected" nodes.
								if disconnected.is_subset(&current) {
									continue;
								}
							}
						}
						peers[recipient_pos].receive_message(&peer.peer_id, packet);
					},
					NetworkMsg::ReportPeer(who, _) => {
						if disconnect {
							to_disconnect.insert(who);
						}
					},
					_ => (),
				}
			}
		}
		for d in to_disconnect {
			if let Some(d) = peers.iter().find(|p| p.peer_id == d) {
				for peer in 0..peers.len() {
					peers[peer].on_disconnect(d);
				}
			}
		}
		// make sure that the protocol(s) has processed all messages that have been queued
		self.peers().iter().for_each(|peer| peer.import_queue_sync());
		had_messages
	}
fn route_single ( & mut self , disconnect : bool , disconnected : Option < HashSet < usize > > , message_filter : & MessageFilter , ) -> bool { let mut had_messages = false ; let mut to_disconnect = HashSet :: new ( ) ; let peers = self . peers ( ) ; for peer in peers { if let Some ( message ) = peer . pending_message ( message_filter ) { match message { NetworkMsg :: Outgoing ( recipient_id , packet ) => { had_messages = true ; let sender_pos = peers . iter ( ) . position ( | p | p . peer_id == peer . peer_id ) . unwrap ( ) ; let recipient_pos = peers . iter ( ) . position ( | p | p . peer_id == recipient_id ) . unwrap ( ) ; if disconnect { if let Some ( ref disconnected ) = disconnected { let mut current = HashSet :: new ( ) ; current . insert ( sender_pos ) ; current . insert ( recipient_pos ) ; // Not routing message between "disconnected" nodes. if disconnected . is_subset ( & current ) { continue ; } } } peers [ recipient_pos ] . receive_message ( & peer . peer_id , packet ) ; } , NetworkMsg :: ReportPeer ( who , _ ) => { if disconnect { to_disconnect . insert ( who ) ; } } , _ => ( ) , } } } for d in to_disconnect { if let Some ( d ) = peers . iter ( ) . find ( | p | p . peer_id == d ) { for peer in 0 .. peers . len ( ) { peers [ peer ] . on_disconnect ( d ) ; } } } // make sure that the protocol(s) has processed all messages that have been queued self . peers ( ) . iter ( ) . for_each ( | peer | peer . import_queue_sync ( ) ) ; had_messages }
Do single round of message routing: single message from every peer is routed.
Do single round of message routing : single message from every peer is routed .
&mut self
disconnect
bool
disconnected
Option<HashSet<usize>>
message_filter
&MessageFilter
&mut self
disconnect
bool
disconnected
Option<HashSet<usize>>
message_filter
&MessageFilter