Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #693 from ethcore/network
Browse files Browse the repository at this point in the history
Limit incoming connections
  • Loading branch information
debris committed Mar 13, 2016
2 parents 1f8e0f8 + 361280a commit 70624f8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion util/src/network/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
match TcpStream::connect(&address) {
Ok(socket) => socket,
Err(e) => {
warn!("Can't connect to address {:?}: {:?}", address, e);
debug!("Can't connect to address {:?}: {:?}", address, e);
return;
}
}
Expand Down Expand Up @@ -695,6 +695,14 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
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| {
session.set_token(session_token);
io.deregister_stream(token).expect("Error deleting handshake registration");
Expand Down

0 comments on commit 70624f8

Please sign in to comment.