Prevent connection deletion until unregister is called; minor tweaks

This commit is contained in:
arkpar 2016-02-17 01:39:16 +01:00
parent b6ccbdb694
commit 39a98cd555
3 changed files with 4 additions and 6 deletions

View File

@ -1179,7 +1179,7 @@ impl ChainSync {
for (peer_id, peer_number) in updated_peers { for (peer_id, peer_number) in updated_peers {
let mut peer_best = self.peers.get(&peer_id).unwrap().latest_hash.clone(); let mut peer_best = self.peers.get(&peer_id).unwrap().latest_hash.clone();
if best_number - peer_number > MAX_PEERS_PROPAGATION as BlockNumber { if best_number - peer_number > MAX_PEERS_PROPAGATION as BlockNumber {
// If we think peer is too far behind just end one latest hash // If we think peer is too far behind just send one latest hash
peer_best = last_parent.clone(); peer_best = last_parent.clone();
} }
sent = sent + match ChainSync::create_new_hashes_rlp(io.chain(), &peer_best, &local_best) { sent = sent + match ChainSync::create_new_hashes_rlp(io.chain(), &peer_best, &local_best) {

View File

@ -682,14 +682,13 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
let mut failure_id = None; let mut failure_id = None;
match token { match token {
FIRST_HANDSHAKE ... LAST_HANDSHAKE => { FIRST_HANDSHAKE ... LAST_HANDSHAKE => {
let mut handshakes = self.handshakes.write().unwrap(); let handshakes = self.handshakes.write().unwrap();
if let Some(handshake) = handshakes.get(token).cloned() { if let Some(handshake) = handshakes.get(token).cloned() {
failure_id = Some(handshake.lock().unwrap().id().clone()); failure_id = Some(handshake.lock().unwrap().id().clone());
handshakes.remove(token);
} }
}, },
FIRST_SESSION ... LAST_SESSION => { FIRST_SESSION ... LAST_SESSION => {
let mut sessions = self.sessions.write().unwrap(); let sessions = self.sessions.write().unwrap();
if let Some(session) = sessions.get(token).cloned() { if let Some(session) = sessions.get(token).cloned() {
let s = session.lock().unwrap(); let s = session.lock().unwrap();
if s.is_ready() { if s.is_ready() {
@ -700,7 +699,6 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
} }
} }
failure_id = Some(s.id().clone()); failure_id = Some(s.id().clone());
sessions.remove(token);
} }
}, },
_ => {}, _ => {},

View File

@ -91,7 +91,7 @@ impl Decodable for PeerCapabilityInfo {
} }
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug)]
struct SessionCapabilityInfo { struct SessionCapabilityInfo {
pub protocol: &'static str, pub protocol: &'static str,
pub version: u8, pub version: u8,