forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket_space.h
148 lines (123 loc) · 3.38 KB
/
packet_space.h
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*++
Copyright (c) Microsoft Corporation.
Licensed under the MIT License.
--*/
typedef enum _QUIC_ENCRYPT_LEVEL {
QUIC_ENCRYPT_LEVEL_INITIAL,
QUIC_ENCRYPT_LEVEL_HANDSHAKE,
QUIC_ENCRYPT_LEVEL_1_RTT, // Also used for 0-RTT
QUIC_ENCRYPT_LEVEL_COUNT
} QUIC_ENCRYPT_LEVEL;
inline
QUIC_PACKET_KEY_TYPE
QuicEncryptLevelToKeyType(
QUIC_ENCRYPT_LEVEL Level
)
{
switch (Level) {
case QUIC_ENCRYPT_LEVEL_INITIAL: return QUIC_PACKET_KEY_INITIAL;
case QUIC_ENCRYPT_LEVEL_HANDSHAKE: return QUIC_PACKET_KEY_HANDSHAKE;
case QUIC_ENCRYPT_LEVEL_1_RTT:
default: return QUIC_PACKET_KEY_1_RTT;
}
}
inline
QUIC_ENCRYPT_LEVEL
QuicKeyTypeToEncryptLevel(
QUIC_PACKET_KEY_TYPE KeyType
)
{
switch (KeyType) {
case QUIC_PACKET_KEY_INITIAL: return QUIC_ENCRYPT_LEVEL_INITIAL;
case QUIC_PACKET_KEY_0_RTT: return QUIC_ENCRYPT_LEVEL_1_RTT;
case QUIC_PACKET_KEY_HANDSHAKE: return QUIC_ENCRYPT_LEVEL_HANDSHAKE;
case QUIC_PACKET_KEY_1_RTT:
default: return QUIC_ENCRYPT_LEVEL_1_RTT;
}
}
typedef struct _QUIC_PACKET_SPACE {
//
// The encryption level this packet space is for.
//
QUIC_ENCRYPT_LEVEL EncryptLevel;
//
// Numbers of entries in the DeferredDatagrams list.
//
uint8_t DeferredDatagramsCount;
//
// The (expected) next packet number to receive. Used for decoding received
// packet numbers.
//
uint64_t NextRecvPacketNumber;
//
// Owning connection of this packet space.
//
PQUIC_CONNECTION Connection;
//
// List of received QUIC_RECV_DATAGRAMs that we don't have the key
// for yet.
//
QUIC_RECV_DATAGRAM* DeferredDatagrams;
//
// Information related to packets that have been received and need to be
// acknowledged.
//
QUIC_ACK_TRACKER AckTracker;
//
// Packet number of the first sent packet of the current key phase.
//
uint64_t WriteKeyPhaseStartPacketNumber;
//
// Packet number of the first received packet of the current key phase.
//
uint64_t ReadKeyPhaseStartPacketNumber;
//
// Count of bytes sent at the current key phase.
//
uint64_t CurrentKeyPhaseBytesSent;
//
// The current KEY_PHASE of the packet space.
//
BOOLEAN CurrentKeyPhase : 1;
//
// True when we force a key change.
//
BOOLEAN AwaitingKeyPhaseConfirmation: 1;
} QUIC_PACKET_SPACE, *PQUIC_PACKET_SPACE;
//
// Helper to get the QUIC_PACKET_SPACE for an ack tracker.
//
inline
PQUIC_PACKET_SPACE
QuicAckTrackerGetPacketSpace(
_In_ PQUIC_ACK_TRACKER Tracker
)
{
return QUIC_CONTAINING_RECORD(Tracker, QUIC_PACKET_SPACE, AckTracker);
}
//
// Initializes a new packet space.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
QuicPacketSpaceInitialize(
_In_ PQUIC_CONNECTION Connection,
_In_ QUIC_ENCRYPT_LEVEL EncryptLevel,
_Out_ PQUIC_PACKET_SPACE* NewPackets
);
//
// Uninitializes the packet space.
//
_IRQL_requires_max_(PASSIVE_LEVEL)
void
QuicPacketSpaceUninitialize(
_In_ PQUIC_PACKET_SPACE Packets
);
//
// Resets the packet space.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicPacketSpaceReset(
_In_ PQUIC_PACKET_SPACE Packets
);