-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathquicer_types.hrl
516 lines (461 loc) · 14.1 KB
/
quicer_types.hrl
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
%%--------------------------------------------------------------------
%% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-ifndef(QUICER_TYPES_HRL).
-define(QUICER_TYPES_HRL, true).
-include("quicer.hrl").
-define(BIT(Bits), (1 bsl (Bits))).
-define(MASK(Bits), (?BIT(Bits) - 1)).
-export_type([handle/0]).
%% @doc Other user defined opts may be used in callbacks
-type user_opts() :: #{_ => _}.
%% Msquic Status Code Translation
-type atom_reason() ::
success
| pending
| continue
| out_of_memory
| invalid_parameter
| invalid_state
| not_supported
| not_found
| buffer_too_small
| handshake_failure
| aborted
| address_in_use
| connection_timeout
| connection_idle
| internal_error
| connection_refused
| protocol_error
| ver_neg_error
| unreachable
| tls_error
| user_canceled
| alpn_neg_failure
| stream_limit_reached.
-type app_errno() :: non_neg_integer().
-type hostname() :: string().
-type listener_handle() :: reference().
-type connection_handle() :: reference().
-type stream_handle() :: reference().
-type conf_handle() :: reference().
-type reg_handle() :: reference().
-type global_handle() :: quic_global.
-type handle() ::
global_handle()
| listener_handle()
| connection_handle()
| stream_handle()
| conf_handle()
| reg_handle().
-type registration_profile() :: execution_profile().
-type quic_handle_level() :: quic_tls | quic_configuration | false.
-type listen_on() :: inet:port_number() | string().
-type listen_opts() :: listen_security_opts() | quic_settings().
-type listen_security_opts() :: #{
alpn := [alpn()],
cert := file:filename(),
certfile := file:filename(),
key := file:filename(),
keyfile := file:filename(),
verify => none | peer | verify_peer | verify_none,
cacertfile => file:filename(),
password => string(),
sslkeylogfile => file:filename(),
allow_insecure => boolean(),
quic_registration => reg_handle(),
conn_acceptors => non_neg_integer()
}.
-type uint64() :: 0..?MASK(64).
-type uint62() :: 0..?MASK(62).
-type uint32() :: 0..?MASK(32).
-type uint16() :: 0..?MASK(16).
-type uint8() :: 0..?MASK(8).
-type quic_settings() :: #{
max_bytes_per_key => uint64(),
handshake_idle_timeout_ms => uint64(),
idle_timeout_ms => uint64(),
%% for client only
tls_client_max_send_buffer => uint32(),
%% for server only
tls_server_max_send_buffer => uint32(),
stream_recv_window_default => uint32(),
stream_recv_buffer_default => uint32(),
conn_flow_control_window => uint32(),
%, max_worker_queue_delay_us => uint32()
max_stateless_operations => uint32(),
initial_window_packets => uint32(),
send_idle_timeout_ms => uint32(),
initial_rtt_ms => uint32(),
max_ack_delay_ms => uint32(),
disconnect_timeout_ms => uint32(),
keep_alive_interval_ms => uint32(),
congestion_control_algorithm => uint16(),
peer_bidi_stream_count => uint16(),
peer_unidi_stream_count => uint16(),
retry_memory_limit => uint16(),
load_balancing_mode => uint16(),
max_operations_per_drain => uint8(),
send_buffering_enabled => uint8(),
pacing_enabled => uint8(),
migration_enabled => uint8(),
datagram_receive_enabled => uint8(),
server_resumption_level => uint8(),
% internal, not exposed
%, version_negotiation_ext_enabled => uint8()
minimum_mtu => uint16(),
maximum_mtu => uint16(),
mtu_discovery_search_complete_timeout_us => uint64(),
mtu_discovery_missing_probe_count => uint8(),
max_binding_stateless_operations => uint16(),
stateless_operation_expiration_ms => uint16()
}.
-type alpn() :: string().
-type conn_opts() ::
quic_settings()
| #{
alpn := [string()],
conn_callback => module(),
cert => file:filename(),
certfile => file:filename(),
key => file:filename(),
keyfile => file:filename(),
password => string(),
verify => none | peer,
%% get NST from last connection, for reconnect.
handle => connection_handle(),
nst => binary(),
cacertfile => file:filename(),
sslkeylogfile => file:filename(),
handshake_idle_timeout_ms => non_neg_integer(),
quic_event_mask => uint32(),
disable_1rtt_encryption => boolean(),
%% Not working well
local_address => string(),
local_bidi_stream_count => uint16(),
local_peer_unidi_stream_count => uint16(),
%% for Application defined options
_ => _
}.
-type conn_shutdown_flag() ::
?QUIC_CONNECTION_SHUTDOWN_FLAG_NONE
| ?QUIC_CONNECTION_SHUTDOWN_FLAG_SILENT.
-type acceptor_opts() :: quic_settings() | #{active => boolean()}.
-type active_n() :: boolean() | once | integer().
-type stream_opts() :: #{
active := active_n(),
open_flag => stream_open_flags(),
start_flag => stream_start_flags(),
event_mask => uint32(),
disable_fpbuffer => boolean(),
stream_id => uint62(),
priority => uint16(),
ideal_send_buffer_size => uint64(),
'0rtt_length' => uint64(),
%% for Application defined options
_ => _
%% @TODO expand
}.
-type stream_open_flags() ::
?QUIC_STREAM_OPEN_FLAG_NONE
%% Open unidirectional stream
| ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL
%% The stream is opened via a 0-RTT packet
| ?QUIC_STREAM_OPEN_FLAG_0_RTT.
-type stream_start_flags() ::
?QUIC_STREAM_START_FLAG_NONE
%% Immediately informs peer that stream is open
| ?QUIC_STREAM_START_FLAG_IMMEDIATE
%% If number of streams is rate limited, notify with event start_completed with status 'stream_limit_reached'
| ?QUIC_STREAM_START_FLAG_FAIL_BLOCKED
%% Shutdown the stream immediately after start failure
| ?QUIC_STREAM_START_FLAG_SHUTDOWN_ON_FAIL
%% Indicate PEER_ACCEPTED event if not accepted at start
| ?QUIC_STREAM_START_FLAG_INDICATE_PEER_ACCEPT.
-type stream_shutdown_flags() ::
%% **Invalid** option for `StreamShutdown`
?QUIC_STREAM_SHUTDOWN_FLAG_NONE
%% Gracefully shutdown the stream
| ?QUIC_STREAM_SHUTDOWN_FLAG_GRACEFUL
%% Abortively shutdown the sending side of the stream
| ?QUIC_STREAM_SHUTDOWN_FLAG_ABORT_SEND
%% Abortively shutdown the sending side of the stream
| ?QUIC_STREAM_SHUTDOWN_FLAG_ABORT_RECEIVE
%% Abortively shutdown both sending and receiveing side of the stream
| ?QUIC_STREAM_SHUTDOWN_FLAG_ABORT
%% Don't wait for ack from peer, must be used with abortive shutdown
| ?QUIC_STREAM_SHUTDOWN_FLAG_IMMEDIATE.
%% is sync send or not
-type send_flags() ::
csend_flags() | ?QUICER_SEND_FLAG_SYNC.
-type csend_flags() ::
?QUIC_SEND_FLAG_NONE
| ?QUIC_SEND_FLAG_ALLOW_0_RTT
| ?QUIC_SEND_FLAG_START
| ?QUIC_SEND_FLAG_FIN
| ?QUIC_SEND_FLAG_DGRAM_PRIORITY
| ?QUIC_SEND_FLAG_DELAY_SEND.
-type stream_start_flag() ::
?QUIC_STREAM_START_FLAG_NONE
| ?QUIC_STREAM_START_FLAG_IMMEDIATE
| ?QUIC_STREAM_START_FLAG_FAIL_BLOCKED
| ?QUIC_STREAM_START_FLAG_SHUTDOWN_ON_FAIL
| ?QUIC_STREAM_START_FLAG_INDICATE_PEER_ACCEPT.
-type new_stream_props() :: #{
is_orphan := boolean(),
flags := stream_open_flags()
}.
-type streams_available_props() :: #{
unidi_streams := non_neg_integer(),
bidi_streams := non_neg_integer()
}.
-type send_complete_flag() ::
?QUIC_SEND_COMPLETE_SUCCESS
| ?QUIC_SEND_COMPLETE_CANCELLED.
%% unspecified
-type optlevel() ::
false
| quic_global
| quic_registration
| quic_configuration
| quic_tls.
-type optname() ::
optname_global()
| optname_listener()
| optname_conn()
| optname_stream()
| optname_reg()
| optname_configuration()
| optname_tls().
%% === | GET | SET| === %%
%% with connection_handle()
-type optname_conn() ::
%% /* Parameters for QUIC_PARAM_LEVEL_CONNECTION. */|
%% | X | |
quic_version
%% | X | |
| local_address
%% | X | X | @TODO SET
| remote_address
%% | X | |
| ideal_processor
%% | X | X |
| settings
%% | X | |
| statistics
%% | X | | @TODO
| statistics_plat
%% | X | X |
| share_udp_binding
%% | X | |
| local_bidi_stream_count
%% | X | |
| local_unidi_stream_count
%% | X | |
| max_stream_ids
%% | X | X |
| close_reason_phrase
%% | X | X |
| stream_scheduling_scheme
%% | X | X |
| datagram_receive_enabled
%% | X | |
| datagram_send_enabled
%% | X | X |
| disable_1rtt_encryption
%% | | X |
| resumption_ticket
%% | | X |
| peer_certificate_valid
%% | | X |
| local_interface.
%% with connection_handle()
-type optname_tls() ::
%% | X | |
schannel_context_attribute_w
%% | X | |
| handshake_info
%% | X | |
| negotiated_alpn.
-type optname_stream() ::
%% | X | X |
active
%% | | X |
| controlling_process
%% | | X |
| stream_id
%% | X | |
| '0rtt_length'
%% | X | |
| ideal_send_buffer_size
%% | | |
| priority.
%% with `undefined' handle
-type optname_global() ::
%% | X | X |
retry_memory_percent
%% | X | | @TODO
| supported_versions
%% | X | X |
| load_balacing_mode
%% | X | |
| perf_counters
%% | X | X |
| global_settings
%% | X | | @TODO
| global_version.
%% | X | X | @TODO
-type optname_reg() :: cid_prefix.
%% with config_handle()
-type optname_configuration() ::
%% | X | X |
settings
%% | | X | @TODO
| ticket_keys.
%% with listener_handle
-type optname_listener() ::
%% | X | |
local_address
%% | X | |
| stats
%% | | X |
| cibir_id.
-type conn_settings() :: [{conn_settings_key(), non_neg_integer()}].
-type conn_settings_key() ::
max_bytes_per_key
| handshake_idle_timeout_ms
| idle_timeout_ms
| tls_client_max_send_buffer
| tls_server_max_send_buffer
| stream_recv_window_default
| stream_recv_buffer_default
| conn_flow_control_window
| max_worker_queue_delay_us
| max_stateless_operations
| initial_window_packets
| send_idle_timeout_ms
| initial_rtt_ms
| max_ack_delay_ms
| disconnect_timeout_ms
| keep_alive_interval_ms
| peer_bidi_stream_count
| peer_unidi_stream_count
| retry_memory_limit
| load_balancing_mode
| max_operations_per_drain
| send_buffering_enabled
| pacing_enabled
| migration_enabled
| datagram_receive_enabled
| server_resumption_level
| version_negotiation_ext_enabled
| desired_versions_list
| desired_versions_list_length.
-type execution_profile() ::
quic_execution_profile_low_latency
| quic_execution_profile_max_throughput
| quic_execution_profile_scavenger
| quic_execution_profile_real_time.
%% Connection Event Props
-type new_conn_props() :: #{
version := integer(),
local_addr := string(),
remote_addr := string(),
server_name := binary(),
alpns := binary(),
client_alpns := binary(),
crypto_buffer := binary()
}.
-type connected_props() :: #{
is_resumed := boolean(),
alpns := string() | undefined
}.
-type conn_closed_props() :: #{
is_handshake_completed := boolean(),
is_peer_acked := boolean(),
is_app_closing := boolean()
}.
-type transport_shutdown_props() :: #{
is_conn_shutdown := boolean(),
is_app_closing := boolean(),
is_shutdown_by_app := boolean(),
is_closed_remotely := boolean(),
status := atom_reason(),
error := error_code()
}.
%% Stream Event Props
-type stream_start_completed_props() :: #{
status := atom(),
stream_id := integer(),
is_peer_accepted := boolean()
}.
-type stream_closed_props() :: map().
-type peer_accepted_props() :: #{
is_conn_shutdown := boolean(),
is_app_closing := boolean(),
is_shutdown_by_app := boolean(),
is_closed_remotely := boolean(),
status := atom_reason(),
error := error_code()
}.
-type recv_data_props() :: #{
absolute_offset := integer(),
len := integer(),
flags := integer()
}.
%% @doc QUIC Application error code, not protocol error code.
%% The app error code will be passed to the peer while shutdown the connection.
%% 0 means no error
-type app_error() :: non_neg_integer().
-type error_code() :: non_neg_integer().
%% @doc addr in quicer, IP and Port
-type quicer_addr() :: string().
%% @doc quic_data fragment with offset index
-type ifrag() :: {Index :: non_neg_integer(), quic_data()}.
-type quic_data_buffer() :: ordsets:ordset(ifrag()).
%% @doc future packet buffer
-type fpbuffer() :: #{
next_offset := non_neg_integer(),
buffer := quic_data_buffer()
}.
%% @doc binary data with offset and size info
-type quic_data() :: #quic_data{}.
%% Not sent yet
-type datagram_send_state() ::
?QUIC_DATAGRAM_SEND_UNKNOWN
%% Sent but not acked yet
| ?QUIC_DATAGRAM_SEND_SENT
%% Suspected lost but still tracked
| ?QUIC_DATAGRAM_SEND_LOST_SUSPECT
%% Lost and no longer tracked
| ?QUIC_DATAGRAM_SEND_LOST_DISCARDED
%% Acknowledged
| ?QUIC_DATAGRAM_SEND_ACKNOWLEDGED
%% Acknowledged after being suspected lost
| ?QUIC_DATAGRAM_SEND_ACKNOWLEDGED_SPURIOUS
%% Send cancelled
| ?QUIC_DATAGRAM_SEND_CANCELED.
-type dgram_state() :: #{
dgram_send_enabled := boolean(),
dgram_max_len := uint64()
}.
-type probe_state() :: #probe_state{}.
-type probe_res() ::
#probe_state{}
| {error, dgram_send_error, atom()}
| {error, atom()}.
%% QUICER_TYPES_HRL
-endif.