summaryrefslogtreecommitdiffstats
path: root/libtransport/src/protocols/rtc/rtc_ldr.h
blob: 24f22ffedf9cf5b799f84faaf29be8f3969e2fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (c) 2021 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once
#include <hicn/transport/config.h>
#include <hicn/transport/interfaces/socket_options_keys.h>
// RtcTransportRecoveryStrategies
#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/content_object.h>
#include <hicn/transport/core/name.h>
#include <protocols/rtc/rtc_recovery_strategy.h>

#include <functional>

namespace transport {

namespace protocol {

namespace rtc {

class RTCLossDetectionAndRecovery
    : public std::enable_shared_from_this<RTCLossDetectionAndRecovery> {
 public:
  RTCLossDetectionAndRecovery(Indexer *indexer, asio::io_service &io_service,
                              interface::RtcTransportRecoveryStrategies type,
                              RecoveryStrategy::SendRtxCallback &&callback,
                              interface::StrategyCallback &&external_callback);

  ~RTCLossDetectionAndRecovery();

  void setState(RTCState *state) { rs_->setState(state); }
  void setRateControl(RTCRateControl *rateControl) {
    rs_->setRateControl(rateControl);
  }

  void setFecParams(uint32_t n, uint32_t k) { rs_->setFecParams(n, k); }

  void setContentSharingMode() { rs_->setContentSharingMode(); }
  void turnOnRecovery() { rs_->turnOnRecovery(); }
  bool isRtxOn() { return rs_->isRtxOn(); }

  void changeRecoveryStrategy(interface::RtcTransportRecoveryStrategies type);

  void onNewRound(bool in_sync);

  // the following functions return true if a loss is detected, false otherwise
  bool onTimeout(uint32_t seq, bool lost);
  bool onPacketRecoveredFec(uint32_t seq);
  bool onDataPacketReceived(const core::ContentObject &content_object);
  bool onNackPacketReceived(const core::ContentObject &nack);
  bool onProbePacketReceived(const core::ContentObject &probe);

  void clear() { rs_->clear(); }

  bool isRtx(uint32_t seq) { return rs_->isRtx(seq); }
  bool isPossibleLossWithNoRtx(uint32_t seq) {
    return rs_->isPossibleLossWithNoRtx(seq);
  }

  uint64_t getRtxRtt(uint32_t seq) { return rs_->getRtxRtt(seq); }

 private:
  // returns true if a loss is detected, false otherwise
  bool detectLoss(uint32_t start, uint32_t stop, bool recv_probe);

  std::shared_ptr<RecoveryStrategy> rs_;
};

}  // end namespace rtc

}  // end namespace protocol

}  // end namespace transport