Skip to content

Commit

Permalink
Don't use active_connection_id 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiraux committed May 4, 2020
1 parent c59fc9e commit 9a51e69
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions scenarii/connection_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scenarii

import (
qt "github.com/QUIC-Tracker/quic-tracker"
"math/rand"

"time"
)
Expand All @@ -11,6 +12,7 @@ const (
CM_UDPConnectionFailed = 2
CM_HostDidNotMigrate = 3
CM_HostDidNotValidateNewPath = 4
CM_TooManyCIDs = 5
)

type ConnectionMigrationScenario struct {
Expand All @@ -21,16 +23,46 @@ func NewConnectionMigrationScenario() *ConnectionMigrationScenario {
return &ConnectionMigrationScenario{AbstractScenario{name: "connection_migration", version: 1}}
}
func (s *ConnectionMigrationScenario) Run(conn *qt.Connection, trace *qt.Trace, preferredPath string, debug bool) {
conn.TLSTPHandler.ActiveConnectionIdLimit = 0
conn.TLSTPHandler.ActiveConnectionIdLimit = 1
connAgents := s.CompleteHandshake(conn, trace, CM_TLSHandshakeFailed)
if connAgents == nil {
return
}
defer connAgents.CloseConnection(false, 0, "")

<-time.NewTimer(3 * time.Second).C // Wait some time before migrating
incPackets := conn.IncomingPackets.RegisterNewChan(1000)
t := time.NewTimer(3 * time.Second)

scid := make([]byte, 8)
var resetToken [16]byte
rand.Read(scid)
rand.Read(resetToken[:])
conn.FrameQueue.Submit(qt.QueuedFrame{&qt.NewConnectionIdFrame{1, 0, uint8(len(scid)), scid, resetToken}, qt.EncryptionLevelBest})

var ncid []byte
wait:
for {
select {
case i := <-incPackets:
p := i.(qt.Packet)
if fp, ok := p.(qt.Framer); ok && fp.Header().PacketType() == qt.ShortHeaderPacket && fp.Contains(qt.NewConnectionIdType) {
ncids := fp.GetAll(qt.NewConnectionIdType)
if len(ncids) > int(conn.TLSTPHandler.ActiveConnectionIdLimit) {
trace.MarkError(CM_TooManyCIDs, "", p)
return
}
ncid = ncids[0].(*qt.NewConnectionIdFrame).ConnectionId
}
case <-t.C:
conn.IncomingPackets.Unregister(incPackets)
incPackets = nil
break wait
}
}

connAgents.Stop("SocketAgent", "SendingAgent")
conn.DestinationCID = ncid
conn.SourceCID = scid

newUdpConn, err := qt.EstablishUDPConnection(conn.Host)
if err != nil {
Expand All @@ -45,7 +77,7 @@ func (s *ConnectionMigrationScenario) Run(conn *qt.Connection, trace *qt.Trace,
connAgents.Get("SendingAgent").Run(conn)
conn.EncryptionLevels.Submit(qt.DirectionalEncryptionLevel{EncryptionLevel: qt.EncryptionLevel1RTT, Available: true})

incPackets := conn.IncomingPackets.RegisterNewChan(1000)
incPackets = conn.IncomingPackets.RegisterNewChan(1000)

responseChan := connAgents.AddHTTPAgent().SendRequest(preferredPath, "GET", trace.Host, nil)
trace.ErrorCode = CM_HostDidNotMigrate // Assume it until proven wrong
Expand Down

0 comments on commit 9a51e69

Please sign in to comment.