X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fremotepeer.cpp;h=c3ad24f01717f1eb3ef68bfc13fae30061ba6c2a;hp=a3fb2879b766138ea49c33c4f157339e82c2126c;hb=6eefdfc697067d184a589fc8a231b16316c09106;hpb=921e54680da16fcf2adb7a90506875aceb6633a4 diff --git a/src/common/remotepeer.cpp b/src/common/remotepeer.cpp index a3fb2879..c3ad24f0 100644 --- a/src/common/remotepeer.cpp +++ b/src/common/remotepeer.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 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 * @@ -30,6 +30,7 @@ #endif #include "remotepeer.h" +#include "util.h" using namespace Protocol; @@ -39,27 +40,28 @@ 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, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError))); - connect(socket, SIGNAL(disconnected()), SIGNAL(disconnected())); + connect(socket, &QAbstractSocket::stateChanged, this, &RemotePeer::onSocketStateChanged); + connect(socket, selectOverload(&QAbstractSocket::error), this, &RemotePeer::onSocketError); + connect(socket, &QAbstractSocket::disconnected, this, &Peer::disconnected); #ifdef HAVE_SSL - QSslSocket *sslSocket = qobject_cast(socket); - if (sslSocket) - connect(sslSocket, SIGNAL(encrypted()), SIGNAL(secureStateChanged())); + auto *sslSocket = qobject_cast(socket); + if (sslSocket) { + connect(sslSocket, &QSslSocket::encrypted, this, [this]() { emit secureStateChanged(true); }); + } #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 +93,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 +123,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 +134,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 +170,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 +210,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 +262,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()); } @@ -252,11 +277,7 @@ void RemotePeer::handle(const HeartBeat &heartBeat) void RemotePeer::handle(const HeartBeatReply &heartBeatReply) { _heartBeatCount = 0; -#if QT_VERSION >= 0x040700 emit lagUpdated(heartBeatReply.timestamp.msecsTo(QDateTime::currentDateTime().toUTC()) / 2); -#else - emit lagUpdated(heartBeatReply.timestamp.time().msecsTo(QDateTime::currentDateTime().toUTC().time()) / 2); -#endif }