pub fn incoming(&mut self, peer_id: PeerId, index: IncomingIndex) {
		trace!("Incoming {}\nin_slots={:?}\nout_slots={:?}", peer_id, self.data.in_slots, self.data.out_slots);
		// if `reserved_only` is set, but this peer is not a part of our discovered list,
		// a) it is not reserved, so we reject the connection
		// b) we are already connected to it, so we reject the connection
		if self.data.reserved_only && !self.data.discovered.is_reserved(&peer_id) {
			self.message_queue.push_back(Message::Reject(index));
			return;
		}

		// check if we are already connected to this peer
		if self.data.out_slots.contains(&peer_id) {
			// we are already connected. in this case we do not answer
			return;
		}

		let slot_type = if self.data.reserved_only {
			SlotType::Reserved
		} else {
			SlotType::Common
		};

		match self.data.in_slots.add_peer(peer_id, slot_type) {
			SlotState::Added(peer_id) => {
				// reserved node may have been previously stored as normal node in discovered list
				self.data.discovered.remove_peer(&peer_id);
				self.message_queue.push_back(Message::Accept(index));
				return;
			},
			SlotState::Swaped { removed, added } => {
				// reserved node may have been previously stored as normal node in discovered list
				self.data.discovered.remove_peer(&added);
				// swap connections.
				self.message_queue.push_back(Message::Drop(removed));
				self.message_queue.push_back(Message::Accept(index));
			},
			SlotState::AlreadyConnected(_) | SlotState::Upgraded(_) => {
				// we are already connected. in this case we do not answer
				return;
			},
			SlotState::MaxConnections(peer_id) => {
				self.data.discovered.add_peer(peer_id, slot_type);
				self.message_queue.push_back(Message::Reject(index));
				return;
			},
		}
	}
/// Indicate that we received an incoming connection. Must be answered either with
/// a corresponding `Accept` or `Reject`, except if we were already connected to this peer.
///
/// Note that this mechanism is orthogonal to `Connect`/`Drop`. Accepting an incoming
/// connection implicitely means `Accept`, but incoming connections aren't cancelled by
/// `dropped`.
///
/// Because of concurrency issues, it is acceptable to call `incoming` with a `PeerId` the
/// peerset is already connected to, in which case it must not answer.
Indicate that we received an incoming connection. Must be answered either with
a corresponding `Accept` or `Reject`, except if we were already connected to this peer.

Note that this mechanism is orthogonal to `Connect`/`Drop`. Accepting an incoming
connection implicitely means `Accept`, but incoming connections aren't cancelled by
`dropped`.

Because of concurrency issues, it is acceptable to call `incoming` with a `PeerId` the
peerset is already connected to, in which case it must not answer.
Indicate that we received an incoming connection . Must be answered either with a corresponding ` Accept ` or ` Reject ` except if we were already connected to this peer . Note that this mechanism is orthogonal to ` Connect ` / ` Drop ` . Accepting an incoming connection implicitely means ` Accept ` but incoming connections aren ' t cancelled by ` dropped ` . Because of concurrency issues it is acceptable to call ` incoming ` with a ` PeerId ` the peerset is already connected to in which case it must not answer .
pub fn incoming(&mut self, peer_id: PeerId, index: IncomingIndex) {
		trace!("Incoming {}\nin_slots={:?}\nout_slots={:?}", peer_id, self.data.in_slots, self.data.out_slots);
		// if `reserved_only` is set, but this peer is not a part of our discovered list,
		// a) it is not reserved, so we reject the connection
		// b) we are already connected to it, so we reject the connection
		if self.data.reserved_only && !self.data.discovered.is_reserved(&peer_id) {
			self.message_queue.push_back(Message::Reject(index));
			return;
		}
		// check if we are already connected to this peer
		if self.data.out_slots.contains(&peer_id) {
			// we are already connected. in this case we do not answer
			return;
		}
		let slot_type = if self.data.reserved_only {
			SlotType::Reserved
		} else {
			SlotType::Common
		};
		match self.data.in_slots.add_peer(peer_id, slot_type) {
			SlotState::Added(peer_id) => {
				// reserved node may have been previously stored as normal node in discovered list
				self.data.discovered.remove_peer(&peer_id);
				self.message_queue.push_back(Message::Accept(index));
				return;
			},
			SlotState::Swaped { removed, added } => {
				// reserved node may have been previously stored as normal node in discovered list
				self.data.discovered.remove_peer(&added);
				// swap connections.
				self.message_queue.push_back(Message::Drop(removed));
				self.message_queue.push_back(Message::Accept(index));
			},
			SlotState::AlreadyConnected(_) | SlotState::Upgraded(_) => {
				// we are already connected. in this case we do not answer
				return;
			},
			SlotState::MaxConnections(peer_id) => {
				self.data.discovered.add_peer(peer_id, slot_type);
				self.message_queue.push_back(Message::Reject(index));
				return;
			},
		}
	}
pub fn incoming ( & mut self , peer_id : PeerId , index : IncomingIndex ) { trace ! ( " \n \n " peer_id self data in_slots self data out_slots ) ; // if `reserved_only` is set, but this peer is not a part of our discovered list, // a) it is not reserved, so we reject the connection // b) we are already connected to it, so we reject the connection if self . data . reserved_only && ! self . data . discovered . is_reserved ( & peer_id ) { self . message_queue . push_back ( Message :: Reject ( index ) ) ; return ; } // check if we are already connected to this peer if self . data . out_slots . contains ( & peer_id ) { // we are already connected. in this case we do not answer return ; } let slot_type = if self . data . reserved_only { SlotType :: Reserved } else { SlotType :: Common } ; match self . data . in_slots . add_peer ( peer_id , slot_type ) { SlotState :: Added ( peer_id ) => { // reserved node may have been previously stored as normal node in discovered list self . data . discovered . remove_peer ( & peer_id ) ; self . message_queue . push_back ( Message :: Accept ( index ) ) ; return ; } , SlotState :: Swaped { removed , added } => { // reserved node may have been previously stored as normal node in discovered list self . data . discovered . remove_peer ( & added ) ; // swap connections. self . message_queue . push_back ( Message :: Drop ( removed ) ) ; self . message_queue . push_back ( Message :: Accept ( index ) ) ; } , SlotState :: AlreadyConnected ( _ ) | SlotState :: Upgraded ( _ ) => { // we are already connected. in this case we do not answer return ; } , SlotState :: MaxConnections ( peer_id ) => { self . data . discovered . add_peer ( peer_id , slot_type ) ; self . message_queue . push_back ( Message :: Reject ( index ) ) ; return ; } , } }
Indicate that we received an incoming connection.
Indicate that we received an incoming connection .
&mut self
peer_id
PeerId
index
IncomingIndex
&mut self
peer_id
PeerId
index
IncomingIndex