-
Notifications
You must be signed in to change notification settings - Fork 16
/
padding.go
65 lines (55 loc) · 1.74 KB
/
padding.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package scenarii
import (
qt "github.com/QUIC-Tracker/quic-tracker"
"github.com/QUIC-Tracker/quic-tracker/agents"
. "github.com/QUIC-Tracker/quic-tracker/lib"
)
const (
P_VNDidNotComplete = 1
P_ReceivedSmth = 2
)
type PaddingScenario struct {
AbstractScenario
}
func NewPaddingScenario() *PaddingScenario {
return &PaddingScenario{AbstractScenario{name: "padding", version: 1}}
}
func (s *PaddingScenario) Run(conn *qt.Connection, trace *qt.Trace, preferredPath string, debug bool) {
connAgents := agents.AttachAgentsToConnection(conn, agents.GetDefaultAgents()...)
defer connAgents.StopAll()
sendEmptyInitialPacket := func() {
var initialLength int
if conn.UseIPv6 {
initialLength = qt.MinimumInitialLengthv6
} else {
initialLength = qt.MinimumInitialLength
}
initialPacket := qt.NewInitialPacket(conn)
payloadLen := len(initialPacket.EncodePayload())
paddingLength := initialLength - (len(initialPacket.Header().Encode()) + int(VarIntLen(uint64(payloadLen))) + payloadLen + conn.CryptoState(qt.EncryptionLevelInitial).Write.Overhead())
for i := 0; i < paddingLength; i++ {
initialPacket.Frames = append(initialPacket.Frames, new(qt.PaddingFrame))
}
conn.DoSendPacket(initialPacket, qt.EncryptionLevelInitial)
}
incPackets := conn.IncomingPackets.RegisterNewChan(1000)
sendEmptyInitialPacket()
select {
case i := <-incPackets:
packet := i.(qt.Packet)
if vn, ok := packet.(*qt.VersionNegotiationPacket); ok {
if err := conn.ProcessVersionNegotation(vn); err != nil {
trace.MarkError(P_VNDidNotComplete, err.Error(), vn)
return
}
sendEmptyInitialPacket()
} else {
trace.MarkError(P_ReceivedSmth, "", packet)
s.Finished()
}
case <-conn.ConnectionClosed:
return
case <-s.Timeout():
return
}
}