ngtcp2_transport_params.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * ngtcp2
  3. *
  4. * Copyright (c) 2023 ngtcp2 contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGTCP2_TRANSPORT_PARAMS_H
  26. #define NGTCP2_TRANSPORT_PARAMS_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* defined(HAVE_CONFIG_H) */
  30. #include <ngtcp2/ngtcp2.h>
  31. /* ngtcp2_transport_param_id is the registry of QUIC transport
  32. parameter ID. */
  33. typedef uint64_t ngtcp2_transport_param_id;
  34. #define NGTCP2_TRANSPORT_PARAM_ORIGINAL_DESTINATION_CONNECTION_ID 0x00
  35. #define NGTCP2_TRANSPORT_PARAM_MAX_IDLE_TIMEOUT 0x01
  36. #define NGTCP2_TRANSPORT_PARAM_STATELESS_RESET_TOKEN 0x02
  37. #define NGTCP2_TRANSPORT_PARAM_MAX_UDP_PAYLOAD_SIZE 0x03
  38. #define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_DATA 0x04
  39. #define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL 0x05
  40. #define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE 0x06
  41. #define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAM_DATA_UNI 0x07
  42. #define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_BIDI 0x08
  43. #define NGTCP2_TRANSPORT_PARAM_INITIAL_MAX_STREAMS_UNI 0x09
  44. #define NGTCP2_TRANSPORT_PARAM_ACK_DELAY_EXPONENT 0x0a
  45. #define NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY 0x0b
  46. #define NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION 0x0c
  47. #define NGTCP2_TRANSPORT_PARAM_PREFERRED_ADDRESS 0x0d
  48. #define NGTCP2_TRANSPORT_PARAM_ACTIVE_CONNECTION_ID_LIMIT 0x0e
  49. #define NGTCP2_TRANSPORT_PARAM_INITIAL_SOURCE_CONNECTION_ID 0x0f
  50. #define NGTCP2_TRANSPORT_PARAM_RETRY_SOURCE_CONNECTION_ID 0x10
  51. /* https://datatracker.ietf.org/doc/html/rfc9221 */
  52. #define NGTCP2_TRANSPORT_PARAM_MAX_DATAGRAM_FRAME_SIZE 0x20
  53. #define NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT 0x2ab2
  54. /* https://datatracker.ietf.org/doc/html/rfc9368 */
  55. #define NGTCP2_TRANSPORT_PARAM_VERSION_INFORMATION 0x11
  56. /* NGTCP2_MAX_STREAMS is the maximum number of streams. */
  57. #define NGTCP2_MAX_STREAMS (1LL << 60)
  58. /*
  59. * ngtcp2_transport_params_copy_new makes a copy of |src|, and assigns
  60. * it to |*pdest|. If |src| is NULL, NULL is assigned to |*pdest|.
  61. *
  62. * Caller is responsible to call ngtcp2_transport_params_del to free
  63. * the memory assigned to |*pdest|.
  64. *
  65. * This function returns 0 if it succeeds, or one of the following
  66. * negative error codes:
  67. *
  68. * NGTCP2_ERR_NOMEM
  69. * Out of memory.
  70. */
  71. int ngtcp2_transport_params_copy_new(ngtcp2_transport_params **pdest,
  72. const ngtcp2_transport_params *src,
  73. const ngtcp2_mem *mem);
  74. /*
  75. * ngtcp2_transport_params_convert_to_latest converts |src| of version
  76. * |transport_params_version| to the latest version
  77. * NGTCP2_TRANSPORT_PARAMS_VERSION.
  78. *
  79. * |dest| must point to the latest version. |src| may be the older
  80. * version, and if so, it may have fewer fields. Accessing those
  81. * fields causes undefined behavior.
  82. *
  83. * If |transport_params_version| == NGTCP2_TRANSPORT_PARAMS_VERSION,
  84. * no conversion is made, and |src| is returned. Otherwise, first
  85. * |dest| is initialized via ngtcp2_transport_params_default, and then
  86. * all valid fields in |src| are copied into |dest|. Finally, |dest|
  87. * is returned.
  88. */
  89. const ngtcp2_transport_params *
  90. ngtcp2_transport_params_convert_to_latest(ngtcp2_transport_params *dest,
  91. int transport_params_version,
  92. const ngtcp2_transport_params *src);
  93. /*
  94. * ngtcp2_transport_params_convert_to_old converts |src| of the latest
  95. * version to |dest| of version |transport_params_version|.
  96. *
  97. * |transport_params_version| must not be the latest version
  98. * NGTCP2_TRANSPORT_PARAMS_VERSION.
  99. *
  100. * |dest| points to the older version, and it may have fewer fields.
  101. * Accessing those fields causes undefined behavior.
  102. *
  103. * This function copies all valid fields in version
  104. * |transport_params_version| from |src| to |dest|.
  105. */
  106. void ngtcp2_transport_params_convert_to_old(int transport_params_version,
  107. ngtcp2_transport_params *dest,
  108. const ngtcp2_transport_params *src);
  109. #endif /* !defined(NGTCP2_TRANSPORT_PARAMS_H) */