Skip to content

Commit eacc9da

Browse files
authored
Worker: BackoffTimerHandleInterface cosmetic (#1785)
1 parent 3e2ff82 commit eacc9da

7 files changed

Lines changed: 84 additions & 82 deletions

File tree

worker/include/handles/BackoffTimerHandle.hpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,7 @@
99
class BackoffTimerHandle : public BackoffTimerHandleInterface, public TimerHandleInterface::Listener
1010
{
1111
public:
12-
explicit BackoffTimerHandle(
13-
/**
14-
* Listener on which OnTimer() callback will be invoked.
15-
*/
16-
BackoffTimerHandleInterface::Listener* listener,
17-
/**
18-
* Base timeout duration (ms).
19-
*/
20-
uint64_t baseTimeoutMs,
21-
/**
22-
* Backoff algorithm.
23-
*/
24-
BackoffAlgorithm backoffAlgorithm,
25-
/**
26-
* Maximum duration of the backoff timeout (ms). If no value is given, no
27-
* limit is set.
28-
*/
29-
std::optional<uint64_t> maxBackoffTimeoutMs,
30-
/**
31-
* Maximum number of restarts. If no value is given, it will restart
32-
* forever until stopped.
33-
*/
34-
std::optional<size_t> maxRestarts);
12+
explicit BackoffTimerHandle(const BackoffTimerHandleOptions& options);
3513

3614
BackoffTimerHandle& operator=(const BackoffTimerHandle&) = delete;
3715

worker/include/handles/BackoffTimerHandleInterface.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ class BackoffTimerHandleInterface
3636
EXPONENTIAL,
3737
};
3838

39+
public:
40+
struct BackoffTimerHandleOptions
41+
{
42+
/**
43+
* Listener on which OnTimer() callback will be invoked.
44+
*/
45+
BackoffTimerHandleInterface::Listener* listener;
46+
/**
47+
* Base timeout duration (ms).
48+
*/
49+
uint64_t baseTimeoutMs;
50+
/**
51+
* Backoff algorithm.
52+
*/
53+
BackoffAlgorithm backoffAlgorithm;
54+
/**
55+
* Maximum duration of the backoff timeout (ms). If no value is given, no
56+
* limit is set.
57+
*/
58+
std::optional<uint64_t> maxBackoffTimeoutMs;
59+
/**
60+
* Maximum number of restarts. If no value is given, it will restart
61+
* forever until stopped.
62+
*/
63+
std::optional<size_t> maxRestarts;
64+
};
65+
3966
public:
4067
static constexpr uint64_t MaxTimeoutMs{ std::numeric_limits<uint64_t>::max() / 2 };
4168

worker/src/RTC/SCTP/association/Association.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@ namespace RTC
4747
listener(listener),
4848
packetSender(this, this->listener),
4949
t1InitTimer(
50-
std::make_unique<BackoffTimerHandle>(
51-
/*listener*/ this,
52-
/*baseTimeoutMs*/ sctpOptions.t1InitTimeoutMs,
53-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
54-
/*maxBackoffTimeoutMs*/ sctpOptions.timerMaxBackoffTimeoutMs,
55-
/*maxRestarts*/ sctpOptions.maxInitRetransmissions)),
50+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
51+
.listener = this,
52+
.baseTimeoutMs = sctpOptions.t1InitTimeoutMs,
53+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
54+
.maxBackoffTimeoutMs = sctpOptions.timerMaxBackoffTimeoutMs,
55+
.maxRestarts = sctpOptions.maxInitRetransmissions,
56+
})),
5657
t1CookieTimer(
57-
std::make_unique<BackoffTimerHandle>(
58-
/*listener*/ this,
59-
/*baseTimeoutMs*/ sctpOptions.t1CookieTimeoutMs,
60-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
61-
/*maxBackoffTimeoutMs*/ sctpOptions.timerMaxBackoffTimeoutMs,
62-
/*maxRestarts*/ sctpOptions.maxInitRetransmissions)),
58+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
59+
.listener = this,
60+
.baseTimeoutMs = sctpOptions.t1CookieTimeoutMs,
61+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
62+
.maxBackoffTimeoutMs = sctpOptions.timerMaxBackoffTimeoutMs,
63+
.maxRestarts = sctpOptions.maxInitRetransmissions })),
6364
t2ShutdownTimer(
64-
std::make_unique<BackoffTimerHandle>(
65-
/*listener*/ this,
66-
/*baseTimeoutMs*/ sctpOptions.t2ShutdownTimeoutMs,
67-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
68-
/*maxBackoffTimeoutMs*/ sctpOptions.timerMaxBackoffTimeoutMs,
69-
/*maxRestarts*/ sctpOptions.maxRetransmissions))
65+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
66+
.listener = this,
67+
.baseTimeoutMs = sctpOptions.t2ShutdownTimeoutMs,
68+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
69+
.maxBackoffTimeoutMs = sctpOptions.timerMaxBackoffTimeoutMs,
70+
.maxRestarts = sctpOptions.maxRetransmissions }))
7071
{
7172
MS_TRACE();
7273
}

worker/src/RTC/SCTP/association/HeartbeatHandler.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ namespace RTC
2929
intervalDurationMs(sctpOptions.heartbeatIntervalMs),
3030
intervalDurationShouldIncludeRtt(sctpOptions.heartbeatIntervalIncludeRtt),
3131
intervalTimer(
32-
std::make_unique<BackoffTimerHandle>(
33-
/*listener*/ this,
34-
/*baseTimeoutMs*/ sctpOptions.initialRtoMs,
35-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
36-
/*maxBackoffTimeoutMs*/ sctpOptions.timerMaxBackoffTimeoutMs,
37-
/*maxRestarts*/ std::nullopt)),
32+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
33+
.listener = this,
34+
.baseTimeoutMs = sctpOptions.initialRtoMs,
35+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
36+
.maxBackoffTimeoutMs = sctpOptions.timerMaxBackoffTimeoutMs,
37+
.maxRestarts = std::nullopt })),
3838
timeoutTimer(
39-
std::make_unique<BackoffTimerHandle>(
40-
/*listener*/ this,
41-
/*baseTimeoutMs*/ sctpOptions.initialRtoMs,
42-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::FIXED,
43-
/*maxBackoffTimeoutMs*/ std::nullopt,
44-
/*maxRestarts*/ 0))
39+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
40+
.listener = this,
41+
.baseTimeoutMs = sctpOptions.initialRtoMs,
42+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::FIXED,
43+
.maxBackoffTimeoutMs = std::nullopt,
44+
.maxRestarts = 0 }))
4545
{
4646
MS_TRACE();
4747
}

worker/src/RTC/SCTP/association/StreamResetHandler.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ namespace RTC
2525
tcbContext(tcbContext),
2626
retransmissionQueue(retransmissionQueue),
2727
reConfigTimer(
28-
std::make_unique<BackoffTimerHandle>(
29-
/*listener*/ this,
30-
/*baseTimeoutMs*/ 0,
31-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
32-
/*maxBackoffTimeoutMs*/ std::nullopt,
33-
/*maxRestarts*/ std::nullopt)),
28+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
29+
.listener = this,
30+
.baseTimeoutMs = 0,
31+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
32+
.maxBackoffTimeoutMs = std::nullopt,
33+
.maxRestarts = std::nullopt,
34+
})),
3435
nextOutgoingReqSeqNbr(tcbContext->GetLocalInitialTsn()),
3536
lastProcessedReqSeqNbr(
3637
this->incomingReConfigRequestSnUnwrapper.Unwrap(tcbContext->GetRemoteInitialTsn() - 1)),

worker/src/RTC/SCTP/association/TransmissionControlBlock.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ namespace RTC
5050
negotiatedCapabilities(negotiatedCapabilities),
5151
isAssociationEstablished(std::move(isAssociationEstablished)),
5252
t3RtxTimer(
53-
std::make_unique<BackoffTimerHandle>(
54-
/*listener*/ this,
55-
/*baseTimeoutMs*/ sctpOptions.initialRtoMs,
56-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
57-
/*maxBackoffTimeoutMs*/ sctpOptions.timerMaxBackoffTimeoutMs,
58-
/*maxRestarts*/ std::nullopt)),
53+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
54+
.listener = this,
55+
.baseTimeoutMs = sctpOptions.initialRtoMs,
56+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
57+
.maxBackoffTimeoutMs = sctpOptions.timerMaxBackoffTimeoutMs,
58+
.maxRestarts = std::nullopt })),
5959
delayedAckTimer(
60-
std::make_unique<BackoffTimerHandle>(
61-
/*listener*/ this,
62-
/*baseTimeoutMs*/ sctpOptions.delayedAckMaxTimeoutMs,
63-
/*backoffAlgorithm*/ BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
64-
/*maxBackoffTimeoutMs*/ std::nullopt,
65-
/*maxRestarts*/ 0)),
60+
std::make_unique<BackoffTimerHandle>(BackoffTimerHandleInterface::BackoffTimerHandleOptions{
61+
.listener = this,
62+
.baseTimeoutMs = sctpOptions.delayedAckMaxTimeoutMs,
63+
.backoffAlgorithm = BackoffTimerHandleInterface::BackoffAlgorithm::EXPONENTIAL,
64+
.maxBackoffTimeoutMs = std::nullopt,
65+
.maxRestarts = 0 })),
6666
rto(sctpOptions),
6767
txErrorCounter(sctpOptions),
6868
// TODO: SCTP: Implement.

worker/src/handles/BackoffTimerHandle.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88

99
/* Instance methods. */
1010

11-
BackoffTimerHandle::BackoffTimerHandle(
12-
BackoffTimerHandleInterface::Listener* listener,
13-
uint64_t baseTimeoutMs,
14-
BackoffAlgorithm backoffAlgorithm,
15-
std::optional<uint64_t> maxBackoffTimeoutMs,
16-
std::optional<size_t> maxRestarts)
17-
: listener(listener),
18-
baseTimeoutMs(baseTimeoutMs),
19-
backoffAlgorithm(backoffAlgorithm),
20-
maxBackoffTimeoutMs(maxBackoffTimeoutMs),
21-
maxRestarts(maxRestarts)
11+
BackoffTimerHandle::BackoffTimerHandle(const BackoffTimerHandleOptions& options)
12+
: listener(options.listener),
13+
baseTimeoutMs(options.baseTimeoutMs),
14+
backoffAlgorithm(options.backoffAlgorithm),
15+
maxBackoffTimeoutMs(options.maxBackoffTimeoutMs),
16+
maxRestarts(options.maxRestarts)
2217
{
2318
MS_TRACE();
2419

0 commit comments

Comments
 (0)