Merge branch '1.0' into 1.x

This commit is contained in:
Aleix Pol 2016-08-14 21:15:13 +02:00
commit 0774020899
3 changed files with 12 additions and 11 deletions

View file

@ -79,12 +79,12 @@ void LanLinkProvider::onStart()
{
const QHostAddress bindAddress = mTestMode? QHostAddress::LocalHost : QHostAddress::Any;
bool success = mUdpSocket.bind(bindAddress, port, QUdpSocket::ShareAddress);
bool success = mUdpSocket.bind(bindAddress, PORT, QUdpSocket::ShareAddress);
Q_ASSERT(success);
qCDebug(KDECONNECT_CORE) << "onStart";
mTcpPort = port;
mTcpPort = PORT;
while (!mServer->listen(bindAddress, mTcpPort)) {
mTcpPort++;
if (mTcpPort > 1764) { //No ports available?
@ -128,7 +128,7 @@ void LanLinkProvider::broadcastToNetwork()
NetworkPackage np("");
NetworkPackage::createIdentityPackage(&np);
np.set("tcpPort", mTcpPort);
mUdpSocket.writeDatagram(np.serialize(), mTestMode ? QHostAddress::LocalHost : QHostAddress("255.255.255.255"), port);
mUdpSocket.writeDatagram(np.serialize(), mTestMode ? QHostAddress::LocalHost : QHostAddress("255.255.255.255"), PORT);
}
//I'm the existing device, a new device is kindly introducing itself.
@ -164,7 +164,7 @@ void LanLinkProvider::newUdpConnection() //udpBroadcastReceived
continue;
}
int tcpPort = receivedPackage->get<int>("tcpPort", port);
int tcpPort = receivedPackage->get<int>("tcpPort", PORT);
//qCDebug(KDECONNECT_CORE) << "Received Udp identity package from" << sender << " asking for a tcp connection on port " << tcpPort;
@ -188,7 +188,7 @@ void LanLinkProvider::connectError()
NetworkPackage np("");
NetworkPackage::createIdentityPackage(&np);
np.set("tcpPort", mTcpPort);
mUdpSocket.writeDatagram(np.serialize(), receivedIdentityPackages[socket].sender, port);
mUdpSocket.writeDatagram(np.serialize(), receivedIdentityPackages[socket].sender, PORT);
//The socket we created didn't work, and we didn't manage
//to create a LanDeviceLink from it, deleting everything.
@ -251,7 +251,7 @@ void LanLinkProvider::connected()
//I think this will never happen, but if it happens the deviceLink
//(or the socket that is now inside it) might not be valid. Delete them.
qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)";
mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, port);
mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, PORT);
}
delete receivedIdentityPackages.take(socket).np;

View file

@ -54,6 +54,8 @@ public:
static void configureSslSocket(QSslSocket* socket, const QString& deviceId, bool isDeviceTrusted);
static void configureSocket(QSslSocket* socket);
const static quint16 PORT = 1716;
public Q_SLOTS:
void onNetworkChange() override;
void onStart() override;
@ -78,7 +80,6 @@ private:
Server* mServer;
QUdpSocket mUdpSocket;
const static quint16 port = 1716;
quint16 mTcpPort;
QMap<QString, LanDeviceLink*> mLinks;

View file

@ -100,7 +100,7 @@ void LanLinkProviderTest::pairedDeviceTcpPackageReceived()
addTrustedDevice();
QUdpSocket* mUdpServer = new QUdpSocket;
bool b = mUdpServer->bind(QHostAddress::LocalHost, 1714, QUdpSocket::ShareAddress);
bool b = mUdpServer->bind(QHostAddress::LocalHost, LanLinkProvider::PORT, QUdpSocket::ShareAddress);
QVERIFY(b);
QSignalSpy spy(mUdpServer, SIGNAL(readyRead()));
@ -161,7 +161,7 @@ void LanLinkProviderTest::pairedDeviceUdpPackageReceived()
QSignalSpy spy(mServer, SIGNAL(newConnection()));
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, 1714); // write an identity package to udp socket here, we do not broadcast it here
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, LanLinkProvider::PORT); // write an identity package to udp socket here, we do not broadcast it here
QCOMPARE(bytesWritten, mIdentityPackage.size());
// We should have an incoming connection now, wait for incoming connection
@ -208,7 +208,7 @@ void LanLinkProviderTest::pairedDeviceUdpPackageReceived()
void LanLinkProviderTest::unpairedDeviceTcpPackageReceived()
{
QUdpSocket* mUdpServer = new QUdpSocket;
bool b = mUdpServer->bind(QHostAddress::LocalHost, 1714, QUdpSocket::ShareAddress);
bool b = mUdpServer->bind(QHostAddress::LocalHost, LanLinkProvider::PORT, QUdpSocket::ShareAddress);
QVERIFY(b);
QSignalSpy spy(mUdpServer, SIGNAL(readyRead()));
@ -263,7 +263,7 @@ void LanLinkProviderTest::unpairedDeviceUdpPackageReceived()
mServer->listen(QHostAddress::LocalHost, PORT);
QSignalSpy spy(mServer, &Server::newConnection);
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, 1714); // write an identity package to udp socket here, we do not broadcast it here
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, LanLinkProvider::PORT); // write an identity package to udp socket here, we do not broadcast it here
QCOMPARE(bytesWritten, mIdentityPackage.size());
QVERIFY(!spy.isEmpty() || spy.wait());