server: Check max peers before connecting

This commit is contained in:
Javed Khan 2016-11-03 01:34:45 +05:30 committed by Dave Collins
parent d8a6de461f
commit b320129e9b

View file

@ -1437,6 +1437,11 @@ func (s *server) handleQuery(state *peerState, querymsg interface{}) {
case connectNodeMsg: case connectNodeMsg:
// XXX(oga) duplicate oneshots? // XXX(oga) duplicate oneshots?
// Limit max number of total peers.
if state.Count() >= cfg.MaxPeers {
msg.reply <- errors.New("max peers reached")
return
}
for _, peer := range state.persistentPeers { for _, peer := range state.persistentPeers {
if peer.Addr() == msg.addr { if peer.Addr() == msg.addr {
if msg.permanent { if msg.permanent {