UDT: Fix invalid initial packet sequence number when random number was a signed negative int

This commit is contained in:
Kleissner
2021-11-04 22:35:57 +01:00
parent d0b5db9437
commit 1573ded639
2 changed files with 8 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
package packet
import "math/rand"
// PacketID represents a UDT packet ID sequence
type PacketID struct {
Seq uint32
@@ -28,3 +30,8 @@ func (p PacketID) BlindDiff(rhs PacketID) int32 {
}
return int32(result)
}
// RandomPacketSequence returns a random packet sequence
func RandomPacketSequence() PacketID {
return PacketID{rand.Uint32() & 0x7FFFFFFF}
}

View File

@@ -2,7 +2,6 @@ package udt
import (
"errors"
"math/rand"
"net"
"sync"
"syscall"
@@ -420,7 +419,7 @@ func newSocket(m *multiplexer, config *Config, sockID uint32, isServer bool, isD
maxFlowWinSize: maxFlowWinSize,
isDatagram: isDatagram,
sockID: sockID,
initPktSeq: packet.PacketID{Seq: rand.Uint32()},
initPktSeq: packet.RandomPacketSequence(),
messageIn: make(chan []byte, 256),
messageOut: make(chan sendMessage, 256),
recvEvent: make(chan recvPktEvent, 256),