* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include <utility>
+
+#include <QtEndian>
+
#include <QHostAddress>
#include <QTimer>
-#include <QtEndian>
#ifdef HAVE_SSL
# include <QSslSocket>
# include <QTcpSocket>
#endif
+#include "proxyline.h"
#include "remotepeer.h"
#include "util.h"
, _socket(socket)
, _compressor(new Compressor(socket, level, this))
, _signalProxy(nullptr)
+ , _proxyLine({})
+ , _useProxyLine(false)
, _heartBeatTimer(new QTimer(this))
, _heartBeatCount(0)
, _lag(0)
QString RemotePeer::description() const
{
- if (socket())
- return socket()->peerAddress().toString();
+ return address();
+}
- return QString();
+QHostAddress RemotePeer::hostAddress() const
+{
+ if (_useProxyLine) {
+ return _proxyLine.sourceHost;
+ }
+ else if (socket()) {
+ return socket()->peerAddress();
+ }
+
+ return {};
}
QString RemotePeer::address() const
{
- if (socket())
- return socket()->peerAddress().toString();
-
- return QString();
+ QHostAddress address = hostAddress();
+ if (address.isNull()) {
+ return {};
+ }
+ else {
+ return address.toString();
+ }
}
quint16 RemotePeer::port() const
{
- if (socket())
+ if (_useProxyLine) {
+ return _proxyLine.sourcePort;
+ }
+ else if (socket()) {
return socket()->peerPort();
+ }
return 0;
}
bool RemotePeer::isLocal() const
{
- if (socket()) {
- if (socket()->peerAddress() == QHostAddress::LocalHost || socket()->peerAddress() == QHostAddress::LocalHostIPv6)
- return true;
- }
- return false;
+ return hostAddress() == QHostAddress::LocalHost ||
+ hostAddress() == QHostAddress::LocalHostIPv6;
}
bool RemotePeer::isOpen() const
if (_msgSize == 0) {
if (_compressor->bytesAvailable() < 4)
return false;
- _compressor->read((char*)&_msgSize, 4);
+ _compressor->read((char*) &_msgSize, 4);
_msgSize = qFromBigEndian<quint32>(_msgSize);
if (_msgSize > maxMessageSize) {
dispatch(HeartBeat(QDateTime::currentDateTime().toUTC()));
++_heartBeatCount;
}
+
+void RemotePeer::setProxyLine(ProxyLine proxyLine)
+{
+ _proxyLine = std::move(proxyLine);
+
+ if (socket()) {
+ if (_proxyLine.protocol != QAbstractSocket::UnknownNetworkLayerProtocol) {
+ QList<QString> subnets = Quassel::optionValue("proxy-cidr").split(",");
+ for (const QString& subnet : subnets) {
+ if (socket()->peerAddress().isInSubnet(QHostAddress::parseSubnet(subnet))) {
+ _useProxyLine = true;
+ return;
+ }
+ }
+ }
+ }
+ _useProxyLine = false;
+}