mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
UDT: Fix invalid initial packet sequence number when random number was a signed negative int
This commit is contained in:
@@ -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}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user