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, secureConnected)
REGISTER_EVENT(IDataSocket, connectionFailed)
//

View File

@ -230,6 +230,7 @@ class IDataSocketEvents : public EventTypes {
public:
IDataSocketEvents() :
m_connected(Event::kUnknown),
m_secureConnected(Event::kUnknown),
m_connectionFailed(Event::kUnknown) { }
//! @name accessors
@ -242,6 +243,13 @@ public:
*/
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
/*!
Returns the socket connection failed event type. A socket sends
@ -254,6 +262,7 @@ public:
private:
Event::Type m_connected;
Event::Type m_secureConnected;
Event::Type m_connectionFailed;
};

View File

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

View File

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

View File

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

View File

@ -18,6 +18,7 @@
#include "SecureSocket.h"
#include "net/TSocketMultiplexerMethodJob.h"
#include "base/TMethodEventJob.h"
#include "net/TCPSocket.h"
#include "mt/Lock.h"
#include "arch/XArch.h"
@ -100,6 +101,29 @@ SecureSocket::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
SecureSocket::secureConnect()
{
@ -609,6 +633,7 @@ SecureSocket::serviceConnect(ISocketMultiplexerJob* job,
// If status > 0, success
if (status > 0) {
sendEvent(m_events->forIDataSocket().secureConnected());
return newJob();
}
@ -714,3 +739,9 @@ SecureSocket::showSecureConnectInfo()
}
return;
}
void
SecureSocket::handleTCPConnected(const Event& event, void*)
{
secureConnect();
}

View File

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