quic_txpim.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_TXPIM_H
  10. # define OSSL_QUIC_TXPIM_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_types.h"
  13. # include "internal/quic_cfq.h"
  14. # include "internal/quic_ackm.h"
  15. /*
  16. * QUIC Transmitted Packet Information Manager
  17. * ===========================================
  18. */
  19. typedef struct quic_txpim_st QUIC_TXPIM;
  20. typedef struct quic_fifd_st QUIC_FIFD;
  21. typedef struct quic_txpim_pkt_st {
  22. /* ACKM-specific data. Caller should fill this. */
  23. OSSL_ACKM_TX_PKT ackm_pkt;
  24. /* Linked list of CFQ items in this packet. */
  25. QUIC_CFQ_ITEM *retx_head;
  26. /* Reserved for FIFD use. */
  27. QUIC_FIFD *fifd;
  28. /* Regenerate-strategy frames. */
  29. unsigned int had_handshake_done_frame : 1;
  30. unsigned int had_max_data_frame : 1;
  31. unsigned int had_max_streams_bidi_frame : 1;
  32. unsigned int had_max_streams_uni_frame : 1;
  33. unsigned int had_ack_frame : 1;
  34. /* Private data follows. */
  35. } QUIC_TXPIM_PKT;
  36. /* Represents a range of bytes in an application or CRYPTO stream. */
  37. typedef struct quic_txpim_chunk_st {
  38. /* The stream ID, or UINT64_MAX for the CRYPTO stream. */
  39. uint64_t stream_id;
  40. /*
  41. * The inclusive range of bytes in the stream. Exceptionally, if end <
  42. * start, designates a frame of zero length (used for FIN-only frames). In
  43. * this case end is the number of the final byte (i.e., one less than the
  44. * final size of the stream).
  45. */
  46. uint64_t start, end;
  47. /*
  48. * Whether a FIN was sent for this stream in the packet. Not valid for
  49. * CRYPTO stream.
  50. */
  51. unsigned int has_fin : 1;
  52. /*
  53. * If set, a STOP_SENDING frame was sent for this stream ID. (If no data was
  54. * sent for the stream, set end < start.)
  55. */
  56. unsigned int has_stop_sending : 1;
  57. /*
  58. * If set, a RESET_STREAM frame was sent for this stream ID. (If no data was
  59. * sent for the stream, set end < start.)
  60. */
  61. unsigned int has_reset_stream : 1;
  62. } QUIC_TXPIM_CHUNK;
  63. QUIC_TXPIM *ossl_quic_txpim_new(void);
  64. /*
  65. * Frees the TXPIM. All QUIC_TXPIM_PKTs which have been handed out by the TXPIM
  66. * must be released via a call to ossl_quic_txpim_pkt_release() before calling
  67. * this function.
  68. */
  69. void ossl_quic_txpim_free(QUIC_TXPIM *txpim);
  70. /*
  71. * Allocates a new QUIC_TXPIM_PKT structure from the pool. Returns NULL on
  72. * failure. The returned structure is cleared of all data and is in a fresh
  73. * initial state.
  74. */
  75. QUIC_TXPIM_PKT *ossl_quic_txpim_pkt_alloc(QUIC_TXPIM *txpim);
  76. /*
  77. * Releases the TXPIM packet, returning it to the pool.
  78. */
  79. void ossl_quic_txpim_pkt_release(QUIC_TXPIM *txpim, QUIC_TXPIM_PKT *fpkt);
  80. /* Clears the chunk list of the packet, removing all entries. */
  81. void ossl_quic_txpim_pkt_clear_chunks(QUIC_TXPIM_PKT *fpkt);
  82. /* Appends a chunk to the packet. The structure is copied. */
  83. int ossl_quic_txpim_pkt_append_chunk(QUIC_TXPIM_PKT *fpkt,
  84. const QUIC_TXPIM_CHUNK *chunk);
  85. /* Adds a CFQ item to the packet by prepending it to the retx_head list. */
  86. void ossl_quic_txpim_pkt_add_cfq_item(QUIC_TXPIM_PKT *fpkt,
  87. QUIC_CFQ_ITEM *item);
  88. /*
  89. * Returns a pointer to an array of stream chunk information structures for the
  90. * given packet. The caller must call ossl_quic_txpim_pkt_get_num_chunks() to
  91. * determine the length of this array. The returned pointer is invalidated
  92. * if the chunk list is mutated, for example via a call to
  93. * ossl_quic_txpim_pkt_append_chunk() or ossl_quic_txpim_pkt_clear_chunks().
  94. *
  95. * The chunks are sorted by (stream_id, start) in ascending order.
  96. */
  97. const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(const QUIC_TXPIM_PKT *fpkt);
  98. /*
  99. * Returns the number of entries in the array returned by
  100. * ossl_quic_txpim_pkt_get_chunks().
  101. */
  102. size_t ossl_quic_txpim_pkt_get_num_chunks(const QUIC_TXPIM_PKT *fpkt);
  103. /*
  104. * Returns the number of QUIC_TXPIM_PKTs allocated by the given TXPIM that have
  105. * yet to be returned to the TXPIM.
  106. */
  107. size_t ossl_quic_txpim_get_in_use(const QUIC_TXPIM *txpim);
  108. #endif