fn accept_response<F: FnOnce(Request<B>) -> Accept<B>>(&self, rtype: &str, peer: PeerId, request_id: u64, try_accept: F) {
		let mut core = self.core.lock();
		let request = match core.remove(peer.clone(), request_id) {
			Some(request) => request,
			None => {
				let reason = format!("Invalid remote {} response from peer", rtype);
				self.send(NetworkMsg::ReportPeer(peer.clone(), Severity::Bad(reason)));
				core.remove_peer(peer);
				return;
			},
		};

		let retry_count = request.retry_count;
		let (retry_count, retry_request_data) = match try_accept(request) {
			Accept::Ok => (retry_count, None),
			Accept::CheckFailed(error, retry_request_data) => {
				let reason = format!("Failed to check remote {} response from peer: {}", rtype, error);
				self.send(NetworkMsg::ReportPeer(peer.clone(), Severity::Bad(reason)));
				core.remove_peer(peer);

				if retry_count > 0 {
					(retry_count - 1, Some(retry_request_data))
				} else {
					trace!(target: "sync", "Failed to get remote {} response for given number of retries", rtype);
					retry_request_data.fail(ClientErrorKind::RemoteFetchFailed.into());
					(0, None)
				}
			},
			Accept::Unexpected(retry_request_data) => {
				let reason = format!("Unexpected response to remote {} from peer", rtype);
				self.send(NetworkMsg::ReportPeer(peer.clone(), Severity::Bad(reason)));
				core.remove_peer(peer);

				(retry_count, Some(retry_request_data))
			},
		};

		if let Some(request_data) = retry_request_data {
			core.insert(retry_count, request_data);
		}

		core.dispatch(self);
	}
/// Try to accept response from given peer.
Try to accept response from given peer.
Try to accept response from given peer .
fn accept_response<F: FnOnce(Request<B>) -> Accept<B>>(&self, rtype: &str, peer: PeerId, request_id: u64, try_accept: F) {
		let mut core = self.core.lock();
		let request = match core.remove(peer.clone(), request_id) {
			Some(request) => request,
			None => {
				let reason = format!("Invalid remote {} response from peer", rtype);
				self.send(NetworkMsg::ReportPeer(peer.clone(), Severity::Bad(reason)));
				core.remove_peer(peer);
				return;
			},
		};
		let retry_count = request.retry_count;
		let (retry_count, retry_request_data) = match try_accept(request) {
			Accept::Ok => (retry_count, None),
			Accept::CheckFailed(error, retry_request_data) => {
				let reason = format!("Failed to check remote {} response from peer: {}", rtype, error);
				self.send(NetworkMsg::ReportPeer(peer.clone(), Severity::Bad(reason)));
				core.remove_peer(peer);
				if retry_count > 0 {
					(retry_count - 1, Some(retry_request_data))
				} else {
					trace!(target: "sync", "Failed to get remote {} response for given number of retries", rtype);
					retry_request_data.fail(ClientErrorKind::RemoteFetchFailed.into());
					(0, None)
				}
			},
			Accept::Unexpected(retry_request_data) => {
				let reason = format!("Unexpected response to remote {} from peer", rtype);
				self.send(NetworkMsg::ReportPeer(peer.clone(), Severity::Bad(reason)));
				core.remove_peer(peer);
				(retry_count, Some(retry_request_data))
			},
		};
		if let Some(request_data) = retry_request_data {
			core.insert(retry_count, request_data);
		}
		core.dispatch(self);
	}
fn accept_response < F : FnOnce ( Request < B > ) -> Accept < B > > ( & self , rtype : & str , peer : PeerId , request_id : u64 , try_accept : F ) { let mut core = self . core . lock ( ) ; let request = match core . remove ( peer . clone ( ) , request_id ) { Some ( request ) => request , None => { let reason = format ! ( " " rtype ) ; self . send ( NetworkMsg :: ReportPeer ( peer . clone ( ) , Severity :: Bad ( reason ) ) ) ; core . remove_peer ( peer ) ; return ; } , } ; let retry_count = request . retry_count ; let ( retry_count , retry_request_data ) = match try_accept ( request ) { Accept :: Ok => ( retry_count , None ) , Accept :: CheckFailed ( error , retry_request_data ) => { let reason = format ! ( " " rtype error ) ; self . send ( NetworkMsg :: ReportPeer ( peer . clone ( ) , Severity :: Bad ( reason ) ) ) ; core . remove_peer ( peer ) ; if retry_count > 0 { ( retry_count - 1 , Some ( retry_request_data ) ) } else { trace ! ( target " " " " rtype ) ; retry_request_data . fail ( ClientErrorKind :: RemoteFetchFailed . into ( ) ) ; ( 0 , None ) } } , Accept :: Unexpected ( retry_request_data ) => { let reason = format ! ( " " rtype ) ; self . send ( NetworkMsg :: ReportPeer ( peer . clone ( ) , Severity :: Bad ( reason ) ) ) ; core . remove_peer ( peer ) ; ( retry_count , Some ( retry_request_data ) ) } , } ; if let Some ( request_data ) = retry_request_data { core . insert ( retry_count , request_data ) ; } core . dispatch ( self ) ; }
Try to accept response from given peer.
Try to accept response from given peer .
&self
rtype
&str
peer
PeerId
request_id
u64
try_accept
F
&self
rtype
&str
peer
PeerId
request_id
u64
try_accept
F