xref: /aosp_15_r20/external/webrtc/net/dcsctp/public/dcsctp_options.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #ifndef NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_
11 #define NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_
12 
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 #include "absl/types/optional.h"
17 #include "net/dcsctp/public/types.h"
18 
19 namespace dcsctp {
20 struct DcSctpOptions {
21   // The largest safe SCTP packet. Starting from the minimum guaranteed MTU
22   // value of 1280 for IPv6 (which may not support fragmentation), take off 85
23   // bytes for DTLS/TURN/TCP/IP and ciphertext overhead.
24   //
25   // Additionally, it's possible that TURN adds an additional 4 bytes of
26   // overhead after a channel has been established, so an additional 4 bytes is
27   // subtracted
28   //
29   // 1280 IPV6 MTU
30   //  -40 IPV6 header
31   //   -8 UDP
32   //  -24 GCM Cipher
33   //  -13 DTLS record header
34   //   -4 TURN ChannelData
35   // = 1191 bytes.
36   static constexpr size_t kMaxSafeMTUSize = 1191;
37 
38   // The local port for which the socket is supposed to be bound to. Incoming
39   // packets will be verified that they are sent to this port number and all
40   // outgoing packets will have this port number as source port.
41   int local_port = 5000;
42 
43   // The remote port to send packets to. All outgoing packets will have this
44   // port number as destination port.
45   int remote_port = 5000;
46 
47   // The announced maximum number of incoming streams. Note that this value is
48   // constant and can't be currently increased in run-time as "Add Incoming
49   // Streams Request" in RFC6525 isn't supported.
50   //
51   // The socket implementation doesn't have any per-stream fixed costs, which is
52   // why the default value is set to be the maximum value.
53   uint16_t announced_maximum_incoming_streams = 65535;
54 
55   // The announced maximum number of outgoing streams. Note that this value is
56   // constant and can't be currently increased in run-time as "Add Outgoing
57   // Streams Request" in RFC6525 isn't supported.
58   //
59   // The socket implementation doesn't have any per-stream fixed costs, which is
60   // why the default value is set to be the maximum value.
61   uint16_t announced_maximum_outgoing_streams = 65535;
62 
63   // Maximum SCTP packet size. The library will limit the size of generated
64   // packets to be less than or equal to this number. This does not include any
65   // overhead of DTLS, TURN, UDP or IP headers.
66   size_t mtu = kMaxSafeMTUSize;
67 
68   // The largest allowed message payload to be sent. Messages will be rejected
69   // if their payload is larger than this value. Note that this doesn't affect
70   // incoming messages, which may larger than this value (but smaller than
71   // `max_receiver_window_buffer_size`).
72   size_t max_message_size = 256 * 1024;
73 
74   // The default stream priority, if not overridden by
75   // `SctpSocket::SetStreamPriority`. The default value is selected to be
76   // compatible with https://www.w3.org/TR/webrtc-priority/, section 4.2-4.3.
77   StreamPriority default_stream_priority = StreamPriority(256);
78 
79   // Maximum received window buffer size. This should be a bit larger than the
80   // largest sized message you want to be able to receive. This essentially
81   // limits the memory usage on the receive side. Note that memory is allocated
82   // dynamically, and this represents the maximum amount of buffered data. The
83   // actual memory usage of the library will be smaller in normal operation, and
84   // will be larger than this due to other allocations and overhead if the
85   // buffer is fully utilized.
86   size_t max_receiver_window_buffer_size = 5 * 1024 * 1024;
87 
88   // Maximum send buffer size. It will not be possible to queue more data than
89   // this before sending it.
90   size_t max_send_buffer_size = 2'000'000;
91 
92   // A threshold that, when the amount of data in the send buffer goes below
93   // this value, will trigger `DcSctpCallbacks::OnTotalBufferedAmountLow`.
94   size_t total_buffered_amount_low_threshold = 1'800'000;
95 
96   // Max allowed RTT value. When the RTT is measured and it's found to be larger
97   // than this value, it will be discarded and not used for e.g. any RTO
98   // calculation. The default value is an extreme maximum but can be adapted
99   // to better match the environment.
100   DurationMs rtt_max = DurationMs(60'000);
101 
102   // Initial RTO value.
103   DurationMs rto_initial = DurationMs(500);
104 
105   // Maximum RTO value.
106   DurationMs rto_max = DurationMs(60'000);
107 
108   // Minimum RTO value. This must be larger than an expected peer delayed ack
109   // timeout.
110   DurationMs rto_min = DurationMs(400);
111 
112   // T1-init timeout.
113   DurationMs t1_init_timeout = DurationMs(1000);
114 
115   // T1-cookie timeout.
116   DurationMs t1_cookie_timeout = DurationMs(1000);
117 
118   // T2-shutdown timeout.
119   DurationMs t2_shutdown_timeout = DurationMs(1000);
120 
121   // For t1-init, t1-cookie, t2-shutdown, t3-rtx, this value - if set - will be
122   // the upper bound on how large the exponentially backed off timeout can
123   // become. The lower the duration, the faster the connection can recover on
124   // transient network issues. Setting this value may require changing
125   // `max_retransmissions` and `max_init_retransmits` to ensure that the
126   // connection is not closed too quickly.
127   absl::optional<DurationMs> max_timer_backoff_duration = absl::nullopt;
128 
129   // Hearbeat interval (on idle connections only). Set to zero to disable.
130   DurationMs heartbeat_interval = DurationMs(30000);
131 
132   // The maximum time when a SACK will be sent from the arrival of an
133   // unacknowledged packet. Whatever is smallest of RTO/2 and this will be used.
134   DurationMs delayed_ack_max_timeout = DurationMs(200);
135 
136   // The minimum limit for the measured RTT variance
137   //
138   // Setting this below the expected delayed ack timeout (+ margin) of the peer
139   // might result in unnecessary retransmissions, as the maximum time it takes
140   // to ACK a DATA chunk is typically RTT + ATO (delayed ack timeout), and when
141   // the SCTP channel is quite idle, and heartbeats dominate the source of RTT
142   // measurement, the RTO would converge with the smoothed RTT (SRTT). The
143   // default ATO is 200ms in usrsctp, and a 20ms (10%) margin would include the
144   // processing time of received packets and the clock granularity when setting
145   // the delayed ack timer on the peer.
146   //
147   // This is described for TCP in
148   // https://datatracker.ietf.org/doc/html/rfc6298#section-4.
149   DurationMs min_rtt_variance = DurationMs(220);
150 
151   // The initial congestion window size, in number of MTUs.
152   // See https://tools.ietf.org/html/rfc4960#section-7.2.1 which defaults at ~3
153   // and https://research.google/pubs/pub36640/ which argues for at least ten
154   // segments.
155   size_t cwnd_mtus_initial = 10;
156 
157   // The minimum congestion window size, in number of MTUs, upon detection of
158   // packet loss by SACK. Note that if the retransmission timer expires, the
159   // congestion window will be as small as one MTU. See
160   // https://tools.ietf.org/html/rfc4960#section-7.2.3.
161   size_t cwnd_mtus_min = 4;
162 
163   // When the congestion window is at or above this number of MTUs, the
164   // congestion control algorithm will avoid filling the congestion window
165   // fully, if that results in fragmenting large messages into quite small
166   // packets. When the congestion window is smaller than this option, it will
167   // aim to fill the congestion window as much as it can, even if it results in
168   // creating small fragmented packets.
169   size_t avoid_fragmentation_cwnd_mtus = 6;
170 
171   // The number of packets that may be sent at once. This is limited to avoid
172   // bursts that too quickly fill the send buffer. Typically in a a socket in
173   // its "slow start" phase (when it sends as much as it can), it will send
174   // up to three packets for every SACK received, so the default limit is set
175   // just above that, and then mostly applicable for (but not limited to) fast
176   // retransmission scenarios.
177   int max_burst = 4;
178 
179   // Maximum Data Retransmit Attempts (per DATA chunk). Set to absl::nullopt for
180   // no limit.
181   absl::optional<int> max_retransmissions = 10;
182 
183   // Max.Init.Retransmits (https://tools.ietf.org/html/rfc4960#section-15). Set
184   // to absl::nullopt for no limit.
185   absl::optional<int> max_init_retransmits = 8;
186 
187   // RFC3758 Partial Reliability Extension
188   bool enable_partial_reliability = true;
189 
190   // RFC8260 Stream Schedulers and User Message Interleaving
191   bool enable_message_interleaving = false;
192 
193   // If RTO should be added to heartbeat_interval
194   bool heartbeat_interval_include_rtt = true;
195 
196   // Disables SCTP packet crc32 verification. Useful when running with fuzzers.
197   bool disable_checksum_verification = false;
198 };
199 }  // namespace dcsctp
200 
201 #endif  // NET_DCSCTP_PUBLIC_DCSCTP_OPTIONS_H_
202