simplified receivedpacket implementation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jake Hillion 2021-02-22 15:53:16 +00:00
parent c9d68d4d2f
commit d0a23a38cb
5 changed files with 25 additions and 40 deletions

View File

@ -4,14 +4,11 @@ import "time"
type Congestion interface {
Sequence() uint32
ReceivedPacket(seq uint32)
ReceivedAck(uint32)
NextAck() uint32
ReceivedNack(uint32)
NextNack() uint32
ReceivedPacket(seq, nack, ack uint32)
AwaitEarlyUpdate(keepalive time.Duration) uint32
Reset()
}

View File

@ -80,8 +80,24 @@ func (c *NewReno) Reset() {
c.hasAcked = false
}
func (c *NewReno) ReceivedPacket(seq, nack, ack uint32) {
c.receivedSequence(seq)
c.receivedNack(nack)
c.receivedAck(ack)
}
func (c *NewReno) receivedSequence(seq uint32) {
c.inboundTimes[seq] = time.Now()
c.acksToSendLock.Lock()
c.acksToSend.Insert(seq)
c.acksToSendLock.Unlock()
c.updateAckNack()
}
// It is assumed that ReceivedAck will only be called by one thread
func (c *NewReno) ReceivedAck(ack uint32) {
func (c *NewReno) receivedAck(ack uint32) {
c.outboundTimesLock.Lock()
defer c.outboundTimesLock.Unlock()
@ -120,7 +136,7 @@ func (c *NewReno) ReceivedAck(ack uint32) {
}
// It is assumed that ReceivedNack will only be called by one thread
func (c *NewReno) ReceivedNack(nack uint32) {
func (c *NewReno) receivedNack(nack uint32) {
log.Printf("nack received for %d", nack)
// TODO : Check for freshness
@ -132,18 +148,6 @@ func (c *NewReno) ReceivedNack(nack uint32) {
}
}
func (c *NewReno) ReceivedPacket(seq uint32) {
log.Printf("seq received for %d", seq)
c.inboundTimes[seq] = time.Now()
c.acksToSendLock.Lock()
c.acksToSend.Insert(seq)
c.acksToSendLock.Unlock()
c.updateAckNack()
}
func (c *NewReno) updateAckNack() {
c.acksToSendLock.Lock()
defer c.acksToSendLock.Unlock()

View File

@ -61,9 +61,7 @@ func (n *newRenoTest) RunSideA(ctx context.Context) {
case <-ctx.Done():
return
case p := <-n.aInbound:
n.sideA.ReceivedPacket(p.seq)
n.sideA.ReceivedAck(p.ack)
n.sideA.ReceivedNack(p.nack)
n.sideA.ReceivedPacket(p.seq, p.nack, p.ack)
}
}
}()
@ -94,9 +92,7 @@ func (n *newRenoTest) RunSideB(ctx context.Context) {
case <-ctx.Done():
return
case p := <-n.bInbound:
n.sideB.ReceivedPacket(p.seq)
n.sideB.ReceivedAck(p.ack)
n.sideB.ReceivedNack(p.nack)
n.sideB.ReceivedPacket(p.seq, p.nack, p.ack)
}
}
}()

View File

@ -34,9 +34,7 @@ func (c *None) String() string {
return fmt.Sprintf("{None}")
}
func (c *None) ReceivedPacket(uint32) {}
func (c *None) ReceivedAck(uint32) {}
func (c *None) ReceivedNack(uint32) {}
func (c *None) ReceivedPacket(seq, nack, ack uint32) {}
func (c *None) Reset() {}
func (c *None) NextNack() uint32 { return 0 }
func (c *None) NextAck() uint32 { return 0 }

View File

@ -217,18 +217,8 @@ func (f *Flow) produceInternal(v proxy.MacVerifier, mustReturn bool) (proxy.Pack
return nil, err
}
// schedule an ack for this sequence number
if p.seq != 0 {
f.congestion.ReceivedPacket(p.seq)
}
// adjust our sending congestion control based on their acks
if p.ack != 0 {
f.congestion.ReceivedAck(p.ack)
}
// adjust our sending congestion control based on their nacks
if p.nack != 0 {
f.congestion.ReceivedNack(p.nack)
}
// adjust congestion control based on this packet's congestion header
f.congestion.ReceivedPacket(p.seq, p.nack, p.ack)
// 12 bytes for header + the MAC + a timestamp
if len(b) == 12+f.v.CodeLength()+8 {