SYNERGY-1003 Connection processing for name with several ips (#7013)

* SYNERGY-1003 Connection processing for name with several ips

* Update ChangeLog

* SYNERGY-1003 Fix compilation

* SYNERGY-1003 Fix code smells
This commit is contained in:
SerhiiGadzhilov 2021-05-24 11:21:32 +03:00 committed by GitHub
parent acdb36bd39
commit c000b886c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 33 deletions

View file

@ -19,6 +19,7 @@ Bug fixes:
- #7009 Clipboard sharing doesn't work on Linux system - #7009 Clipboard sharing doesn't work on Linux system
- #7010 Fix Ubuntu 16.04 pipeline in Azure - #7010 Fix Ubuntu 16.04 pipeline in Azure
- #7011 Fix language synchronisation checkbox spelling - #7011 Fix language synchronisation checkbox spelling
- #7013 Wrong connection pop up appears if the user connects using a domain name which is assigned to list of IP's
Enhancements: Enhancements:
- #6954 Move language selection to advanced section - #6954 Move language selection to advanced section

View file

@ -45,6 +45,7 @@ EventTypes::setEvents(IEventQueue* events)
REGISTER_EVENT(Client, connected) REGISTER_EVENT(Client, connected)
REGISTER_EVENT(Client, connectionFailed) REGISTER_EVENT(Client, connectionFailed)
REGISTER_EVENT(Client, connectionRefused)
REGISTER_EVENT(Client, disconnected) REGISTER_EVENT(Client, disconnected)
// //

View file

@ -42,11 +42,6 @@ type_##Events::name_() \
class ClientEvents : public EventTypes { class ClientEvents : public EventTypes {
public: public:
ClientEvents() :
m_connected(Event::kUnknown),
m_connectionFailed(Event::kUnknown),
m_disconnected(Event::kUnknown) { }
//! @name accessors //! @name accessors
//@{ //@{
@ -64,6 +59,13 @@ public:
*/ */
Event::Type connectionFailed(); Event::Type connectionFailed();
//! Get connection refused event type
/*!
Returns the connection refused event type. This is sent when the
server refuses for some reason. The event data is a FailInfo*.
*/
Event::Type connectionRefused();
//! Get disconnected event type //! Get disconnected event type
/*! /*!
Returns the disconnected event type. This is sent when the client Returns the disconnected event type. This is sent when the client
@ -75,9 +77,10 @@ public:
//@} //@}
private: private:
Event::Type m_connected; Event::Type m_connected = Event::kUnknown;
Event::Type m_connectionFailed; Event::Type m_connectionFailed = Event::kUnknown;
Event::Type m_disconnected; Event::Type m_connectionRefused = Event::kUnknown;
Event::Type m_disconnected = Event::kUnknown;
}; };
class IStreamEvents : public EventTypes { class IStreamEvents : public EventTypes {

View file

@ -176,12 +176,9 @@ Client::connect(size_t addressIndex)
void void
Client::disconnect(const char* msg) Client::disconnect(const char* msg)
{ {
m_connectOnResume = false; cleanup();
cleanupTimer();
cleanupScreen(); if (msg) {
cleanupConnecting();
cleanupConnection();
if (msg != NULL) {
sendConnectionFailedEvent(msg); sendConnectionFailedEvent(msg);
} }
else { else {
@ -189,6 +186,19 @@ Client::disconnect(const char* msg)
} }
} }
void
Client::refuseConnection(const char* msg)
{
cleanup();
if (msg) {
auto info = new FailInfo(msg);
info->m_retry = true;
Event event(m_events->forClient().connectionRefused(), getEventTarget(), info, Event::kDontFreeData);
m_events->addEvent(event);
}
}
void void
Client::handshakeComplete() Client::handshakeComplete()
{ {
@ -540,6 +550,16 @@ Client::setupTimer()
&Client::handleConnectTimeout)); &Client::handleConnectTimeout));
} }
void
Client::cleanup()
{
m_connectOnResume = false;
cleanupTimer();
cleanupScreen();
cleanupConnecting();
cleanupConnection();
}
void void
Client::cleanupConnecting() Client::cleanupConnecting()
{ {

View file

@ -83,6 +83,13 @@ public:
*/ */
void disconnect(const char* msg); void disconnect(const char* msg);
//! Refuse connection
/*!
Disconnects from the server with an optional error message.
Unlike disconnect this function doesn't try to use other ip addresses
*/
void refuseConnection(const char* msg);
//! Notify of handshake complete //! Notify of handshake complete
/*! /*!
Notifies the client that the connection handshake has completed. Notifies the client that the connection handshake has completed.
@ -180,6 +187,7 @@ private:
void setupConnection(); void setupConnection();
void setupScreen(); void setupScreen();
void setupTimer(); void setupTimer();
void cleanup();
void cleanupConnecting(); void cleanupConnecting();
void cleanupConnection(); void cleanupConnection();
void cleanupScreen(); void cleanupScreen();

View file

@ -188,25 +188,25 @@ ServerProxy::parseHandshakeMessage(const UInt8* code)
ProtocolUtil::readf(m_stream, ProtocolUtil::readf(m_stream,
kMsgEIncompatible + 4, &major, &minor); kMsgEIncompatible + 4, &major, &minor);
LOG((CLOG_ERR "server has incompatible version %d.%d", major, minor)); LOG((CLOG_ERR "server has incompatible version %d.%d", major, minor));
m_client->disconnect("server has incompatible version"); m_client->refuseConnection("server has incompatible version");
return kDisconnect; return kDisconnect;
} }
else if (memcmp(code, kMsgEBusy, 4) == 0) { else if (memcmp(code, kMsgEBusy, 4) == 0) {
LOG((CLOG_ERR "server already has a connected client with name \"%s\"", m_client->getName().c_str())); LOG((CLOG_ERR "server already has a connected client with name \"%s\"", m_client->getName().c_str()));
m_client->disconnect("server already has a connected client with our name"); m_client->refuseConnection("server already has a connected client with our name");
return kDisconnect; return kDisconnect;
} }
else if (memcmp(code, kMsgEUnknown, 4) == 0) { else if (memcmp(code, kMsgEUnknown, 4) == 0) {
LOG((CLOG_ERR "server refused client with name \"%s\"", m_client->getName().c_str())); LOG((CLOG_ERR "server refused client with name \"%s\"", m_client->getName().c_str()));
m_client->disconnect("server refused client with our name"); m_client->refuseConnection("server refused client with our name");
return kDisconnect; return kDisconnect;
} }
else if (memcmp(code, kMsgEBad, 4) == 0) { else if (memcmp(code, kMsgEBad, 4) == 0) {
LOG((CLOG_ERR "server disconnected due to a protocol error")); LOG((CLOG_ERR "server disconnected due to a protocol error"));
m_client->disconnect("server reported a protocol error"); m_client->refuseConnection("server reported a protocol error");
return kDisconnect; return kDisconnect;
} }
else { else {

View file

@ -57,6 +57,7 @@
#include "platform/OSXDragSimulator.h" #include "platform/OSXDragSimulator.h"
#endif #endif
#include <memory>
#include <iostream> #include <iostream>
#include <stdio.h> #include <stdio.h>
@ -301,11 +302,9 @@ ClientApp::handleClientConnected(const Event&, void*)
void void
ClientApp::handleClientFailed(const Event& e, void*) ClientApp::handleClientFailed(const Event& e, void*)
{ {
Client::FailInfo* info = if ( (++m_lastServerAddressIndex) < m_client->getLastResolvedAddressesCount()) {
static_cast<Client::FailInfo*>(e.getData()); std::unique_ptr<Client::FailInfo> info(static_cast<Client::FailInfo*>(e.getData()));
if (m_lastServerAddressIndex + 1 < m_client->getLastResolvedAddressesCount()) {
m_lastServerAddressIndex++;
updateStatus(String("Failed to connect to server: ") + info->m_what + " Trying next address..."); updateStatus(String("Failed to connect to server: ") + info->m_what + " Trying next address...");
LOG((CLOG_NOTE "Failed to connect to server: %s. Trying next address...", info->m_what.c_str())); LOG((CLOG_NOTE "Failed to connect to server: %s. Trying next address...", info->m_what.c_str()));
if (!m_suspended) { if (!m_suspended) {
@ -314,19 +313,27 @@ ClientApp::handleClientFailed(const Event& e, void*)
} }
else { else {
m_lastServerAddressIndex = 0; m_lastServerAddressIndex = 0;
updateStatus(String("Failed to connect to server: ") + info->m_what); handleClientRefused(e, nullptr);
if (!args().m_restartable || !info->m_retry) { }
LOG((CLOG_ERR "failed to connect to server: %s", info->m_what.c_str()));
m_events->addEvent(Event(Event::kQuit)); }
}
else { void
LOG((CLOG_WARN "failed to connect to server: %s", info->m_what.c_str())); ClientApp::handleClientRefused(const Event& e, void*)
if (!m_suspended) { {
scheduleClientRestart(nextRestartTimeout()); std::unique_ptr<Client::FailInfo> info(static_cast<Client::FailInfo*>(e.getData()));
}
updateStatus(String("Failed to connect to server: ") + info->m_what);
if (!args().m_restartable || !info->m_retry) {
LOG((CLOG_ERR "failed to connect to server: %s", info->m_what.c_str()));
m_events->addEvent(Event(Event::kQuit));
}
else {
LOG((CLOG_WARN "failed to connect to server: %s", info->m_what.c_str()));
if (!m_suspended) {
scheduleClientRestart(nextRestartTimeout());
} }
} }
delete info;
} }
@ -366,6 +373,11 @@ ClientApp::openClient(const String& name, const NetworkAddress& address,
client->getEventTarget(), client->getEventTarget(),
new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientFailed)); new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientFailed));
m_events->adoptHandler(
m_events->forClient().connectionRefused(),
client->getEventTarget(),
new TMethodEventJob<ClientApp>(this, &ClientApp::handleClientRefused));
m_events->adoptHandler( m_events->adoptHandler(
m_events->forClient().disconnected(), m_events->forClient().disconnected(),
client->getEventTarget(), client->getEventTarget(),
@ -389,6 +401,7 @@ ClientApp::closeClient(Client* client)
m_events->removeHandler(m_events->forClient().connected(), client); m_events->removeHandler(m_events->forClient().connected(), client);
m_events->removeHandler(m_events->forClient().connectionFailed(), client); m_events->removeHandler(m_events->forClient().connectionFailed(), client);
m_events->removeHandler(m_events->forClient().connectionRefused(), client);
m_events->removeHandler(m_events->forClient().disconnected(), client); m_events->removeHandler(m_events->forClient().disconnected(), client);
delete client; delete client;
} }

View file

@ -67,6 +67,7 @@ public:
void scheduleClientRestart(double retryTime); void scheduleClientRestart(double retryTime);
void handleClientConnected(const Event&, void*); void handleClientConnected(const Event&, void*);
void handleClientFailed(const Event& e, void*); void handleClientFailed(const Event& e, void*);
void handleClientRefused(const Event& e, void*);
void handleClientDisconnected(const Event&, void*); void handleClientDisconnected(const Event&, void*);
Client* openClient(const String& name, const NetworkAddress& address, Client* openClient(const String& name, const NetworkAddress& address,
synergy::Screen* screen); synergy::Screen* screen);