Skip to content

Commit

Permalink
[core] ignore boardcasts of already linked devices
Browse files Browse the repository at this point in the history
  • Loading branch information
R1tschY committed Feb 17, 2018
1 parent 9d8e69e commit 8634d6e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/core/backend/lan/lanlinkprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ void LanLinkProvider::onNetworkConfigurationChanged(const QNetworkConfiguration&

LanLinkProvider::~LanLinkProvider()
{
qCDebug(coreLogger) << "BACKTRACE:";
}

void LanLinkProvider::onStart()
Expand Down Expand Up @@ -161,12 +160,20 @@ void LanLinkProvider::newUdpConnection() //udpBroadcastReceived
continue;
}

if (receivedPackage->get<QString>(QStringLiteral("deviceId")) == KdeConnectConfig::instance()->deviceId()) {
auto deviceId = receivedPackage->get<QString>(QStringLiteral("deviceId"));
if (deviceId == KdeConnectConfig::instance()->deviceId()) {
qCDebug(coreLogger) << "Ignoring my own broadcast";
delete receivedPackage;
continue;
}

if (m_links.contains(deviceId)) {
qCDebug(coreLogger) << "Ignoring broadcast of linked device"
<< deviceId;
delete receivedPackage;
continue;
}

int tcpPort = receivedPackage->get<int>(QStringLiteral("tcpPort"));

qCDebug(coreLogger) << "Received Udp identity package from" << sender << " asking for a tcp connection on port " << tcpPort;
Expand Down Expand Up @@ -462,9 +469,8 @@ void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, Netwo
//Do we have a link for this device already?
auto linkIterator = m_links.find(deviceId);
if (linkIterator != m_links.end()) {
qCDebug(coreLogger) << "Reusing link to" << deviceId;
deviceLink = linkIterator.value();
deviceLink->reset(socket, connectionOrigin);
qCDebug(coreLogger) << "A link already exists to" << deviceId;
return;
} else {
deviceLink = new LanDeviceLink(deviceId, this, socket, connectionOrigin);
connect(deviceLink, &QObject::destroyed, this, &LanLinkProvider::deviceLinkDestroyed);
Expand Down

0 comments on commit 8634d6e

Please sign in to comment.