]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - include/internal/quic_stream.h
Improve the QUIC_RSTREAM implementation
[thirdparty/openssl.git] / include / internal / quic_stream.h
index 1fd7d85d3c4d19e9c1822b228f06522470895887..42d6ed2d7d96ce6afb55eae408b44ca06d97c547 100644 (file)
@@ -308,9 +308,11 @@ typedef struct quic_rstream_st QUIC_RSTREAM;
  * controller and statistics module. They can be NULL for unit testing.
  * If they are non-NULL, the `rxfc` is called when receive stream data
  * is read by application. `statm` is queried for current rtt.
+ * `rbuf_size` is the initial size of the ring buffer to be used
+ * when ossl_quic_rstream_move_to_rbuf() is called.
  */
 QUIC_RSTREAM *ossl_quic_rstream_new(QUIC_RXFC *rxfc,
-                                    OSSL_STATM *statm);
+                                    OSSL_STATM *statm, size_t rbuf_size);
 
 /*
  * Frees a QUIC_RSTREAM and any associated storage.
@@ -357,6 +359,55 @@ int ossl_quic_rstream_peek(QUIC_RSTREAM *qrs, unsigned char *buf, size_t size,
  */
 int ossl_quic_rstream_available(QUIC_RSTREAM *qrs, size_t *avail, int *fin);
 
+/*
+ * Sets *record to the beginning of the first readable stream data chunk and
+ * *reclen to the size of the chunk. *fin is set to 1 if the end of the
+ * chunk is the last of the stream data chunks.
+ * If there is no record available *record is set to NULL and *rec_len to 0;
+ * ossl_quic_rstream_release_record() should not be called in that case.
+ * Returns 1 on success (including calls if no record is available, or
+ * after end of the stream - in that case *fin will be set to 1 and
+ * *rec_len to 0), 0 on error.
+ * It is an error to call ossl_quic_rstream_get_record() multiple times
+ * without calling ossl_quic_rstream_release_record() in between.
+ */
+int ossl_quic_rstream_get_record(QUIC_RSTREAM *qrs,
+                                 const unsigned char **record, size_t *rec_len,
+                                 int *fin);
+
+/*
+ * Releases (possibly partially) the record returned by
+ * previous ossl_quic_rstream_get_record() call.
+ * read_len between previously returned *rec_len and SIZE_MAX indicates
+ * release of the whole record. Otherwise only part of the record is
+ * released. The remaining part of the record is unlocked, another
+ * call to ossl_quic_rstream_get_record() is needed to obtain further
+ * stream data.
+ * Returns 1 on success, 0 on error.
+ * It is an error to call ossl_quic_rstream_release_record() multiple
+ * times without calling ossl_quic_rstream_get_record() in between.
+ */
+int ossl_quic_rstream_release_record(QUIC_RSTREAM *qrs, size_t read_len);
+
+/*
+ * Moves received frame data from decrypted packets to ring buffer.
+ * This should be called when there are too many decrypted packets allocated.
+ * Returns 1 on success, 0 when it was not possible to release all
+ * referenced packets due to an insufficient size of the ring buffer.
+ * Exception is the packet from the record returned previously by
+ * ossl_quic_rstream_get_record() - that one will be always skipped.
+ */
+int ossl_quic_rstream_move_to_rbuf(QUIC_RSTREAM *qrs);
+
+/*
+ * Resizes the internal ring buffer to a new `rbuf_size` size.
+ * Returns 1 on success, 0 on error.
+ * Possible error conditions are an allocation failure, trying to resize
+ * the ring buffer when ossl_quic_rstream_get_record() was called and
+ * not yet released, or trying to resize the ring buffer to a smaller size
+ * than currently occupied.
+ */
+int ossl_quic_rstream_resize_rbuf(QUIC_RSTREAM *qrs, size_t rbuf_size);
 # endif
 
 #endif