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;
|
retry = 0;
|
||||||
// No error, set ready, process and return ok
|
// No error, set ready, process and return ok
|
||||||
m_secureReady = true;
|
m_secureReady = true;
|
||||||
|
sendEvent(m_events->forIDataSocket().secureConnected());
|
||||||
|
|
||||||
auto fingerprint = m_ssl.getFingerprint();
|
auto fingerprint = m_ssl.getFingerprint();
|
||||||
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
|
LOG((CLOG_NOTE "server fingerprint: %s", fingerprint.c_str()));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "server/ClientListener.h"
|
#include "server/ClientListener.h"
|
||||||
|
#include "server/Server.h"
|
||||||
|
|
||||||
#include "server/ClientProxy.h"
|
#include "server/ClientProxy.h"
|
||||||
#include "server/ClientProxyUnknown.h"
|
#include "server/ClientProxyUnknown.h"
|
||||||
|
|
@ -130,10 +131,22 @@ void ClientListener::stop()
|
||||||
cleanupClientSockets();
|
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()
|
void ClientListener::restart()
|
||||||
{
|
{
|
||||||
stop();
|
if (m_server && m_server->isClientMode()){
|
||||||
start();
|
stop();
|
||||||
|
start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -185,22 +198,20 @@ ClientListener::handleClientAccepted(const Event&, void* vsocket)
|
||||||
m_events->adoptHandler(m_events->forClientProxyUnknown().failure(),
|
m_events->adoptHandler(m_events->forClientProxyUnknown().failure(),
|
||||||
client,
|
client,
|
||||||
new TMethodEventJob<ClientListener>(this,
|
new TMethodEventJob<ClientListener>(this,
|
||||||
&ClientListener::handleUnknownClient, client));
|
&ClientListener::handleUnknownClientFailure, client));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClientListener::handleUnknownClient(const Event&, void* vclient)
|
ClientListener::handleUnknownClient(const Event&, void* vclient)
|
||||||
{
|
{
|
||||||
ClientProxyUnknown* unknownClient =
|
auto unknownClient = static_cast<ClientProxyUnknown*>(vclient);
|
||||||
static_cast<ClientProxyUnknown*>(vclient);
|
|
||||||
|
|
||||||
// we should have the client in our new client list
|
// we should have the client in our new client list
|
||||||
assert(m_newClients.count(unknownClient) == 1);
|
assert(m_newClients.count(unknownClient) == 1);
|
||||||
|
|
||||||
// get the real client proxy and install it
|
// get the real client proxy and install it
|
||||||
ClientProxy* client = unknownClient->orphanClientProxy();
|
auto client = unknownClient->orphanClientProxy();
|
||||||
bool handshakeOk = true;
|
if (client) {
|
||||||
if (client != NULL) {
|
|
||||||
// handshake was successful
|
// handshake was successful
|
||||||
m_waitingClients.push_back(client);
|
m_waitingClients.push_back(client);
|
||||||
m_events->addEvent(Event(m_events->forClientListener().connected(),
|
m_events->addEvent(Event(m_events->forClientListener().connected(),
|
||||||
|
|
@ -212,21 +223,16 @@ ClientListener::handleUnknownClient(const Event&, void* vclient)
|
||||||
&ClientListener::handleClientDisconnected,
|
&ClientListener::handleClientDisconnected,
|
||||||
client));
|
client));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
handshakeOk = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now finished with unknown client
|
// now finished with unknown client
|
||||||
m_events->removeHandler(m_events->forClientProxyUnknown().success(), client);
|
removeUnknownClient(unknownClient);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
delete unknownClient;
|
void ClientListener::handleUnknownClientFailure(const Event &, void* vclient)
|
||||||
|
{
|
||||||
|
auto unknownClient = static_cast<ClientProxyUnknown*>(vclient);
|
||||||
|
removeUnknownClient(unknownClient);
|
||||||
|
restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,14 @@ private:
|
||||||
void handleClientConnecting(const Event&, void*);
|
void handleClientConnecting(const Event&, void*);
|
||||||
void handleClientAccepted(const Event&, void*);
|
void handleClientAccepted(const Event&, void*);
|
||||||
void handleUnknownClient(const Event&, void*);
|
void handleUnknownClient(const Event&, void*);
|
||||||
|
void handleUnknownClientFailure(const Event&, void*);
|
||||||
void handleClientDisconnected(const Event&, void*);
|
void handleClientDisconnected(const Event&, void*);
|
||||||
|
|
||||||
void cleanupListenSocket();
|
void cleanupListenSocket();
|
||||||
void cleanupClientSockets();
|
void cleanupClientSockets();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
void removeUnknownClient(ClientProxyUnknown* unknownClient);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::set<ClientProxyUnknown*> NewClients;
|
typedef std::set<ClientProxyUnknown*> NewClients;
|
||||||
|
|
|
||||||
|
|
@ -1432,10 +1432,7 @@ Server::handleClientDisconnected(const Event&, void* vclient)
|
||||||
removeOldClient(client);
|
removeOldClient(client);
|
||||||
|
|
||||||
delete client;
|
delete client;
|
||||||
|
m_clientListener->restart();
|
||||||
if (m_args.m_config->isClientMode()) {
|
|
||||||
m_clientListener->restart();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -2421,6 +2418,11 @@ Server::isReceivedFileSizeValid()
|
||||||
return m_expectedFileSize == m_receivedFileData.size();
|
return m_expectedFileSize == m_receivedFileData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Server::isClientMode() const
|
||||||
|
{
|
||||||
|
return m_args.m_config->isClientMode();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Server::sendFileToClient(const char* filename)
|
Server::sendFileToClient(const char* filename)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,9 @@ public:
|
||||||
//! Return fake drag file list
|
//! Return fake drag file list
|
||||||
DragFileList getFakeDragFileList() { return m_fakeDragFileList; }
|
DragFileList getFakeDragFileList() { return m_fakeDragFileList; }
|
||||||
|
|
||||||
|
//! Returns true if it's client mode and server initiates connection
|
||||||
|
bool isClientMode() const;
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue