fn download_new(&mut self, protocol: &mut Context<B>, who: PeerId) {
		if let Some(ref mut peer) = self.peers.get_mut(&who) {
			// when there are too many blocks in the queue => do not try to download new blocks
			if self.queue_blocks.len() > MAX_IMPORTING_BLOCKS {
				trace!(target: "sync", "Too many blocks in the queue.");
				return;
			}
			match peer.state {
				PeerSyncState::Available => {
					trace!(target: "sync", "Considering new block download from {}, common block is {}, best is {:?}", who, peer.common_number, peer.best_number);
					if let Some(range) = self.blocks.needed_blocks(who.clone(), MAX_BLOCKS_TO_REQUEST, peer.best_number, peer.common_number) {
						trace!(target: "sync", "Requesting blocks from {}, ({} to {})", who, range.start, range.end);
						let request = message::generic::BlockRequest {
							id: 0,
							fields: self.required_block_attributes.clone(),
							from: message::FromBlock::Number(range.start),
							to: None,
							direction: message::Direction::Ascending,
							max: Some((range.end - range.start).as_() as u32),
						};
						peer.state = PeerSyncState::DownloadingNew(range.start);
						protocol.send_block_request(who, request);
					} else {
						trace!(target: "sync", "Nothing to request");
					}
				},
				_ => trace!(target: "sync", "Peer {} is busy", who),
			}
		}
	}
// Issue a request for a peer to download new blocks, if any are available
Issue a request for a peer to download new blocks, if any are available
Issue a request for a peer to download new blocks if any are available
fn download_new(&mut self, protocol: &mut Context<B>, who: PeerId) {
		if let Some(ref mut peer) = self.peers.get_mut(&who) {
			// when there are too many blocks in the queue => do not try to download new blocks
			if self.queue_blocks.len() > MAX_IMPORTING_BLOCKS {
				trace!(target: "sync", "Too many blocks in the queue.");
				return;
			}
			match peer.state {
				PeerSyncState::Available => {
					trace!(target: "sync", "Considering new block download from {}, common block is {}, best is {:?}", who, peer.common_number, peer.best_number);
					if let Some(range) = self.blocks.needed_blocks(who.clone(), MAX_BLOCKS_TO_REQUEST, peer.best_number, peer.common_number) {
						trace!(target: "sync", "Requesting blocks from {}, ({} to {})", who, range.start, range.end);
						let request = message::generic::BlockRequest {
							id: 0,
							fields: self.required_block_attributes.clone(),
							from: message::FromBlock::Number(range.start),
							to: None,
							direction: message::Direction::Ascending,
							max: Some((range.end - range.start).as_() as u32),
						};
						peer.state = PeerSyncState::DownloadingNew(range.start);
						protocol.send_block_request(who, request);
					} else {
						trace!(target: "sync", "Nothing to request");
					}
				},
				_ => trace!(target: "sync", "Peer {} is busy", who),
			}
		}
	}
fn download_new ( & mut self , protocol : & mut Context < B > , who : PeerId ) { if let Some ( ref mut peer ) = self . peers . get_mut ( & who ) { // when there are too many blocks in the queue => do not try to download new blocks if self . queue_blocks . len ( ) > MAX_IMPORTING_BLOCKS { trace ! ( target " " " " ) ; return ; } match peer . state { PeerSyncState :: Available => { trace ! ( target " " " " who peer common_number peer best_number ) ; if let Some ( range ) = self . blocks . needed_blocks ( who . clone ( ) , MAX_BLOCKS_TO_REQUEST , peer . best_number , peer . common_number ) { trace ! ( target " " " " who range start range end ) ; let request = message :: generic :: BlockRequest { id : 0 , fields : self . required_block_attributes . clone ( ) , from : message :: FromBlock :: Number ( range . start ) , to : None , direction : message :: Direction :: Ascending , max : Some ( ( range . end - range . start ) . as_ ( ) as u32 ) , } ; peer . state = PeerSyncState :: DownloadingNew ( range . start ) ; protocol . send_block_request ( who , request ) ; } else { trace ! ( target " " " " ) ; } } , _ => trace ! ( target " " " " who ) , } } }
Issue a request for a peer to download new blocks, if any are available
Issue a request for a peer to download new blocks if any are available
&mut self
protocol
&mut Context<B>
who
PeerId
&mut self
protocol
&mut Context<B>
who
PeerId