fn on_status_message(&mut self, who: PeerId, status: message::Status<B>) {
		trace!(target: "sync", "New peer {} {:?}", who, status);
		{
			if self.context_data.peers.contains_key(&who) {
				debug!("Unexpected status packet from {}", who);
				return;
			}
			if status.genesis_hash != self.genesis_hash {
				let reason = format!(
					"Peer is on different chain (our genesis: {} theirs: {})",
					self.genesis_hash, status.genesis_hash
				);
				self.network_chan.send(NetworkMsg::ReportPeer(
					who,
					Severity::Bad(reason),
				));
				return;
			}
			if status.version < MIN_VERSION && CURRENT_VERSION < status.min_supported_version {
				let reason = format!("Peer using unsupported protocol version {}", status.version);
				self.network_chan.send(NetworkMsg::ReportPeer(
					who,
					Severity::Bad(reason),
				));
				return;
			}
			if self.config.roles & Roles::LIGHT == Roles::LIGHT {
				let self_best_block = self
					.context_data
					.chain
					.info()
					.ok()
					.and_then(|info| info.best_queued_number)
					.unwrap_or_else(|| Zero::zero());
				let blocks_difference = self_best_block
					.as_()
					.checked_sub(status.best_number.as_())
					.unwrap_or(0);
				if blocks_difference > LIGHT_MAXIMAL_BLOCKS_DIFFERENCE {
					self.network_chan.send(NetworkMsg::ReportPeer(
						who,
						Severity::Useless(
							"Peer is far behind us and will unable to serve light requests"
								.to_string(),
						),
					));
					return;
				}
			}

			let cache_limit = NonZeroUsize::new(1_000_000).expect("1_000_000 > 0; qed");

			let info = match self.handshaking_peers.remove(&who) {
				Some(_handshaking) => {
					let peer_info = PeerInfo {
						protocol_version: status.version,
						roles: status.roles,
						best_hash: status.best_hash,
						best_number: status.best_number
					};
					self.connected_peers
						.write()
						.insert(who.clone(), ConnectedPeer { peer_info: peer_info.clone() });
					peer_info
				},
				None => {
					debug!(target: "sync", "Received status from previously unconnected node {}", who);
					return;
				},
			};

			let peer = Peer {
				info,
				block_request: None,
				known_extrinsics: LruHashSet::new(cache_limit),
				known_blocks: LruHashSet::new(cache_limit),
				next_request_id: 0,
				obsolete_requests: HashMap::new(),
			};
			self.context_data.peers.insert(who.clone(), peer);

			debug!(target: "sync", "Connected {}", who);
		}

		let mut context = ProtocolContext::new(&mut self.context_data, &self.network_chan);
		self.on_demand
			.as_ref()
			.map(|s| s.on_connect(who.clone(), status.roles, status.best_number));
		self.sync.new_peer(&mut context, who.clone());
		self.consensus_gossip
			.new_peer(&mut context, who.clone(), status.roles);
		self.specialization.on_connect(&mut context, who, status);
	}
/// Called by peer to report status
Called by peer to report status
Called by peer to report status
fn on_status_message(&mut self, who: PeerId, status: message::Status<B>) {
		trace!(target: "sync", "New peer {} {:?}", who, status);
		{
			if self.context_data.peers.contains_key(&who) {
				debug!("Unexpected status packet from {}", who);
				return;
			}
			if status.genesis_hash != self.genesis_hash {
				let reason = format!(
					"Peer is on different chain (our genesis: {} theirs: {})",
					self.genesis_hash, status.genesis_hash
				);
				self.network_chan.send(NetworkMsg::ReportPeer(
					who,
					Severity::Bad(reason),
				));
				return;
			}
			if status.version < MIN_VERSION && CURRENT_VERSION < status.min_supported_version {
				let reason = format!("Peer using unsupported protocol version {}", status.version);
				self.network_chan.send(NetworkMsg::ReportPeer(
					who,
					Severity::Bad(reason),
				));
				return;
			}
			if self.config.roles & Roles::LIGHT == Roles::LIGHT {
				let self_best_block = self
					.context_data
					.chain
					.info()
					.ok()
					.and_then(|info| info.best_queued_number)
					.unwrap_or_else(|| Zero::zero());
				let blocks_difference = self_best_block
					.as_()
					.checked_sub(status.best_number.as_())
					.unwrap_or(0);
				if blocks_difference > LIGHT_MAXIMAL_BLOCKS_DIFFERENCE {
					self.network_chan.send(NetworkMsg::ReportPeer(
						who,
						Severity::Useless(
							"Peer is far behind us and will unable to serve light requests"
								.to_string(),
						),
					));
					return;
				}
			}
			let cache_limit = NonZeroUsize::new(1_000_000).expect("1_000_000 > 0; qed");
			let info = match self.handshaking_peers.remove(&who) {
				Some(_handshaking) => {
					let peer_info = PeerInfo {
						protocol_version: status.version,
						roles: status.roles,
						best_hash: status.best_hash,
						best_number: status.best_number
					};
					self.connected_peers
						.write()
						.insert(who.clone(), ConnectedPeer { peer_info: peer_info.clone() });
					peer_info
				},
				None => {
					debug!(target: "sync", "Received status from previously unconnected node {}", who);
					return;
				},
			};
			let peer = Peer {
				info,
				block_request: None,
				known_extrinsics: LruHashSet::new(cache_limit),
				known_blocks: LruHashSet::new(cache_limit),
				next_request_id: 0,
				obsolete_requests: HashMap::new(),
			};
			self.context_data.peers.insert(who.clone(), peer);
			debug!(target: "sync", "Connected {}", who);
		}
		let mut context = ProtocolContext::new(&mut self.context_data, &self.network_chan);
		self.on_demand
			.as_ref()
			.map(|s| s.on_connect(who.clone(), status.roles, status.best_number));
		self.sync.new_peer(&mut context, who.clone());
		self.consensus_gossip
			.new_peer(&mut context, who.clone(), status.roles);
		self.specialization.on_connect(&mut context, who, status);
	}
fn on_status_message ( & mut self , who : PeerId , status : message :: Status < B > ) { trace ! ( target " " " " who status ) ; { if self . context_data . peers . contains_key ( & who ) { debug ! ( " " who ) ; return ; } if status . genesis_hash != self . genesis_hash { let reason = format ! ( " " self genesis_hash status genesis_hash ) ; self . network_chan . send ( NetworkMsg :: ReportPeer ( who , Severity :: Bad ( reason ) , ) ) ; return ; } if status . version < MIN_VERSION && CURRENT_VERSION < status . min_supported_version { let reason = format ! ( " " status version ) ; self . network_chan . send ( NetworkMsg :: ReportPeer ( who , Severity :: Bad ( reason ) , ) ) ; return ; } if self . config . roles & Roles :: LIGHT == Roles :: LIGHT { let self_best_block = self . context_data . chain . info ( ) . ok ( ) . and_then ( | info | info . best_queued_number ) . unwrap_or_else ( | | Zero :: zero ( ) ) ; let blocks_difference = self_best_block . as_ ( ) . checked_sub ( status . best_number . as_ ( ) ) . unwrap_or ( 0 ) ; if blocks_difference > LIGHT_MAXIMAL_BLOCKS_DIFFERENCE { self . network_chan . send ( NetworkMsg :: ReportPeer ( who , Severity :: Useless ( " " . to_string ( ) , ) , ) ) ; return ; } } let cache_limit = NonZeroUsize :: new ( 1_000_000 ) . expect ( " " ) ; let info = match self . handshaking_peers . remove ( & who ) { Some ( _handshaking ) => { let peer_info = PeerInfo { protocol_version : status . version , roles : status . roles , best_hash : status . best_hash , best_number : status . best_number } ; self . connected_peers . write ( ) . insert ( who . clone ( ) , ConnectedPeer { peer_info : peer_info . clone ( ) } ) ; peer_info } , None => { debug ! ( target " " " " who ) ; return ; } , } ; let peer = Peer { info , block_request : None , known_extrinsics : LruHashSet :: new ( cache_limit ) , known_blocks : LruHashSet :: new ( cache_limit ) , next_request_id : 0 , obsolete_requests : HashMap :: new ( ) , } ; self . context_data . peers . insert ( who . clone ( ) , peer ) ; debug ! ( target " " " " who ) ; } let mut context = ProtocolContext :: new ( & mut self . context_data , & self . network_chan ) ; self . on_demand . as_ref ( ) . map ( | s | s . on_connect ( who . clone ( ) , status . roles , status . best_number ) ) ; self . sync . new_peer ( & mut context , who . clone ( ) ) ; self . consensus_gossip . new_peer ( & mut context , who . clone ( ) , status . roles ) ; self . specialization . on_connect ( & mut context , who , status ) ; }
Called by peer to report status
Called by peer to report status
&mut self
who
PeerId
status
message::Status<B>
&mut self
who
PeerId
status
message::Status<B>