fn peerset_report_connect(&mut self, peer_id: PeerId) {
		let mut occ_entry = match self.peers.entry(peer_id) {
			Entry::Occupied(entry) => entry,
			Entry::Vacant(entry) => {
				// If there's no entry in `self.peers`, start dialing.
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Starting to connect", entry.key());
				debug!(target: "sub-libp2p", "Libp2p <= Dial {:?}", entry.key());
				self.events.push(NetworkBehaviourAction::DialPeer { peer_id: entry.key().clone() });
				entry.insert(PeerState::Requested);
				return;
			}
		};

		match mem::replace(occ_entry.get_mut(), PeerState::Poisoned) {
			PeerState::Banned { ref until } if *until > Instant::now() => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Will start to connect at \
					until {:?}", occ_entry.key(), until);
				*occ_entry.into_mut() = PeerState::PendingRequest {
					timer: tokio_timer::Delay::new(until.clone()),
				};
			},

			PeerState::Banned { .. } => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Starting to connect", occ_entry.key());
				debug!(target: "sub-libp2p", "Libp2p <= Dial {:?}", occ_entry.key());
				self.events.push(NetworkBehaviourAction::DialPeer { peer_id: occ_entry.key().clone() });
				*occ_entry.into_mut() = PeerState::Requested;
			},

			PeerState::Disabled { open, ref connected_point, banned_until: Some(ref banned) }
				if *banned > Instant::now() => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Has idle connection through \
					{:?} but node is banned until {:?}", occ_entry.key(), connected_point, banned);
				*occ_entry.into_mut() = PeerState::DisabledPendingEnable {
					connected_point: connected_point.clone(),
					open,
					timer: tokio_timer::Delay::new(banned.clone()),
				};
			},

			PeerState::Disabled { open, connected_point, banned_until: _ } => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Enabling previously-idle \
					connection through {:?}", occ_entry.key(), connected_point);
				debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", occ_entry.key());
				self.events.push(NetworkBehaviourAction::SendEvent {
					peer_id: occ_entry.key().clone(),
					event: CustomProtoHandlerIn::Enable(connected_point.clone().into()),
				});
				*occ_entry.into_mut() = PeerState::Enabled { connected_point, open };
			},

			PeerState::Incoming { connected_point, .. } => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Enabling incoming \
					connection through {:?}", occ_entry.key(), connected_point);
				if let Some(inc) = self.incoming.iter_mut()
					.find(|i| i.peer_id == *occ_entry.key() && i.alive) {
					inc.alive = false;
				} else {
					error!(target: "sub-libp2p", "State mismatch in libp2p: no entry in \
						incoming for incoming peer")
				}
				debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", occ_entry.key());
				self.events.push(NetworkBehaviourAction::SendEvent {
					peer_id: occ_entry.key().clone(),
					event: CustomProtoHandlerIn::Enable(connected_point.clone().into()),
				});
				*occ_entry.into_mut() = PeerState::Enabled { connected_point, open: false };
			},

			st @ PeerState::Enabled { .. } => {
				warn!(target: "sub-libp2p", "PSM => Connect({:?}): Already connected to this \
					peer", occ_entry.key());
				*occ_entry.into_mut() = st;
			},
			st @ PeerState::DisabledPendingEnable { .. } => {
				warn!(target: "sub-libp2p", "PSM => Connect({:?}): Already have an idle \
					connection to this peer and waiting to enable it", occ_entry.key());
				*occ_entry.into_mut() = st;
			},
			st @ PeerState::Requested { .. } | st @ PeerState::PendingRequest { .. } => {
				warn!(target: "sub-libp2p", "PSM => Connect({:?}): Received a previous \
					request for that peer", occ_entry.key());
				*occ_entry.into_mut() = st;
			},

			PeerState::Poisoned =>
				error!(target: "sub-libp2p", "State of {:?} is poisoned", occ_entry.key()),
		}
	}
/// Function that is called when the peerset wants us to connect to a node.
Function that is called when the peerset wants us to connect to a node.
Function that is called when the peerset wants us to connect to a node .
fn peerset_report_connect(&mut self, peer_id: PeerId) {
		let mut occ_entry = match self.peers.entry(peer_id) {
			Entry::Occupied(entry) => entry,
			Entry::Vacant(entry) => {
				// If there's no entry in `self.peers`, start dialing.
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Starting to connect", entry.key());
				debug!(target: "sub-libp2p", "Libp2p <= Dial {:?}", entry.key());
				self.events.push(NetworkBehaviourAction::DialPeer { peer_id: entry.key().clone() });
				entry.insert(PeerState::Requested);
				return;
			}
		};
		match mem::replace(occ_entry.get_mut(), PeerState::Poisoned) {
			PeerState::Banned { ref until } if *until > Instant::now() => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Will start to connect at \
					until {:?}", occ_entry.key(), until);
				*occ_entry.into_mut() = PeerState::PendingRequest {
					timer: tokio_timer::Delay::new(until.clone()),
				};
			},
			PeerState::Banned { .. } => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Starting to connect", occ_entry.key());
				debug!(target: "sub-libp2p", "Libp2p <= Dial {:?}", occ_entry.key());
				self.events.push(NetworkBehaviourAction::DialPeer { peer_id: occ_entry.key().clone() });
				*occ_entry.into_mut() = PeerState::Requested;
			},
			PeerState::Disabled { open, ref connected_point, banned_until: Some(ref banned) }
				if *banned > Instant::now() => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Has idle connection through \
					{:?} but node is banned until {:?}", occ_entry.key(), connected_point, banned);
				*occ_entry.into_mut() = PeerState::DisabledPendingEnable {
					connected_point: connected_point.clone(),
					open,
					timer: tokio_timer::Delay::new(banned.clone()),
				};
			},
			PeerState::Disabled { open, connected_point, banned_until: _ } => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Enabling previously-idle \
					connection through {:?}", occ_entry.key(), connected_point);
				debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", occ_entry.key());
				self.events.push(NetworkBehaviourAction::SendEvent {
					peer_id: occ_entry.key().clone(),
					event: CustomProtoHandlerIn::Enable(connected_point.clone().into()),
				});
				*occ_entry.into_mut() = PeerState::Enabled { connected_point, open };
			},
			PeerState::Incoming { connected_point, .. } => {
				debug!(target: "sub-libp2p", "PSM => Connect({:?}): Enabling incoming \
					connection through {:?}", occ_entry.key(), connected_point);
				if let Some(inc) = self.incoming.iter_mut()
					.find(|i| i.peer_id == *occ_entry.key() && i.alive) {
					inc.alive = false;
				} else {
					error!(target: "sub-libp2p", "State mismatch in libp2p: no entry in \
						incoming for incoming peer")
				}
				debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", occ_entry.key());
				self.events.push(NetworkBehaviourAction::SendEvent {
					peer_id: occ_entry.key().clone(),
					event: CustomProtoHandlerIn::Enable(connected_point.clone().into()),
				});
				*occ_entry.into_mut() = PeerState::Enabled { connected_point, open: false };
			},
			st @ PeerState::Enabled { .. } => {
				warn!(target: "sub-libp2p", "PSM => Connect({:?}): Already connected to this \
					peer", occ_entry.key());
				*occ_entry.into_mut() = st;
			},
			st @ PeerState::DisabledPendingEnable { .. } => {
				warn!(target: "sub-libp2p", "PSM => Connect({:?}): Already have an idle \
					connection to this peer and waiting to enable it", occ_entry.key());
				*occ_entry.into_mut() = st;
			},
			st @ PeerState::Requested { .. } | st @ PeerState::PendingRequest { .. } => {
				warn!(target: "sub-libp2p", "PSM => Connect({:?}): Received a previous \
					request for that peer", occ_entry.key());
				*occ_entry.into_mut() = st;
			},
			PeerState::Poisoned =>
				error!(target: "sub-libp2p", "State of {:?} is poisoned", occ_entry.key()),
		}
	}
fn peerset_report_connect ( & mut self , peer_id : PeerId ) { let mut occ_entry = match self . peers . entry ( peer_id ) { Entry :: Occupied ( entry ) => entry , Entry :: Vacant ( entry ) => { // If there's no entry in `self.peers`, start dialing. debug ! ( target " " " " entry key ( ) ) ; debug ! ( target " " " " entry key ( ) ) ; self . events . push ( NetworkBehaviourAction :: DialPeer { peer_id : entry . key ( ) . clone ( ) } ) ; entry . insert ( PeerState :: Requested ) ; return ; } } ; match mem :: replace ( occ_entry . get_mut ( ) , PeerState :: Poisoned ) { PeerState :: Banned { ref until } if * until > Instant :: now ( ) => { debug ! ( target " " " \
 " occ_entry key ( ) until ) ; * occ_entry . into_mut ( ) = PeerState :: PendingRequest { timer : tokio_timer :: Delay :: new ( until . clone ( ) ) , } ; } , PeerState :: Banned { .. } => { debug ! ( target " " " " occ_entry key ( ) ) ; debug ! ( target " " " " occ_entry key ( ) ) ; self . events . push ( NetworkBehaviourAction :: DialPeer { peer_id : occ_entry . key ( ) . clone ( ) } ) ; * occ_entry . into_mut ( ) = PeerState :: Requested ; } , PeerState :: Disabled { open , ref connected_point , banned_until : Some ( ref banned ) } if * banned > Instant :: now ( ) => { debug ! ( target " " " \
 " occ_entry key ( ) connected_point banned ) ; * occ_entry . into_mut ( ) = PeerState :: DisabledPendingEnable { connected_point : connected_point . clone ( ) , open , timer : tokio_timer :: Delay :: new ( banned . clone ( ) ) , } ; } , PeerState :: Disabled { open , connected_point , banned_until : _ } => { debug ! ( target " " " \
 " occ_entry key ( ) connected_point ) ; debug ! ( target " " " " occ_entry key ( ) ) ; self . events . push ( NetworkBehaviourAction :: SendEvent { peer_id : occ_entry . key ( ) . clone ( ) , event : CustomProtoHandlerIn :: Enable ( connected_point . clone ( ) . into ( ) ) , } ) ; * occ_entry . into_mut ( ) = PeerState :: Enabled { connected_point , open } ; } , PeerState :: Incoming { connected_point , .. } => { debug ! ( target " " " \
 " occ_entry key ( ) connected_point ) ; if let Some ( inc ) = self . incoming . iter_mut ( ) . find ( | i | i . peer_id == * occ_entry . key ( ) && i . alive ) { inc . alive = false ; } else { error ! ( target " " " \
 " ) } debug ! ( target " " " " occ_entry key ( ) ) ; self . events . push ( NetworkBehaviourAction :: SendEvent { peer_id : occ_entry . key ( ) . clone ( ) , event : CustomProtoHandlerIn :: Enable ( connected_point . clone ( ) . into ( ) ) , } ) ; * occ_entry . into_mut ( ) = PeerState :: Enabled { connected_point , open : false } ; } , st @ PeerState :: Enabled { .. } => { warn ! ( target " " " \
 " occ_entry key ( ) ) ; * occ_entry . into_mut ( ) = st ; } , st @ PeerState :: DisabledPendingEnable { .. } => { warn ! ( target " " " \
 " occ_entry key ( ) ) ; * occ_entry . into_mut ( ) = st ; } , st @ PeerState :: Requested { .. } | st @ PeerState :: PendingRequest { .. } => { warn ! ( target " " " \
 " occ_entry key ( ) ) ; * occ_entry . into_mut ( ) = st ; } , PeerState :: Poisoned => error ! ( target " " " " occ_entry key ( ) ) , } }
Function that is called when the peerset wants us to connect to a node.
Function that is called when the peerset wants us to connect to a node .
&mut self
peer_id
PeerId
&mut self
peer_id
PeerId