2024-06-05 20:10:03 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-03-10 09:44:48 +00:00
|
|
|
package sctp
|
|
|
|
|
|
|
|
type payloadQueue struct {
|
2024-10-10 11:33:36 +00:00
|
|
|
chunks *queue[*chunkPayloadData]
|
|
|
|
nBytes int
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newPayloadQueue() *payloadQueue {
|
2024-10-10 11:33:36 +00:00
|
|
|
return &payloadQueue{chunks: newQueue[*chunkPayloadData](128)}
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *payloadQueue) pushNoCheck(p *chunkPayloadData) {
|
2024-10-10 11:33:36 +00:00
|
|
|
q.chunks.PushBack(p)
|
2022-03-10 09:44:48 +00:00
|
|
|
q.nBytes += len(p.userData)
|
|
|
|
}
|
|
|
|
|
|
|
|
// pop pops only if the oldest chunk's TSN matches the given TSN.
|
|
|
|
func (q *payloadQueue) pop(tsn uint32) (*chunkPayloadData, bool) {
|
2024-10-10 11:33:36 +00:00
|
|
|
if q.chunks.Len() > 0 && tsn == q.chunks.Front().tsn {
|
|
|
|
c := q.chunks.PopFront()
|
|
|
|
q.nBytes -= len(c.userData)
|
|
|
|
return c, true
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
// get returns reference to chunkPayloadData with the given TSN value.
|
|
|
|
func (q *payloadQueue) get(tsn uint32) (*chunkPayloadData, bool) {
|
2024-10-10 11:33:36 +00:00
|
|
|
length := q.chunks.Len()
|
|
|
|
if length == 0 {
|
|
|
|
return nil, false
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
2024-10-10 11:33:36 +00:00
|
|
|
head := q.chunks.Front().tsn
|
|
|
|
if tsn < head || int(tsn-head) >= length {
|
|
|
|
return nil, false
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
2024-10-10 11:33:36 +00:00
|
|
|
return q.chunks.At(int(tsn - head)), true
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *payloadQueue) markAsAcked(tsn uint32) int {
|
|
|
|
var nBytesAcked int
|
2024-10-10 11:33:36 +00:00
|
|
|
if c, ok := q.get(tsn); ok {
|
2022-03-10 09:44:48 +00:00
|
|
|
c.acked = true
|
|
|
|
c.retransmit = false
|
|
|
|
nBytesAcked = len(c.userData)
|
|
|
|
q.nBytes -= nBytesAcked
|
|
|
|
c.userData = []byte{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nBytesAcked
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *payloadQueue) markAllToRetrasmit() {
|
2024-10-10 11:33:36 +00:00
|
|
|
for i := 0; i < q.chunks.Len(); i++ {
|
|
|
|
c := q.chunks.At(i)
|
2022-03-10 09:44:48 +00:00
|
|
|
if c.acked || c.abandoned() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
c.retransmit = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *payloadQueue) getNumBytes() int {
|
|
|
|
return q.nBytes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *payloadQueue) size() int {
|
2024-10-10 11:33:36 +00:00
|
|
|
return q.chunks.Len()
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|