ApiListener#NewClientHandlerInternal(): reject connections from already connected endpoints

This commit is contained in:
Alexander A. Klimov 2020-10-26 15:20:58 +01:00
parent e9b8fc234b
commit 38110e55d3

View File

@ -657,17 +657,22 @@ void ApiListener::NewClientHandlerInternal(boost::asio::yield_context yc, const
if (ctype == ClientJsonRpc) {
Log(LogNotice, "ApiListener", "New JSON-RPC client");
if (endpoint && endpoint->GetConnected()) {
Log(LogNotice, "ApiListener")
<< "Ignoring JSON-RPC connection " << conninfo
<< ". We're already connected to Endpoint '" << endpoint->GetName() << "'.";
return;
}
JsonRpcConnection::Ptr aclient = new JsonRpcConnection(identity, verify_ok, client, role);
if (endpoint) {
bool needSync = !endpoint->GetConnected();
endpoint->AddClient(aclient);
IoEngine::SpawnCoroutine(IoEngine::Get().GetIoContext(), [this, aclient, endpoint, needSync](asio::yield_context yc) {
IoEngine::SpawnCoroutine(IoEngine::Get().GetIoContext(), [this, aclient, endpoint](asio::yield_context yc) {
CpuBoundWork syncClient (yc);
SyncClient(aclient, endpoint, needSync);
SyncClient(aclient, endpoint, true);
});
} else if (!AddAnonymousClient(aclient)) {