| 135 | } |
| 136 | |
| 137 | void PingManager::onPingFinished(const std::string &ip, bool isSuccess, int32_t timeMs, bool isFromDisconnectedVpnState) |
| 138 | { |
| 139 | Q_UNUSED(isFromDisconnectedVpnState); |
| 140 | QString ipStr = QString::fromStdString(ip); |
| 141 | |
| 142 | auto itNode = ips_.find(ipStr); |
| 143 | if (itNode == ips_.end()) { |
| 144 | return; |
| 145 | } |
| 146 | itNode->nowPinging = false; |
| 147 | |
| 148 | // Note: we only issue ping requests in the disconnected state. However, it is possible we transitioned to the |
| 149 | // connecting/connected state between the time the ping request was issued to PingHost and when it was executed. |
| 150 | PingIpState &p = itNode.value(); |
| 151 | if (isSuccess) { |
| 152 | p.nextTimeForFailedPing = 0; |
| 153 | p.latestPingFailed = false; |
| 154 | p.failedPingsInRow = 0; |
| 155 | |
| 156 | // If the ping was executed in the connected state, we'll mark it as never happening and reissue it when |
| 157 | // we're back in the disconnected state. |
| 158 | if (isFromDisconnectedVpnState) { |
| 159 | p.iterationTime = pingStorage_.currentIterationTime(); |
| 160 | pingStorage_.setPing(ipStr, timeMs); |
| 161 | emit pingInfoChanged(ipStr, timeMs); |
| 162 | addLog("PingManager::onPingFinished", QString::fromLatin1("ping successful: %1 (%2 - %3) %4ms").arg(p.ipInfo.ip, p.ipInfo.city, p.ipInfo.nick).arg(timeMs)); |
| 163 | } |
| 164 | else { |
| 165 | addLog("PingManager::onPingFinished", QString::fromLatin1("discarding ping while connected: %1 (%2 - %3) %4ms").arg(p.ipInfo.ip, p.ipInfo.city, p.ipInfo.nick).arg(timeMs)); |
| 166 | } |
| 167 | } |
| 168 | else { |
| 169 | p.latestPingFailed = true; |
| 170 | p.failedPingsInRow++; |
| 171 | |
| 172 | if (p.failedPingsInRow >= MAX_FAILED_PING_IN_ROW) { |
| 173 | p.failedPingsInRow = 0; |
| 174 | p.nextTimeForFailedPing = QDateTime::currentMSecsSinceEpoch() + 1000 * 60; |
| 175 | p.curDelayForFailedPing = MIN_DELAY_FOR_FAILED_IN_ROW_PINGS; |
| 176 | |
| 177 | p.iterationTime = pingStorage_.currentIterationTime(); |
| 178 | pingStorage_.setPing(ipStr, PingTime::PING_FAILED); |
| 179 | emit pingInfoChanged(ipStr, PingTime::PING_FAILED); |
| 180 | |
| 181 | addLog("PingManager::onPingFinished", QString::fromLatin1("ping failed: %1 (%2 - %3)").arg(p.ipInfo.ip, p.ipInfo.city, p.ipInfo.nick)); |
| 182 | } |
| 183 | else { |
| 184 | p.curDelayForFailedPing = exponentialBackoff_GetNextDelay(p.curDelayForFailedPing); |
| 185 | p.nextTimeForFailedPing = QDateTime::currentMSecsSinceEpoch() + 1000 * p.curDelayForFailedPing; |
| 186 | } |
| 187 | |
| 188 | } |
| 189 | if (pingStorage_.isAllNodesHaveCurIteration()) { |
| 190 | addLog("PingManager::onPingFinished", "All nodes have the same iteration time"); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | int PingManager::exponentialBackoff_GetNextDelay(int curDelay, float factor, float jitter, float maxDelay) |
nothing calls this directly
no test coverage detected