Fix issue with reconnection when server initiate TLS connection. (#7230)
* Restart socket when unknown client connection fails * Send connected event from client side Co-authored-by: Serhii Hadzhilov <serhii@symless.com>
This commit is contained in:
parent
876a110969
commit
7d4a368864
5 changed files with 38 additions and 24 deletions
|
|
@ -321,6 +321,7 @@ SecureClientSocket::secureConnect(int socket)
|
|||
retry = 0;
|
||||
// No error, set ready, process and return ok
|
||||
m_secureReady = true;
|
||||
sendEvent(m_events->forIDataSocket().secureConnected());
|
||||
|
||||
auto fingerprint = m_ssl.getFingerprint();
|
||||
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "server/ClientListener.h"
|
||||
#include "server/Server.h"
|
||||
|
||||
#include "server/ClientProxy.h"
|
||||
#include "server/ClientProxyUnknown.h"
|
||||
|
|
@ -130,10 +131,22 @@ void ClientListener::stop()
|
|||
cleanupClientSockets();
|
||||
}
|
||||
|
||||
void ClientListener::removeUnknownClient(ClientProxyUnknown* unknownClient)
|
||||
{
|
||||
if (unknownClient) {
|
||||
m_events->removeHandler(m_events->forClientProxyUnknown().success(), unknownClient);
|
||||
m_events->removeHandler(m_events->forClientProxyUnknown().failure(), unknownClient);
|
||||
m_newClients.erase(unknownClient);
|
||||
delete unknownClient;
|
||||
}
|
||||
}
|
||||
|
||||
void ClientListener::restart()
|
||||
{
|
||||
stop();
|
||||
start();
|
||||
if (m_server && m_server->isClientMode()){
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -185,22 +198,20 @@ ClientListener::handleClientAccepted(const Event&, void* vsocket)
|
|||
m_events->adoptHandler(m_events->forClientProxyUnknown().failure(),
|
||||
client,
|
||||
new TMethodEventJob<ClientListener>(this,
|
||||
&ClientListener::handleUnknownClient, client));
|
||||
&ClientListener::handleUnknownClientFailure, client));
|
||||
}
|
||||
|
||||
void
|
||||
ClientListener::handleUnknownClient(const Event&, void* vclient)
|
||||
{
|
||||
ClientProxyUnknown* unknownClient =
|
||||
static_cast<ClientProxyUnknown*>(vclient);
|
||||
auto unknownClient = static_cast<ClientProxyUnknown*>(vclient);
|
||||
|
||||
// we should have the client in our new client list
|
||||
assert(m_newClients.count(unknownClient) == 1);
|
||||
|
||||
// get the real client proxy and install it
|
||||
ClientProxy* client = unknownClient->orphanClientProxy();
|
||||
bool handshakeOk = true;
|
||||
if (client != NULL) {
|
||||
auto client = unknownClient->orphanClientProxy();
|
||||
if (client) {
|
||||
// handshake was successful
|
||||
m_waitingClients.push_back(client);
|
||||
m_events->addEvent(Event(m_events->forClientListener().connected(),
|
||||
|
|
@ -212,21 +223,16 @@ ClientListener::handleUnknownClient(const Event&, void* vclient)
|
|||
&ClientListener::handleClientDisconnected,
|
||||
client));
|
||||
}
|
||||
else {
|
||||
handshakeOk = false;
|
||||
}
|
||||
|
||||
// now finished with unknown client
|
||||
m_events->removeHandler(m_events->forClientProxyUnknown().success(), client);
|
||||
m_events->removeHandler(m_events->forClientProxyUnknown().failure(), client);
|
||||
m_newClients.erase(unknownClient);
|
||||
PacketStreamFilter* streamFileter = dynamic_cast<PacketStreamFilter*>(unknownClient->getStream());
|
||||
IDataSocket* socket = NULL;
|
||||
if (streamFileter != NULL) {
|
||||
socket = dynamic_cast<IDataSocket*>(streamFileter->getStream());
|
||||
}
|
||||
removeUnknownClient(unknownClient);
|
||||
}
|
||||
|
||||
delete unknownClient;
|
||||
void ClientListener::handleUnknownClientFailure(const Event &, void* vclient)
|
||||
{
|
||||
auto unknownClient = static_cast<ClientProxyUnknown*>(vclient);
|
||||
removeUnknownClient(unknownClient);
|
||||
restart();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -78,12 +78,14 @@ private:
|
|||
void handleClientConnecting(const Event&, void*);
|
||||
void handleClientAccepted(const Event&, void*);
|
||||
void handleUnknownClient(const Event&, void*);
|
||||
void handleUnknownClientFailure(const Event&, void*);
|
||||
void handleClientDisconnected(const Event&, void*);
|
||||
|
||||
void cleanupListenSocket();
|
||||
void cleanupClientSockets();
|
||||
void start();
|
||||
void stop();
|
||||
void removeUnknownClient(ClientProxyUnknown* unknownClient);
|
||||
|
||||
private:
|
||||
typedef std::set<ClientProxyUnknown*> NewClients;
|
||||
|
|
|
|||
|
|
@ -1432,10 +1432,7 @@ Server::handleClientDisconnected(const Event&, void* vclient)
|
|||
removeOldClient(client);
|
||||
|
||||
delete client;
|
||||
|
||||
if (m_args.m_config->isClientMode()) {
|
||||
m_clientListener->restart();
|
||||
}
|
||||
m_clientListener->restart();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -2421,6 +2418,11 @@ Server::isReceivedFileSizeValid()
|
|||
return m_expectedFileSize == m_receivedFileData.size();
|
||||
}
|
||||
|
||||
bool Server::isClientMode() const
|
||||
{
|
||||
return m_args.m_config->isClientMode();
|
||||
}
|
||||
|
||||
void
|
||||
Server::sendFileToClient(const char* filename)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -186,6 +186,9 @@ public:
|
|||
//! Return fake drag file list
|
||||
DragFileList getFakeDragFileList() { return m_fakeDragFileList; }
|
||||
|
||||
//! Returns true if it's client mode and server initiates connection
|
||||
bool isClientMode() const;
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Reference in a new issue