From 1cc49e5bd7542366995f501adf60da4ad90869e2 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 18 Feb 2013 23:48:00 +0100 Subject: [PATCH] Rename Internal-, Remote- and LegacyConnection to -Peer While I'm not tooo happy with the word "Peer", I couldn't think of another one that fits their purpose better. "Connection" was certainly less correct, and we have so many different connections in the codebase that it got way too confusing. At least, while Peer might not be a perfect match, it is consistent with how we always called that in Quassel (and they still inherit from SignalProxy::AbstractPeer and have been doing so for years!). --- src/client/coreconnection.cpp | 48 +++---- src/client/coreconnection.h | 8 +- src/common/CMakeLists.txt | 12 +- ...nternalconnection.cpp => internalpeer.cpp} | 42 +++---- .../{internalconnection.h => internalpeer.h} | 16 +-- .../{legacyconnection.cpp => legacypeer.cpp} | 32 ++--- .../{legacyconnection.h => legacypeer.h} | 12 +- .../{remoteconnection.cpp => remotepeer.cpp} | 30 ++--- .../{remoteconnection.h => remotepeer.h} | 13 +- src/common/signalproxy.h | 4 +- src/core/core.cpp | 117 +++++++++--------- src/core/core.h | 10 +- src/core/coresession.cpp | 20 +-- src/core/coresession.h | 8 +- src/core/sessionthread.cpp | 32 ++--- src/core/sessionthread.h | 12 +- src/qtui/monoapplication.cpp | 4 +- 17 files changed, 209 insertions(+), 211 deletions(-) rename src/common/{internalconnection.cpp => internalpeer.cpp} (80%) rename src/common/{internalconnection.h => internalpeer.h} (89%) rename src/common/protocols/legacy/{legacyconnection.cpp => legacypeer.cpp} (89%) rename src/common/protocols/legacy/{legacyconnection.h => legacypeer.h} (91%) rename src/common/{remoteconnection.cpp => remotepeer.cpp} (86%) rename src/common/{remoteconnection.h => remotepeer.h} (92%) diff --git a/src/client/coreconnection.cpp b/src/client/coreconnection.cpp index 8fc5c515..fb553fec 100644 --- a/src/client/coreconnection.cpp +++ b/src/client/coreconnection.cpp @@ -28,14 +28,14 @@ #include "clientsettings.h" #include "coreaccountmodel.h" #include "identity.h" -#include "internalconnection.h" +#include "internalpeer.h" #include "network.h" #include "networkmodel.h" #include "quassel.h" #include "signalproxy.h" #include "util.h" -#include "protocols/legacy/legacyconnection.h" +#include "protocols/legacy/legacypeer.h" CoreConnection::CoreConnection(CoreAccountModel *model, QObject *parent) : QObject(parent), @@ -123,7 +123,7 @@ void CoreConnection::updateProgress(int value, int max) void CoreConnection::reconnectTimeout() { - if (!_connection) { + if (!_peer) { CoreConnectionSettings s; if (_wantReconnect && s.autoReconnect()) { #ifdef HAVE_KDE @@ -201,7 +201,7 @@ void CoreConnection::solidNetworkStatusChanged(Solid::Networking::Status status) bool CoreConnection::isEncrypted() const { - return _connection && _connection->isSecure(); + return _peer && _peer->isSecure(); } @@ -211,7 +211,7 @@ bool CoreConnection::isLocalConnection() const return false; if (currentAccount().isInternal()) return true; - if (_connection->isLocal()) + if (_peer->isLocal()) return true; return false; @@ -331,10 +331,10 @@ void CoreConnection::coreHasData(const QVariant &item) // if the connection is an orphan, the signalProxy adopts it. // -> we don't need to care about it anymore - disconnect(_connection, 0, this, 0); + disconnect(_peer, 0, this, 0); - _connection->setParent(0); - Client::signalProxy()->addPeer(_connection); + _peer->setParent(0); + Client::signalProxy()->addPeer(_peer); sessionStateReceived(msg["SessionState"].toMap()); } @@ -378,15 +378,15 @@ void CoreConnection::resetConnection(bool wantReconnect) _wantReconnect = wantReconnect; - if (_connection) { + if (_peer) { disconnect(_socket, 0, this, 0); - disconnect(_connection, 0, this, 0); - _connection->close(); + disconnect(_peer, 0, this, 0); + _peer->close(); - if (_connection->parent() == this) - _connection->deleteLater(); // if it's not us, it belongs to the sigproxy which will delete it + if (_peer->parent() == this) + _peer->deleteLater(); // if it's not us, it belongs to the sigproxy which will delete it _socket = 0; // socket is owned and will be deleted by RemoteConnection - _connection = 0; + _peer = 0; } else if (_socket) { disconnect(_socket, 0, this, 0); @@ -475,9 +475,9 @@ void CoreConnection::connectToCurrentAccount() } emit startInternalCore(); - InternalConnection *conn = new InternalConnection(); - Client::instance()->signalProxy()->addPeer(conn); // sigproxy will take ownership - emit connectToInternalCore(conn); + InternalPeer *peer = new InternalPeer(); + Client::instance()->signalProxy()->addPeer(peer); // sigproxy will take ownership + emit connectToInternalCore(peer); return; } @@ -525,10 +525,10 @@ void CoreConnection::connectToCurrentAccount() void CoreConnection::coreSocketConnected() { // Create the connection which will handle the incoming data - Q_ASSERT(!_connection); - _connection = new LegacyConnection(_socket, this); - connect(_connection, SIGNAL(dataReceived(QVariant)), SLOT(coreHasData(QVariant))); - connect(_connection, SIGNAL(transferProgress(int,int)), SLOT(updateProgress(int,int))); + Q_ASSERT(!_peer); + _peer = new LegacyPeer(_socket, this); + connect(_peer, SIGNAL(dataReceived(QVariant)), SLOT(coreHasData(QVariant))); + connect(_peer, SIGNAL(transferProgress(int,int)), SLOT(updateProgress(int,int))); // Phase One: Send client info and wait for core info @@ -546,7 +546,7 @@ void CoreConnection::coreSocketConnected() clientInit["UseCompression"] = false; #endif - qobject_cast(_connection)->writeSocketData(clientInit); + qobject_cast(_peer)->writeSocketData(clientInit); } @@ -695,7 +695,7 @@ void CoreConnection::loginToCore(const QString &prevError) clientLogin["MsgType"] = "ClientLogin"; clientLogin["User"] = currentAccount().user(); clientLogin["Password"] = currentAccount().password(); - qobject_cast(_connection)->writeSocketData(clientLogin); + qobject_cast(_peer)->writeSocketData(clientLogin); } @@ -809,5 +809,5 @@ void CoreConnection::doCoreSetup(const QVariant &setupData) QVariantMap setup; setup["MsgType"] = "CoreSetupData"; setup["SetupData"] = setupData; - qobject_cast(_connection)->writeSocketData(setup); + qobject_cast(_peer)->writeSocketData(setup); } diff --git a/src/client/coreconnection.h b/src/client/coreconnection.h index f6ff7ef8..836d8cc2 100644 --- a/src/client/coreconnection.h +++ b/src/client/coreconnection.h @@ -37,11 +37,11 @@ #endif #include "coreaccount.h" -#include "remoteconnection.h" +#include "remotepeer.h" #include "types.h" class CoreAccountModel; -class InternalConnection; +class InternalPeer; class Network; class SignalProxy; @@ -107,7 +107,7 @@ signals: void coreSetupFailed(const QString &error); void startInternalCore(); - void connectToInternalCore(InternalConnection *connection); + void connectToInternalCore(InternalPeer *connection); // These signals MUST be handled synchronously! void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString()); @@ -176,7 +176,7 @@ private: QVariantMap _coreMsgBuffer; QPointer _socket; - QPointer _connection; + QPointer _peer; ConnectionState _state; QTimer _reconnectTimer; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 3043bb12..fe1d4f97 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -17,7 +17,7 @@ set(SOURCES eventmanager.cpp identity.cpp ignorelistmanager.cpp - internalconnection.cpp + internalpeer.cpp ircchannel.cpp ircevent.cpp irclisthelper.cpp @@ -29,13 +29,13 @@ set(SOURCES networkconfig.cpp networkevent.cpp quassel.cpp - remoteconnection.cpp + remotepeer.cpp settings.cpp signalproxy.cpp syncableobject.cpp util.cpp - protocols/legacy/legacyconnection.cpp + protocols/legacy/legacypeer.cpp ) set(MOC_HDRS @@ -49,18 +49,18 @@ set(MOC_HDRS eventmanager.h identity.h ignorelistmanager.h - internalconnection.h + internalpeer.h ircchannel.h irclisthelper.h ircuser.h network.h networkconfig.h - remoteconnection.h + remotepeer.h settings.h signalproxy.h syncableobject.h - protocols/legacy/legacyconnection.h + protocols/legacy/legacypeer.h ) set(HEADERS ${MOC_HDRS} diff --git a/src/common/internalconnection.cpp b/src/common/internalpeer.cpp similarity index 80% rename from src/common/internalconnection.cpp rename to src/common/internalpeer.cpp index 2dda1382..15e67ed3 100644 --- a/src/common/internalconnection.cpp +++ b/src/common/internalpeer.cpp @@ -21,7 +21,7 @@ #include #include -#include "internalconnection.h" +#include "internalpeer.h" using namespace Protocol; @@ -29,14 +29,14 @@ template class PeerMessageEvent : public QEvent { public: - PeerMessageEvent(InternalConnection *sender, InternalConnection::EventType eventType, const T &message) + PeerMessageEvent(InternalPeer *sender, InternalPeer::EventType eventType, const T &message) : QEvent(QEvent::Type(eventType)), sender(sender), message(message) {} - InternalConnection *sender; + InternalPeer *sender; T message; }; -InternalConnection::InternalConnection(QObject *parent) +InternalPeer::InternalPeer(QObject *parent) : SignalProxy::AbstractPeer(parent), _proxy(0), _peer(0), @@ -46,38 +46,38 @@ InternalConnection::InternalConnection(QObject *parent) } -InternalConnection::~InternalConnection() +InternalPeer::~InternalPeer() { if (_isOpen) emit disconnected(); } -QString InternalConnection::description() const +QString InternalPeer::description() const { return tr("internal connection"); } -bool InternalConnection::isOpen() const +bool InternalPeer::isOpen() const { return true; } -bool InternalConnection::isSecure() const +bool InternalPeer::isSecure() const { return true; } -bool InternalConnection::isLocal() const +bool InternalPeer::isLocal() const { return true; } -void InternalConnection::close(const QString &reason) +void InternalPeer::close(const QString &reason) { // FIXME Q_UNUSED(reason) @@ -85,13 +85,13 @@ void InternalConnection::close(const QString &reason) } -int InternalConnection::lag() const +int InternalPeer::lag() const { return 0; } -void InternalConnection::setSignalProxy(SignalProxy *proxy) +void InternalPeer::setSignalProxy(::SignalProxy *proxy) { if (!proxy && _proxy) { _proxy = 0; @@ -111,7 +111,7 @@ void InternalConnection::setSignalProxy(SignalProxy *proxy) } -void InternalConnection::setPeer(InternalConnection *peer) +void InternalPeer::setPeer(InternalPeer *peer) { if (_peer) { qWarning() << Q_FUNC_INFO << "Peer already set, ignoring!"; @@ -122,7 +122,7 @@ void InternalConnection::setPeer(InternalConnection *peer) } -void InternalConnection::peerDisconnected() +void InternalPeer::peerDisconnected() { disconnect(_peer, 0, this, 0); _peer = 0; @@ -133,32 +133,32 @@ void InternalConnection::peerDisconnected() } -void InternalConnection::dispatch(const SyncMessage &msg) +void InternalPeer::dispatch(const SyncMessage &msg) { dispatch(SyncMessageEvent, msg); } -void InternalConnection::dispatch(const RpcCall &msg) +void InternalPeer::dispatch(const RpcCall &msg) { dispatch(RpcCallEvent, msg); } -void InternalConnection::dispatch(const InitRequest &msg) +void InternalPeer::dispatch(const InitRequest &msg) { dispatch(InitRequestEvent, msg); } -void InternalConnection::dispatch(const InitData &msg) +void InternalPeer::dispatch(const InitData &msg) { dispatch(InitDataEvent, msg); } template -void InternalConnection::dispatch(EventType eventType, const T &msg) +void InternalPeer::dispatch(EventType eventType, const T &msg) { if (!_peer) { qWarning() << Q_FUNC_INFO << "Cannot dispatch a message without a peer!"; @@ -173,7 +173,7 @@ void InternalConnection::dispatch(EventType eventType, const T &msg) template -void InternalConnection::handle(const T &msg) +void InternalPeer::handle(const T &msg) { if (!_proxy) { qWarning() << Q_FUNC_INFO << "Cannot handle a message without having a signal proxy set!"; @@ -184,7 +184,7 @@ void InternalConnection::handle(const T &msg) } -void InternalConnection::customEvent(QEvent *event) +void InternalPeer::customEvent(QEvent *event) { switch ((int)event->type()) { case SyncMessageEvent: { diff --git a/src/common/internalconnection.h b/src/common/internalpeer.h similarity index 89% rename from src/common/internalconnection.h rename to src/common/internalpeer.h index dd17f033..4c82ceb3 100644 --- a/src/common/internalconnection.h +++ b/src/common/internalpeer.h @@ -18,8 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef INTERNALCONNECTION_H -#define INTERNALCONNECTION_H +#ifndef INTERNALPEER_H +#define INTERNALPEER_H #include @@ -28,7 +28,7 @@ class QEvent; -class InternalConnection : public SignalProxy::AbstractPeer +class InternalPeer : public SignalProxy::AbstractPeer { Q_OBJECT @@ -40,16 +40,16 @@ public: InitDataEvent }; - InternalConnection(QObject *parent = 0); - virtual ~InternalConnection(); + InternalPeer(QObject *parent = 0); + virtual ~InternalPeer(); QString description() const; SignalProxy *signalProxy() const; void setSignalProxy(SignalProxy *proxy); - InternalConnection *peer() const; - void setPeer(InternalConnection *peer); + InternalPeer *peer() const; + void setPeer(InternalPeer *peer); bool isOpen() const; bool isSecure() const; @@ -85,7 +85,7 @@ private: private: SignalProxy *_proxy; - InternalConnection *_peer; + InternalPeer *_peer; bool _isOpen; }; diff --git a/src/common/protocols/legacy/legacyconnection.cpp b/src/common/protocols/legacy/legacypeer.cpp similarity index 89% rename from src/common/protocols/legacy/legacyconnection.cpp rename to src/common/protocols/legacy/legacypeer.cpp index a9969a98..709291f5 100644 --- a/src/common/protocols/legacy/legacyconnection.cpp +++ b/src/common/protocols/legacy/legacypeer.cpp @@ -18,12 +18,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "legacyconnection.h" +#include "legacypeer.h" using namespace Protocol; -LegacyConnection::LegacyConnection(QTcpSocket *socket, QObject *parent) - : RemoteConnection(socket, parent), +LegacyPeer::LegacyPeer(QTcpSocket *socket, QObject *parent) + : RemotePeer(socket, parent), _blockSize(0), _useCompression(false) { @@ -34,9 +34,9 @@ LegacyConnection::LegacyConnection(QTcpSocket *socket, QObject *parent) } -void LegacyConnection::setSignalProxy(SignalProxy *proxy) +void LegacyPeer::setSignalProxy(::SignalProxy *proxy) { - RemoteConnection::setSignalProxy(proxy); + RemotePeer::setSignalProxy(proxy); if (proxy) { // enable compression now if requested - the initial handshake is uncompressed in the legacy protocol! @@ -46,7 +46,7 @@ void LegacyConnection::setSignalProxy(SignalProxy *proxy) } -void LegacyConnection::socketDataAvailable() +void LegacyPeer::socketDataAvailable() { QVariant item; while (readSocketData(item)) { @@ -59,7 +59,7 @@ void LegacyConnection::socketDataAvailable() } -bool LegacyConnection::readSocketData(QVariant &item) +bool LegacyPeer::readSocketData(QVariant &item) { if (_blockSize == 0) { if (socket()->bytesAvailable() < 4) @@ -118,7 +118,7 @@ bool LegacyConnection::readSocketData(QVariant &item) } -void LegacyConnection::writeSocketData(const QVariant &item) +void LegacyPeer::writeSocketData(const QVariant &item) { if (!socket()->isOpen()) { qWarning() << Q_FUNC_INFO << "Can't write to a closed socket!"; @@ -147,7 +147,7 @@ void LegacyConnection::writeSocketData(const QVariant &item) } -void LegacyConnection::handlePackedFunc(const QVariant &packedFunc) +void LegacyPeer::handlePackedFunc(const QVariant &packedFunc) { QVariantList params(packedFunc.toList()); @@ -228,43 +228,43 @@ void LegacyConnection::handlePackedFunc(const QVariant &packedFunc) } -void LegacyConnection::dispatch(const Protocol::SyncMessage &msg) +void LegacyPeer::dispatch(const Protocol::SyncMessage &msg) { dispatchPackedFunc(QVariantList() << (qint16)Sync << msg.className() << msg.objectName() << msg.slotName() << msg.params()); } -void LegacyConnection::dispatch(const Protocol::RpcCall &msg) +void LegacyPeer::dispatch(const Protocol::RpcCall &msg) { dispatchPackedFunc(QVariantList() << (qint16)RpcCall << msg.slotName() << msg.params()); } -void LegacyConnection::dispatch(const Protocol::InitRequest &msg) +void LegacyPeer::dispatch(const Protocol::InitRequest &msg) { dispatchPackedFunc(QVariantList() << (qint16)InitRequest << msg.className() << msg.objectName()); } -void LegacyConnection::dispatch(const Protocol::InitData &msg) +void LegacyPeer::dispatch(const Protocol::InitData &msg) { dispatchPackedFunc(QVariantList() << (qint16)InitData << msg.className() << msg.objectName() << msg.initData()); } -void LegacyConnection::dispatch(const Protocol::HeartBeat &msg) +void LegacyPeer::dispatch(const Protocol::HeartBeat &msg) { dispatchPackedFunc(QVariantList() << (qint16)HeartBeat << msg.timestamp().time()); } -void LegacyConnection::dispatch(const Protocol::HeartBeatReply &msg) +void LegacyPeer::dispatch(const Protocol::HeartBeatReply &msg) { dispatchPackedFunc(QVariantList() << (qint16)HeartBeatReply << msg.timestamp().time()); } -void LegacyConnection::dispatchPackedFunc(const QVariantList &packedFunc) +void LegacyPeer::dispatchPackedFunc(const QVariantList &packedFunc) { writeSocketData(QVariant(packedFunc)); } diff --git a/src/common/protocols/legacy/legacyconnection.h b/src/common/protocols/legacy/legacypeer.h similarity index 91% rename from src/common/protocols/legacy/legacyconnection.h rename to src/common/protocols/legacy/legacypeer.h index 04ac1c36..a3aa178b 100644 --- a/src/common/protocols/legacy/legacyconnection.h +++ b/src/common/protocols/legacy/legacypeer.h @@ -18,16 +18,16 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef LEGACYCONNECTION_H -#define LEGACYCONNECTION_H +#ifndef LEGACYPEER_H +#define LEGACYPEER_H #include -#include "../../remoteconnection.h" +#include "../../remotepeer.h" class QDataStream; -class LegacyConnection : public RemoteConnection +class LegacyPeer : public RemotePeer { Q_OBJECT @@ -41,8 +41,8 @@ public: HeartBeatReply }; - LegacyConnection(QTcpSocket *socket, QObject *parent = 0); - ~LegacyConnection() {} + LegacyPeer(QTcpSocket *socket, QObject *parent = 0); + ~LegacyPeer() {} void setSignalProxy(SignalProxy *proxy); diff --git a/src/common/remoteconnection.cpp b/src/common/remotepeer.cpp similarity index 86% rename from src/common/remoteconnection.cpp rename to src/common/remotepeer.cpp index c67d3c76..e33f56a9 100644 --- a/src/common/remoteconnection.cpp +++ b/src/common/remotepeer.cpp @@ -25,11 +25,11 @@ # include #endif -#include "remoteconnection.h" +#include "remotepeer.h" using namespace Protocol; -RemoteConnection::RemoteConnection(QTcpSocket *socket, QObject *parent) +RemotePeer::RemotePeer(QTcpSocket *socket, QObject *parent) : SignalProxy::AbstractPeer(parent), _socket(socket), _signalProxy(0), @@ -51,7 +51,7 @@ RemoteConnection::RemoteConnection(QTcpSocket *socket, QObject *parent) } -QString RemoteConnection::description() const +QString RemotePeer::description() const { if (socket()) return socket()->peerAddress().toString(); @@ -60,13 +60,13 @@ QString RemoteConnection::description() const } -SignalProxy *RemoteConnection::signalProxy() const +::SignalProxy *RemotePeer::signalProxy() const { return _signalProxy; } -void RemoteConnection::setSignalProxy(SignalProxy *proxy) +void RemotePeer::setSignalProxy(::SignalProxy *proxy) { if (proxy == _signalProxy) return; @@ -91,7 +91,7 @@ void RemoteConnection::setSignalProxy(SignalProxy *proxy) } -void RemoteConnection::changeHeartBeatInterval(int secs) +void RemotePeer::changeHeartBeatInterval(int secs) { if(secs <= 0) _heartBeatTimer->stop(); @@ -102,19 +102,19 @@ void RemoteConnection::changeHeartBeatInterval(int secs) } -int RemoteConnection::lag() const +int RemotePeer::lag() const { return _lag; } -QTcpSocket *RemoteConnection::socket() const +QTcpSocket *RemotePeer::socket() const { return _socket; } -bool RemoteConnection::isSecure() const +bool RemotePeer::isSecure() const { if (socket()) { if (isLocal()) @@ -129,7 +129,7 @@ bool RemoteConnection::isSecure() const } -bool RemoteConnection::isLocal() const +bool RemotePeer::isLocal() const { if (socket()) { if (socket()->peerAddress() == QHostAddress::LocalHost || socket()->peerAddress() == QHostAddress::LocalHostIPv6) @@ -139,13 +139,13 @@ bool RemoteConnection::isLocal() const } -bool RemoteConnection::isOpen() const +bool RemotePeer::isOpen() const { return socket() && socket()->state() == QTcpSocket::ConnectedState; } -void RemoteConnection::close(const QString &reason) +void RemotePeer::close(const QString &reason) { if (!reason.isEmpty()) { qWarning() << "Disconnecting:" << reason; @@ -157,13 +157,13 @@ void RemoteConnection::close(const QString &reason) } -void RemoteConnection::handle(const HeartBeat &heartBeat) +void RemotePeer::handle(const HeartBeat &heartBeat) { dispatch(HeartBeatReply(heartBeat.timestamp())); } -void RemoteConnection::handle(const HeartBeatReply &heartBeatReply) +void RemotePeer::handle(const HeartBeatReply &heartBeatReply) { _heartBeatCount = 0; #if QT_VERSION < 0x040700 @@ -174,7 +174,7 @@ void RemoteConnection::handle(const HeartBeatReply &heartBeatReply) } -void RemoteConnection::sendHeartBeat() +void RemotePeer::sendHeartBeat() { if (signalProxy()->maxHeartBeatCount() > 0 && _heartBeatCount >= signalProxy()->maxHeartBeatCount()) { qWarning() << "Disconnecting peer:" << description() diff --git a/src/common/remoteconnection.h b/src/common/remotepeer.h similarity index 92% rename from src/common/remoteconnection.h rename to src/common/remotepeer.h index 6d12d70f..e41a6a3b 100644 --- a/src/common/remoteconnection.h +++ b/src/common/remotepeer.h @@ -18,8 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef REMOTECONNECTION_H -#define REMOTECONNECTION_H +#ifndef REMOTEPEER_H +#define REMOTEPEER_H #include #include @@ -29,13 +29,13 @@ class QTimer; -class RemoteConnection : public SignalProxy::AbstractPeer +class RemotePeer : public SignalProxy::AbstractPeer { Q_OBJECT public: - RemoteConnection(QTcpSocket *socket, QObject *parent = 0); - virtual ~RemoteConnection() {}; + RemotePeer(QTcpSocket *socket, QObject *parent = 0); + virtual ~RemotePeer() {}; void setSignalProxy(SignalProxy *proxy); @@ -91,10 +91,9 @@ private: int _lag; }; - // Template methods we need in the header template inline -void RemoteConnection::handle(const T &protoMessage) +void RemotePeer::handle(const T &protoMessage) { if (!signalProxy()) { qWarning() << Q_FUNC_INFO << "Cannot handle messages without a SignalProxy!"; diff --git a/src/common/signalproxy.h b/src/common/signalproxy.h index 7f70f7e2..d446fefc 100644 --- a/src/common/signalproxy.h +++ b/src/common/signalproxy.h @@ -168,8 +168,8 @@ private: friend class SignalRelay; friend class SyncableObject; - friend class InternalConnection; - friend class RemoteConnection; + friend class InternalPeer; + friend class RemotePeer; }; diff --git a/src/core/core.cpp b/src/core/core.cpp index e7c56e55..4413211e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -23,17 +23,16 @@ #include "core.h" #include "coresession.h" #include "coresettings.h" -#include "internalconnection.h" +#include "internalpeer.h" #include "postgresqlstorage.h" #include "quassel.h" -#include "signalproxy.h" #include "sqlitestorage.h" #include "network.h" #include "logger.h" #include "util.h" -#include "protocols/legacy/legacyconnection.h" +#include "protocols/legacy/legacypeer.h" // migration related #include @@ -57,8 +56,8 @@ const int Core::AddClientEventId = QEvent::registerEventType(); class AddClientEvent : public QEvent { public: - AddClientEvent(RemoteConnection *connection, UserId uid) : QEvent(QEvent::Type(Core::AddClientEventId)), connection(connection), userId(uid) {} - RemoteConnection *connection; + AddClientEvent(RemotePeer *p, UserId uid) : QEvent(QEvent::Type(Core::AddClientEventId)), peer(p), userId(uid) {} + RemotePeer *peer; UserId userId; }; @@ -218,8 +217,8 @@ void Core::init() Core::~Core() { - foreach(RemoteConnection *connection, clientInfo.keys()) { - connection->close(); // disconnect non authed clients + foreach(RemotePeer *peer, clientInfo.keys()) { + peer->close(); // disconnect non authed clients } qDeleteAll(sessions); qDeleteAll(_storageBackends); @@ -518,13 +517,13 @@ void Core::incomingConnection() Q_ASSERT(server); while (server->hasPendingConnections()) { QTcpSocket *socket = server->nextPendingConnection(); - RemoteConnection *connection = new LegacyConnection(socket, this); + RemotePeer *peer = new LegacyPeer(socket, this); - connect(connection, SIGNAL(disconnected()), SLOT(clientDisconnected())); - connect(connection, SIGNAL(dataReceived(QVariant)), SLOT(processClientMessage(QVariant))); - connect(connection, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError))); + connect(peer, SIGNAL(disconnected()), SLOT(clientDisconnected())); + connect(peer, SIGNAL(dataReceived(QVariant)), SLOT(processClientMessage(QVariant))); + connect(peer, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError))); - clientInfo.insert(connection, QVariantMap()); + clientInfo.insert(peer, QVariantMap()); quInfo() << qPrintable(tr("Client connected from")) << qPrintable(socket->peerAddress().toString()); if (!_configured) { @@ -536,8 +535,8 @@ void Core::incomingConnection() void Core::processClientMessage(const QVariant &data) { - RemoteConnection *connection = qobject_cast(sender()); - if (!connection) { + RemotePeer *peer = qobject_cast(sender()); + if (!peer) { qWarning() << Q_FUNC_INFO << "Message not sent by RemoteConnection!"; return; } @@ -546,7 +545,7 @@ void Core::processClientMessage(const QVariant &data) if (!msg.contains("MsgType")) { // Client is way too old, does not even use the current init format qWarning() << qPrintable(tr("Antique client trying to connect... refusing.")); - connection->close(); + peer->close(); return; } @@ -561,9 +560,9 @@ void Core::processClientMessage(const QVariant &data) reply["Error"] = tr("Your Quassel Client is too old!
" "This core needs at least client/core protocol version %1.
" "Please consider upgrading your client.").arg(Quassel::buildInfo().coreNeedsProtocol); - connection->writeSocketData(reply); - qWarning() << qPrintable(tr("Client")) << connection->description() << qPrintable(tr("too old, rejecting.")); - connection->close(); + peer->writeSocketData(reply); + qWarning() << qPrintable(tr("Client")) << peer->description() << qPrintable(tr("too old, rejecting.")); + peer->close(); return; } @@ -590,7 +589,7 @@ void Core::processClientMessage(const QVariant &data) #ifdef HAVE_SSL SslServer *sslServer = qobject_cast(&_server); - QSslSocket *sslSocket = qobject_cast(connection->socket()); + QSslSocket *sslSocket = qobject_cast(peer->socket()); bool supportSsl = sslServer && sslSocket && sslServer->isCertValid(); #else bool supportSsl = false; @@ -626,15 +625,15 @@ void Core::processClientMessage(const QVariant &data) else { reply["Configured"] = true; } - clientInfo[connection] = msg; // store for future reference + clientInfo[peer] = msg; // store for future reference reply["MsgType"] = "ClientInitAck"; - connection->writeSocketData(reply); - connection->socket()->flush(); // ensure that the write cache is flushed before we switch to ssl + peer->writeSocketData(reply); + peer->socket()->flush(); // ensure that the write cache is flushed before we switch to ssl #ifdef HAVE_SSL // after we told the client that we are ssl capable we switch to ssl mode if (supportSsl && msg["UseSsl"].toBool()) { - qDebug() << qPrintable(tr("Starting TLS for Client:")) << connection->description(); + qDebug() << qPrintable(tr("Starting TLS for Client:")) << peer->description(); connect(sslSocket, SIGNAL(sslErrors(const QList &)), SLOT(sslErrors(const QList &))); sslSocket->startServerEncryption(); } @@ -642,20 +641,20 @@ void Core::processClientMessage(const QVariant &data) #ifndef QT_NO_COMPRESS if (supportsCompression && msg["UseCompression"].toBool()) { - connection->socket()->setProperty("UseCompression", true); - qDebug() << "Using compression for Client:" << qPrintable(connection->socket()->peerAddress().toString()); + peer->socket()->setProperty("UseCompression", true); + qDebug() << "Using compression for Client:" << qPrintable(peer->socket()->peerAddress().toString()); } #endif } else { // for the rest, we need an initialized connection - if (!clientInfo.contains(connection)) { + if (!clientInfo.contains(peer)) { QVariantMap reply; reply["MsgType"] = "ClientLoginReject"; reply["Error"] = tr("Client not initialized!
You need to send an init message before trying to login."); - connection->writeSocketData(reply); - qWarning() << qPrintable(tr("Client")) << qPrintable(connection->socket()->peerAddress().toString()) << qPrintable(tr("did not send an init message before trying to login, rejecting.")); - connection->close(); return; + peer->writeSocketData(reply); + qWarning() << qPrintable(tr("Client")) << qPrintable(peer->socket()->peerAddress().toString()) << qPrintable(tr("did not send an init message before trying to login, rejecting.")); + peer->close(); return; } if (msg["MsgType"] == "CoreSetupData") { QVariantMap reply; @@ -667,7 +666,7 @@ void Core::processClientMessage(const QVariant &data) else { reply["MsgType"] = "CoreSetupAck"; } - connection->writeSocketData(reply); + peer->writeSocketData(reply); } else if (msg["MsgType"] == "ClientLogin") { QVariantMap reply; @@ -675,13 +674,13 @@ void Core::processClientMessage(const QVariant &data) if (uid == 0) { reply["MsgType"] = "ClientLoginReject"; reply["Error"] = tr("Invalid username or password!
The username/password combination you supplied could not be found in the database."); - connection->writeSocketData(reply); + peer->writeSocketData(reply); return; } reply["MsgType"] = "ClientLoginAck"; - connection->writeSocketData(reply); - quInfo() << qPrintable(tr("Client")) << qPrintable(connection->socket()->peerAddress().toString()) << qPrintable(tr("initialized and authenticated successfully as \"%1\" (UserId: %2).").arg(msg["User"].toString()).arg(uid.toInt())); - setupClientSession(connection, uid); + peer->writeSocketData(reply); + quInfo() << qPrintable(tr("Client")) << qPrintable(peer->socket()->peerAddress().toString()) << qPrintable(tr("initialized and authenticated successfully as \"%1\" (UserId: %2).").arg(msg["User"].toString()).arg(uid.toInt())); + setupClientSession(peer, uid); } } } @@ -690,12 +689,12 @@ void Core::processClientMessage(const QVariant &data) // Potentially called during the initialization phase (before handing the connection off to the session) void Core::clientDisconnected() { - RemoteConnection *connection = qobject_cast(sender()); - Q_ASSERT(connection); + RemotePeer *peer = qobject_cast(sender()); + Q_ASSERT(peer); - quInfo() << qPrintable(tr("Non-authed client disconnected.")) << qPrintable(connection->socket()->peerAddress().toString()); - clientInfo.remove(connection); - connection->deleteLater(); + quInfo() << qPrintable(tr("Non-authed client disconnected.")) << qPrintable(peer->socket()->peerAddress().toString()); + clientInfo.remove(peer); + peer->deleteLater(); // make server listen again if still not configured if (!_configured) { @@ -707,12 +706,12 @@ void Core::clientDisconnected() } -void Core::setupClientSession(RemoteConnection *connection, UserId uid) +void Core::setupClientSession(RemotePeer *peer, UserId uid) { // From now on everything is handled by the client session - disconnect(connection, 0, this, 0); - connection->socket()->flush(); - clientInfo.remove(connection); + disconnect(peer, 0, this, 0); + peer->socket()->flush(); + clientInfo.remove(peer); // Find or create session for validated user SessionThread *session; @@ -722,15 +721,15 @@ void Core::setupClientSession(RemoteConnection *connection, UserId uid) else { session = createSession(uid); if (!session) { - qWarning() << qPrintable(tr("Could not initialize session for client:")) << qPrintable(connection->socket()->peerAddress().toString()); - connection->close(); + qWarning() << qPrintable(tr("Could not initialize session for client:")) << qPrintable(peer->socket()->peerAddress().toString()); + peer->close(); return; } } // as we are currently handling an event triggered by incoming data on this socket // it is unsafe to directly move the socket to the client thread. - QCoreApplication::postEvent(this, new AddClientEvent(connection, uid)); + QCoreApplication::postEvent(this, new AddClientEvent(peer, uid)); } @@ -738,27 +737,27 @@ void Core::customEvent(QEvent *event) { if (event->type() == AddClientEventId) { AddClientEvent *addClientEvent = static_cast(event); - addClientHelper(addClientEvent->connection, addClientEvent->userId); + addClientHelper(addClientEvent->peer, addClientEvent->userId); return; } } -void Core::addClientHelper(RemoteConnection *connection, UserId uid) +void Core::addClientHelper(RemotePeer *peer, UserId uid) { // Find or create session for validated user if (!sessions.contains(uid)) { - qWarning() << qPrintable(tr("Could not find a session for client:")) << qPrintable(connection->socket()->peerAddress().toString()); - connection->close(); + qWarning() << qPrintable(tr("Could not find a session for client:")) << qPrintable(peer->socket()->peerAddress().toString()); + peer->close(); return; } SessionThread *session = sessions[uid]; - session->addClient(connection); + session->addClient(peer); } -void Core::setupInternalClientSession(InternalConnection *clientConnection) +void Core::setupInternalClientSession(InternalPeer *clientPeer) { if (!_configured) { stopListening(); @@ -774,9 +773,9 @@ void Core::setupInternalClientSession(InternalConnection *clientConnection) return; } - InternalConnection *coreConnection = new InternalConnection(this); - coreConnection->setPeer(clientConnection); - clientConnection->setPeer(coreConnection); + InternalPeer *corePeer = new InternalPeer(this); + corePeer->setPeer(clientPeer); + clientPeer->setPeer(corePeer); // Find or create session for validated user SessionThread *sessionThread; @@ -785,7 +784,7 @@ void Core::setupInternalClientSession(InternalConnection *clientConnection) else sessionThread = createSession(uid); - sessionThread->addClient(coreConnection); + sessionThread->addClient(corePeer); } @@ -816,9 +815,9 @@ void Core::sslErrors(const QList &errors) void Core::socketError(QAbstractSocket::SocketError err) { - RemoteConnection *connection = qobject_cast(sender()); - if (connection && err != QAbstractSocket::RemoteHostClosedError) - qWarning() << "Core::socketError()" << connection->socket() << err << connection->socket()->errorString(); + RemotePeer *peer = qobject_cast(sender()); + if (peer && err != QAbstractSocket::RemoteHostClosedError) + qWarning() << "Core::socketError()" << peer->socket() << err << peer->socket()->errorString(); } diff --git a/src/core/core.h b/src/core/core.h index dfecbe00..ebe80619 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -42,7 +42,7 @@ #include "types.h" class CoreSession; -class RemoteConnection; +class RemotePeer; struct NetworkInfo; class SessionThread; class SignalProxy; @@ -485,7 +485,7 @@ public slots: /** \note This method is threadsafe. */ void syncStorage(); - void setupInternalClientSession(InternalConnection *clientConnection); + void setupInternalClientSession(InternalPeer *clientConnection); signals: //! Sent when a BufferInfo is updated in storage. @@ -520,8 +520,8 @@ private: static Core *instanceptr; SessionThread *createSession(UserId userId, bool restoreState = false); - void setupClientSession(RemoteConnection *connection, UserId uid); - void addClientHelper(RemoteConnection *connection, UserId uid); + void setupClientSession(RemotePeer *peer, UserId uid); + void addClientHelper(RemotePeer *peer, UserId uid); //void processCoreSetup(QTcpSocket *socket, QVariantMap &msg); QString setupCoreForInternalUsage(); QString setupCore(QVariantMap setupData); @@ -548,7 +548,7 @@ private: OidentdConfigGenerator *_oidentdConfigGenerator; - QHash clientInfo; + QHash clientInfo; QHash _storageBackends; diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index fb0aad8e..d44cf2b5 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -37,7 +37,7 @@ #include "coreusersettings.h" #include "ctcpparser.h" #include "eventstringifier.h" -#include "internalconnection.h" +#include "internalpeer.h" #include "ircchannel.h" #include "ircparser.h" #include "ircuser.h" @@ -46,7 +46,7 @@ #include "storage.h" #include "util.h" -#include "protocols/legacy/legacyconnection.h" +#include "protocols/legacy/legacypeer.h" class ProcessMessagesEvent : public QEvent { @@ -206,28 +206,28 @@ void CoreSession::restoreSessionState() } -void CoreSession::addClient(RemoteConnection *connection) +void CoreSession::addClient(RemotePeer *peer) { QVariantMap reply; reply["MsgType"] = "SessionInit"; reply["SessionState"] = sessionState(); - connection->writeSocketData(reply); - signalProxy()->addPeer(connection); + peer->writeSocketData(reply); + signalProxy()->addPeer(peer); } -void CoreSession::addClient(InternalConnection *connection) +void CoreSession::addClient(InternalPeer *peer) { - signalProxy()->addPeer(connection); + signalProxy()->addPeer(peer); emit sessionState(sessionState()); } void CoreSession::removeClient(SignalProxy::AbstractPeer *peer) { - RemoteConnection *connection = qobject_cast(peer); - if (connection) - quInfo() << qPrintable(tr("Client")) << connection->description() << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt())); + RemotePeer *p = qobject_cast(peer); + if (p) + quInfo() << qPrintable(tr("Client")) << p->description() << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt())); } diff --git a/src/core/coresession.h b/src/core/coresession.h index b104631e..fdb952f7 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -42,11 +42,11 @@ class CoreSessionEventProcessor; class CtcpParser; class EventManager; class EventStringifier; -class InternalConnection; +class InternalPeer; class IrcParser; class MessageEvent; class NetworkConnection; -class RemoteConnection; +class RemotePeer; struct NetworkInfo; @@ -89,8 +89,8 @@ public: void restoreSessionState(); public slots: - void addClient(RemoteConnection *connection); - void addClient(InternalConnection *connection); + void addClient(RemotePeer *peer); + void addClient(InternalPeer *peer); void msgFromClient(BufferInfo, QString message); diff --git a/src/core/sessionthread.cpp b/src/core/sessionthread.cpp index 24cba31c..e886db5a 100644 --- a/src/core/sessionthread.cpp +++ b/src/core/sessionthread.cpp @@ -20,8 +20,8 @@ #include "core.h" #include "coresession.h" -#include "internalconnection.h" -#include "remoteconnection.h" +#include "internalpeer.h" +#include "remotepeer.h" #include "sessionthread.h" #include "signalproxy.h" @@ -86,13 +86,13 @@ void SessionThread::addClient(QObject *peer) void SessionThread::addClientToSession(QObject *peer) { - RemoteConnection *connection = qobject_cast(peer); - if (connection) { - addRemoteClientToSession(connection); + RemotePeer *remote = qobject_cast(peer); + if (remote) { + addRemoteClientToSession(remote); return; } - InternalConnection *internal = qobject_cast(peer); + InternalPeer *internal = qobject_cast(peer); if (internal) { addInternalClientToSession(internal); return; @@ -102,27 +102,27 @@ void SessionThread::addClientToSession(QObject *peer) } -void SessionThread::addRemoteClientToSession(RemoteConnection *connection) +void SessionThread::addRemoteClientToSession(RemotePeer *remotePeer) { - connection->setParent(0); - connection->moveToThread(session()->thread()); - emit addRemoteClient(connection); + remotePeer->setParent(0); + remotePeer->moveToThread(session()->thread()); + emit addRemoteClient(remotePeer); } -void SessionThread::addInternalClientToSession(InternalConnection *connection) +void SessionThread::addInternalClientToSession(InternalPeer *internalPeer) { - connection->setParent(0); - connection->moveToThread(session()->thread()); - emit addInternalClient(connection); + internalPeer->setParent(0); + internalPeer->moveToThread(session()->thread()); + emit addInternalClient(internalPeer); } void SessionThread::run() { _session = new CoreSession(user(), _restoreState); - connect(this, SIGNAL(addRemoteClient(RemoteConnection*)), _session, SLOT(addClient(RemoteConnection*))); - connect(this, SIGNAL(addInternalClient(InternalConnection*)), _session, SLOT(addClient(InternalConnection*))); + connect(this, SIGNAL(addRemoteClient(RemotePeer*)), _session, SLOT(addClient(RemotePeer*))); + connect(this, SIGNAL(addInternalClient(InternalPeer*)), _session, SLOT(addClient(InternalPeer*))); connect(_session, SIGNAL(sessionState(QVariant)), Core::instance(), SIGNAL(sessionState(QVariant))); emit initialized(); exec(); diff --git a/src/core/sessionthread.h b/src/core/sessionthread.h index 9639f684..b36b2433 100644 --- a/src/core/sessionthread.h +++ b/src/core/sessionthread.h @@ -27,8 +27,8 @@ #include "types.h" class CoreSession; -class InternalConnection; -class RemoteConnection; +class InternalPeer; +class RemotePeer; class QIODevice; class SessionThread : public QThread @@ -54,8 +54,8 @@ signals: void initialized(); void shutdown(); - void addRemoteClient(RemoteConnection *); - void addInternalClient(InternalConnection *); + void addRemoteClient(RemotePeer *peer); + void addInternalClient(InternalPeer *peer); private: CoreSession *_session; @@ -66,8 +66,8 @@ private: bool isSessionInitialized(); void addClientToSession(QObject *peer); - void addRemoteClientToSession(RemoteConnection *connection); - void addInternalClientToSession(InternalConnection *client); + void addRemoteClientToSession(RemotePeer *remotePeer); + void addInternalClientToSession(InternalPeer *internalPeer); }; diff --git a/src/qtui/monoapplication.cpp b/src/qtui/monoapplication.cpp index 67bee8e1..69ca4482 100644 --- a/src/qtui/monoapplication.cpp +++ b/src/qtui/monoapplication.cpp @@ -24,7 +24,7 @@ #include "core.h" #include "qtui.h" -class InternalConnection; +class InternalPeer; MonolithicApplication::MonolithicApplication(int &argc, char **argv) : QtUiApplication(argc, argv), @@ -70,6 +70,6 @@ void MonolithicApplication::startInternalCore() } Core *core = Core::instance(); CoreConnection *connection = Client::coreConnection(); - connect(connection, SIGNAL(connectToInternalCore(InternalConnection*)), core, SLOT(setupInternalClientSession(InternalConnection*))); + connect(connection, SIGNAL(connectToInternalCore(InternalPeer*)), core, SLOT(setupInternalClientSession(InternalPeer*))); connect(core, SIGNAL(sessionState(QVariant)), connection, SLOT(internalSessionStateReceived(QVariant))); } -- 2.20.1