quic_cc.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_QUIC_CC_H
  10. # define OSSL_QUIC_CC_H
  11. #include "openssl/params.h"
  12. #include "internal/time.h"
  13. typedef struct ossl_cc_data_st *OSSL_CC_DATA;
  14. typedef struct ossl_cc_method_st {
  15. void *dummy;
  16. /*
  17. * Create a new OSSL_CC_DATA object to handle the congestion control
  18. * calculations.
  19. *
  20. * |settings| are mandatory settings that will cause the
  21. * new() call to fail if they are not understood).
  22. * |options| are optional settings that will not
  23. * cause the new() call to fail if they are not understood.
  24. * |changeables| contain additional parameters that the congestion
  25. * control algorithms need that can be updated during the
  26. * connection lifetime - for example size of the datagram payload.
  27. * To avoid calling a function with OSSL_PARAM array every time
  28. * these parameters are changed the addresses of these param
  29. * values are considered permanent and the values can be updated
  30. * any time.
  31. */
  32. OSSL_CC_DATA *(*new)(OSSL_PARAM *settings, OSSL_PARAM *options,
  33. OSSL_PARAM *changeables);
  34. /*
  35. * Release the OSSL_CC_DATA.
  36. */
  37. void (*free)(OSSL_CC_DATA *ccdata);
  38. /*
  39. * Reset the congestion control state.
  40. * |flags| to support different level of reset (partial/full).
  41. */
  42. void (*reset)(OSSL_CC_DATA *ccdata, int flags);
  43. /*
  44. * Set number of packets exempted from CC - used for probing
  45. * |numpackets| is a small value (2).
  46. * Returns 0 on error, 1 otherwise.
  47. */
  48. int (*set_exemption)(OSSL_CC_DATA *ccdata, int numpackets);
  49. /*
  50. * Get current number of packets exempted from CC.
  51. * Returns negative value on error, the number otherwise.
  52. */
  53. int (*get_exemption)(OSSL_CC_DATA *ccdata);
  54. /*
  55. * Returns 1 if sending is allowed, 0 otherwise.
  56. */
  57. int (*can_send)(OSSL_CC_DATA *ccdata);
  58. /*
  59. * Returns number of bytes allowed to be sent.
  60. * |time_since_last_send| is time since last send operation
  61. * in microseconds.
  62. * |time_valid| is 1 if the |time_since_last_send| holds
  63. * a meaningful value, 0 otherwise.
  64. */
  65. uint64_t (*get_send_allowance)(OSSL_CC_DATA *ccdata,
  66. OSSL_TIME time_since_last_send,
  67. int time_valid);
  68. /*
  69. * Returns the maximum number of bytes allowed to be in flight.
  70. */
  71. uint64_t (*get_bytes_in_flight_max)(OSSL_CC_DATA *ccdata);
  72. /*
  73. * To be called when a packet with retransmittable data was sent.
  74. * |num_retransmittable_bytes| is the number of bytes sent
  75. * in the packet that are retransmittable.
  76. * Returns 1 on success, 0 otherwise.
  77. */
  78. int (*on_data_sent)(OSSL_CC_DATA *ccdata,
  79. uint64_t num_retransmittable_bytes);
  80. /*
  81. * To be called when retransmittable data was invalidated.
  82. * I.E. they are not considered in-flight anymore but
  83. * are neither acknowledged nor lost. In particular used when
  84. * 0RTT data was rejected.
  85. * |num_retransmittable_bytes| is the number of bytes
  86. * of the invalidated data.
  87. * Returns 1 if sending is unblocked (can_send returns 1), 0
  88. * otherwise.
  89. */
  90. int (*on_data_invalidated)(OSSL_CC_DATA *ccdata,
  91. uint64_t num_retransmittable_bytes);
  92. /*
  93. * To be called when sent data was acked.
  94. * |time_now| is current time in microseconds.
  95. * |largest_pn_acked| is the largest packet number of the acked
  96. * packets.
  97. * |num_retransmittable_bytes| is the number of retransmittable
  98. * packet bytes that were newly acked.
  99. * Returns 1 if sending is unblocked (can_send returns 1), 0
  100. * otherwise.
  101. */
  102. int (*on_data_acked)(OSSL_CC_DATA *ccdata,
  103. OSSL_TIME time_now,
  104. uint64_t last_pn_acked,
  105. uint64_t num_retransmittable_bytes);
  106. /*
  107. * To be called when sent data is considered lost.
  108. * |largest_pn_lost| is the largest packet number of the lost
  109. * packets.
  110. * |largest_pn_sent| is the largest packet number sent on this
  111. * connection.
  112. * |num_retransmittable_bytes| is the number of retransmittable
  113. * packet bytes that are newly considered lost.
  114. * |persistent_congestion| is 1 if the congestion is considered
  115. * persistent (see RFC 9002 Section 7.6), 0 otherwise.
  116. */
  117. void (*on_data_lost)(OSSL_CC_DATA *ccdata,
  118. uint64_t largest_pn_lost,
  119. uint64_t largest_pn_sent,
  120. uint64_t num_retransmittable_bytes,
  121. int persistent_congestion);
  122. /*
  123. * To be called when all lost data from the previous call to
  124. * on_data_lost() was actually acknowledged.
  125. * This reverts the size of the congestion window to the state
  126. * before the on_data_lost() call.
  127. * Returns 1 if sending is unblocked, 0 otherwise.
  128. */
  129. int (*on_spurious_congestion_event)(OSSL_CC_DATA *ccdata);
  130. } OSSL_CC_METHOD;
  131. extern const OSSL_CC_METHOD ossl_cc_dummy_method;
  132. #endif