mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-16 18:37:51 +01:00
UDT: Removing light ACK. This reduces complexity.
This commit is contained in:
@@ -175,11 +175,7 @@ func DecodePacket(data []byte) (p Packet, err error) {
|
||||
case ptKeepalive:
|
||||
p = &KeepAlivePacket{}
|
||||
case ptAck:
|
||||
if len(data) == 20 {
|
||||
p = &LightAckPacket{}
|
||||
} else {
|
||||
p = &AckPacket{}
|
||||
}
|
||||
p = &AckPacket{}
|
||||
case ptNak:
|
||||
p = &NakPacket{}
|
||||
case ptCongestion:
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package packet
|
||||
|
||||
// Structure of packets and functions for writing/reading them
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// LightAckPacket is a UDT variant of the ACK packet for acknowledging received data with minimal information
|
||||
type LightAckPacket struct {
|
||||
ctrlHeader
|
||||
PktSeqHi PacketID // The packet sequence number to which all the previous packets have been received (excluding)
|
||||
}
|
||||
|
||||
// WriteTo writes this packet to the provided buffer, returning the length of the packet
|
||||
func (p *LightAckPacket) WriteTo(buf []byte) (uint, error) {
|
||||
l := len(buf)
|
||||
if l < 20 {
|
||||
return 0, errors.New("lightack packet too small")
|
||||
}
|
||||
|
||||
if _, err := p.writeHdrTo(buf, ptAck, 0); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
endianness.PutUint32(buf[16:20], p.PktSeqHi.Seq)
|
||||
|
||||
return 20, nil
|
||||
}
|
||||
|
||||
func (p *LightAckPacket) readFrom(data []byte) (err error) {
|
||||
l := len(data)
|
||||
if l < 20 {
|
||||
return errors.New("lightack packet too small")
|
||||
}
|
||||
if _, err = p.readHdrFrom(data); err != nil {
|
||||
return err
|
||||
}
|
||||
p.PktSeqHi = PacketID{endianness.Uint32(data[16:20])}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PacketType returns the packetType associated with this packet
|
||||
func (p *LightAckPacket) PacketType() PacketType {
|
||||
return ptAck
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLightAckPacket(t *testing.T) {
|
||||
pkt1 := &LightAckPacket{
|
||||
PktSeqHi: PacketID{Seq: 91},
|
||||
}
|
||||
pkt1.SetHeader(59, 100)
|
||||
testPacket(pkt1, t)
|
||||
}
|
||||
@@ -690,7 +690,7 @@ func (s *udtSocket) readPacket(m *multiplexer, p packet.Packet) {
|
||||
s.readHandshake(m, sp)
|
||||
case *packet.ShutdownPacket: // sent by either peer
|
||||
s.shutdownEvent <- shutdownMessage{sockState: sockStateClosed, permitLinger: s.isServer} // if client tells us done, it is done.
|
||||
case *packet.AckPacket, *packet.LightAckPacket, *packet.NakPacket: // receiver -> sender
|
||||
case *packet.AckPacket, *packet.NakPacket: // receiver -> sender
|
||||
s.sendEvent <- recvPktEvent{pkt: p, now: now}
|
||||
case *packet.UserDefControlPacket:
|
||||
s.cong.onCustomMsg(*sp)
|
||||
|
||||
@@ -131,8 +131,6 @@ func (s *udtSocketSend) goSendEvent() {
|
||||
switch sp := evt.pkt.(type) {
|
||||
case *packet.AckPacket:
|
||||
s.ingestAck(sp, evt.now)
|
||||
case *packet.LightAckPacket:
|
||||
s.ingestLightAck(sp, evt.now)
|
||||
case *packet.NakPacket:
|
||||
s.ingestNak(sp, evt.now)
|
||||
case *packet.CongestionPacket:
|
||||
@@ -365,18 +363,6 @@ func (s *udtSocketSend) sendDataPacket(dp sendPacketEntry, isResend bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// ingestLightAck is called to process a "light" ACK packet
|
||||
func (s *udtSocketSend) ingestLightAck(p *packet.LightAckPacket, now time.Time) {
|
||||
// Update the largest acknowledged sequence number.
|
||||
|
||||
pktSeqHi := p.PktSeqHi
|
||||
diff := pktSeqHi.BlindDiff(s.recvAckSeq)
|
||||
if diff > 0 {
|
||||
s.flowWindowSize += uint(diff)
|
||||
s.recvAckSeq = pktSeqHi
|
||||
}
|
||||
}
|
||||
|
||||
func (s *udtSocketSend) assertValidSentPktID(pktType string, pktSeq packet.PacketID) bool {
|
||||
if s.sendPktSeq.BlindDiff(pktSeq) < 0 {
|
||||
s.shutdownEvent <- shutdownMessage{sockState: sockStateCorrupted, permitLinger: false,
|
||||
|
||||
Reference in New Issue
Block a user