moving to mainaint_sync

This commit is contained in:
Nikolay Volf 2016-02-04 04:28:16 +03:00
parent 86cfe95113
commit 376c99c247
2 changed files with 7 additions and 8 deletions

View File

@ -985,14 +985,8 @@ impl ChainSync {
} }
/// Handle peer timeouts /// Handle peer timeouts
pub fn maintain_peers(&mut self, io: &mut SyncIo) { pub fn maintain_peers(&self, io: &mut SyncIo) {
let tick = time::precise_time_s(); let tick = time::precise_time_s();
if !io.chain().queue_info().full && self.state == SyncState::Waiting {
self.state = SyncState::Idle;
self.continue_sync(io);
}
for (peer_id, peer) in &self.peers { for (peer_id, peer) in &self.peers {
if peer.asking != PeerAsking::Nothing && (tick - peer.ask_time) > CONNECTION_TIMEOUT_SEC { if peer.asking != PeerAsking::Nothing && (tick - peer.ask_time) > CONNECTION_TIMEOUT_SEC {
io.disconnect_peer(*peer_id); io.disconnect_peer(*peer_id);
@ -1001,7 +995,11 @@ impl ChainSync {
} }
/// Maintain other peers. Send out any new blocks and transactions /// Maintain other peers. Send out any new blocks and transactions
pub fn _maintain_sync(&mut self, _io: &mut SyncIo) { pub fn maintain_sync(&mut self, io: &mut SyncIo) {
if !io.chain().queue_info().full && self.state == SyncState::Waiting {
self.state = SyncState::Idle;
self.continue_sync(io);
}
} }
} }

View File

@ -107,6 +107,7 @@ impl NetworkProtocolHandler<SyncMessage> for EthSync {
fn timeout(&self, io: &NetworkContext<SyncMessage>, _timer: TimerToken) { fn timeout(&self, io: &NetworkContext<SyncMessage>, _timer: TimerToken) {
self.sync.write().unwrap().maintain_peers(&mut NetSyncIo::new(io, self.chain.deref())); self.sync.write().unwrap().maintain_peers(&mut NetSyncIo::new(io, self.chain.deref()));
self.sync.write().unwrap().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref()));
} }
} }