diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/libwebrtc/net/dcsctp/socket/heartbeat_handler.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/net/dcsctp/socket/heartbeat_handler.cc')
-rw-r--r-- | third_party/libwebrtc/net/dcsctp/socket/heartbeat_handler.cc | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/third_party/libwebrtc/net/dcsctp/socket/heartbeat_handler.cc b/third_party/libwebrtc/net/dcsctp/socket/heartbeat_handler.cc index 902dff962f..31211e0d13 100644 --- a/third_party/libwebrtc/net/dcsctp/socket/heartbeat_handler.cc +++ b/third_party/libwebrtc/net/dcsctp/socket/heartbeat_handler.cc @@ -21,6 +21,7 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "api/array_view.h" +#include "api/units/time_delta.h" #include "net/dcsctp/packet/bounded_byte_reader.h" #include "net/dcsctp/packet/bounded_byte_writer.h" #include "net/dcsctp/packet/chunk/heartbeat_ack_chunk.h" @@ -35,6 +36,8 @@ #include "rtc_base/logging.h" namespace dcsctp { +using ::webrtc::TimeDelta; +using ::webrtc::Timestamp; // This is stored (in serialized form) as HeartbeatInfoParameter sent in // HeartbeatRequestChunk and received back in HeartbeatAckChunk. It should be @@ -49,11 +52,11 @@ class HeartbeatInfo { static constexpr size_t kBufferSize = sizeof(uint64_t); static_assert(kBufferSize == 8, "Unexpected buffer size"); - explicit HeartbeatInfo(TimeMs created_at) : created_at_(created_at) {} + explicit HeartbeatInfo(Timestamp created_at) : created_at_(created_at) {} std::vector<uint8_t> Serialize() { - uint32_t high_bits = static_cast<uint32_t>(*created_at_ >> 32); - uint32_t low_bits = static_cast<uint32_t>(*created_at_); + uint32_t high_bits = static_cast<uint32_t>(created_at_.ms() >> 32); + uint32_t low_bits = static_cast<uint32_t>(created_at_.ms()); std::vector<uint8_t> data(kBufferSize); BoundedByteWriter<kBufferSize> writer(data); @@ -75,13 +78,13 @@ class HeartbeatInfo { uint32_t low_bits = reader.Load32<4>(); uint64_t created_at = static_cast<uint64_t>(high_bits) << 32 | low_bits; - return HeartbeatInfo(TimeMs(created_at)); + return HeartbeatInfo(Timestamp::Millis(created_at)); } - TimeMs created_at() const { return created_at_; } + Timestamp created_at() const { return created_at_; } private: - const TimeMs created_at_; + const Timestamp created_at_; }; HeartbeatHandler::HeartbeatHandler(absl::string_view log_prefix, @@ -91,17 +94,18 @@ HeartbeatHandler::HeartbeatHandler(absl::string_view log_prefix, : log_prefix_(log_prefix), ctx_(context), timer_manager_(timer_manager), - interval_duration_(options.heartbeat_interval), + interval_duration_(options.heartbeat_interval.ToTimeDelta()), interval_duration_should_include_rtt_( options.heartbeat_interval_include_rtt), interval_timer_(timer_manager_->CreateTimer( "heartbeat-interval", absl::bind_front(&HeartbeatHandler::OnIntervalTimerExpiry, this), - TimerOptions(interval_duration_, TimerBackoffAlgorithm::kFixed))), + TimerOptions(interval_duration_, + TimerBackoffAlgorithm::kFixed))), timeout_timer_(timer_manager_->CreateTimer( "heartbeat-timeout", absl::bind_front(&HeartbeatHandler::OnTimeoutTimerExpiry, this), - TimerOptions(options.rto_initial, + TimerOptions(options.rto_initial.ToTimeDelta(), TimerBackoffAlgorithm::kExponential, /*max_restarts=*/0))) { // The interval timer must always be running as long as the association is up. @@ -109,7 +113,7 @@ HeartbeatHandler::HeartbeatHandler(absl::string_view log_prefix, } void HeartbeatHandler::RestartTimer() { - if (interval_duration_ == DurationMs(0)) { + if (interval_duration_.IsZero()) { // Heartbeating has been disabled. return; } @@ -117,7 +121,8 @@ void HeartbeatHandler::RestartTimer() { if (interval_duration_should_include_rtt_) { // The RTT should be used, but it's not easy accessible. The RTO will // suffice. - interval_timer_->set_duration(interval_duration_ + ctx_->current_rto()); + interval_timer_->set_duration( + interval_duration_ + ctx_->current_rto()); } else { interval_timer_->set_duration(interval_duration_); } @@ -153,8 +158,8 @@ void HeartbeatHandler::HandleHeartbeatAck(HeartbeatAckChunk chunk) { return; } - TimeMs now = ctx_->callbacks().TimeMillis(); - if (info->created_at() > TimeMs(0) && info->created_at() <= now) { + Timestamp now = ctx_->callbacks().Now(); + if (info->created_at() > Timestamp::Zero() && info->created_at() <= now) { ctx_->ObserveRTT(now - info->created_at()); } @@ -164,13 +169,13 @@ void HeartbeatHandler::HandleHeartbeatAck(HeartbeatAckChunk chunk) { ctx_->ClearTxErrorCounter(); } -absl::optional<DurationMs> HeartbeatHandler::OnIntervalTimerExpiry() { +TimeDelta HeartbeatHandler::OnIntervalTimerExpiry() { if (ctx_->is_connection_established()) { - HeartbeatInfo info(ctx_->callbacks().TimeMillis()); + HeartbeatInfo info(ctx_->callbacks().Now()); timeout_timer_->set_duration(ctx_->current_rto()); timeout_timer_->Start(); RTC_DLOG(LS_INFO) << log_prefix_ << "Sending HEARTBEAT with timeout " - << *timeout_timer_->duration(); + << webrtc::ToString(timeout_timer_->duration()); Parameters parameters = Parameters::Builder() .Add(HeartbeatInfoParameter(info.Serialize())) @@ -183,14 +188,14 @@ absl::optional<DurationMs> HeartbeatHandler::OnIntervalTimerExpiry() { << log_prefix_ << "Will not send HEARTBEAT when connection not established"; } - return absl::nullopt; + return TimeDelta::Zero(); } -absl::optional<DurationMs> HeartbeatHandler::OnTimeoutTimerExpiry() { +TimeDelta HeartbeatHandler::OnTimeoutTimerExpiry() { // Note that the timeout timer is not restarted. It will be started again when // the interval timer expires. RTC_DCHECK(!timeout_timer_->is_running()); ctx_->IncrementTxErrorCounter("HEARTBEAT timeout"); - return absl::nullopt; + return TimeDelta::Zero(); } } // namespace dcsctp |