This commit is contained in:
Sky Johnson 2025-07-22 07:46:52 -05:00
parent 5b6a4ff114
commit a36687c5b2
2 changed files with 5 additions and 14 deletions

View File

@ -95,10 +95,7 @@ func (rq *RetransmitQueue) GetExpired() []*RetransmitEntry {
// calculateTimeout computes timeout with exponential backoff // calculateTimeout computes timeout with exponential backoff
func (rq *RetransmitQueue) calculateTimeout(attempts int) time.Duration { func (rq *RetransmitQueue) calculateTimeout(attempts int) time.Duration {
timeout := rq.baseTimeout * time.Duration(attempts*attempts) // Quadratic backoff timeout := min(rq.baseTimeout*time.Duration(attempts*attempts), rq.maxTimeout) // Quadratic backoff
if timeout > rq.maxTimeout {
timeout = rq.maxTimeout
}
return timeout return timeout
} }
@ -169,10 +166,7 @@ func (fm *FragmentManager) FragmentPacket(data []byte, startSeq uint16) []*Proto
seq := startSeq seq := startSeq
for offset := 0; offset < len(data); offset += chunkSize { for offset := 0; offset < len(data); offset += chunkSize {
end := offset + chunkSize end := min(offset+chunkSize, len(data))
if end > len(data) {
end = len(data)
}
var fragmentData []byte var fragmentData []byte
if offset == 0 { if offset == 0 {

View File

@ -390,8 +390,7 @@ func BenchmarkCRC(b *testing.B) {
data[i] = byte(i) data[i] = byte(i)
} }
b.ResetTimer() for b.Loop() {
for range b.N {
CalculateCRC32(data) CalculateCRC32(data)
} }
} }
@ -403,8 +402,7 @@ func BenchmarkCompression(b *testing.B) {
data[i] = byte(i % 256) data[i] = byte(i % 256)
} }
b.ResetTimer() for b.Loop() {
for range b.N {
compressed, _ := Compress(data) compressed, _ := Compress(data)
Decompress(compressed) Decompress(compressed)
} }
@ -420,8 +418,7 @@ func BenchmarkEncryption(b *testing.B) {
data[i] = byte(i) data[i] = byte(i)
} }
b.ResetTimer() for b.Loop() {
for range b.N {
encrypted := crypto.Encrypt(data) encrypted := crypto.Encrypt(data)
crypto.Decrypt(encrypted) crypto.Decrypt(encrypted)
} }