Skip to content

Commit

Permalink
Shares the RTT estimates through the connection context
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiraux committed Mar 26, 2019
1 parent af63899 commit 089d64d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions agents/handshake_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
. "github.com/QUIC-Tracker/quic-tracker"
"github.com/davecgh/go-spew/spew"
"strings"
"time"
)

type HandshakeStatus struct {
Expand Down Expand Up @@ -45,6 +46,7 @@ func (a *HandshakeAgent) Run(conn *Connection) {

firstInitialReceived := false
tlsCompleted := false
pingTimer := time.NewTimer(0)
var tlsPacket Packet

go func() {
Expand Down Expand Up @@ -89,6 +91,7 @@ func (a *HandshakeAgent) Run(conn *Connection) {
default:
a.HandshakeStatus.Submit(HandshakeStatus{false, p.(Packet), errors.New("received incorrect packet type during handshake")})
}
pingTimer.Reset(time.Duration(conn.SmoothedRTT + conn.RTTVar) * time.Microsecond)
case p := <-outPackets:
if !tlsCompleted {
break
Expand All @@ -115,6 +118,11 @@ func (a *HandshakeAgent) Run(conn *Connection) {
case i := <-socketStatus:
if strings.Contains(i.(error).Error(), "connection refused") {
a.HandshakeStatus.Submit(HandshakeStatus{false, nil , i.(error)})
return
}
case <-pingTimer.C:
if firstInitialReceived {
conn.PreparePacket.Submit(EncryptionLevelBest)
}
case <-conn.ConnectionRestarted:
incPackets = conn.IncomingPackets.RegisterNewChan(1000)
Expand Down
7 changes: 7 additions & 0 deletions agents/rtt_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type RTTAgent struct {
BaseAgent
conn *Connection
MinRTT uint64
LatestRTT uint64
SmoothedRTT uint64
Expand All @@ -25,6 +26,7 @@ type SentPacket struct {

func (a *RTTAgent) Run(conn *Connection) {
a.Init("RTTAgent", conn.OriginalDestinationCID)
a.conn = conn
a.MinRTT = math.MaxUint64

a.SentPackets = map[PNSpace]map[PacketNumber]SentPacket{
Expand Down Expand Up @@ -106,5 +108,10 @@ func (a *RTTAgent) UpdateRTT(ackDelay uint64, ackOnly bool) { // TODO: https://t
a.RTTVar = uint64(0.75 * float64(a.RTTVar) + 0.25 * float64(RTTVarSample))
a.SmoothedRTT = uint64(0.875 * float64(a.SmoothedRTT) + 0.125 * float64(a.LatestRTT))
}

a.conn.MinRTT = a.MinRTT
a.conn.SmoothedRTT = a.SmoothedRTT
a.conn.RTTVar = a.RTTVar

a.Logger.Printf("LatestRTT = %d, MinRTT = %d, SmoothedRTT = %d, RTTVar = %d", a.LatestRTT, a.MinRTT, a.SmoothedRTT, a.RTTVar)
}
4 changes: 4 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ type Connection struct {
LargestPNsReceived map[PNSpace]PacketNumber // Stores the largest PN received
LargestPNsAcknowledged map[PNSpace]PacketNumber // Stores the largest PN we have sent that were acknowledged by the peer

MinRTT uint64
SmoothedRTT uint64
RTTVar uint64

AckQueue map[PNSpace][]PacketNumber // Stores the packet numbers to be acked TODO: This should be a channel actually
Logger *log.Logger
}
Expand Down

0 comments on commit 089d64d

Please sign in to comment.