if (maxMessageLength >= 0 && data_length > maxMessageLength) {
std::stringstream errorMessage;
- errorMessage << "Max data length exceeded: " << (maxMessageLength / 1024 / 1024) << " MB";
+ errorMessage << "Max data length exceeded: " << (maxMessageLength / 1024) << " KB";
BOOST_THROW_EXCEPTION(std::invalid_argument(errorMessage.str()));
}
endpoint->AddClient(aclient);
m_SyncQueue.Enqueue(std::bind(&ApiListener::SyncClient, this, aclient, endpoint, needSync));
- } else
- AddAnonymousClient(aclient);
+ } else {
+ if (!AddAnonymousClient(aclient)) {
+ Log(LogNotice, "ApiListener", "Ignoring anonymous JSON-RPC connection. Max connections exceeded.");
+ aclient->Disconnect();
+ }
+ }
} else {
Log(LogNotice, "ApiListener", "New HTTP client");
return 0;
}
-void ApiListener::AddAnonymousClient(const JsonRpcConnection::Ptr& aclient)
+bool ApiListener::AddAnonymousClient(const JsonRpcConnection::Ptr& aclient)
{
boost::mutex::scoped_lock lock(m_AnonymousClientsLock);
+ if (m_AnonymousClients.size() > 25)
+ return false;
+
m_AnonymousClients.insert(aclient);
+ return true;
}
void ApiListener::RemoveAnonymousClient(const JsonRpcConnection::Ptr& aclient)
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
std::pair<Dictionary::Ptr, Dictionary::Ptr> GetStatus();
- void AddAnonymousClient(const JsonRpcConnection::Ptr& aclient);
+ bool AddAnonymousClient(const JsonRpcConnection::Ptr& aclient);
void RemoveAnonymousClient(const JsonRpcConnection::Ptr& aclient);
std::set<JsonRpcConnection::Ptr> GetAnonymousClients() const;