Debian Codegraph @

association_rack_options.go

raw
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package sctp
5
6 import (
7 "time"
8 )
9
10 // rackSettings holds the optional RACK related settings for an association.
11 type rackSettings struct {
12 // Optional: size of window used to determine minimum RTT for RACK (defaults to 30s)
13 rackMinRTTWnd *windowedMin
14
15 // Optional: cap the minimum reordering window: 0 = use quarter-RTT
16 rackReoWndFloor time.Duration
17
18 // Optional: receiver worst-case delayed-ACK for PTO when only one packet is in flight
19 rackWCDelAck time.Duration
20 }
21
22 // AssociationRACKOption represents a function that can be used to configure an Association's RACK options.
23 type AssociationRACKOption func(*rackSettings) error
24
25 // RACK config options //
26
27 // WithRackMinRTTWnd sets the length of the local minimum window used to determine the minRTT.
28 // By default this is 30 seconds.
29 func WithRackMinRTTWnd(rackMinRTTWnd time.Duration) AssociationRACKOption {
30 return func(a *rackSettings) error {
31 if rackMinRTTWnd <= 0 {
32 return errInvalidRackMinRTTWnd
33 }
34 a.rackMinRTTWnd = newWindowedMin(rackMinRTTWnd)
35
36 return nil
37 }
38 }
39
40 // WithRackReoWndFloor sets the RACK reordering window floor for the association.
41 // By default this is 0.
42 func WithRackReoWndFloor(rackReoWndFloor time.Duration) AssociationRACKOption {
43 return func(a *rackSettings) error {
44 if rackReoWndFloor < 0 {
45 return errInvalidRackReoWndFloor
46 }
47 a.rackReoWndFloor = rackReoWndFloor
48
49 return nil
50 }
51 }
52
53 // WithRackWCDelAck sets the receiver worst-case delayed-ACK for PTO when only 1 packet is in flight.
54 // By default this is 200 ms.
55 func WithRackWCDelAck(rackWCDelAck time.Duration) AssociationRACKOption {
56 return func(a *rackSettings) error {
57 if rackWCDelAck <= 0 {
58 return errInvalidRackWcDelAck
59 }
60 a.rackWCDelAck = rackWCDelAck
61
62 return nil
63 }
64 }
65
66 // WithRACKOptions configures optional RACK settings using the above options.
67 // This also creates the new windowedMin slice used for tracking the minRTT.
68 func WithRACKOptions(opts ...AssociationRACKOption) AssociationOption {
69 return sharedOption(func(c *Config) error {
70 cfg := c.rack
71 for _, opt := range opts {
72 if opt == nil {
73 continue
74 }
75
76 if err := opt(&cfg); err != nil {
77 return err
78 }
79 }
80
81 c.rack = cfg
82
83 return nil
84 })
85 }