Files
core/udt/packet/pktseq.go
Kleissner 75e3d9a42e Initial UDT implementation for file transfer.
New function RequestFileTransferUDT to download files from other peers.
2021-10-24 04:26:30 +02:00

32 lines
738 B
Go

package packet
// PacketID represents a UDT packet ID sequence
type PacketID struct {
Seq uint32
}
// Incr increments this packet ID
func (p *PacketID) Incr() {
p.Seq = (p.Seq + 1) & 0x7FFFFFFF
}
// Decr decrements this packet ID
func (p *PacketID) Decr() {
p.Seq = (p.Seq - 1) & 0x7FFFFFFF
}
// Add returns a packet ID after adding the specified offset
func (p PacketID) Add(off int32) PacketID {
newSeq := (p.Seq + 1) & 0x7FFFFFFF
return PacketID{newSeq}
}
// BlindDiff attempts to return the difference after subtracting the argument from itself
func (p PacketID) BlindDiff(rhs PacketID) int32 {
result := (p.Seq - rhs.Seq) & 0x7FFFFFFF
if result&0x40000000 != 0 {
result = result | 0x80000000
}
return int32(result)
}