diff --git a/server.go b/server.go index 2c5d3fd5..4a9fec48 100644 --- a/server.go +++ b/server.go @@ -1437,6 +1437,11 @@ func (s *server) handleQuery(state *peerState, querymsg interface{}) { case connectNodeMsg: // 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 { if peer.Addr() == msg.addr { if msg.permanent {