Fixed daemon sending lots of identity packets at startup
The way we were detecting the active network interfaces caused to detect all of them at the application startup.
This commit is contained in:
parent
6c6f2b1a03
commit
dacaee6629
6 changed files with 24 additions and 24 deletions
|
@ -65,7 +65,7 @@ void LanLinkProvider::onStart()
|
|||
}
|
||||
}
|
||||
|
||||
onNetworkChange(QNetworkSession::Connected);
|
||||
onNetworkChange();
|
||||
}
|
||||
|
||||
void LanLinkProvider::onStop()
|
||||
|
@ -75,16 +75,16 @@ void LanLinkProvider::onStop()
|
|||
}
|
||||
|
||||
//I'm in a new network, let's be polite and introduce myself
|
||||
void LanLinkProvider::onNetworkChange(QNetworkSession::State state)
|
||||
void LanLinkProvider::onNetworkChange()
|
||||
{
|
||||
Q_UNUSED(state);
|
||||
|
||||
if (!mTcpServer->isListening()) {
|
||||
//Not started
|
||||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT(mTcpPort != 0);
|
||||
|
||||
qCDebug(KDECONNECT_CORE()) << "Sending identity packet";
|
||||
NetworkPackage np("");
|
||||
NetworkPackage::createIdentityPackage(&np);
|
||||
np.set("tcpPort", mTcpPort);
|
||||
|
@ -136,6 +136,7 @@ void LanLinkProvider::connectError()
|
|||
disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||
disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError()));
|
||||
|
||||
qCDebug(KDECONNECT_CORE) << "Fallback (1), try reverse connection (send udp packet)";
|
||||
NetworkPackage np("");
|
||||
NetworkPackage::createIdentityPackage(&np);
|
||||
np.set("tcpPort", mTcpPort);
|
||||
|
@ -192,7 +193,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.
|
||||
delete deviceLink;
|
||||
qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection";
|
||||
qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)";
|
||||
mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, port);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
int priority() { return PRIORITY_HIGH; }
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void onNetworkChange(QNetworkSession::State state);
|
||||
virtual void onNetworkChange();
|
||||
virtual void onStart();
|
||||
virtual void onStop();
|
||||
void connected();
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
public Q_SLOTS:
|
||||
virtual void onStart() = 0;
|
||||
virtual void onStop() = 0;
|
||||
virtual void onNetworkChange(QNetworkSession::State state) = 0;
|
||||
virtual void onNetworkChange() = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
//NOTE: The provider will destroy the DeviceLink when it's no longer accessible,
|
||||
|
|
|
@ -31,14 +31,11 @@ LoopbackLinkProvider::LoopbackLinkProvider()
|
|||
|
||||
LoopbackLinkProvider::~LoopbackLinkProvider()
|
||||
{
|
||||
//delete echoDeviceLink;
|
||||
|
||||
}
|
||||
|
||||
void LoopbackLinkProvider::onNetworkChange(QNetworkSession::State state)
|
||||
void LoopbackLinkProvider::onNetworkChange()
|
||||
{
|
||||
Q_UNUSED(state);
|
||||
//kDebug(kdeconnect_kded()) << "Echo Device discovery emitted";
|
||||
|
||||
LoopbackDeviceLink* newLoopbackDeviceLink = new LoopbackDeviceLink("loopback", this);
|
||||
Q_EMIT onConnectionReceived(identityPackage, newLoopbackDeviceLink);
|
||||
|
||||
|
@ -51,7 +48,7 @@ void LoopbackLinkProvider::onNetworkChange(QNetworkSession::State state)
|
|||
|
||||
void LoopbackLinkProvider::onStart()
|
||||
{
|
||||
onNetworkChange(QNetworkSession::Connected);
|
||||
onNetworkChange();
|
||||
}
|
||||
|
||||
void LoopbackLinkProvider::onStop()
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
virtual void onStart();
|
||||
virtual void onStop();
|
||||
virtual void onNetworkChange(QNetworkSession::State state);
|
||||
virtual void onNetworkChange();
|
||||
|
||||
private:
|
||||
LoopbackDeviceLink* loopbackDeviceLink;
|
||||
|
|
|
@ -45,6 +45,7 @@ struct DaemonPrivate
|
|||
|
||||
//Every known device
|
||||
QMap<QString, Device*> mDevices;
|
||||
|
||||
};
|
||||
|
||||
Daemon* Daemon::instance()
|
||||
|
@ -82,15 +83,14 @@ Daemon::Daemon(QObject *parent)
|
|||
}
|
||||
setDiscoveryEnabled(true);
|
||||
|
||||
//Listen to connectivity changes
|
||||
QNetworkConfigurationManager* manager = new QNetworkConfigurationManager();
|
||||
QNetworkSession* network = new QNetworkSession(manager->defaultConfiguration());
|
||||
connect(manager, SIGNAL(configurationAdded(QNetworkConfiguration)),
|
||||
this, SLOT(forceOnNetworkChange()));
|
||||
Q_FOREACH (LinkProvider* a, d->mLinkProviders) {
|
||||
connect(network, SIGNAL(stateChanged(QNetworkSession::State)),
|
||||
a, SLOT(onNetworkChange(QNetworkSession::State)));
|
||||
}
|
||||
//Detect when a network interface changes status (TODO: Move to the lan link provider?)
|
||||
QNetworkConfigurationManager* networkManager;
|
||||
networkManager = new QNetworkConfigurationManager(this);
|
||||
connect(networkManager, &QNetworkConfigurationManager::configurationChanged, [this, networkManager](QNetworkConfiguration config) {
|
||||
qCDebug(KDECONNECT_CORE()) << config.name() << " state changed to " << config.state();
|
||||
qCDebug(KDECONNECT_CORE()) << "Online status: " << (networkManager->isOnline()? "online":"offline");
|
||||
forceOnNetworkChange();
|
||||
});
|
||||
|
||||
//Register on DBus
|
||||
QDBusConnection::sessionBus().registerService("org.kde.kdeconnect");
|
||||
|
@ -111,8 +111,9 @@ void Daemon::setDiscoveryEnabled(bool b)
|
|||
|
||||
void Daemon::forceOnNetworkChange()
|
||||
{
|
||||
qCDebug(KDECONNECT_CORE) << "Sending onNetworkChange to " << d->mLinkProviders.size() << " LinkProviders";
|
||||
Q_FOREACH (LinkProvider* a, d->mLinkProviders) {
|
||||
a->onNetworkChange(QNetworkSession::Connected);
|
||||
a->onNetworkChange();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,6 +175,7 @@ void Daemon::onDeviceReachableStatusChanged()
|
|||
|
||||
void Daemon::setAnnouncedName(QString name)
|
||||
{
|
||||
qCDebug(KDECONNECT_CORE()) << "Announcing name";
|
||||
KdeConnectConfig::instance()->setName(name);
|
||||
forceOnNetworkChange();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue