removed cc reset
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Jake Hillion 2021-02-22 16:28:55 +00:00
parent d0a23a38cb
commit 87c0b57502
3 changed files with 51 additions and 61 deletions

View File

@ -10,5 +10,4 @@ type Congestion interface {
ReceivedPacket(seq, nack, ack uint32)
AwaitEarlyUpdate(keepalive time.Duration) uint32
Reset()
}

View File

@ -11,6 +11,7 @@ import (
)
const RttExponentialFactor = 0.1
const RttLossDelay = 1.5
type NewReno struct {
sequence chan uint32
@ -71,21 +72,61 @@ func NewNewReno() *NewReno {
return &c
}
func (c *NewReno) Reset() {
c.outboundTimes = make(map[uint32]time.Time)
c.inboundTimes = make(map[uint32]time.Time)
c.windowSize = 8
c.rtt = (1 * time.Millisecond).Seconds()
c.slowStart = true
c.hasAcked = false
}
func (c *NewReno) ReceivedPacket(seq, nack, ack uint32) {
c.receivedSequence(seq)
c.receivedNack(nack)
c.receivedAck(ack)
}
func (c *NewReno) Sequence() uint32 {
c.outboundTimesLock.Lock()
defer c.outboundTimesLock.Unlock()
for c.inFlight >= c.windowSize {
<-c.ackNotifier
}
atomic.AddInt32(&c.inFlight, 1)
s := <-c.sequence
n := time.Now()
c.lastSent = n
c.outboundTimes[s] = n
return s
}
func (c *NewReno) NextAck() uint32 {
a := c.ack
c.lastAck = a
return a
}
func (c *NewReno) NextNack() uint32 {
n := c.nack
c.lastNack = n
return n
}
func (c *NewReno) AwaitEarlyUpdate(keepalive time.Duration) uint32 {
for {
rtt := time.Duration(math.Round(c.rtt) * float64(time.Second))
time.Sleep(rtt)
c.updateAckNack()
// CASE 1: waiting ACKs or NACKs and no message sent in the last RTT
if ((c.lastAck != c.ack) || (c.lastNack != c.nack)) && time.Now().After(c.lastSent.Add(rtt)) {
return 0
}
// CASE 3: No message sent within the keepalive time
if keepalive != 0 && time.Now().After(c.lastSent.Add(keepalive)) {
return c.Sequence()
}
}
}
func (c *NewReno) receivedSequence(seq uint32) {
c.inboundTimes[seq] = time.Now()
@ -184,52 +225,3 @@ func (c *NewReno) updateAckNack() {
atomic.StoreUint32(&c.ack, ack)
}
func (c *NewReno) Sequence() uint32 {
c.outboundTimesLock.Lock()
defer c.outboundTimesLock.Unlock()
for c.inFlight >= c.windowSize {
<-c.ackNotifier
}
atomic.AddInt32(&c.inFlight, 1)
s := <-c.sequence
n := time.Now()
c.lastSent = n
c.outboundTimes[s] = n
return s
}
func (c *NewReno) NextAck() uint32 {
a := c.ack
c.lastAck = a
return a
}
func (c *NewReno) NextNack() uint32 {
n := c.nack
c.lastNack = n
return n
}
func (c *NewReno) AwaitEarlyUpdate(keepalive time.Duration) uint32 {
for {
rtt := time.Duration(math.Round(c.rtt) * float64(time.Second))
time.Sleep(rtt)
c.updateAckNack()
// CASE 1: waiting ACKs or NACKs and no message sent in the last RTT
if ((c.lastAck != c.ack) || (c.lastNack != c.nack)) && time.Now().After(c.lastSent.Add(rtt)) {
return 0
}
// CASE 3: No message sent within the keepalive time
if keepalive != 0 && time.Now().After(c.lastSent.Add(keepalive)) {
return c.Sequence()
}
}
}

View File

@ -34,8 +34,7 @@ func (c *None) String() string {
return fmt.Sprintf("{None}")
}
func (c *None) ReceivedPacket(seq, nack, ack uint32) {}
func (c *None) Reset() {}
func (c *None) ReceivedPacket(uint32, uint32, uint32) {}
func (c *None) NextNack() uint32 { return 0 }
func (c *None) NextAck() uint32 { return 0 }
func (c *None) AwaitEarlyUpdate(time.Duration) uint32 { select {} }