MINOR: mux-quic: complete functions to detect stream type
Improve the functions used to detect the stream characteristics :
uni/bidirectional and local/remote initiated.
Most notably, these functions are now designed to work transparently for
a MUX in the frontend or backend side. For this, we use the connection
to determine the current MUX side. This will be useful if QUIC is
implemented on the server side.
diff --git a/include/haproxy/mux_quic.h b/include/haproxy/mux_quic.h
index 4e588bc..56bbad5 100644
--- a/include/haproxy/mux_quic.h
+++ b/include/haproxy/mux_quic.h
@@ -7,6 +7,7 @@
#endif
#include <haproxy/api.h>
+#include <haproxy/connection.h>
#include <haproxy/mux_quic-t.h>
#include <haproxy/xprt_quic-t.h>
@@ -42,12 +43,26 @@
return id & QCS_ID_TYPE_MASK;
}
-/* Return 1 if the stream with <id> as ID attached to <qcc> connection
- * has been locally initiated, 0 if not.
- */
-static inline int qc_local_stream_id(struct qcc *qcc, uint64_t id)
+/* Return true if stream has been opened locally. */
+static inline int quic_stream_is_local(struct qcc *qcc, uint64_t id)
+{
+ return conn_is_back(qcc->conn) == !(id & QCS_ID_SRV_INTIATOR_BIT);
+}
+
+/* Return true if stream is opened by peer. */
+static inline int quic_stream_is_remote(struct qcc *qcc, uint64_t id)
+{
+ return !quic_stream_is_local(qcc, id);
+}
+
+static inline int quic_stream_is_uni(uint64_t id)
+{
+ return id & QCS_ID_DIR_BIT;
+}
+
+static inline int quic_stream_is_bidi(uint64_t id)
{
- return id & QCS_ID_SRV_INTIATOR_BIT;
+ return !quic_stream_is_uni(id);
}
struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id);
diff --git a/src/mux_quic.c b/src/mux_quic.c
index c16e3d2..7c52ac0 100644
--- a/src/mux_quic.c
+++ b/src/mux_quic.c
@@ -113,7 +113,7 @@
strm_type = id & QCS_ID_TYPE_MASK;
sub_id = id >> QCS_ID_TYPE_SHIFT;
strm_node = NULL;
- if (qc_local_stream_id(qcc, id)) {
+ if (quic_stream_is_local(qcc, id)) {
/* Local streams: this stream must be already opened. */
strm_node = eb64_lookup(&qcc->streams_by_id, id);
if (!strm_node) {