Limit incoming connections

This commit is contained in:
arkpar 2016-03-12 19:52:37 +01:00
parent 0b4355d549
commit 361280a9be

View File

@ -541,7 +541,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
match TcpStream::connect(&address) { match TcpStream::connect(&address) {
Ok(socket) => socket, Ok(socket) => socket,
Err(e) => { Err(e) => {
warn!("Can't connect to address {:?}: {:?}", address, e); debug!("Can't connect to address {:?}: {:?}", address, e);
return; return;
} }
} }
@ -695,6 +695,14 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
return; return;
} }
}; };
if !originated {
let session_count = sessions.count();
let ideal_peers = { self.info.read().unwrap().deref().config.ideal_peers };
if session_count >= ideal_peers as usize {
session.disconnect(DisconnectReason::TooManyPeers);
return;
}
}
let result = sessions.insert_with(move |session_token| { let result = sessions.insert_with(move |session_token| {
session.set_token(session_token); session.set_token(session_token);
io.deregister_stream(token).expect("Error deleting handshake registration"); io.deregister_stream(token).expect("Error deleting handshake registration");