X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcommon%2Fremotepeer.cpp;h=942bbd6827a038bf26b2c34afb7af905878d1459;hb=fcacaaf16551524c7ebb6114254d005274cc3d63;hp=01b3962dc103528fdd60d450d05eece3b9750647;hpb=0a43227b8cd44625f4881cc1545d42c8c8a4876c;p=quassel.git diff --git a/src/common/remotepeer.cpp b/src/common/remotepeer.cpp index 01b3962d..942bbd68 100644 --- a/src/common/remotepeer.cpp +++ b/src/common/remotepeer.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -39,27 +39,27 @@ RemotePeer::RemotePeer(::AuthHandler *authHandler, QTcpSocket *socket, Compresso : Peer(authHandler, parent), _socket(socket), _compressor(new Compressor(socket, level, this)), - _signalProxy(0), + _signalProxy(nullptr), _heartBeatTimer(new QTimer(this)), _heartBeatCount(0), _lag(0), _msgSize(0) { socket->setParent(this); - connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(onSocketStateChanged(QAbstractSocket::SocketState))); + connect(socket, &QAbstractSocket::stateChanged, this, &RemotePeer::onSocketStateChanged); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError))); - connect(socket, SIGNAL(disconnected()), SIGNAL(disconnected())); + connect(socket, &QAbstractSocket::disconnected, this, &Peer::disconnected); #ifdef HAVE_SSL - QSslSocket *sslSocket = qobject_cast(socket); + auto *sslSocket = qobject_cast(socket); if (sslSocket) connect(sslSocket, SIGNAL(encrypted()), SIGNAL(secureStateChanged())); #endif - connect(_compressor, SIGNAL(readyRead()), SLOT(onReadyRead())); - connect(_compressor, SIGNAL(error(Compressor::Error)), SLOT(onCompressionError(Compressor::Error))); + connect(_compressor, &Compressor::readyRead, this, &RemotePeer::onReadyRead); + connect(_compressor, &Compressor::error, this, &RemotePeer::onCompressionError); - connect(_heartBeatTimer, SIGNAL(timeout()), SLOT(sendHeartBeat())); + connect(_heartBeatTimer, &QTimer::timeout, this, &RemotePeer::sendHeartBeat); } @@ -91,6 +91,22 @@ QString RemotePeer::description() const return QString(); } +QString RemotePeer::address() const +{ + if (socket()) + return socket()->peerAddress().toString(); + + return QString(); +} + +quint16 RemotePeer::port() const +{ + if (socket()) + return socket()->peerPort(); + + return 0; +} + ::SignalProxy *RemotePeer::signalProxy() const { @@ -105,8 +121,8 @@ void RemotePeer::setSignalProxy(::SignalProxy *proxy) if (!proxy) { _heartBeatTimer->stop(); - disconnect(signalProxy(), 0, this, 0); - _signalProxy = 0; + disconnect(signalProxy(), nullptr, this, nullptr); + _signalProxy = nullptr; if (isOpen()) close(); } @@ -116,7 +132,7 @@ void RemotePeer::setSignalProxy(::SignalProxy *proxy) return; } _signalProxy = proxy; - connect(proxy, SIGNAL(heartBeatIntervalChanged(int)), SLOT(changeHeartBeatInterval(int))); + connect(proxy, &SignalProxy::heartBeatIntervalChanged, this, &RemotePeer::changeHeartBeatInterval); _heartBeatTimer->setInterval(proxy->heartBeatInterval() * 1000); _heartBeatTimer->start(); } @@ -152,7 +168,7 @@ bool RemotePeer::isSecure() const if (isLocal()) return true; #ifdef HAVE_SSL - QSslSocket *sslSocket = qobject_cast(socket()); + auto *sslSocket = qobject_cast(socket()); if (sslSocket && sslSocket->isEncrypted()) return true; #endif @@ -192,8 +208,15 @@ void RemotePeer::close(const QString &reason) void RemotePeer::onReadyRead() { QByteArray msg; - while (readMessage(msg)) + while (readMessage(msg)) { + if (SignalProxy::current()) + SignalProxy::current()->setSourcePeer(this); + processMessage(msg); + + if (SignalProxy::current()) + SignalProxy::current()->setSourcePeer(nullptr); + } } @@ -237,7 +260,7 @@ bool RemotePeer::readMessage(QByteArray &msg) void RemotePeer::writeMessage(const QByteArray &msg) { - quint32 size = qToBigEndian(msg.size()); + auto size = qToBigEndian(msg.size()); _compressor->write((const char*)&size, 4, Compressor::NoFlush); _compressor->write(msg.constData(), msg.size()); }