mirror of
https://invent.kde.org/network/krfb
synced 2024-07-08 12:05:49 +00:00
implemented configurable SLP lifetimes in kinet
svn path=/trunk/kdenetwork/krfb/; revision=191284
This commit is contained in:
parent
bdc64b9b64
commit
38f4d170f5
2
TODO
2
TODO
|
@ -6,8 +6,6 @@ For 3.2:
|
||||||
- set desktop name (username@hostname)
|
- set desktop name (username@hostname)
|
||||||
- apply multi-desktop patch
|
- apply multi-desktop patch
|
||||||
- trayicon mouse-over text
|
- trayicon mouse-over text
|
||||||
- configurable slp lifetime in kinetd
|
|
||||||
- slp registration refresh in kinetd when lifetime expired
|
|
||||||
- when krfb is started with URL arguments and without connection
|
- when krfb is started with URL arguments and without connection
|
||||||
quality, add some kind of smart algorithm to determine whether the
|
quality, add some kind of smart algorithm to determine whether the
|
||||||
other host is local (maybe using SLP to announce the connectivity
|
other host is local (maybe using SLP to announce the connectivity
|
||||||
|
|
|
@ -93,7 +93,8 @@ void PortListener::loadConfig(KService::Ptr s) {
|
||||||
m_argument = QString::null;
|
m_argument = QString::null;
|
||||||
m_multiInstance = false;
|
m_multiInstance = false;
|
||||||
|
|
||||||
QVariant vid, vport, vautoport, venabled, vargument, vmultiInstance, vurl, vsattributes;
|
QVariant vid, vport, vautoport, venabled, vargument, vmultiInstance, vurl,
|
||||||
|
vsattributes, vslifetime;
|
||||||
|
|
||||||
m_execPath = s->exec().utf8();
|
m_execPath = s->exec().utf8();
|
||||||
vid = s->property("X-KDE-KINETD-id");
|
vid = s->property("X-KDE-KINETD-id");
|
||||||
|
@ -104,6 +105,7 @@ void PortListener::loadConfig(KService::Ptr s) {
|
||||||
vmultiInstance = s->property("X-KDE-KINETD-multiInstance");
|
vmultiInstance = s->property("X-KDE-KINETD-multiInstance");
|
||||||
vurl = s->property("X-KDE-KINETD-serviceURL");
|
vurl = s->property("X-KDE-KINETD-serviceURL");
|
||||||
vsattributes = s->property("X-KDE-KINETD-serviceAttributes");
|
vsattributes = s->property("X-KDE-KINETD-serviceAttributes");
|
||||||
|
vslifetime = s->property("X-KDE-KINETD-serviceLifetime");
|
||||||
|
|
||||||
if (!vid.isValid()) {
|
if (!vid.isValid()) {
|
||||||
kdDebug() << "Kinetd cannot load service "<<m_serviceName
|
kdDebug() << "Kinetd cannot load service "<<m_serviceName
|
||||||
|
@ -120,6 +122,9 @@ void PortListener::loadConfig(KService::Ptr s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m_serviceName = vid.toString();
|
m_serviceName = vid.toString();
|
||||||
|
m_serviceLifetime = vslifetime.toInt();
|
||||||
|
if (m_serviceLifetime < 120) // never less than 120 s
|
||||||
|
m_serviceLifetime = 120;
|
||||||
m_portBase = vport.toInt();
|
m_portBase = vport.toInt();
|
||||||
if (vautoport.isValid())
|
if (vautoport.isValid())
|
||||||
m_autoPortRange = vautoport.toInt();
|
m_autoPortRange = vautoport.toInt();
|
||||||
|
@ -143,6 +148,7 @@ void PortListener::loadConfig(KService::Ptr s) {
|
||||||
else
|
else
|
||||||
m_serviceAttributes = "";
|
m_serviceAttributes = "";
|
||||||
|
|
||||||
|
m_slpLifetimeEnd = QDateTime::currentDateTime().addSecs(m_serviceLifetime);
|
||||||
m_defaultPortBase = m_portBase;
|
m_defaultPortBase = m_portBase;
|
||||||
m_defaultAutoPortRange = m_autoPortRange;
|
m_defaultAutoPortRange = m_autoPortRange;
|
||||||
|
|
||||||
|
@ -193,7 +199,7 @@ bool PortListener::isValid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PortListener::isEnabled() {
|
bool PortListener::isEnabled() {
|
||||||
return m_enabled;
|
return m_enabled && m_valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PortListener::port() {
|
int PortListener::port() {
|
||||||
|
@ -289,19 +295,36 @@ void PortListener::setServiceRegistrationEnabledInternal(bool e) {
|
||||||
m_registeredServiceURL = processServiceTemplate(m_serviceURL);
|
m_registeredServiceURL = processServiceTemplate(m_serviceURL);
|
||||||
m_serviceRegistered = m_srvreg->registerService(
|
m_serviceRegistered = m_srvreg->registerService(
|
||||||
m_registeredServiceURL,
|
m_registeredServiceURL,
|
||||||
processServiceTemplate(m_serviceAttributes));
|
processServiceTemplate(m_serviceAttributes),
|
||||||
|
m_serviceLifetime);
|
||||||
if (!m_serviceRegistered)
|
if (!m_serviceRegistered)
|
||||||
kdDebug(7021) << "Failure registering SLP service (no slpd running?)"<< endl;
|
kdDebug(7021) << "Failure registering SLP service (no slpd running?)"<< endl;
|
||||||
|
// make lifetime 30s shorter, because the timeout is not precise
|
||||||
|
m_slpLifetimeEnd = QDateTime::currentDateTime().addSecs(m_serviceLifetime-30);
|
||||||
} else {
|
} else {
|
||||||
m_srvreg->unregisterService(m_registeredServiceURL);
|
m_srvreg->unregisterService(m_registeredServiceURL);
|
||||||
m_serviceRegistered = false;
|
m_serviceRegistered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PortListener::refreshRegistration() {
|
||||||
|
if (m_serviceRegistered && (m_slpLifetimeEnd.addSecs(-90) < QDateTime::currentDateTime())) {
|
||||||
|
setServiceRegistrationEnabledInternal(false);
|
||||||
|
setServiceRegistrationEnabledInternal(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QDateTime PortListener::expiration() {
|
QDateTime PortListener::expiration() {
|
||||||
return m_expirationTime;
|
return m_expirationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDateTime PortListener::serviceLifetimeEnd() {
|
||||||
|
if (m_serviceRegistered)
|
||||||
|
return m_slpLifetimeEnd;
|
||||||
|
else
|
||||||
|
return QDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
QString PortListener::name() {
|
QString PortListener::name() {
|
||||||
return m_serviceName;
|
return m_serviceName;
|
||||||
}
|
}
|
||||||
|
@ -325,6 +348,7 @@ KInetD::KInetD(QCString &n) :
|
||||||
m_portListeners.setAutoDelete(true);
|
m_portListeners.setAutoDelete(true);
|
||||||
connect(&m_expirationTimer, SIGNAL(timeout()), SLOT(setExpirationTimer()));
|
connect(&m_expirationTimer, SIGNAL(timeout()), SLOT(setExpirationTimer()));
|
||||||
connect(&m_portRetryTimer, SIGNAL(timeout()), SLOT(portRetryTimer()));
|
connect(&m_portRetryTimer, SIGNAL(timeout()), SLOT(portRetryTimer()));
|
||||||
|
connect(&m_reregistrationTimer, SIGNAL(timeout()), SLOT(reregistrationTimer()));
|
||||||
loadServiceList();
|
loadServiceList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,10 +366,18 @@ void KInetD::loadServiceList()
|
||||||
PortListener *pl = new PortListener(s, m_config, m_srvreg);
|
PortListener *pl = new PortListener(s, m_config, m_srvreg);
|
||||||
if (pl->isValid())
|
if (pl->isValid())
|
||||||
m_portListeners.append(pl);
|
m_portListeners.append(pl);
|
||||||
|
else
|
||||||
|
delete pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
setExpirationTimer();
|
setExpirationTimer();
|
||||||
setPortRetryTimer(true);
|
setPortRetryTimer(true);
|
||||||
|
setReregistrationTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInetD::expirationTimer() {
|
||||||
|
setExpirationTimer();
|
||||||
|
setReregistrationTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KInetD::setExpirationTimer() {
|
void KInetD::setExpirationTimer() {
|
||||||
|
@ -359,6 +391,42 @@ void KInetD::setExpirationTimer() {
|
||||||
|
|
||||||
void KInetD::portRetryTimer() {
|
void KInetD::portRetryTimer() {
|
||||||
setPortRetryTimer(true);
|
setPortRetryTimer(true);
|
||||||
|
setReregistrationTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInetD::setReregistrationTimer() {
|
||||||
|
QDateTime d;
|
||||||
|
PortListener *pl = m_portListeners.first();
|
||||||
|
while (pl) {
|
||||||
|
QDateTime d2 = pl->serviceLifetimeEnd();
|
||||||
|
if (!d2.isNull()) {
|
||||||
|
if (d2 < QDateTime::currentDateTime()) {
|
||||||
|
m_reregistrationTimer.start(0, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (d.isNull() || (d2 < d))
|
||||||
|
d = d2;
|
||||||
|
}
|
||||||
|
pl = m_portListeners.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!d.isNull()) {
|
||||||
|
int s = QDateTime::currentDateTime().secsTo(d);
|
||||||
|
if (s < 30)
|
||||||
|
s = 30; // max frequency 30s
|
||||||
|
m_reregistrationTimer.start(s*1000, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_reregistrationTimer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KInetD::reregistrationTimer() {
|
||||||
|
PortListener *pl = m_portListeners.first();
|
||||||
|
while (pl) {
|
||||||
|
pl->refreshRegistration();
|
||||||
|
pl = m_portListeners.next();
|
||||||
|
}
|
||||||
|
setReregistrationTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KInetD::setPortRetryTimer(bool retry) {
|
void KInetD::setPortRetryTimer(bool retry) {
|
||||||
|
@ -366,12 +434,12 @@ void KInetD::setPortRetryTimer(bool retry) {
|
||||||
|
|
||||||
PortListener *pl = m_portListeners.first();
|
PortListener *pl = m_portListeners.first();
|
||||||
while (pl) {
|
while (pl) {
|
||||||
if (pl->isEnabled() && (pl->port() == -1))
|
if (pl->isEnabled() && (pl->port() < 0))
|
||||||
if (retry) {
|
if (retry) {
|
||||||
if (!pl->acquirePort())
|
if (!pl->acquirePort())
|
||||||
unmappedPorts++;
|
unmappedPorts++;
|
||||||
}
|
}
|
||||||
else if (pl->port() == -1)
|
else if (pl->port() < 0)
|
||||||
unmappedPorts++;
|
unmappedPorts++;
|
||||||
pl = m_portListeners.next();
|
pl = m_portListeners.next();
|
||||||
}
|
}
|
||||||
|
@ -448,6 +516,7 @@ bool KInetD::setPort(QString service, int port, int autoPortRange)
|
||||||
|
|
||||||
bool s = pl->setPort(port, autoPortRange);
|
bool s = pl->setPort(port, autoPortRange);
|
||||||
setPortRetryTimer(false);
|
setPortRetryTimer(false);
|
||||||
|
setReregistrationTimer();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,6 +534,7 @@ void KInetD::setEnabled(QString service, bool enable)
|
||||||
|
|
||||||
pl->setEnabled(enable);
|
pl->setEnabled(enable);
|
||||||
setExpirationTimer();
|
setExpirationTimer();
|
||||||
|
setReregistrationTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KInetD::setEnabled(QString service, QDateTime expiration)
|
void KInetD::setEnabled(QString service, QDateTime expiration)
|
||||||
|
@ -475,6 +545,7 @@ void KInetD::setEnabled(QString service, QDateTime expiration)
|
||||||
|
|
||||||
pl->setEnabled(expiration);
|
pl->setEnabled(expiration);
|
||||||
setExpirationTimer();
|
setExpirationTimer();
|
||||||
|
setReregistrationTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KInetD::setServiceRegistrationEnabled(QString service, bool enable)
|
void KInetD::setServiceRegistrationEnabled(QString service, bool enable)
|
||||||
|
@ -484,6 +555,7 @@ void KInetD::setServiceRegistrationEnabled(QString service, bool enable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pl->setServiceRegistrationEnabled(enable);
|
pl->setServiceRegistrationEnabled(enable);
|
||||||
|
setReregistrationTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KInetD::isServiceRegistrationEnabled(QString service)
|
bool KInetD::isServiceRegistrationEnabled(QString service)
|
||||||
|
|
|
@ -36,6 +36,7 @@ private:
|
||||||
bool m_valid;
|
bool m_valid;
|
||||||
QString m_serviceName;
|
QString m_serviceName;
|
||||||
QString m_serviceURL, m_serviceAttributes, m_registeredServiceURL;
|
QString m_serviceURL, m_serviceAttributes, m_registeredServiceURL;
|
||||||
|
int m_serviceLifetime;
|
||||||
int m_port;
|
int m_port;
|
||||||
int m_portBase, m_autoPortRange;
|
int m_portBase, m_autoPortRange;
|
||||||
int m_defaultPortBase, m_defaultAutoPortRange;
|
int m_defaultPortBase, m_defaultAutoPortRange;
|
||||||
|
@ -45,6 +46,7 @@ private:
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
bool m_serviceRegistered, m_registerService;
|
bool m_serviceRegistered, m_registerService;
|
||||||
QDateTime m_expirationTime;
|
QDateTime m_expirationTime;
|
||||||
|
QDateTime m_slpLifetimeEnd;
|
||||||
|
|
||||||
KServerSocket *m_socket;
|
KServerSocket *m_socket;
|
||||||
KProcess m_process;
|
KProcess m_process;
|
||||||
|
@ -69,10 +71,12 @@ public:
|
||||||
void setServiceRegistrationEnabled(bool enabled);
|
void setServiceRegistrationEnabled(bool enabled);
|
||||||
bool isServiceRegistrationEnabled();
|
bool isServiceRegistrationEnabled();
|
||||||
QDateTime expiration();
|
QDateTime expiration();
|
||||||
|
QDateTime serviceLifetimeEnd();
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
int port();
|
int port();
|
||||||
QString processServiceTemplate(const QString &a);
|
QString processServiceTemplate(const QString &a);
|
||||||
bool setPort(int port = -1, int autoProbeRange = 1);
|
bool setPort(int port = -1, int autoProbeRange = 1);
|
||||||
|
void refreshRegistration();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void accepted(KSocket*);
|
void accepted(KSocket*);
|
||||||
|
@ -162,16 +166,20 @@ k_dcop:
|
||||||
private:
|
private:
|
||||||
QDateTime getNextExpirationTime();
|
QDateTime getNextExpirationTime();
|
||||||
void setPortRetryTimer(bool retry);
|
void setPortRetryTimer(bool retry);
|
||||||
|
void setReregistrationTimer();
|
||||||
|
void setExpirationTimer();
|
||||||
|
|
||||||
KConfig *m_config;
|
KConfig *m_config;
|
||||||
KServiceRegistry *m_srvreg;
|
KServiceRegistry *m_srvreg;
|
||||||
QPtrList<PortListener> m_portListeners;
|
QPtrList<PortListener> m_portListeners;
|
||||||
QTimer m_expirationTimer;
|
QTimer m_expirationTimer;
|
||||||
QTimer m_portRetryTimer;
|
QTimer m_portRetryTimer;
|
||||||
|
QTimer m_reregistrationTimer;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void setExpirationTimer();
|
void expirationTimer();
|
||||||
void portRetryTimer();
|
void portRetryTimer();
|
||||||
|
void reregistrationTimer();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KInetD(QCString &n);
|
KInetD(QCString &n);
|
||||||
|
|
|
@ -88,3 +88,9 @@ Type=QString
|
||||||
[PropertyDef::X-KDE-KINETD-serviceAttributes]
|
[PropertyDef::X-KDE-KINETD-serviceAttributes]
|
||||||
Type=QString
|
Type=QString
|
||||||
|
|
||||||
|
# the lifetime of a service in seconds. kinets will renew the service
|
||||||
|
# automatically. Max 65535, never use anything under 2 min. Something like
|
||||||
|
# 5-20 minutes is a sane value for most desktop applications.
|
||||||
|
[PropertyDef::X-KDE-KINETD-serviceLifetime]
|
||||||
|
Type=int
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ X-KDE-KINETD-argument=--kinetd
|
||||||
X-KDE-KINETD-multiInstance=false
|
X-KDE-KINETD-multiInstance=false
|
||||||
X-KDE-KINETD-serviceURL=service:remotedesktop.kde:vnc://%h:%p;(type=shared),(username=%u),(fullname=%f)
|
X-KDE-KINETD-serviceURL=service:remotedesktop.kde:vnc://%h:%p;(type=shared),(username=%u),(fullname=%f)
|
||||||
X-KDE-KINETD-serviceAttributes=(type=shared),(username=%u),(fullname=%f)
|
X-KDE-KINETD-serviceAttributes=(type=shared),(username=%u),(fullname=%f)
|
||||||
|
X-KDE-KINETD-serviceLifetime=1200
|
||||||
|
|
||||||
Name=KRfb Desktop Sharing
|
Name=KRfb Desktop Sharing
|
||||||
Name[bg]=Споделяне на Работно място KRfb
|
Name[bg]=Споделяне на Работно място KRfb
|
||||||
|
|
Loading…
Reference in New Issue
Block a user