summaryrefslogtreecommitdiffstats
path: root/src/client/net
diff options
context:
space:
mode:
authorManuel Schneider2014-11-28 14:54:54 +0100
committerManuel Schneider2014-11-28 14:54:54 +0100
commit303dfd7c1798f4aa211653d1bc66a9998cbe6ceb (patch)
treec3c105a29bdac1ade88a06e7ae264028dbab1150 /src/client/net
parentRemove redundant flags (diff)
downloadpvs2-303dfd7c1798f4aa211653d1bc66a9998cbe6ceb.tar.gz
pvs2-303dfd7c1798f4aa211653d1bc66a9998cbe6ceb.tar.xz
pvs2-303dfd7c1798f4aa211653d1bc66a9998cbe6ceb.zip
Reset debug timeouts, fix autoconnect, remove magic numbers
Diffstat (limited to 'src/client/net')
-rw-r--r--src/client/net/serverconnection.cpp7
-rw-r--r--src/client/net/serverconnection.h3
-rw-r--r--src/client/net/serverdiscovery.cpp13
-rw-r--r--src/client/net/serverdiscovery.h11
4 files changed, 20 insertions, 14 deletions
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp
index 7954c34..46cba79 100644
--- a/src/client/net/serverconnection.cpp
+++ b/src/client/net/serverconnection.cpp
@@ -18,8 +18,8 @@
#define CHALLENGE_LEN 20
-ServerConnection::ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash) :
- QObject(NULL), _timerDelete(0), _jpegQuality(80), _authed(0), _sessionName(sessionName), _certHash(certHash)
+ServerConnection::ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect) :
+ QObject(NULL), _timerDelete(0), _jpegQuality(80), _authed(0), _sessionName(sessionName), _certHash(certHash), _autoConnect(autoConnect)
{
_socket = new QSslSocket();
_blank = new BlankScreen();
@@ -132,7 +132,8 @@ void ServerConnection::handleMsg()
}
// Check challenge response
QByteArray serverhash(_fromServer.getFieldBytes(_HASH));
- if (serverhash != genSha1(&_sessionName, &_myChallenge))
+ if (serverhash != genSha1(&_sessionName, &_myChallenge)
+ && !_autoConnect)
{
qDebug("invalid. STOP.");
emit stateChange(ConnectWindow::InvalidSslHash);
diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h
index a45d434..6d53c52 100644
--- a/src/client/net/serverconnection.h
+++ b/src/client/net/serverconnection.h
@@ -17,6 +17,7 @@ private:
int _timerId, _timerDelete, _timerConnectionCheck;
int _jpegQuality;
int _authed;
+ bool _autoConnect;
qint64 _lastData;
NetworkMessage _fromServer, _toServer;
@@ -29,7 +30,7 @@ private:
void handleMsg();
public:
- ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash);
+ ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
void disconnectFromServer();
~ServerConnection();
const inline bool isConnected() const
diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp
index 0062561..5dba327 100644
--- a/src/client/net/serverdiscovery.cpp
+++ b/src/client/net/serverdiscovery.cpp
@@ -10,7 +10,10 @@
/***************************************************************************//**
* Ctor
*/
-ServerDiscovery::ServerDiscovery(QObject *parent) : QObject(parent)
+ServerDiscovery::ServerDiscovery(QObject *parent)
+ : QObject(parent),
+ _minDiscoveryInterval(500),
+ _maxDiscoveryInterval(5000)
{
_hashErrorCount = 0;
_ipErrorCount = 0;
@@ -29,7 +32,7 @@ ServerDiscovery::ServerDiscovery(QObject *parent) : QObject(parent)
connect(&_discoverySocket, SIGNAL(readyRead()), this, SLOT(onUdpReadyRead()));
/* Setup the discovery timer */
- _discoveryTimer.setInterval(500);
+ _discoveryTimer.setInterval(_minDiscoveryInterval);
_discoveryTimer.setSingleShot(true);
//
connect(&_discoveryTimer, SIGNAL(timeout()), this, SLOT(doDiscovery()));
@@ -65,7 +68,7 @@ void ServerDiscovery::start(const QByteArray& sessionName, QString mgrIP)
_hashErrorCount = _ipErrorCount = 0;
// reset anbd start the discovery timer
- _discoveryTimer.setInterval(500);
+ _discoveryTimer.setInterval(_minDiscoveryInterval);
_discoveryTimer.start();
}
@@ -131,7 +134,7 @@ void ServerDiscovery::doDiscovery()
}
// Start the timer again with a larger interval
- if (_discoveryTimer.interval() < 5000)
+ if (_discoveryTimer.interval() < _maxDiscoveryInterval)
_discoveryTimer.setInterval(_discoveryTimer.interval() * 2);
_discoveryTimer.start();
}
@@ -189,7 +192,7 @@ void ServerDiscovery::onUdpReadyRead()
<< addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes;
// Tell that a server hs been found
- emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert);
+ emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert, (_mgrIP == addr));
// Stop the discovery
this->stop();
diff --git a/src/client/net/serverdiscovery.h b/src/client/net/serverdiscovery.h
index fee9fd0..a41c946 100644
--- a/src/client/net/serverdiscovery.h
+++ b/src/client/net/serverdiscovery.h
@@ -24,9 +24,11 @@ class ServerDiscovery : public QObject
inline bool isActive(){ return _discoveryTimer.isActive(); }
private:
- QTimer _discoveryTimer;
- int _hashErrorCount;
- int _ipErrorCount;
+ QTimer _discoveryTimer;
+ const int _minDiscoveryInterval;
+ const int _maxDiscoveryInterval;
+ int _hashErrorCount;
+ int _ipErrorCount;
QByteArray _nameBytes;
QByteArray _salt2;
QUdpSocket _discoverySocket;
@@ -37,9 +39,8 @@ class ServerDiscovery : public QObject
static const int UDPBUFSIZ = 9000;
static const int SALT_LEN = 18;
-public:
signals:
- void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash);
+ void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
void error(ErrorType e, int count);
public slots: