1 /* 2 * Copyright (c) 2017 Fastly, Kazuho Oku 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to 6 * deal in the Software without restriction, including without limitation the 7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 * sell copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 * IN THE SOFTWARE. 21 */ 22 #ifndef quicly_constants_h 23 #define quicly_constants_h 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #include <stddef.h> 30 #include <stdint.h> 31 #include "picotls.h" 32 33 #define QUICLY_DELAYED_ACK_TIMEOUT 25 /* milliseconds */ 34 #define QUICLY_DEFAULT_MAX_ACK_DELAY 25 /* milliseconds */ 35 #define QUICLY_LOCAL_MAX_ACK_DELAY 25 /* milliseconds */ 36 #define QUICLY_DEFAULT_ACK_DELAY_EXPONENT 3 37 #define QUICLY_LOCAL_ACK_DELAY_EXPONENT 10 38 #define QUICLY_MIN_INITIAL_DCID_LEN 8 39 #define QUICLY_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT 2 /* If this transport parameter is absent, a default of 2 is assumed. (18.2) */ 40 /** 41 * how many CIDs is quicly willing to manage at the same time? 42 * this value is used in two ways: 43 * - active_connection_id_limit transport parameter advertised to the remote peer 44 * - maximum number of connection IDs we issue to the remote peer at a moment 45 */ 46 #define QUICLY_LOCAL_ACTIVE_CONNECTION_ID_LIMIT 4 47 #define QUICLY_MIN_ACTIVE_CONNECTION_ID_LIMIT 2 48 #define QUICLY_DEFAULT_MAX_UDP_PAYLOAD_SIZE 65527 49 #define QUICLY_MIN_CLIENT_INITIAL_SIZE 1200 50 #define QUICLY_DEFAULT_MIN_PTO 1 /* milliseconds */ 51 #define QUICLY_DEFAULT_INITIAL_RTT 66 /* initial retransmission timeout is *3, i.e. 200ms */ 52 #define QUICLY_LOSS_DEFAULT_PACKET_THRESHOLD 3 53 54 #define QUICLY_DEFAULT_PACKET_TOLERANCE 2 55 #define QUICLY_MAX_PACKET_TOLERANCE 10 56 #define QUICLY_FIRST_ACK_FREQUENCY_LOSS_EPISODE 4 57 58 #define QUICLY_AEAD_TAG_SIZE 16 59 60 #define QUICLY_MAX_CID_LEN_V1 20 61 #define QUICLY_STATELESS_RESET_TOKEN_LEN 16 62 63 #define QUICLY_EPOCH_INITIAL 0 64 #define QUICLY_EPOCH_0RTT 1 65 #define QUICLY_EPOCH_HANDSHAKE 2 66 #define QUICLY_EPOCH_1RTT 3 67 #define QUICLY_NUM_EPOCHS 4 68 69 /* coexists with picotls error codes, assuming that int is at least 32-bits */ 70 #define QUICLY_ERROR_IS_QUIC(e) (((e) & ~0x1ffff) == 0x20000) 71 #define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) (((e) & ~0xffff) == 0x20000) 72 #define QUICLY_ERROR_IS_QUIC_APPLICATION(e) (((e) & ~0xffff) == 0x30000) 73 #define QUICLY_ERROR_GET_ERROR_CODE(e) ((uint16_t)(e)) 74 #define QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(e) ((uint16_t)(e) + 0x20000) 75 #define QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(e) ((uint16_t)(e) + 0x30000) 76 /** 77 * PTLS_ERROR_NO_MEMORY and QUICLY_ERROR_STATE_EXHAUSTION are special error codes that are internal but can be passed to 78 * quicly_close. These are converted to QUICLY_TRANSPORT_ERROR_INTERNAL when sent over the wire. 79 */ 80 #define QUICLY_ERROR_IS_CONCEALED(err) ((err) == PTLS_ERROR_NO_MEMORY || (err) == QUICLY_ERROR_STATE_EXHAUSTION) 81 82 /* transport error codes */ 83 #define QUICLY_TRANSPORT_ERROR_NONE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x0) 84 #define QUICLY_TRANSPORT_ERROR_INTERNAL QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x1) 85 #define QUICLY_TRANSPORT_ERROR_CONNECTION_REFUSED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x2) 86 #define QUICLY_TRANSPORT_ERROR_FLOW_CONTROL QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x3) 87 #define QUICLY_TRANSPORT_ERROR_STREAM_LIMIT QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x4) 88 #define QUICLY_TRANSPORT_ERROR_STREAM_STATE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x5) 89 #define QUICLY_TRANSPORT_ERROR_FINAL_SIZE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x6) 90 #define QUICLY_TRANSPORT_ERROR_FRAME_ENCODING QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x7) 91 #define QUICLY_TRANSPORT_ERROR_TRANSPORT_PARAMETER QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x8) 92 #define QUICLY_TRANSPORT_ERROR_CONNECTION_ID_LIMIT QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x9) 93 #define QUICLY_TRANSPORT_ERROR_PROTOCOL_VIOLATION QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xa) 94 #define QUICLY_TRANSPORT_ERROR_INVALID_TOKEN QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xb) 95 #define QUICLY_TRANSPORT_ERROR_APPLICATION QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xc) 96 #define QUICLY_TRANSPORT_ERROR_CRYPTO_BUFFER_EXCEEDED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xd) 97 #define QUICLY_TRANSPORT_ERROR_KEY_UPDATE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xe) 98 #define QUICLY_TRANSPORT_ERROR_AEAD_LIMIT_REACHED QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0xf) 99 #define QUICLY_TRANSPORT_ERROR_TLS_ALERT_BASE QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(0x100) 100 101 /* internal error codes, used purely for signaling status to the application */ 102 #define QUICLY_ERROR_PACKET_IGNORED 0xff01 103 #define QUICLY_ERROR_SENDBUF_FULL 0xff02 /* internal use only; the error code is never exposed to the application */ 104 #define QUICLY_ERROR_FREE_CONNECTION 0xff03 /* returned by quicly_send when the connection is freeable */ 105 #define QUICLY_ERROR_RECEIVED_STATELESS_RESET 0xff04 106 #define QUICLY_ERROR_NO_COMPATIBLE_VERSION 0xff05 107 #define QUICLY_ERROR_IS_CLOSING 0xff06 /* indicates that the connection has already entered closing state */ 108 #define QUICLY_ERROR_STATE_EXHAUSTION 0xff07 109 #define QUICLY_ERROR_INVALID_INITIAL_VERSION 0xff08 110 #define QUICLY_ERROR_DECRYPTION_FAILED 0xff09 111 112 typedef int64_t quicly_stream_id_t; 113 114 typedef struct st_quicly_conn_t quicly_conn_t; 115 116 /** 117 * Used for emitting arbitrary debug message through probes. The debug message might get emitted unescaped as a JSON string, 118 * therefore cannot contain characters that are required to be escaped as a JSON string (e.g., `\n`, `"`). 119 */ 120 void quicly__debug_printf(quicly_conn_t *conn, const char *function, int line, const char *fmt, ...) 121 __attribute__((format(printf, 4, 5))); 122 123 #define quicly_debug_printf(conn, ...) quicly__debug_printf((conn), __FUNCTION__, __LINE__, __VA_ARGS__) 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif 130