service/NtfyPushReceiver.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "NtfyPushReceiver.h" | ||
| 2 | #include "NtfyStream.h" | ||
| 3 | |||
| 4 | #include <QDateTime> | ||
| 5 | #include <QJsonDocument> | ||
| 6 | #include <QJsonObject> | ||
| 7 | #include <QLoggingCategory> | ||
| 8 | #include <QNetworkAccessManager> | ||
| 9 | #include <QNetworkReply> | ||
| 10 | #include <QNetworkRequest> | ||
| 11 | #include <QRandomGenerator> | ||
| 12 | #include <QUrlQuery> | ||
| 13 | |||
| 14 |
4/7✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 8 taken 25 times.
✓ Branch 4 → 5 taken 2 times.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 2 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
|
27 | Q_LOGGING_CATEGORY(lcNtfy, "mailjd.davpush.ntfy") |
| 15 | |||
| 16 | namespace { | ||
| 17 | constexpr int kRecentIds = 128; | ||
| 18 | 43 | qint64 nowMs() { return QDateTime::currentMSecsSinceEpoch(); } | |
| 19 | } // namespace | ||
| 20 | |||
| 21 |
3/3✓ Branch 8 → 9 taken 14 times.
✓ Branch 9 → 10 taken 14 times.
✓ Branch 10 → 11 taken 14 times.
|
14 | NtfyPushReceiver::NtfyPushReceiver(QObject *parent) : PushReceiver(parent) { |
| 22 |
3/6✓ Branch 12 → 13 taken 14 times.
✓ Branch 13 → 14 taken 14 times.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 14 times.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
|
14 | m_nam = new QNetworkAccessManager(this); |
| 23 |
1/1✓ Branch 16 → 17 taken 14 times.
|
14 | m_nam->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy); |
| 24 | 16 | m_jitter = [] { return QRandomGenerator::global()->generateDouble(); }; | |
| 25 |
3/3✓ Branch 20 → 21 taken 42 times.
✓ Branch 22 → 20 taken 42 times.
✓ Branch 22 → 23 taken 14 times.
|
56 | for (QTimer *timer : {&m_reconnectTimer, &m_heartbeatTimer, &m_connectTimer}) timer->setSingleShot(true); |
| 26 |
1/1✓ Branch 23 → 24 taken 14 times.
|
14 | connect(&m_reconnectTimer, &QTimer::timeout, this, &NtfyPushReceiver::connectStream); |
| 27 |
1/1✓ Branch 25 → 26 taken 14 times.
|
14 | connect(&m_heartbeatTimer, &QTimer::timeout, this, [this] { |
| 28 |
7/7✓ Branch 2 → 3 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 13 → 4 taken 1 time.
✓ Branch 13 → 14 taken 1 time.
|
2 | qCInfo(lcNtfy) << "No keepalive within" << m_timing.heartbeatTimeoutMs << "ms, renewing the stream"; |
| 29 | 1 | dropStream(); | |
| 30 |
1/1✓ Branch 18 → 19 taken 1 time.
|
2 | scheduleReconnect(Failure::Timeout, QStringLiteral("no keepalive from the push service")); |
| 31 | 1 | }); | |
| 32 |
1/1✓ Branch 27 → 28 taken 14 times.
|
14 | connect(&m_connectTimer, &QTimer::timeout, this, [this] { |
| 33 | ✗ | dropStream(); | |
| 34 | ✗ | scheduleReconnect(Failure::Timeout, QStringLiteral("push service did not answer")); | |
| 35 | ✗ | }); | |
| 36 | 14 | } | |
| 37 | |||
| 38 | 17 | NtfyPushReceiver::~NtfyPushReceiver() { | |
| 39 | 14 | m_running = false; | |
| 40 | 14 | dropStream(); | |
| 41 | 17 | } | |
| 42 | |||
| 43 | 13 | void NtfyPushReceiver::setNetworkAccessManager(QNetworkAccessManager *nam) { | |
| 44 |
4/8✓ Branch 2 → 3 taken 13 times.
✗ Branch 2 → 6 not taken.
✓ Branch 4 → 5 taken 13 times.
✗ Branch 4 → 6 not taken.
✓ Branch 7 → 8 taken 13 times.
✗ Branch 7 → 10 not taken.
✓ Branch 8 → 9 taken 13 times.
✗ Branch 8 → 10 not taken.
|
13 | if (m_nam && m_nam->parent() == this) delete m_nam; |
| 45 | 13 | m_nam = nam; | |
| 46 |
1/2✓ Branch 10 → 11 taken 13 times.
✗ Branch 10 → 13 not taken.
|
13 | if (m_nam) { |
| 47 | 13 | m_nam->setParent(this); | |
| 48 | 13 | m_nam->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy); | |
| 49 | } | ||
| 50 | 13 | } | |
| 51 | |||
| 52 | 1 | QString NtfyPushReceiver::endpoint() const { | |
| 53 |
3/6✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 1 time.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
|
1 | if (m_config.server.isEmpty() || m_config.channel.isEmpty()) return {}; |
| 54 |
3/3✓ Branch 15 → 16 taken 1 time.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 17 → 18 taken 1 time.
|
1 | return m_config.server + QLatin1Char('/') + m_config.channel + QStringLiteral("?up=1"); |
| 55 | } | ||
| 56 | |||
| 57 | 14 | void NtfyPushReceiver::start(const Config &config) { | |
| 58 | 14 | stop(); | |
| 59 | 14 | m_config = config; | |
| 60 | 14 | m_lastMessageId = config.resumeAfterId; | |
| 61 | 14 | m_running = true; | |
| 62 | 14 | m_attempt = 0; | |
| 63 | 14 | m_hadConnection = false; | |
| 64 | 14 | connectStream(); | |
| 65 | 14 | } | |
| 66 | |||
| 67 | 18 | void NtfyPushReceiver::stop() { | |
| 68 | 18 | m_running = false; | |
| 69 | 18 | m_reconnectTimer.stop(); | |
| 70 | 18 | dropStream(); | |
| 71 | 18 | m_connectedSince = 0; | |
| 72 | 18 | m_nextAttemptAt = 0; | |
| 73 |
1/1✓ Branch 5 → 6 taken 18 times.
|
18 | setState(DavPushReceiverState::Stopped); |
| 74 | 18 | } | |
| 75 | |||
| 76 | 73 | void NtfyPushReceiver::dropStream() { | |
| 77 | 73 | m_heartbeatTimer.stop(); | |
| 78 | 73 | m_connectTimer.stop(); | |
| 79 | 73 | m_buffer.clear(); | |
| 80 | 73 | m_opened = false; | |
| 81 |
2/2✓ Branch 6 → 7 taken 24 times.
✓ Branch 6 → 12 taken 49 times.
|
73 | if (m_reply) { |
| 82 | 24 | QNetworkReply *reply = m_reply; | |
| 83 | 24 | m_reply = nullptr; | |
| 84 | 24 | reply->disconnect(this); | |
| 85 | 24 | reply->abort(); | |
| 86 | 24 | reply->deleteLater(); | |
| 87 | } | ||
| 88 | 73 | } | |
| 89 | |||
| 90 | 24 | void NtfyPushReceiver::connectStream() { | |
| 91 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 24 times.
|
24 | if (!m_running) return; |
| 92 |
1/1✓ Branch 4 → 5 taken 24 times.
|
24 | dropStream(); |
| 93 |
4/4✓ Branch 10 → 11 taken 24 times.
✓ Branch 11 → 12 taken 24 times.
✓ Branch 12 → 13 taken 24 times.
✓ Branch 13 → 14 taken 24 times.
|
24 | QUrl url(m_config.server + QLatin1Char('/') + m_config.channel + QStringLiteral("/json")); |
| 94 |
2/2✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 31 taken 23 times.
|
24 | if (!m_lastMessageId.isEmpty()) { |
| 95 |
1/1✓ Branch 21 → 22 taken 1 time.
|
1 | QUrlQuery query; |
| 96 |
1/1✓ Branch 25 → 26 taken 1 time.
|
2 | query.addQueryItem(QStringLiteral("since"), m_lastMessageId); |
| 97 |
1/1✓ Branch 28 → 29 taken 1 time.
|
1 | url.setQuery(query); |
| 98 | 1 | } | |
| 99 |
2/3✓ Branch 32 → 33 taken 24 times.
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 43 taken 24 times.
|
24 | if (url.scheme() != QLatin1String("https")) { |
| 100 | ✗ | setState(DavPushReceiverState::Failed, Failure::Protocol, QStringLiteral("push service must use HTTPS")); | |
| 101 | ✗ | return; | |
| 102 | } | ||
| 103 |
1/1✓ Branch 43 → 44 taken 24 times.
|
24 | QNetworkRequest request(url); |
| 104 |
3/3✓ Branch 44 → 45 taken 24 times.
✓ Branch 45 → 46 taken 24 times.
✓ Branch 46 → 47 taken 24 times.
|
24 | request.setRawHeader("Accept", "application/x-ndjson"); |
| 105 |
5/5✓ Branch 50 → 51 taken 5 times.
✓ Branch 50 → 57 taken 19 times.
✓ Branch 51 → 52 taken 5 times.
✓ Branch 52 → 53 taken 5 times.
✓ Branch 53 → 54 taken 5 times.
|
24 | if (!m_config.token.isEmpty()) request.setRawHeader("Authorization", "Bearer " + m_config.token); |
| 106 |
1/1✓ Branch 58 → 59 taken 24 times.
|
24 | request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::ManualRedirectPolicy); |
| 107 |
1/1✓ Branch 60 → 61 taken 24 times.
|
24 | request.setTransferTimeout(0); // long-lived stream: own heartbeat instead |
| 108 | 24 | m_nextAttemptAt = 0; | |
| 109 |
1/1✓ Branch 62 → 63 taken 24 times.
|
24 | setState(DavPushReceiverState::Connecting); |
| 110 |
2/2✓ Branch 64 → 65 taken 24 times.
✓ Branch 65 → 66 taken 24 times.
|
24 | m_reply = m_nam->get(request); |
| 111 |
1/1✓ Branch 67 → 68 taken 24 times.
|
24 | connect(m_reply, &QNetworkReply::readyRead, this, &NtfyPushReceiver::onReadyRead); |
| 112 |
1/1✓ Branch 70 → 71 taken 24 times.
|
24 | connect(m_reply, &QNetworkReply::finished, this, &NtfyPushReceiver::onFinished); |
| 113 |
1/1✓ Branch 72 → 73 taken 24 times.
|
24 | m_connectTimer.start(m_timing.connectTimeoutMs); |
| 114 | 24 | } | |
| 115 | |||
| 116 | 13 | void NtfyPushReceiver::onReadyRead() { | |
| 117 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 13 times.
|
14 | if (!m_reply) return; |
| 118 |
1/1✓ Branch 6 → 7 taken 13 times.
|
13 | const QByteArray chunk = m_reply->readAll(); |
| 119 |
1/1✓ Branch 8 → 9 taken 13 times.
|
13 | emit bytesReceived(chunk.size()); |
| 120 | 13 | const bool bufferWasLarge = m_buffer.size() + chunk.size() > kMaxBufferBytes; | |
| 121 |
1/1✓ Branch 11 → 12 taken 13 times.
|
13 | const NtfyStream::Lines lines = NtfyStream::feed(&m_buffer, chunk, kMaxFrameBytes, kMaxBufferBytes); |
| 122 |
3/4✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 32 taken 12 times.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 32 taken 1 time.
|
13 | if (lines.overflow && bufferWasLarge) { |
| 123 | ✗ | qCWarning(lcNtfy) << "Receive buffer overflow, renewing the stream"; | |
| 124 | ✗ | dropStream(); | |
| 125 | ✗ | scheduleReconnect(Failure::Overflow, QStringLiteral("push stream exceeded its buffer")); | |
| 126 | ✗ | return; | |
| 127 | } | ||
| 128 |
1/2✗ Branch 44 → 33 not taken.
✓ Branch 44 → 45 taken 13 times.
|
13 | for (int i = 0; i < lines.oversized; ++i) |
| 129 | ✗ | qCWarning(lcNtfy) << "Oversized frame dropped"; | |
| 130 | // S106-081: the stream of THIS call — a handler that restarted the | ||
| 131 | // receiver installs a new reply, and the old stream's remaining lines must | ||
| 132 | // not reach the new configuration. | ||
| 133 | 13 | const QPointer<QNetworkReply> stream = m_reply; | |
| 134 |
2/2✓ Branch 60 → 48 taken 16 times.
✓ Branch 60 → 61 taken 12 times.
|
28 | for (const QByteArray &line : lines.complete) { |
| 135 |
1/1✓ Branch 49 → 50 taken 16 times.
|
16 | processLine(line); |
| 136 |
5/6✓ Branch 51 → 52 taken 15 times.
✓ Branch 51 → 54 taken 1 time.
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 55 taken 15 times.
✓ Branch 56 → 57 taken 1 time.
✓ Branch 56 → 58 taken 15 times.
|
16 | if (!m_reply || m_reply != stream) return; // dropped or replaced by a handler |
| 137 | } | ||
| 138 |
2/2✓ Branch 61 → 63 taken 1 time.
✓ Branch 61 → 71 taken 11 times.
|
12 | if (lines.overflow) { |
| 139 |
1/1✓ Branch 63 → 64 taken 1 time.
|
1 | dropStream(); |
| 140 |
1/1✓ Branch 67 → 68 taken 1 time.
|
1 | scheduleReconnect(Failure::Overflow, QStringLiteral("push stream frame too large")); |
| 141 | } | ||
| 142 | 15 | } | |
| 143 | |||
| 144 | 16 | void NtfyPushReceiver::processLine(const QByteArray &line) { | |
| 145 |
1/1✓ Branch 2 → 3 taken 16 times.
|
16 | const NtfyStream::Event event = NtfyStream::decode(line); |
| 146 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 16 taken 15 times.
|
16 | if (!event.valid) { |
| 147 |
6/6✓ Branch 4 → 5 taken 1 time.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 9 → 10 taken 1 time.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 14 → 6 taken 1 time.
✓ Branch 14 → 15 taken 1 time.
|
2 | qCWarning(lcNtfy) << "Ignoring a malformed frame:" << event.error; |
| 148 | 1 | return; | |
| 149 | } | ||
| 150 | 15 | const QString &kind = event.kind; | |
| 151 | 15 | m_lastActivity = nowMs(); | |
| 152 |
1/1✓ Branch 17 → 18 taken 15 times.
|
15 | m_connectTimer.stop(); |
| 153 |
1/1✓ Branch 18 → 19 taken 15 times.
|
15 | m_heartbeatTimer.start(m_timing.heartbeatTimeoutMs); |
| 154 |
3/8✓ Branch 19 → 20 taken 8 times.
✓ Branch 19 → 30 taken 7 times.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 29 taken 8 times.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 29 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
|
15 | if (!m_opened && (kind == QLatin1String("open") || kind == QLatin1String("keepalive") || |
| 155 |
2/2✓ Branch 31 → 32 taken 8 times.
✓ Branch 31 → 54 taken 7 times.
|
15 | kind == QLatin1String("message"))) { |
| 156 | 8 | m_opened = true; | |
| 157 | 8 | m_connectedSince = nowMs(); | |
| 158 | 8 | const bool afterGap = m_hadConnection; | |
| 159 | 8 | m_hadConnection = true; | |
| 160 |
1/1✓ Branch 34 → 35 taken 8 times.
|
8 | setState(DavPushReceiverState::Connected); |
| 161 |
8/8✓ Branch 36 → 37 taken 8 times.
✓ Branch 40 → 41 taken 8 times.
✓ Branch 41 → 42 taken 8 times.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 44 taken 7 times.
✓ Branch 45 → 46 taken 8 times.
✓ Branch 49 → 38 taken 8 times.
✓ Branch 49 → 50 taken 8 times.
|
16 | qCInfo(lcNtfy) << "Push stream open" << (afterGap ? "(after a gap)" : ""); |
| 162 |
1/1✓ Branch 50 → 51 taken 8 times.
|
8 | emit streamResumed(afterGap); |
| 163 |
1/2✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 8 times.
|
8 | if (!m_reply) return; |
| 164 | } | ||
| 165 |
2/2✓ Branch 56 → 57 taken 10 times.
✓ Branch 56 → 58 taken 5 times.
|
15 | if (kind != QLatin1String("message")) return; |
| 166 | 5 | const QString &id = event.id; | |
| 167 |
1/2✓ Branch 59 → 60 taken 5 times.
✗ Branch 59 → 68 not taken.
|
5 | if (!id.isEmpty()) { |
| 168 |
2/2✓ Branch 61 → 62 taken 1 time.
✓ Branch 61 → 63 taken 4 times.
|
5 | if (m_recentIds.contains(id)) return; |
| 169 |
1/1✓ Branch 63 → 64 taken 4 times.
|
4 | m_recentIds.append(id); |
| 170 |
1/2✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 4 times.
|
4 | if (m_recentIds.size() > kRecentIds) m_recentIds.removeFirst(); |
| 171 | 4 | m_lastMessageId = id; | |
| 172 | } | ||
| 173 |
1/2✗ Branch 68 → 69 not taken.
✓ Branch 68 → 80 taken 4 times.
|
4 | if (!event.payloadValid) { |
| 174 | ✗ | qCWarning(lcNtfy) << "Discarding a message with invalid base64"; | |
| 175 | ✗ | return; | |
| 176 | } | ||
| 177 |
1/1✓ Branch 80 → 81 taken 4 times.
|
4 | emit messageReceived(event.payload, id); |
| 178 | 16 | } | |
| 179 | |||
| 180 | 15 | void NtfyPushReceiver::onFinished() { | |
| 181 | 15 | QNetworkReply *reply = m_reply; | |
| 182 |
2/4✓ Branch 3 → 4 taken 15 times.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 15 times.
|
28 | if (!reply || !m_running) return; |
| 183 |
2/2✓ Branch 6 → 7 taken 15 times.
✓ Branch 7 → 8 taken 15 times.
|
15 | const int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); |
| 184 |
1/1✓ Branch 9 → 10 taken 15 times.
|
15 | const auto error = reply->error(); |
| 185 |
1/1✓ Branch 14 → 15 taken 15 times.
|
30 | const QByteArray retryAfter = reply->rawHeader("Retry-After"); |
| 186 |
1/1✓ Branch 15 → 16 taken 15 times.
|
15 | dropStream(); |
| 187 |
3/4✓ Branch 16 → 17 taken 13 times.
✓ Branch 16 → 18 taken 2 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 28 taken 13 times.
|
15 | if (status == 401 || status == 403) { |
| 188 |
2/2✓ Branch 22 → 23 taken 2 times.
✓ Branch 23 → 24 taken 2 times.
|
6 | scheduleReconnect(Failure::Authentication, QStringLiteral("push service rejected the sign-in (HTTP %1)").arg(status), |
| 189 | m_timing.failureBackoffMs); | ||
| 190 | 2 | return; | |
| 191 | } | ||
| 192 |
2/2✓ Branch 28 → 29 taken 2 times.
✓ Branch 28 → 41 taken 11 times.
|
13 | if (status == 429) { |
| 193 | 2 | bool ok = false; | |
| 194 |
1/1✓ Branch 29 → 30 taken 2 times.
|
2 | const qint64 seconds = retryAfter.toLongLong(&ok); |
| 195 | // S106-080: seconds * 1000 overflowed int for huge server values; the | ||
| 196 | // delay is computed wide and capped at one day. | ||
| 197 |
2/3✓ Branch 30 → 31 taken 2 times.
✗ Branch 30 → 33 not taken.
✓ Branch 31 → 32 taken 2 times.
|
2 | const qint64 delayMs = ok ? qBound<qint64>(qint64(0), seconds, qint64(86400)) * 1000 : 0; |
| 198 |
1/1✓ Branch 37 → 38 taken 2 times.
|
4 | scheduleReconnect(Failure::RateLimited, QStringLiteral("push service rate limit"), int(delayMs)); |
| 199 | 2 | return; | |
| 200 | } | ||
| 201 |
4/4✓ Branch 41 → 42 taken 8 times.
✓ Branch 41 → 53 taken 3 times.
✓ Branch 42 → 43 taken 1 time.
✓ Branch 42 → 53 taken 7 times.
|
11 | if (status >= 300 && status < 400) { |
| 202 | // S106-079: redirects are never followed (ManualRedirectPolicy) — a moved | ||
| 203 | // push service is a visible configuration problem, not a quiet endless | ||
| 204 | // "stream closed" reconnect loop. | ||
| 205 |
1/1✓ Branch 48 → 49 taken 1 time.
|
2 | scheduleReconnect(Failure::Protocol, |
| 206 |
1/1✓ Branch 47 → 48 taken 1 time.
|
3 | QStringLiteral("push service moved to another address (HTTP %1)").arg(status), |
| 207 | m_timing.failureBackoffMs, /*needsUser=*/true); | ||
| 208 | 1 | return; | |
| 209 | } | ||
| 210 |
2/2✓ Branch 53 → 54 taken 1 time.
✓ Branch 53 → 61 taken 9 times.
|
10 | if (error == QNetworkReply::SslHandshakeFailedError) { |
| 211 |
1/1✓ Branch 57 → 58 taken 1 time.
|
2 | scheduleReconnect(Failure::Tls, QStringLiteral("TLS verification of the push service failed"), |
| 212 | m_timing.failureBackoffMs); | ||
| 213 | 1 | return; | |
| 214 | } | ||
| 215 |
2/2✓ Branch 61 → 62 taken 7 times.
✓ Branch 61 → 72 taken 2 times.
|
9 | if (status >= 400) { |
| 216 |
2/2✓ Branch 66 → 67 taken 7 times.
✓ Branch 67 → 68 taken 7 times.
|
14 | scheduleReconnect(Failure::Protocol, QStringLiteral("push service answered HTTP %1").arg(status)); |
| 217 | 7 | return; | |
| 218 | } | ||
| 219 |
1/1✓ Branch 79 → 80 taken 2 times.
|
2 | scheduleReconnect(Failure::Network, error == QNetworkReply::NoError |
| 220 |
2/4✓ Branch 72 → 73 taken 1 time.
✓ Branch 72 → 76 taken 1 time.
✗ Branch 147 → 148 not taken.
✗ Branch 147 → 149 not taken.
|
7 | ? QStringLiteral("push stream closed by the server") |
| 221 |
4/6✓ Branch 81 → 82 taken 1 time.
✓ Branch 81 → 83 taken 1 time.
✓ Branch 83 → 84 taken 1 time.
✓ Branch 83 → 85 taken 1 time.
✗ Branch 143 → 144 not taken.
✗ Branch 143 → 145 not taken.
|
2 | : QStringLiteral("push stream interrupted")); |
| 222 | 15 | } | |
| 223 | |||
| 224 | 17 | int NtfyPushReceiver::backoffDelayMs() const { | |
| 225 | 17 | const qint64 exponential = qint64(m_timing.backoffBaseMs) << qMin(m_attempt, 20); | |
| 226 | 17 | const qint64 capped = qMin<qint64>(exponential, m_timing.backoffMaxMs); | |
| 227 | // Earlier-only jitter (up to 20 %): the configured maximum never grows. | ||
| 228 |
3/4✓ Branch 5 → 6 taken 17 times.
✗ Branch 5 → 8 not taken.
✓ Branch 6 → 7 taken 17 times.
✓ Branch 9 → 10 taken 17 times.
|
17 | return int(capped - qint64(capped * 0.2 * qBound(0.0, m_jitter ? m_jitter() : 0.0, 0.999))); |
| 229 | } | ||
| 230 | |||
| 231 | 17 | void NtfyPushReceiver::scheduleReconnect(Failure failure, const QString &detail, int minimumDelayMs, | |
| 232 | bool needsUser) { | ||
| 233 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 17 times.
|
17 | if (!m_running) return; |
| 234 |
4/6✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 8 taken 14 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 17 times.
|
17 | if (m_connectedSince > 0 && nowMs() - m_connectedSince >= m_timing.stableAfterMs) m_attempt = 0; |
| 235 | 17 | m_connectedSince = 0; | |
| 236 |
1/1✓ Branch 11 → 12 taken 17 times.
|
17 | const int delay = qMax(backoffDelayMs(), minimumDelayMs); |
| 237 | 17 | ++m_attempt; | |
| 238 | 17 | m_nextAttemptAt = nowMs() + delay; | |
| 239 |
6/6✓ Branch 14 → 15 taken 16 times.
✓ Branch 14 → 17 taken 1 time.
✓ Branch 15 → 16 taken 14 times.
✓ Branch 15 → 17 taken 2 times.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 18 taken 13 times.
|
17 | const bool needsAction = needsUser || failure == Failure::Authentication || failure == Failure::Tls; |
| 240 |
9/9✓ Branch 19 → 20 taken 17 times.
✓ Branch 23 → 24 taken 17 times.
✓ Branch 24 → 25 taken 17 times.
✓ Branch 26 → 27 taken 17 times.
✓ Branch 27 → 28 taken 17 times.
✓ Branch 28 → 29 taken 17 times.
✓ Branch 29 → 30 taken 17 times.
✓ Branch 35 → 21 taken 17 times.
✓ Branch 35 → 36 taken 17 times.
|
34 | qCInfo(lcNtfy) << "Push stream" << failure << "- reconnect in" << delay << "ms"; |
| 241 |
2/2✓ Branch 36 → 37 taken 4 times.
✓ Branch 36 → 38 taken 13 times.
|
17 | setState(needsAction ? DavPushReceiverState::Failed : DavPushReceiverState::Backoff, failure, detail); |
| 242 | 17 | m_reconnectTimer.start(delay); | |
| 243 | } | ||
| 244 |