Conflicts:

src/lib/client/Client.cpp
	src/lib/net/TCPSocketFactory.cpp
This commit is contained in:
Jerry (Xinyu Hou) 2016-08-24 15:14:12 +01:00 committed by Andrew Nelless
parent e32402b5c6
commit 95464d97cf
7 changed files with 69 additions and 12 deletions

View File

@ -82,6 +82,7 @@ REGISTER_EVENT(IpcServerProxy, messageReceived)
// //
REGISTER_EVENT(IDataSocket, connected) REGISTER_EVENT(IDataSocket, connected)
REGISTER_EVENT(IDataSocket, secureConnected)
REGISTER_EVENT(IDataSocket, connectionFailed) REGISTER_EVENT(IDataSocket, connectionFailed)
// //

View File

@ -230,6 +230,7 @@ class IDataSocketEvents : public EventTypes {
public: public:
IDataSocketEvents() : IDataSocketEvents() :
m_connected(Event::kUnknown), m_connected(Event::kUnknown),
m_secureConnected(Event::kUnknown),
m_connectionFailed(Event::kUnknown) { } m_connectionFailed(Event::kUnknown) { }
//! @name accessors //! @name accessors
@ -242,6 +243,13 @@ public:
*/ */
Event::Type connected(); Event::Type connected();
//! Get secure connected event type
/*!
Returns the secure socket connected event type. A secure socket sends
this event when a remote connection has been established.
*/
Event::Type secureConnected();
//! Get connection failed event type //! Get connection failed event type
/*! /*!
Returns the socket connection failed event type. A socket sends Returns the socket connection failed event type. A socket sends
@ -254,6 +262,7 @@ public:
private: private:
Event::Type m_connected; Event::Type m_connected;
Event::Type m_secureConnected;
Event::Type m_connectionFailed; Event::Type m_connectionFailed;
}; };

View File

@ -435,10 +435,19 @@ Client::setupConnecting()
{ {
assert(m_stream != NULL); assert(m_stream != NULL);
if (m_args.m_enableCrypto) {
m_events->adoptHandler(m_events->forIDataSocket().secureConnected(),
m_stream->getEventTarget(),
new TMethodEventJob<Client>(this,
&Client::handleConnected));
}
else {
m_events->adoptHandler(m_events->forIDataSocket().connected(), m_events->adoptHandler(m_events->forIDataSocket().connected(),
m_stream->getEventTarget(), m_stream->getEventTarget(),
new TMethodEventJob<Client>(this, new TMethodEventJob<Client>(this,
&Client::handleConnected)); &Client::handleConnected));
}
m_events->adoptHandler(m_events->forIDataSocket().connectionFailed(), m_events->adoptHandler(m_events->forIDataSocket().connectionFailed(),
m_stream->getEventTarget(), m_stream->getEventTarget(),
new TMethodEventJob<Client>(this, new TMethodEventJob<Client>(this,
@ -589,8 +598,6 @@ Client::handleConnected(const Event&, void*)
m_sentClipboard[id] = false; m_sentClipboard[id] = false;
m_timeClipboard[id] = 0; m_timeClipboard[id] = 0;
} }
m_socket->secureConnect();
} }
void void

View File

@ -39,9 +39,9 @@
TCPSocket::TCPSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer) : TCPSocket::TCPSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer) :
IDataSocket(events), IDataSocket(events),
m_events(events),
m_mutex(), m_mutex(),
m_flushed(&m_mutex, true), m_flushed(&m_mutex, true),
m_events(events),
m_socketMultiplexer(socketMultiplexer) m_socketMultiplexer(socketMultiplexer)
{ {
try { try {
@ -56,10 +56,10 @@ TCPSocket::TCPSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer)
TCPSocket::TCPSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer, ArchSocket socket) : TCPSocket::TCPSocket(IEventQueue* events, SocketMultiplexer* socketMultiplexer, ArchSocket socket) :
IDataSocket(events), IDataSocket(events),
m_events(events),
m_mutex(), m_mutex(),
m_socket(socket), m_socket(socket),
m_flushed(&m_mutex, true), m_flushed(&m_mutex, true),
m_events(events),
m_socketMultiplexer(socketMultiplexer) m_socketMultiplexer(socketMultiplexer)
{ {
assert(m_socket != NULL); assert(m_socket != NULL);

View File

@ -58,6 +58,9 @@ public:
// IDataSocket overrides // IDataSocket overrides
virtual void connect(const NetworkAddress&); virtual void connect(const NetworkAddress&);
virtual ISocketMultiplexerJob*
newJob();
virtual void secureConnect() {} virtual void secureConnect() {}
virtual void secureAccept() {} virtual void secureAccept() {}
virtual void setFingerprintFilename(String& f) {} virtual void setFingerprintFilename(String& f) {}
@ -71,8 +74,7 @@ protected:
virtual int secureWrite(const void*, int, int& ) { return 0; } virtual int secureWrite(const void*, int, int& ) { return 0; }
void setJob(ISocketMultiplexerJob*); void setJob(ISocketMultiplexerJob*);
ISocketMultiplexerJob*
newJob();
bool isReadable() { return m_readable; } bool isReadable() { return m_readable; }
bool isWritable() { return m_writable; } bool isWritable() { return m_writable; }
@ -99,6 +101,8 @@ private:
protected: protected:
bool m_readable; bool m_readable;
bool m_writable; bool m_writable;
bool m_connected;
IEventQueue* m_events;
private: private:
Mutex m_mutex; Mutex m_mutex;
@ -106,7 +110,5 @@ private:
StreamBuffer m_inputBuffer; StreamBuffer m_inputBuffer;
StreamBuffer m_outputBuffer; StreamBuffer m_outputBuffer;
CondVar<bool> m_flushed; CondVar<bool> m_flushed;
bool m_connected;
IEventQueue* m_events;
SocketMultiplexer* m_socketMultiplexer; SocketMultiplexer* m_socketMultiplexer;
}; };

View File

@ -18,6 +18,7 @@
#include "SecureSocket.h" #include "SecureSocket.h"
#include "net/TSocketMultiplexerMethodJob.h" #include "net/TSocketMultiplexerMethodJob.h"
#include "base/TMethodEventJob.h"
#include "net/TCPSocket.h" #include "net/TCPSocket.h"
#include "mt/Lock.h" #include "mt/Lock.h"
#include "arch/XArch.h" #include "arch/XArch.h"
@ -100,6 +101,29 @@ SecureSocket::close()
TCPSocket::close(); TCPSocket::close();
} }
void
SecureSocket::connect(const NetworkAddress& addr)
{
m_events->adoptHandler(m_events->forIDataSocket().connected(),
getEventTarget(),
new TMethodEventJob<SecureSocket>(this,
&SecureSocket::handleTCPConnected));
TCPSocket::connect(addr);
}
ISocketMultiplexerJob*
SecureSocket::newJob()
{
// after TCP connection is established, SecureSocket will pick up
// connected event and do secureConnect
if (m_connected && !m_secureReady) {
return NULL;
}
return TCPSocket::newJob();
}
void void
SecureSocket::secureConnect() SecureSocket::secureConnect()
{ {
@ -609,6 +633,7 @@ SecureSocket::serviceConnect(ISocketMultiplexerJob* job,
// If status > 0, success // If status > 0, success
if (status > 0) { if (status > 0) {
sendEvent(m_events->forIDataSocket().secureConnected());
return newJob(); return newJob();
} }
@ -714,3 +739,9 @@ SecureSocket::showSecureConnectInfo()
} }
return; return;
} }
void
SecureSocket::handleTCPConnected(const Event& event, void*)
{
secureConnect();
}

View File

@ -41,6 +41,11 @@ public:
// ISocket overrides // ISocket overrides
void close(); void close();
// IDataSocket overrides
virtual void connect(const NetworkAddress&);
ISocketMultiplexerJob*
newJob();
void secureConnect(); void secureConnect();
void secureAccept(); void secureAccept();
bool isReady() const { return m_secureReady; } bool isReady() const { return m_secureReady; }
@ -81,6 +86,8 @@ private:
void showSecureLibInfo(); void showSecureLibInfo();
void showSecureCipherInfo(); void showSecureCipherInfo();
void handleTCPConnected(const Event& event, void*);
private: private:
Ssl* m_ssl; Ssl* m_ssl;
bool m_secureReady; bool m_secureReady;