X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fremotepeer.h;h=f18e91cde4f591a7d6c6e69b745f854148805dce;hp=e41a6a3bc3d823a3631f59764860f7221ef6d1e7;hb=a95ad2de573027f9bee36db972bcae4195168d0c;hpb=04315f46a16fc3627218377071e008b6b9744992 diff --git a/src/common/remotepeer.h b/src/common/remotepeer.h index e41a6a3b..f18e91cd 100644 --- a/src/common/remotepeer.h +++ b/src/common/remotepeer.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,92 +18,95 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef REMOTEPEER_H -#define REMOTEPEER_H +#pragma once + +#include "common-export.h" #include -#include +#include "compressor.h" +#include "peer.h" #include "protocol.h" #include "signalproxy.h" class QTimer; -class RemotePeer : public SignalProxy::AbstractPeer +class AuthHandler; + +class COMMON_EXPORT RemotePeer : public Peer { Q_OBJECT public: - RemotePeer(QTcpSocket *socket, QObject *parent = 0); - virtual ~RemotePeer() {}; + // import the virtuals from the baseclass + using Peer::dispatch; + using Peer::handle; + + RemotePeer(AuthHandler* authHandler, QTcpSocket* socket, Compressor::CompressionLevel level, QObject* parent = nullptr); - void setSignalProxy(SignalProxy *proxy); + void setSignalProxy(SignalProxy* proxy) override; - QString description() const; + virtual QString protocolName() const = 0; + QString description() const override; + virtual quint16 enabledFeatures() const { return 0; } - bool isOpen() const; - bool isSecure() const; - bool isLocal() const; + QString address() const override; + quint16 port() const override; - int lag() const; + bool isOpen() const override; + bool isSecure() const override; + bool isLocal() const override; + + int lag() const override; bool compressionEnabled() const; void setCompressionEnabled(bool enabled); - QTcpSocket *socket() const; - - // this is only used for the auth phase and should be replaced by something more generic - virtual void writeSocketData(const QVariant &item) = 0; + QTcpSocket* socket() const; public slots: - void close(const QString &reason = QString()); + void close(const QString& reason = QString()) override; signals: - // this is only used for the auth phase and should be replaced by something more generic - void dataReceived(const QVariant &item); - - void disconnected(); - void error(QAbstractSocket::SocketError); - void transferProgress(int current, int max); + void socketError(QAbstractSocket::SocketError error, const QString& errorString); + void statusMessage(const QString& msg); + + // Only used by LegacyPeer + void protocolVersionMismatch(int actual, int expected); protected: - SignalProxy *signalProxy() const; + SignalProxy* signalProxy() const override; - template - void handle(const T &protoMessage); + void writeMessage(const QByteArray& msg); + virtual void processMessage(const QByteArray& msg) = 0; // These protocol messages get handled internally and won't reach SignalProxy - void handle(const Protocol::HeartBeat &heartBeat); - void handle(const Protocol::HeartBeatReply &heartBeatReply); - virtual void dispatch(const Protocol::HeartBeat &msg) = 0; - virtual void dispatch(const Protocol::HeartBeatReply &msg) = 0; + void handle(const Protocol::HeartBeat& heartBeat); + void handle(const Protocol::HeartBeatReply& heartBeatReply); + virtual void dispatch(const Protocol::HeartBeat& msg) = 0; + virtual void dispatch(const Protocol::HeartBeatReply& msg) = 0; + +protected slots: + virtual void onSocketStateChanged(QAbstractSocket::SocketState state); + virtual void onSocketError(QAbstractSocket::SocketError error); private slots: + void onReadyRead(); + void onCompressionError(Compressor::Error error); + void sendHeartBeat(); void changeHeartBeatInterval(int secs); private: - QTcpSocket *_socket; - SignalProxy *_signalProxy; - QTimer *_heartBeatTimer; + bool readMessage(QByteArray& msg); + +private: + QTcpSocket* _socket; + Compressor* _compressor; + SignalProxy* _signalProxy; + QTimer* _heartBeatTimer; int _heartBeatCount; int _lag; + quint32 _msgSize; }; - -// Template methods we need in the header -template inline -void RemotePeer::handle(const T &protoMessage) -{ - if (!signalProxy()) { - qWarning() << Q_FUNC_INFO << "Cannot handle messages without a SignalProxy!"; - return; - } - - // _heartBeatCount = 0; - - signalProxy()->handle(this, protoMessage); -} - - -#endif