#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),
void CoreConnection::reconnectTimeout()
{
- if (!_connection) {
+ if (!_peer) {
CoreConnectionSettings s;
if (_wantReconnect && s.autoReconnect()) {
#ifdef HAVE_KDE
bool CoreConnection::isEncrypted() const
{
- return _connection && _connection->isSecure();
+ return _peer && _peer->isSecure();
}
return false;
if (currentAccount().isInternal())
return true;
- if (_connection->isLocal())
+ if (_peer->isLocal())
return true;
return false;
// 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());
}
_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);
}
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;
}
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
clientInit["UseCompression"] = false;
#endif
- qobject_cast<RemoteConnection *>(_connection)->writeSocketData(clientInit);
+ qobject_cast<RemotePeer *>(_peer)->writeSocketData(clientInit);
}
clientLogin["MsgType"] = "ClientLogin";
clientLogin["User"] = currentAccount().user();
clientLogin["Password"] = currentAccount().password();
- qobject_cast<RemoteConnection*>(_connection)->writeSocketData(clientLogin);
+ qobject_cast<RemotePeer*>(_peer)->writeSocketData(clientLogin);
}
QVariantMap setup;
setup["MsgType"] = "CoreSetupData";
setup["SetupData"] = setupData;
- qobject_cast<RemoteConnection *>(_connection)->writeSocketData(setup);
+ qobject_cast<RemotePeer *>(_peer)->writeSocketData(setup);
}
#endif
#include "coreaccount.h"
-#include "remoteconnection.h"
+#include "remotepeer.h"
#include "types.h"
class CoreAccountModel;
-class InternalConnection;
+class InternalPeer;
class Network;
class SignalProxy;
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());
QVariantMap _coreMsgBuffer;
QPointer<QTcpSocket> _socket;
- QPointer<SignalProxy::AbstractPeer> _connection;
+ QPointer<SignalProxy::AbstractPeer> _peer;
ConnectionState _state;
QTimer _reconnectTimer;
eventmanager.cpp
identity.cpp
ignorelistmanager.cpp
- internalconnection.cpp
+ internalpeer.cpp
ircchannel.cpp
ircevent.cpp
irclisthelper.cpp
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
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}
#include <QCoreApplication>
#include <QThread>
-#include "internalconnection.h"
+#include "internalpeer.h"
using namespace Protocol;
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),
}
-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)
}
-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;
}
-void InternalConnection::setPeer(InternalConnection *peer)
+void InternalPeer::setPeer(InternalPeer *peer)
{
if (_peer) {
qWarning() << Q_FUNC_INFO << "Peer already set, ignoring!";
}
-void InternalConnection::peerDisconnected()
+void InternalPeer::peerDisconnected()
{
disconnect(_peer, 0, this, 0);
_peer = 0;
}
-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<class T>
-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!";
template<class T>
-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!";
}
-void InternalConnection::customEvent(QEvent *event)
+void InternalPeer::customEvent(QEvent *event)
{
switch ((int)event->type()) {
case SyncMessageEvent: {
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef INTERNALCONNECTION_H
-#define INTERNALCONNECTION_H
+#ifndef INTERNALPEER_H
+#define INTERNALPEER_H
#include <QTcpSocket>
class QEvent;
-class InternalConnection : public SignalProxy::AbstractPeer
+class InternalPeer : public SignalProxy::AbstractPeer
{
Q_OBJECT
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;
private:
SignalProxy *_proxy;
- InternalConnection *_peer;
+ InternalPeer *_peer;
bool _isOpen;
};
* 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)
{
}
-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!
}
-void LegacyConnection::socketDataAvailable()
+void LegacyPeer::socketDataAvailable()
{
QVariant item;
while (readSocketData(item)) {
}
-bool LegacyConnection::readSocketData(QVariant &item)
+bool LegacyPeer::readSocketData(QVariant &item)
{
if (_blockSize == 0) {
if (socket()->bytesAvailable() < 4)
}
-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!";
}
-void LegacyConnection::handlePackedFunc(const QVariant &packedFunc)
+void LegacyPeer::handlePackedFunc(const QVariant &packedFunc)
{
QVariantList params(packedFunc.toList());
}
-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));
}
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef LEGACYCONNECTION_H
-#define LEGACYCONNECTION_H
+#ifndef LEGACYPEER_H
+#define LEGACYPEER_H
#include <QDataStream>
-#include "../../remoteconnection.h"
+#include "../../remotepeer.h"
class QDataStream;
-class LegacyConnection : public RemoteConnection
+class LegacyPeer : public RemotePeer
{
Q_OBJECT
HeartBeatReply
};
- LegacyConnection(QTcpSocket *socket, QObject *parent = 0);
- ~LegacyConnection() {}
+ LegacyPeer(QTcpSocket *socket, QObject *parent = 0);
+ ~LegacyPeer() {}
void setSignalProxy(SignalProxy *proxy);
# include <QSslSocket>
#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),
}
-QString RemoteConnection::description() const
+QString RemotePeer::description() const
{
if (socket())
return socket()->peerAddress().toString();
}
-SignalProxy *RemoteConnection::signalProxy() const
+::SignalProxy *RemotePeer::signalProxy() const
{
return _signalProxy;
}
-void RemoteConnection::setSignalProxy(SignalProxy *proxy)
+void RemotePeer::setSignalProxy(::SignalProxy *proxy)
{
if (proxy == _signalProxy)
return;
}
-void RemoteConnection::changeHeartBeatInterval(int secs)
+void RemotePeer::changeHeartBeatInterval(int secs)
{
if(secs <= 0)
_heartBeatTimer->stop();
}
-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())
}
-bool RemoteConnection::isLocal() const
+bool RemotePeer::isLocal() const
{
if (socket()) {
if (socket()->peerAddress() == QHostAddress::LocalHost || socket()->peerAddress() == QHostAddress::LocalHostIPv6)
}
-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;
}
-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
}
-void RemoteConnection::sendHeartBeat()
+void RemotePeer::sendHeartBeat()
{
if (signalProxy()->maxHeartBeatCount() > 0 && _heartBeatCount >= signalProxy()->maxHeartBeatCount()) {
qWarning() << "Disconnecting peer:" << description()
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef REMOTECONNECTION_H
-#define REMOTECONNECTION_H
+#ifndef REMOTEPEER_H
+#define REMOTEPEER_H
#include <QDateTime>
#include <QTcpSocket>
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);
int _lag;
};
-
// Template methods we need in the header
template<class T> 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!";
friend class SignalRelay;
friend class SyncableObject;
- friend class InternalConnection;
- friend class RemoteConnection;
+ friend class InternalPeer;
+ friend class RemotePeer;
};
#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 <QFile>
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;
};
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);
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) {
void Core::processClientMessage(const QVariant &data)
{
- RemoteConnection *connection = qobject_cast<RemoteConnection *>(sender());
- if (!connection) {
+ RemotePeer *peer = qobject_cast<RemotePeer *>(sender());
+ if (!peer) {
qWarning() << Q_FUNC_INFO << "Message not sent by RemoteConnection!";
return;
}
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;
}
reply["Error"] = tr("<b>Your Quassel Client is too old!</b><br>"
"This core needs at least client/core protocol version %1.<br>"
"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;
}
#ifdef HAVE_SSL
SslServer *sslServer = qobject_cast<SslServer *>(&_server);
- QSslSocket *sslSocket = qobject_cast<QSslSocket *>(connection->socket());
+ QSslSocket *sslSocket = qobject_cast<QSslSocket *>(peer->socket());
bool supportSsl = sslServer && sslSocket && sslServer->isCertValid();
#else
bool supportSsl = false;
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<QSslError> &)), SLOT(sslErrors(const QList<QSslError> &)));
sslSocket->startServerEncryption();
}
#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("<b>Client not initialized!</b><br>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;
else {
reply["MsgType"] = "CoreSetupAck";
}
- connection->writeSocketData(reply);
+ peer->writeSocketData(reply);
}
else if (msg["MsgType"] == "ClientLogin") {
QVariantMap reply;
if (uid == 0) {
reply["MsgType"] = "ClientLoginReject";
reply["Error"] = tr("<b>Invalid username or password!</b><br>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);
}
}
}
// Potentially called during the initialization phase (before handing the connection off to the session)
void Core::clientDisconnected()
{
- RemoteConnection *connection = qobject_cast<RemoteConnection *>(sender());
- Q_ASSERT(connection);
+ RemotePeer *peer = qobject_cast<RemotePeer *>(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) {
}
-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;
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));
}
{
if (event->type() == AddClientEventId) {
AddClientEvent *addClientEvent = static_cast<AddClientEvent *>(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();
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;
else
sessionThread = createSession(uid);
- sessionThread->addClient(coreConnection);
+ sessionThread->addClient(corePeer);
}
void Core::socketError(QAbstractSocket::SocketError err)
{
- RemoteConnection *connection = qobject_cast<RemoteConnection *>(sender());
- if (connection && err != QAbstractSocket::RemoteHostClosedError)
- qWarning() << "Core::socketError()" << connection->socket() << err << connection->socket()->errorString();
+ RemotePeer *peer = qobject_cast<RemotePeer *>(sender());
+ if (peer && err != QAbstractSocket::RemoteHostClosedError)
+ qWarning() << "Core::socketError()" << peer->socket() << err << peer->socket()->errorString();
}
#include "types.h"
class CoreSession;
-class RemoteConnection;
+class RemotePeer;
struct NetworkInfo;
class SessionThread;
class SignalProxy;
/** \note This method is threadsafe.
*/
void syncStorage();
- void setupInternalClientSession(InternalConnection *clientConnection);
+ void setupInternalClientSession(InternalPeer *clientConnection);
signals:
//! Sent when a BufferInfo is updated in storage.
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);
OidentdConfigGenerator *_oidentdConfigGenerator;
- QHash<RemoteConnection *, QVariantMap> clientInfo;
+ QHash<RemotePeer *, QVariantMap> clientInfo;
QHash<QString, Storage *> _storageBackends;
#include "coreusersettings.h"
#include "ctcpparser.h"
#include "eventstringifier.h"
-#include "internalconnection.h"
+#include "internalpeer.h"
#include "ircchannel.h"
#include "ircparser.h"
#include "ircuser.h"
#include "storage.h"
#include "util.h"
-#include "protocols/legacy/legacyconnection.h"
+#include "protocols/legacy/legacypeer.h"
class ProcessMessagesEvent : public QEvent
{
}
-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<RemoteConnection *>(peer);
- if (connection)
- quInfo() << qPrintable(tr("Client")) << connection->description() << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
+ RemotePeer *p = qobject_cast<RemotePeer *>(peer);
+ if (p)
+ quInfo() << qPrintable(tr("Client")) << p->description() << qPrintable(tr("disconnected (UserId: %1).").arg(user().toInt()));
}
class CtcpParser;
class EventManager;
class EventStringifier;
-class InternalConnection;
+class InternalPeer;
class IrcParser;
class MessageEvent;
class NetworkConnection;
-class RemoteConnection;
+class RemotePeer;
struct NetworkInfo;
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);
#include "core.h"
#include "coresession.h"
-#include "internalconnection.h"
-#include "remoteconnection.h"
+#include "internalpeer.h"
+#include "remotepeer.h"
#include "sessionthread.h"
#include "signalproxy.h"
void SessionThread::addClientToSession(QObject *peer)
{
- RemoteConnection *connection = qobject_cast<RemoteConnection *>(peer);
- if (connection) {
- addRemoteClientToSession(connection);
+ RemotePeer *remote = qobject_cast<RemotePeer *>(peer);
+ if (remote) {
+ addRemoteClientToSession(remote);
return;
}
- InternalConnection *internal = qobject_cast<InternalConnection *>(peer);
+ InternalPeer *internal = qobject_cast<InternalPeer *>(peer);
if (internal) {
addInternalClientToSession(internal);
return;
}
-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();
#include "types.h"
class CoreSession;
-class InternalConnection;
-class RemoteConnection;
+class InternalPeer;
+class RemotePeer;
class QIODevice;
class SessionThread : public QThread
void initialized();
void shutdown();
- void addRemoteClient(RemoteConnection *);
- void addInternalClient(InternalConnection *);
+ void addRemoteClient(RemotePeer *peer);
+ void addInternalClient(InternalPeer *peer);
private:
CoreSession *_session;
bool isSessionInitialized();
void addClientToSession(QObject *peer);
- void addRemoteClientToSession(RemoteConnection *connection);
- void addInternalClientToSession(InternalConnection *client);
+ void addRemoteClientToSession(RemotePeer *remotePeer);
+ void addInternalClientToSession(InternalPeer *internalPeer);
};
#include "core.h"
#include "qtui.h"
-class InternalConnection;
+class InternalPeer;
MonolithicApplication::MonolithicApplication(int &argc, char **argv)
: QtUiApplication(argc, argv),
}
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)));
}