/
closed_connection.go
49 lines (42 loc) · 1.25 KB
/
closed_connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package scenarii
import (
qt "github.com/QUIC-Tracker/quic-tracker"
"time"
)
const (
CCS_TLSHandshakeFailed = 1
CCS_NoPacketsReceived = 2
CSS_APacketWasReceived = 3
)
type ClosedConnectionScenario struct {
AbstractScenario
}
func NewClosedConnectionScenario() *ClosedConnectionScenario {
return &ClosedConnectionScenario{AbstractScenario{name: "closed_connection", version: 1}}
}
func (s *ClosedConnectionScenario) Run(conn *qt.Connection, trace *qt.Trace, preferredPath string, debug bool) {
connAgents := s.CompleteHandshake(conn, trace, CCS_TLSHandshakeFailed)
if connAgents == nil {
return
}
<-time.NewTimer(time.Duration(2 * conn.SmoothedRTT) * time.Microsecond).C
conn.CloseConnection(false, 0, "")
<-time.NewTimer(time.Duration(8 * conn.SmoothedRTT) * time.Microsecond).C
incomingPackets := conn.IncomingPackets.RegisterNewChan(1000)
for i := 0; i < 3; i++ {
ping := qt.PingFrame(0)
conn.FrameQueue.Submit(qt.QueuedFrame{&ping, qt.EncryptionLevel1RTT})
<-time.NewTimer(time.Duration(3 * conn.SmoothedRTT) * time.Microsecond).C
}
trace.ErrorCode = CCS_NoPacketsReceived
for {
select {
case <-incomingPackets:
trace.ErrorCode = CSS_APacketWasReceived
case <-conn.ConnectionClosed:
return
case <-s.Timeout():
return
}
}
}