Debian Codegraph @

payload_queue.go

raw
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package sctp
5
6 type payloadQueue struct {
7 chunks *queue[*chunkPayloadData]
8 nBytes int
9 }
10
11 func newPayloadQueue() *payloadQueue {
12 return &payloadQueue{chunks: newQueue[*chunkPayloadData](128)}
13 }
14
15 func (q *payloadQueue) pushNoCheck(p *chunkPayloadData) {
16 q.chunks.PushBack(p)
17 q.nBytes += len(p.userData)
18 }
19
20 // pop pops only if the oldest chunk's TSN matches the given TSN.
21 func (q *payloadQueue) pop(tsn uint32) (*chunkPayloadData, bool) {
22 if q.chunks.Len() > 0 && tsn == q.chunks.Front().tsn {
23 c := q.chunks.PopFront()
24 q.nBytes -= len(c.userData)
25
26 return c, true
27 }
28
29 return nil, false
30 }
31
32 // get returns reference to chunkPayloadData with the given TSN value.
33 func (q *payloadQueue) get(tsn uint32) (*chunkPayloadData, bool) {
34 length := q.chunks.Len()
35 if length == 0 {
36 return nil, false
37 }
38
39 offset := tsn - q.chunks.Front().tsn
40 if int64(offset) >= int64(length) {
41 return nil, false
42 }
43
44 return q.chunks.At(int(offset)), true
45 }
46
47 func (q *payloadQueue) markAsAcked(tsn uint32) int {
48 var nBytesAcked int
49 if c, ok := q.get(tsn); ok {
50 c.acked = true
51 c.retransmit = false
52 nBytesAcked = len(c.userData)
53 q.nBytes -= nBytesAcked
54 c.userData = []byte{}
55 }
56
57 return nBytesAcked
58 }
59
60 func (q *payloadQueue) markAllToRetrasmit() {
61 for i := 0; i < q.chunks.Len(); i++ {
62 c := q.chunks.At(i)
63 if c.acked || c.abandoned() {
64 continue
65 }
66 c.retransmit = true
67 }
68 }
69
70 func (q *payloadQueue) getNumBytes() int {
71 return q.nBytes
72 }
73
74 func (q *payloadQueue) size() int {
75 return q.chunks.Len()
76 }