1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include "common-export.h"
27 #include "compressor.h"
30 #include "proxyline.h"
31 #include "signalproxy.h"
37 class COMMON_EXPORT RemotePeer : public Peer
42 // import the virtuals from the baseclass
46 RemotePeer(AuthHandler* authHandler, QTcpSocket* socket, Compressor::CompressionLevel level, QObject* parent = nullptr);
48 void setSignalProxy(SignalProxy* proxy) override;
50 void setProxyLine(ProxyLine proxyLine);
52 virtual QString protocolName() const = 0;
53 QString description() const override;
54 virtual quint16 enabledFeatures() const { return 0; }
56 QString address() const override;
57 QHostAddress hostAddress() const;
58 quint16 port() const override;
60 bool isOpen() const override;
61 bool isSecure() const override;
62 bool isLocal() const override;
64 int lag() const override;
66 bool compressionEnabled() const;
67 void setCompressionEnabled(bool enabled);
69 QTcpSocket* socket() const;
72 void close(const QString& reason = QString()) override;
75 void transferProgress(int current, int max);
76 void socketError(QAbstractSocket::SocketError error, const QString& errorString);
77 void statusMessage(const QString& msg);
79 // Only used by LegacyPeer
80 void protocolVersionMismatch(int actual, int expected);
83 SignalProxy* signalProxy() const override;
85 void writeMessage(const QByteArray& msg);
86 virtual void processMessage(const QByteArray& msg) = 0;
88 // These protocol messages get handled internally and won't reach SignalProxy
89 void handle(const Protocol::HeartBeat& heartBeat);
90 void handle(const Protocol::HeartBeatReply& heartBeatReply);
91 virtual void dispatch(const Protocol::HeartBeat& msg) = 0;
92 virtual void dispatch(const Protocol::HeartBeatReply& msg) = 0;
95 virtual void onSocketStateChanged(QAbstractSocket::SocketState state);
96 virtual void onSocketError(QAbstractSocket::SocketError error);
100 void onCompressionError(Compressor::Error error);
102 void sendHeartBeat();
103 void changeHeartBeatInterval(int secs);
106 bool readMessage(QByteArray& msg);
110 Compressor* _compressor;
111 SignalProxy* _signalProxy;
112 ProxyLine _proxyLine;
114 QTimer* _heartBeatTimer;