status-go/vendor/github.com/pion/sctp/payload_queue.go

74 lines
1.6 KiB
Go
Raw Normal View History

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 {
chunks *queue[*chunkPayloadData]
nBytes int
2022-03-10 09:44:48 +00:00
}
func newPayloadQueue() *payloadQueue {
return &payloadQueue{chunks: newQueue[*chunkPayloadData](128)}
2022-03-10 09:44:48 +00:00
}
func (q *payloadQueue) pushNoCheck(p *chunkPayloadData) {
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) {
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) {
length := q.chunks.Len()
if length == 0 {
return nil, false
2022-03-10 09:44:48 +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
}
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
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() {
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 {
return q.chunks.Len()
2022-03-10 09:44:48 +00:00
}