summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/net/dcsctp/public/dcsctp_options.h
blob: 4511bed4a4a85b3f5ec3b9cbdc506142225130f6 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
#ifndef NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_
#define NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_

#include <stddef.h>
#include <stdint.h>

#include "absl/types/optional.h"
#include "net/dcsctp/public/types.h"

namespace dcsctp {
struct DcSctpOptions {
  // The largest safe SCTP packet. Starting from the minimum guaranteed MTU
  // value of 1280 for IPv6 (which may not support fragmentation), take off 85
  // bytes for DTLS/TURN/TCP/IP and ciphertext overhead.
  //
  // Additionally, it's possible that TURN adds an additional 4 bytes of
  // overhead after a channel has been established, so an additional 4 bytes is
  // subtracted
  //
  // 1280 IPV6 MTU
  //  -40 IPV6 header
  //   -8 UDP
  //  -24 GCM Cipher
  //  -13 DTLS record header
  //   -4 TURN ChannelData
  // = 1191 bytes.
  static constexpr size_t kMaxSafeMTUSize = 1191;

  // The local port for which the socket is supposed to be bound to. Incoming
  // packets will be verified that they are sent to this port number and all
  // outgoing packets will have this port number as source port.
  int local_port = 5000;

  // The remote port to send packets to. All outgoing packets will have this
  // port number as destination port.
  int remote_port = 5000;

  // The announced maximum number of incoming streams. Note that this value is
  // constant and can't be currently increased in run-time as "Add Incoming
  // Streams Request" in RFC6525 isn't supported.
  //
  // The socket implementation doesn't have any per-stream fixed costs, which is
  // why the default value is set to be the maximum value.
  uint16_t announced_maximum_incoming_streams = 65535;

  // The announced maximum number of outgoing streams. Note that this value is
  // constant and can't be currently increased in run-time as "Add Outgoing
  // Streams Request" in RFC6525 isn't supported.
  //
  // The socket implementation doesn't have any per-stream fixed costs, which is
  // why the default value is set to be the maximum value.
  uint16_t announced_maximum_outgoing_streams = 65535;

  // Maximum SCTP packet size. The library will limit the size of generated
  // packets to be less than or equal to this number. This does not include any
  // overhead of DTLS, TURN, UDP or IP headers.
  size_t mtu = kMaxSafeMTUSize;

  // The largest allowed message payload to be sent. Messages will be rejected
  // if their payload is larger than this value. Note that this doesn't affect
  // incoming messages, which may larger than this value (but smaller than
  // `max_receiver_window_buffer_size`).
  size_t max_message_size = 256 * 1024;

  // The default stream priority, if not overridden by
  // `SctpSocket::SetStreamPriority`. The default value is selected to be
  // compatible with https://www.w3.org/TR/webrtc-priority/, section 4.2-4.3.
  StreamPriority default_stream_priority = StreamPriority(256);

  // Maximum received window buffer size. This should be a bit larger than the
  // largest sized message you want to be able to receive. This essentially
  // limits the memory usage on the receive side. Note that memory is allocated
  // dynamically, and this represents the maximum amount of buffered data. The
  // actual memory usage of the library will be smaller in normal operation, and
  // will be larger than this due to other allocations and overhead if the
  // buffer is fully utilized.
  size_t max_receiver_window_buffer_size = 5 * 1024 * 1024;

  // Maximum send buffer size. It will not be possible to queue more data than
  // this before sending it.
  size_t max_send_buffer_size = 2'000'000;

  // A threshold that, when the amount of data in the send buffer goes below
  // this value, will trigger `DcSctpCallbacks::OnTotalBufferedAmountLow`.
  size_t total_buffered_amount_low_threshold = 1'800'000;

  // Max allowed RTT value. When the RTT is measured and it's found to be larger
  // than this value, it will be discarded and not used for e.g. any RTO
  // calculation. The default value is an extreme maximum but can be adapted
  // to better match the environment.
  DurationMs rtt_max = DurationMs(60'000);

  // Initial RTO value.
  DurationMs rto_initial = DurationMs(500);

  // Maximum RTO value.
  DurationMs rto_max = DurationMs(60'000);

  // Minimum RTO value. This must be larger than an expected peer delayed ack
  // timeout.
  DurationMs rto_min = DurationMs(400);

  // T1-init timeout.
  DurationMs t1_init_timeout = DurationMs(1000);

  // T1-cookie timeout.
  DurationMs t1_cookie_timeout = DurationMs(1000);

  // T2-shutdown timeout.
  DurationMs t2_shutdown_timeout = DurationMs(1000);

  // For t1-init, t1-cookie, t2-shutdown, t3-rtx, this value - if set - will be
  // the upper bound on how large the exponentially backed off timeout can
  // become. The lower the duration, the faster the connection can recover on
  // transient network issues. Setting this value may require changing
  // `max_retransmissions` and `max_init_retransmits` to ensure that the
  // connection is not closed too quickly.
  absl::optional<DurationMs> max_timer_backoff_duration = absl::nullopt;

  // Hearbeat interval (on idle connections only). Set to zero to disable.
  DurationMs heartbeat_interval = DurationMs(30000);

  // The maximum time when a SACK will be sent from the arrival of an
  // unacknowledged packet. Whatever is smallest of RTO/2 and this will be used.
  DurationMs delayed_ack_max_timeout = DurationMs(200);

  // The minimum limit for the measured RTT variance
  //
  // Setting this below the expected delayed ack timeout (+ margin) of the peer
  // might result in unnecessary retransmissions, as the maximum time it takes
  // to ACK a DATA chunk is typically RTT + ATO (delayed ack timeout), and when
  // the SCTP channel is quite idle, and heartbeats dominate the source of RTT
  // measurement, the RTO would converge with the smoothed RTT (SRTT). The
  // default ATO is 200ms in usrsctp, and a 20ms (10%) margin would include the
  // processing time of received packets and the clock granularity when setting
  // the delayed ack timer on the peer.
  //
  // This is described for TCP in
  // https://datatracker.ietf.org/doc/html/rfc6298#section-4.
  DurationMs min_rtt_variance = DurationMs(220);

  // The initial congestion window size, in number of MTUs.
  // See https://tools.ietf.org/html/rfc4960#section-7.2.1 which defaults at ~3
  // and https://research.google/pubs/pub36640/ which argues for at least ten
  // segments.
  size_t cwnd_mtus_initial = 10;

  // The minimum congestion window size, in number of MTUs, upon detection of
  // packet loss by SACK. Note that if the retransmission timer expires, the
  // congestion window will be as small as one MTU. See
  // https://tools.ietf.org/html/rfc4960#section-7.2.3.
  size_t cwnd_mtus_min = 4;

  // When the congestion window is at or above this number of MTUs, the
  // congestion control algorithm will avoid filling the congestion window
  // fully, if that results in fragmenting large messages into quite small
  // packets. When the congestion window is smaller than this option, it will
  // aim to fill the congestion window as much as it can, even if it results in
  // creating small fragmented packets.
  size_t avoid_fragmentation_cwnd_mtus = 6;

  // The number of packets that may be sent at once. This is limited to avoid
  // bursts that too quickly fill the send buffer. Typically in a a socket in
  // its "slow start" phase (when it sends as much as it can), it will send
  // up to three packets for every SACK received, so the default limit is set
  // just above that, and then mostly applicable for (but not limited to) fast
  // retransmission scenarios.
  int max_burst = 4;

  // Maximum Data Retransmit Attempts (per DATA chunk). Set to absl::nullopt for
  // no limit.
  absl::optional<int> max_retransmissions = 10;

  // Max.Init.Retransmits (https://tools.ietf.org/html/rfc4960#section-15). Set
  // to absl::nullopt for no limit.
  absl::optional<int> max_init_retransmits = 8;

  // RFC3758 Partial Reliability Extension
  bool enable_partial_reliability = true;

  // RFC8260 Stream Schedulers and User Message Interleaving
  bool enable_message_interleaving = false;

  // If RTO should be added to heartbeat_interval
  bool heartbeat_interval_include_rtt = true;

  // Disables SCTP packet crc32 verification. Useful when running with fuzzers.
  bool disable_checksum_verification = false;
};
}  // namespace dcsctp

#endif  // NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_