This repository has been archived by the owner on Aug 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.go
121 lines (97 loc) · 2.68 KB
/
common.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Maxime Piraux's master's thesis
Copyright (C) 2017-2018 Maxime Piraux
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package masterthesis
import (
"encoding/binary"
"github.com/mpiraux/pigotls"
)
var QuicVersion uint32 = 0xff00000d // See https://tools.ietf.org/html/draft-ietf-quic-transport-08#section-4
var QuicALPNToken = "hq-13" // See https://www.ietf.org/mail-archive/web/quic/current/msg01882.html
const (
MinimumInitialLength = 1252
MinimumInitialLengthv6 = 1232
MaxUDPPayloadSize = 65507
MaximumVersion = 0xff00000d
MinimumVersion = 0xff00000d
)
// errors
const (
ERR_STREAM_ID_ERROR = 0x4
ERR_PROTOCOL_VIOLATION = 0xA
)
type PNSpace int
const (
PNSpaceInitial PNSpace = iota
PNSpaceHandshake
PNSpaceAppData
PNSpaceNoSpace
)
var PNSpaceToString = map[PNSpace]string{
PNSpaceInitial: "Initial",
PNSpaceHandshake: "Handshake",
PNSpaceAppData: "Application data",
}
var PNSpaceToEpoch = map[PNSpace]pigotls.Epoch{
PNSpaceInitial: pigotls.EpochInitial,
PNSpaceHandshake: pigotls.EpochHandshake,
PNSpaceAppData: pigotls.Epoch1RTT,
}
func (pns PNSpace) String() string {
return PNSpaceToString[pns]
}
func (pns PNSpace) Epoch() pigotls.Epoch {
return PNSpaceToEpoch[pns]
}
func Uint32ToBEBytes(uint32 uint32) []byte {
b := make([]byte, 4, 4)
binary.BigEndian.PutUint32(b, uint32)
return b
}
func Uint16ToBEBytes(uint16 uint16) []byte {
b := make([]byte, 2, 2)
binary.BigEndian.PutUint16(b, uint16)
return b
}
func Max(a, b int) int { if a < b { return b }; return a}
type PacketNumberQueue []uint64
func (a PacketNumberQueue) Less(i, j int) bool { return a[i] > a[j] }
func (a PacketNumberQueue) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a PacketNumberQueue) Len() int { return len(a) }
type ConnectionID []byte
func (c ConnectionID) CIDL() uint8 {
if len(c) == 0 {
return 0
}
return uint8(len(c) - 3)
}
func min(a, b uint64) uint64 {
if a < b {
return a
}
return b
}
func max(a, b uint64) uint64 {
if a > b {
return a
}
return b
}
type UnprocessedPayload struct {
EncryptionLevel
Payload []byte
}
type QueuedFrame struct {
Frame
EncryptionLevel
}