Skip to content

Commit

Permalink
Adds a spin bit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiraux committed Mar 23, 2019
1 parent 327c542 commit b215436
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
5 changes: 4 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ type Connection struct {

Tls *pigotls.Connection
TLSTPHandler *TLSTransportParameterHandler
KeyPhaseIndex uint

KeyPhaseIndex uint
SpinBit SpinBit
LastSpinNumber PacketNumber

CryptoStates map[EncryptionLevel]*CryptoState

Expand Down
10 changes: 10 additions & 0 deletions headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (t PacketType) PNSpace() PNSpace {
}

type ShortHeader struct {
SpinBit SpinBit
KeyPhase KeyPhaseBit
DestinationCID ConnectionID
truncatedPN TruncatedPN
Expand All @@ -158,6 +159,9 @@ func (h *ShortHeader) Encode() []byte {
buffer := new(bytes.Buffer)
var typeByte uint8
typeByte |= 0x40
if h.SpinBit == SpinValueOne {
typeByte |= 0x20
}
if h.KeyPhase == KeyPhaseOne {
typeByte |= 0x04
}
Expand All @@ -177,6 +181,7 @@ func (h *ShortHeader) HeaderLength() int { return 1 + len(h.
func ReadShortHeader(buffer *bytes.Reader, conn *Connection) *ShortHeader {
h := new(ShortHeader)
typeByte, _ := buffer.ReadByte()
h.SpinBit = (typeByte & 0x20) == 0x20
h.KeyPhase = (typeByte & 0x04) == 0x04

h.DestinationCID = make([]byte, len(conn.SourceCID))
Expand All @@ -187,6 +192,7 @@ func ReadShortHeader(buffer *bytes.Reader, conn *Connection) *ShortHeader {
}
func NewShortHeader(conn *Connection) *ShortHeader {
h := new(ShortHeader)
h.SpinBit = conn.SpinBit
h.KeyPhase = conn.KeyPhaseIndex % 2 == 1
h.DestinationCID = conn.DestinationCID
h.packetNumber = conn.nextPacketNumber(PNSpaceAppData)
Expand All @@ -197,3 +203,7 @@ func NewShortHeader(conn *Connection) *ShortHeader {
type KeyPhaseBit bool
const KeyPhaseZero KeyPhaseBit = false
const KeyPhaseOne KeyPhaseBit = true

type SpinBit bool
const SpinValueZero SpinBit = false
const SpinValueOne SpinBit = true
1 change: 1 addition & 0 deletions scenarii/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ func GetAllScenarii() map[string]Scenario {
"http3_encoder_stream": NewHTTP3EncoderStreamScenario(),
"http3_uni_streams_limits": NewHTTP3UniStreamsLimitsScenario(),
"http3_reserved_frames": NewHTTP3ReservedFramesScenario(),
"spin_bit": NewSpinBitScenario(),
}
}
62 changes: 62 additions & 0 deletions scenarii/spin_bit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package scenarii

import (
. "github.com/QUIC-Tracker/quic-tracker"
)

const (
SB_TLSHandshakeFailed = 1
SB_DoesNotSpin = 2
)

type SpinBitScenario struct {
AbstractScenario
}

func NewSpinBitScenario() *SpinBitScenario {
return &SpinBitScenario{AbstractScenario{name: "spin_bit", version: 1, ipv6: false}}
}
func (s *SpinBitScenario) Run(conn *Connection, trace *Trace, preferredPath string, debug bool) {
connAgents := s.CompleteHandshake(conn, trace, SB_TLSHandshakeFailed)
if connAgents == nil {
return
}
defer connAgents.CloseConnection(false, 0, "")

incomingPackets := conn.IncomingPackets.RegisterNewChan(1000)

conn.SendHTTP09GETRequest(preferredPath, 0)

var lastServerSpin SpinBit
spins := 0

forLoop:
for {
select {
case i := <-incomingPackets:
switch p := i.(type) {
case *ProtectedPacket:
hdr := p.Header().(*ShortHeader)
if hdr.PacketNumber() > conn.LastSpinNumber {
if hdr.SpinBit != lastServerSpin {
lastServerSpin = hdr.SpinBit
spins++
}
conn.SpinBit = !hdr.SpinBit
conn.LastSpinNumber = hdr.PacketNumber()
}
if conn.Streams.Get(0).ReadClosed && !conn.Streams.Get(4).WriteClosed {
conn.SendHTTP09GETRequest(preferredPath, 4)
}
}
case <-conn.ConnectionClosed:
break forLoop
case <-s.Timeout():
break forLoop
}
}

if spins <= 1 {
trace.ErrorCode = SB_DoesNotSpin
}
}

0 comments on commit b215436

Please sign in to comment.