aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/protocols/rtc/probe_handler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/protocols/rtc/probe_handler.cc')
-rw-r--r--libtransport/src/protocols/rtc/probe_handler.cc37
1 files changed, 25 insertions, 12 deletions
diff --git a/libtransport/src/protocols/rtc/probe_handler.cc b/libtransport/src/protocols/rtc/probe_handler.cc
index abb234757..6a84914ab 100644
--- a/libtransport/src/protocols/rtc/probe_handler.cc
+++ b/libtransport/src/protocols/rtc/probe_handler.cc
@@ -36,11 +36,18 @@ ProbeHandler::ProbeHandler(SendProbeCallback &&send_callback,
ProbeHandler::~ProbeHandler() {}
-uint64_t ProbeHandler::getRtt(uint32_t seq) {
+uint64_t ProbeHandler::getRtt(uint32_t seq, bool is_valid) {
auto it = pending_probes_.find(seq);
if (it == pending_probes_.end()) return 0;
+ if (!is_valid) {
+ // delete the probe anyway
+ pending_probes_.erase(it);
+ valid_batch_ = false;
+ return 0;
+ }
+
uint64_t now = utils::SteadyTime::nowMs().count();
uint64_t rtt = now - it->second;
if (rtt < 1) rtt = 1;
@@ -52,6 +59,7 @@ uint64_t ProbeHandler::getRtt(uint32_t seq) {
}
double ProbeHandler::getProbeLossRate() {
+ if (!valid_batch_) return 1.0;
return 1.0 - ((double)recv_probes_ / (double)sent_probes_);
}
@@ -71,11 +79,26 @@ void ProbeHandler::stopProbes() {
max_probes_ = 0;
sent_probes_ = 0;
recv_probes_ = 0;
+ valid_batch_ = true;
probe_timer_->cancel();
}
void ProbeHandler::sendProbes() {
if (probe_interval_ == 0) return;
+
+ std::weak_ptr<ProbeHandler> self(shared_from_this());
+ probe_timer_->expires_from_now(std::chrono::microseconds(probe_interval_));
+ probe_timer_->async_wait([self](const std::error_code &ec) {
+ if (ec) return;
+ auto s = self.lock();
+ if (s) {
+ s->generateProbe();
+ }
+ });
+}
+
+void ProbeHandler::generateProbe() {
+ if (probe_interval_ == 0) return;
if (max_probes_ != 0 && sent_probes_ >= max_probes_) return;
uint64_t now = utils::SteadyTime::nowMs().count();
@@ -97,17 +120,7 @@ void ProbeHandler::sendProbes() {
}
}
- if (probe_interval_ == 0) return;
-
- std::weak_ptr<ProbeHandler> self(shared_from_this());
- probe_timer_->expires_from_now(std::chrono::microseconds(probe_interval_));
- probe_timer_->async_wait([self](const std::error_code &ec) {
- if (ec) return;
- auto s = self.lock();
- if (s) {
- s->sendProbes();
- }
- });
+ sendProbes();
}
ProbeType ProbeHandler::getProbeType(uint32_t seq) {