2017-09-08 16:54:59 +02:00
|
|
|
#include "./internalerror.h"
|
2018-04-11 23:15:15 +02:00
|
|
|
#include "./syncthinglauncher.h"
|
2017-09-08 16:54:59 +02:00
|
|
|
|
|
|
|
#include "../settings/settings.h"
|
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingconnection.h>
|
|
|
|
#include <syncthingconnector/syncthingservice.h>
|
2017-09-08 16:54:59 +02:00
|
|
|
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
|
|
|
using namespace Data;
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2021-10-02 20:31:20 +02:00
|
|
|
/*!
|
|
|
|
* \brief Constructs a new error suitable for display purposes (password in \a url is redacted).
|
|
|
|
*/
|
|
|
|
InternalError::InternalError(const QString &message, const QUrl &url, const QByteArray &response)
|
|
|
|
: message(message)
|
|
|
|
, url(url)
|
|
|
|
, response(response)
|
|
|
|
, when(CppUtilities::DateTime::now())
|
|
|
|
{
|
|
|
|
if (!this->url.password().isEmpty()) {
|
|
|
|
this->url.setPassword(QStringLiteral("redacted"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:26:00 +02:00
|
|
|
/*!
|
|
|
|
* \brief Returns whether the error is relevant. Only in this case a notification for the error should be shown.
|
2018-04-02 20:50:59 +02:00
|
|
|
* \todo Unify with SyncthingNotifier::isDisconnectRelevant().
|
2018-04-02 20:26:00 +02:00
|
|
|
*/
|
2017-09-08 16:54:59 +02:00
|
|
|
bool InternalError::isRelevant(const SyncthingConnection &connection, SyncthingErrorCategory category, int networkError)
|
|
|
|
{
|
2018-04-02 20:26:00 +02:00
|
|
|
// ignore overall connection errors when auto reconnect tries >= 1
|
|
|
|
if (category != SyncthingErrorCategory::OverallConnection && connection.autoReconnectTries() >= 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore errors when disabled in settings
|
2017-09-08 16:54:59 +02:00
|
|
|
const auto &settings = Settings::values();
|
2018-04-02 20:26:00 +02:00
|
|
|
if (!settings.notifyOn.internalErrors) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip further considerations if connection is remote
|
|
|
|
if (!connection.isLocal()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// consider process/launcher or systemd unit status
|
2020-10-26 17:39:10 +01:00
|
|
|
const auto remoteHostClosed(networkError == QNetworkReply::RemoteHostClosedError || networkError == QNetworkReply::ProxyConnectionClosedError);
|
2018-04-02 20:26:00 +02:00
|
|
|
// ignore "remote host closed" error if we've just stopped Syncthing ourselves
|
2018-04-11 23:15:15 +02:00
|
|
|
const auto *launcher(SyncthingLauncher::mainInstance());
|
|
|
|
if (settings.launcher.considerForReconnect && remoteHostClosed && launcher && launcher->isManuallyStopped()) {
|
2018-04-02 20:26:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-08 16:54:59 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
2018-04-11 23:15:15 +02:00
|
|
|
const auto *const service(SyncthingService::mainInstance());
|
|
|
|
if (settings.systemd.considerForReconnect && remoteHostClosed && service && service->isManuallyStopped()) {
|
2018-04-02 20:26:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-04-02 20:50:59 +02:00
|
|
|
#endif
|
2018-04-02 20:26:00 +02:00
|
|
|
|
|
|
|
// ignore inavailability after start or standby-wakeup
|
2020-10-26 17:39:10 +01:00
|
|
|
if (settings.ignoreInavailabilityAfterStart) {
|
|
|
|
switch (networkError) {
|
|
|
|
case QNetworkReply::ConnectionRefusedError:
|
|
|
|
case QNetworkReply::HostNotFoundError:
|
|
|
|
case QNetworkReply::TemporaryNetworkFailureError:
|
|
|
|
case QNetworkReply::NetworkSessionFailedError:
|
|
|
|
case QNetworkReply::ProxyConnectionRefusedError:
|
|
|
|
case QNetworkReply::ProxyNotFoundError:
|
|
|
|
if ((launcher && launcher->isRunning())
|
2018-04-02 20:50:59 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
2020-10-26 17:39:10 +01:00
|
|
|
&& ((service && service->isSystemdAvailable()
|
|
|
|
&& !service->isActiveWithoutSleepFor(launcher->activeSince(), settings.ignoreInavailabilityAfterStart))
|
|
|
|
|| !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart))
|
2018-04-02 20:50:59 +02:00
|
|
|
#else
|
2020-10-26 17:39:10 +01:00
|
|
|
&& !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart)
|
2018-04-02 20:50:59 +02:00
|
|
|
#endif
|
2020-10-26 17:39:10 +01:00
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-10 21:05:40 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
2020-10-26 17:39:10 +01:00
|
|
|
if (service && !service->isActiveWithoutSleepFor(settings.ignoreInavailabilityAfterStart)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-10 21:05:40 +02:00
|
|
|
#endif
|
2020-10-26 17:39:10 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-04-02 20:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-09-08 16:54:59 +02:00
|
|
|
}
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|