/*
 * QUIC mux-demux for connections
 *
 * Copyright 2021 HAProxy Technologies, Frédéric Lécaille <flecaille@haproxy.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 *
 */

#include <import/eb32tree.h>
#include <haproxy/api.h>
#include <haproxy/cfgparse.h>
#include <haproxy/connection.h>
#include <haproxy/h3.h>
#include <haproxy/istbuf.h>
#include <haproxy/log.h>
#include <haproxy/mux_quic.h>
#include <haproxy/net_helper.h>
#include <haproxy/quic_frame.h>
#include <haproxy/session-t.h>
#include <haproxy/stats.h>
#include <haproxy/stream.h>
#include <haproxy/stream_interface.h>
#include <haproxy/trace.h>

/* dummy streams returned for closed, error, refused, idle and states */
static const struct qcs *qc_closed_stream;

/* Connection flags (32 bit), in qcc->flags */
#define QC_CF_NONE              0x00000000

/* Flags indicating why writing to the mux is blocked. */
#define QC_CF_MUX_MALLOC        0x00000001  // mux blocked on lack of connection's mux buffer
#define QC_CF_MUX_MFULL         0x00000002  // mux blocked on connection's mux buffer full
#define QC_CF_MUX_BLOCK_ANY     0x00000003  // aggregate of the mux flags above

/* Flags indicating why writing to the demux is blocked.
 * The first two ones directly affect the ability for the mux to receive data
 * from the connection. The other ones affect the mux's ability to demux
 * received data.
 */
#define QC_CF_DEM_DFULL         0x00000004  // demux blocked on connection's demux buffer full

#define QC_CF_DEM_MBUSY         0x00000008  // demux blocked on connection's mux side busy
#define QC_CF_DEM_MROOM         0x00000010  // demux blocked on lack of room in mux buffer
#define QC_CF_DEM_SALLOC        0x00000020  // demux blocked on lack of stream's request buffer
#define QC_CF_DEM_SFULL         0x00000040  // demux blocked on stream request buffer full
#define QC_CF_DEM_TOOMANY       0x00000100  // demux blocked waiting for some conn_streams to leave
#define QC_CF_DEM_BLOCK_ANY     0x00000170  // aggregate of the demux flags above except DFULL

/* other flags */
#define QC_CF_IS_BACK           0x00008000  // this is an outgoing connection

#define QC_SS_MASK(state) (1UL << (state))
#define QC_SS_IDLE_BIT    (1UL << QC_SS_IDLE)
#define QC_SS_RLOC_BIT    (1UL << QC_SS_RLOC)
#define QC_SS_RREM_BIT    (1UL << QC_SS_RREM)
#define QC_SS_OPEN_BIT    (1UL << QC_SS_OPEN)
#define QC_SS_HREM_BIT    (1UL << QC_SS_HREM)
#define QC_SS_HLOC_BIT    (1UL << QC_SS_HLOC)
#define QC_SS_ERROR_BIT   (1UL << QC_SS_ERROR)
#define QC_SS_CLOSED_BIT  (1UL << QC_SS_CLOSED)


/* trace source and events */
static void qc_trace(enum trace_level level, uint64_t mask, \
                     const struct trace_source *src,
                     const struct ist where, const struct ist func,
                     const void *a1, const void *a2, const void *a3, const void *a4);

/* The event representation is split like this :
 *   strm  - application layer
 *   qcs   - internal QUIC stream
 *   qcc   - internal QUIC connection
 *   conn  - external connection
 *
 */
static const struct trace_event qc_trace_events[] = {
#define           QC_EV_QCC_NEW       (1ULL <<  0)
	{ .mask = QC_EV_QCC_NEW,      .name = "qcc_new",     .desc = "new QUIC connection" },
#define           QC_EV_QCC_RECV      (1ULL <<  1)
	{ .mask = QC_EV_QCC_RECV,     .name = "qcc_recv",    .desc = "Rx on QUIC connection" },
#define           QC_EV_QCC_SEND      (1ULL <<  2)
	{ .mask = QC_EV_QCC_SEND,     .name = "qcc_send",    .desc = "Tx on QUIC connection" },
#define           QC_EV_QCC_FCTL      (1ULL <<  3)
	{ .mask = QC_EV_QCC_FCTL,     .name = "qcc_fctl",    .desc = "QUIC connection flow-controlled" },
#define           QC_EV_QCC_BLK       (1ULL <<  4)
	{ .mask = QC_EV_QCC_BLK,      .name = "qcc_blk",     .desc = "QUIC connection blocked" },
#define           QC_EV_QCC_WAKE      (1ULL <<  5)
	{ .mask = QC_EV_QCC_WAKE,     .name = "qcc_wake",    .desc = "QUIC connection woken up" },
#define           QC_EV_QCC_END       (1ULL <<  6)
	{ .mask = QC_EV_QCC_END,      .name = "qcc_end",     .desc = "QUIC connection terminated" },
#define           QC_EV_QCC_ERR       (1ULL <<  7)
	{ .mask = QC_EV_QCC_ERR,      .name = "qcc_err",     .desc = "error on QUIC connection" },
#define           QC_EV_TX_FRAME      (1ULL <<  8)
	{ .mask = QC_EV_TX_FRAME,     .name = "tx_frame",    .desc = "transmission of any QUIC frame" },
#define           QC_EV_QCS_NEW       (1ULL <<  9)
	{ .mask = QC_EV_QCS_NEW,      .name = "qcs_new",     .desc = "new QUIC stream" },
#define           QC_EV_QCS_GET       (1ULL << 10)
	{ .mask = QC_EV_QCS_GET,      .name = "qcs_get",     .desc = "get QUIC stream by ID" },
#define           QC_EV_QCS_SEND      (1ULL << 11)
	{ .mask = QC_EV_QCS_SEND,     .name = "qcs_send",    .desc = "Tx for QUIC stream" },
#define           QC_EV_QCS_FCTL      (1ULL << 12)
	{ .mask = QC_EV_QCS_FCTL,     .name = "qcs_fctl",    .desc = "QUIC stream flow-controlled" },
#define           QC_EV_QCS_BLK       (1ULL << 13)
	{ .mask = QC_EV_QCS_BLK,      .name = "qcs_blk",     .desc = "QUIC stream blocked" },
#define           QC_EV_QCS_WAKE      (1ULL << 14)
	{ .mask = QC_EV_QCS_WAKE,     .name = "qcs_wake",    .desc = "QUIC stream woken up" },
#define           QC_EV_QCS_END       (1ULL << 15)
	{ .mask = QC_EV_QCS_END,      .name = "qcs_end",     .desc = "QUIC stream terminated" },
#define           QC_EV_QCS_ERR       (1ULL << 16)
	{ .mask = QC_EV_QCS_ERR,      .name = "qcs_err",     .desc = "error on QUIC stream" },
#define           QC_EV_STRM_NEW      (1ULL << 17)
	{ .mask = QC_EV_STRM_NEW,     .name = "strm_new",    .desc = "app-layer stream creation" },
#define           QC_EV_STRM_RECV     (1ULL << 18)
	{ .mask = QC_EV_STRM_RECV,    .name = "strm_recv",   .desc = "receiving data for stream" },
#define           QC_EV_STRM_SEND     (1ULL << 19)
	{ .mask = QC_EV_STRM_SEND,    .name = "strm_send",   .desc = "sending data for stream" },
#define           QC_EV_STRM_FULL     (1ULL << 20)
	{ .mask = QC_EV_STRM_FULL,    .name = "strm_full",   .desc = "stream buffer full" },
#define           QC_EV_STRM_WAKE     (1ULL << 21)
	{ .mask = QC_EV_STRM_WAKE,    .name = "strm_wake",   .desc = "stream woken up" },
#define           QC_EV_STRM_SHUT     (1ULL << 22)
	{ .mask = QC_EV_STRM_SHUT,    .name = "strm_shut",   .desc = "stream shutdown" },
#define           QC_EV_STRM_END      (1ULL << 23)
	{ .mask = QC_EV_STRM_END,     .name = "strm_end",    .desc = "detaching app-layer stream" },
#define           QC_EV_STRM_ERR      (1ULL << 24)
	{ .mask = QC_EV_STRM_ERR,     .name = "strm_err",    .desc = "stream error" },
	{ }
};

static const struct name_desc qc_trace_lockon_args[4] = {
	/* arg1 */ { /* already used by the connection */ },
	/* arg2 */ { .name = "qcs", .desc = "QUIC stream" },
	/* arg3 */ { },
	/* arg4 */ { }
};

static const struct name_desc qc_trace_decoding[] = {
#define QC_VERB_CLEAN    1
	{ .name="clean",    .desc="only user-friendly stuff, generally suitable for level \"user\"" },
#define QC_VERB_MINIMAL  2
	{ .name="minimal",  .desc="report only qcc/qcs state and flags, no real decoding" },
#define QC_VERB_SIMPLE   3
	{ .name="simple",   .desc="add request/response status line or frame info when available" },
#define QC_VERB_ADVANCED 4
	{ .name="advanced", .desc="add header fields or frame decoding when available" },
#define QC_VERB_COMPLETE 5
	{ .name="complete", .desc="add full data dump when available" },
	{ /* end */ }
};

static struct trace_source trace_mux_quic = {
	.name = IST("mux_quic"),
	.desc = "QUIC multiplexer",
	.arg_def = TRC_ARG1_CONN,  // TRACE()'s first argument is always a connection
	.default_cb = qc_trace,
	.known_events = qc_trace_events,
	.lockon_args = qc_trace_lockon_args,
	.decoding = qc_trace_decoding,
	.report_events = ~0,  // report everything by default
};

#define TRACE_SOURCE &trace_mux_quic
INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE);

/* quic stats module */
enum {
	QC_ST_RESET_STREAM_RCVD,

	QC_ST_CONN_PROTO_ERR,
	QC_ST_STRM_PROTO_ERR,
	QC_ST_RESET_STREAM_SENT,

	QC_ST_OPEN_CONN,
	QC_ST_OPEN_STREAM,
	QC_ST_TOTAL_CONN,
	QC_ST_TOTAL_STREAM,

	QC_STATS_COUNT /* must be the last member of the enum */
};

static struct name_desc qc_stats[] = {
	[QC_ST_RESET_STREAM_RCVD] = { .name = "qc_rst_stream_rcvd",
	                              .desc = "Total number of received RESET_STREAM frames" },

	[QC_ST_CONN_PROTO_ERR]    = { .name = "qc_detected_conn_protocol_errors",
	                              .desc = "Total number of connection protocol errors" },
	[QC_ST_STRM_PROTO_ERR]    = { .name = "qc_detected_strm_protocol_errors",
	                              .desc = "Total number of stream protocol errors" },
	[QC_ST_RESET_STREAM_SENT] = { .name = "qc_rst_stream_resp",
	                              .desc = "Total number of RESET_STREAM sent on detected error" },

	[QC_ST_OPEN_CONN]    = { .name = "qc_open_connections",
	                         .desc = "Count of currently open connections" },
	[QC_ST_OPEN_STREAM]  = { .name = "qc_backend_open_streams",
	                         .desc = "Count of currently open streams" },
	[QC_ST_TOTAL_CONN]   = { .name = "qc_open_connections",
	                         .desc = "Total number of connections" },
	[QC_ST_TOTAL_STREAM] = { .name = "qc_backend_open_streams",
	                         .desc = "Total number of streams" },
};

static struct qc_counters {
	long long rst_stream_rcvd; /* total number of RESET_STREAM frame received */

	long long conn_proto_err;  /* total number of protocol errors detected */
	long long strm_proto_err;  /* total number of protocol errors detected */
	long long rst_stream_resp; /* total number of RESET_STREAM frame sent on error */

	long long open_conns;    /* count of currently open connections */
	long long open_streams;  /* count of currently open streams */
	long long total_conns;   /* total number of connections */
	long long total_streams; /* total number of streams */
} qc_counters;

static void qc_fill_stats(void *data, struct field *stats)
{
	struct qc_counters *counters = data;

	stats[QC_ST_RESET_STREAM_RCVD] = mkf_u64(FN_COUNTER, counters->rst_stream_rcvd);

	stats[QC_ST_CONN_PROTO_ERR]  = mkf_u64(FN_COUNTER, counters->conn_proto_err);
	stats[QC_ST_STRM_PROTO_ERR]  = mkf_u64(FN_COUNTER, counters->strm_proto_err);
	stats[QC_ST_RESET_STREAM_SENT] = mkf_u64(FN_COUNTER, counters->rst_stream_resp);

	stats[QC_ST_OPEN_CONN]    = mkf_u64(FN_GAUGE,   counters->open_conns);
	stats[QC_ST_OPEN_STREAM]  = mkf_u64(FN_GAUGE,   counters->open_streams);
	stats[QC_ST_TOTAL_CONN]   = mkf_u64(FN_COUNTER, counters->total_conns);
	stats[QC_ST_TOTAL_STREAM] = mkf_u64(FN_COUNTER, counters->total_streams);
}

static struct stats_module qc_stats_module = {
	.name          = "quic",
	.fill_stats    = qc_fill_stats,
	.stats         = qc_stats,
	.stats_count   = QC_STATS_COUNT,
	.counters      = &qc_counters,
	.counters_size = sizeof(qc_counters),
	.domain_flags  = MK_STATS_PROXY_DOMAIN(STATS_PX_CAP_FE|STATS_PX_CAP_BE),
	.clearable     = 1,
};

INITCALL1(STG_REGISTER, stats_register_module, &qc_stats_module);

/* the qcc connection pool */
DECLARE_STATIC_POOL(pool_head_qcc, "qcc", sizeof(struct qcc));
/* the qcs stream pool */
DECLARE_POOL(pool_head_qcs, "qcs", sizeof(struct qcs));

static struct task *qc_timeout_task(struct task *t, void *context, unsigned int state);
static int qc_send(struct qcc *qcc);
static int qc_recv(struct qcc *qcc);
static int qc_process(struct qcc *qcc);
static struct task *qc_io_cb(struct task *t, void *ctx, unsigned int state);
static inline struct qcs *qcc_st_by_id(struct qcc *qcc, int id);
static struct task *qc_deferred_shut(struct task *t, void *ctx, unsigned int state);
static struct qcs *qcc_bck_stream_new(struct qcc *qcc, int dir,
                                      struct conn_stream *cs, struct session *sess);
static void qcs_alert(struct qcs *qcs);

/* returns a qcc state as an abbreviated 3-letter string, or "???" if unknown */
static inline const char *qcc_st_to_str(enum qc_cs st)
{
	switch (st) {
	case QC_CS_NOERR:     return "NER";
	default:              return "???";
	}
}

/* marks an error on the connection */
void qc_error(struct qcc *qcc, int err)
{
	TRACE_POINT(QC_EV_QCC_ERR, qcc->conn, 0, 0, (void *)(long)(err));
	qcc->errcode = err;
	qcc->st0 = QC_CS_ERROR;
}

static inline const char *qcs_rx_st_to_str(enum qcs_rx_st st)
{
	switch (st) {
	case QC_RX_SS_IDLE:       return "IDL";
	case QC_RX_SS_RECV:       return "RCV";
	case QC_RX_SS_SIZE_KNOWN: return "SKNWN";
	case QC_RX_SS_DATA_RECVD: return "DATARCVD";
	case QC_RX_SS_DATA_READ : return "DATAREAD";
	case QC_RX_SS_RST_RECVD:  return "RSTRCVD";
	case QC_RX_SS_RST_READ:   return "RSTREAD";
	default:                  return "???";
	}
}

static inline const char *qcs_tx_st_to_str(enum qcs_tx_st st)
{
	switch (st) {
	case QC_TX_SS_IDLE:       return "IDL";
	case QC_TX_SS_READY:      return "READY";
	case QC_TX_SS_SEND:       return "SEND";
	case QC_TX_SS_DATA_SENT:  return "DATASENT";
	case QC_TX_SS_DATA_RECVD: return "DATARCVD";
	case QC_TX_SS_RST_SENT:   return "RSTSENT";
	case QC_TX_SS_RST_RECVD:  return "RSTRCVD";
    default:                  return "???";
	}
}

/* the QUIC traces always expect that arg1, if non-null, is of type connection
 * (from which we can derive qcc), that arg2, if non-null, is of type qcs.
 */
static void qc_trace(enum trace_level level, uint64_t mask, const struct trace_source *src,
                     const struct ist where, const struct ist func,
                     const void *a1, const void *a2, const void *a3, const void *a4)
{
	const struct connection *conn = a1;
	const struct qcc *qcc = conn ? conn->ctx : NULL;
	const struct qcs *qcs = a2;

	if (!qcc)
		return;

	if (src->verbosity > QC_VERB_CLEAN) {
		chunk_appendf(&trace_buf, " : qcc=%p(%c,%s)",
		              qcc, conn_is_back(conn) ? 'B' : 'F', qcc_st_to_str(qcc->st0));
		if (qcs) {
			chunk_appendf(&trace_buf, " qcs=%p(rx.%s,tx.%s)",
			              qcs, qcs_rx_st_to_str(qcs->rx.st), qcs_tx_st_to_str(qcs->tx.st));
		}
	}
}


/* Detect a pending read0 for a QUIC connection. It happens if a read0 is pending
 * on the connection AND if there is no more data in the demux buffer. The
 * function returns 1 to report a read0 or 0 otherwise.
 */
__maybe_unused
static int qcc_read0_pending(struct qcc *qcc)
{
	if (conn_xprt_read0_pending(qcc->conn) && !qcc->rx.inmux)
		return 1;
	return 0;
}

/* returns true if the connection is allowed to expire, false otherwise. A
 * connection may expire when:
 *   - it has no stream
 *   - it has data in the mux buffer
 *   - it has streams in the blocked list
 *   - it has streams in the fctl list
 *   - it has streams in the send list
 * Otherwise it means some streams are waiting in the data layer and it should
 * not expire.
 */
__maybe_unused
static inline int qcc_may_expire(const struct qcc *qcc)
{
	return eb_is_empty(&qcc->streams_by_id) ||
	       br_data(qcc->mbuf) ||
	       !LIST_ISEMPTY(&qcc->blocked_list) ||
	       !LIST_ISEMPTY(&qcc->fctl_list) ||
	       !LIST_ISEMPTY(&qcc->send_list);
}

static __inline int
qcc_is_dead(const struct qcc *qcc)
{
	if (eb_is_empty(&qcc->streams_by_id) &&     /* don't close if streams exist */
	    ((qcc->conn->flags & CO_FL_ERROR) ||    /* errors close immediately */
	     (qcc->st0 >= QC_CS_ERROR && !qcc->task) || /* a timeout stroke earlier */
	     (!(qcc->conn->owner)) || /* Nobody's left to take care of the connection, drop it now */
	     (!br_data(qcc->mbuf) &&  /* mux buffer empty, also process clean events below */
	      conn_xprt_read0_pending(qcc->conn))))
		return 1;

	return 0;
}

/*****************************************************/
/* functions below are for dynamic buffer management */
/*****************************************************/

/* indicates whether or not the we may call the qc_recv() function to attempt
 * to receive data into the buffer and/or demux pending data. The condition is
 * a bit complex due to some API limits for now. The rules are the following :
 *   - if an error or a shutdown was detected on the connection and the buffer
 *     is empty, we must not attempt to receive
 *   - if the demux buf failed to be allocated, we must not try to receive and
 *     we know there is nothing pending
 *   - if no flag indicates a blocking condition, we may attempt to receive,
 *     regardless of whether the demux buffer is full or not, so that only
 *     de demux part decides whether or not to block. This is needed because
 *     the connection API indeed prevents us from re-enabling receipt that is
 *     already enabled in a polled state, so we must always immediately stop
 *     as soon as the demux can't proceed so as never to hit an end of read
 *     with data pending in the buffers.
 *   - otherwise must may not attempt
 */
static inline int qc_recv_allowed(const struct qcc *qcc)
{
	if (qcc->rx.inmux == 0 &&
	    (qcc->st0 >= QC_CS_ERROR ||
	     qcc->conn->flags & CO_FL_ERROR ||
	     conn_xprt_read0_pending(qcc->conn)))
		return 0;

	if (!(qcc->flags & QC_CF_DEM_BLOCK_ANY))
		return 1;

	return 0;
}

/* restarts reading on the connection if it was not enabled */
static inline void qcc_restart_reading(const struct qcc *qcc, int consider_buffer)
{
	if (!qc_recv_allowed(qcc))
		return;

	if ((!consider_buffer || !qcc->rx.inmux)
	    && (qcc->wait_event.events & SUB_RETRY_RECV))
		return;

	tasklet_wakeup(qcc->wait_event.tasklet);
}

/* Tries to grab a buffer and to re-enable processing on mux <target>. The qcc
 * flags are used to figure what buffer was requested. It returns 1 if the
 * allocation succeeds, in which case the connection is woken up, or 0 if it's
 * impossible to wake up and we prefer to be woken up later.
 */
static int qc_buf_available(void *target)
{
	struct qcc *qcc = target;

	if ((qcc->flags & QC_CF_MUX_MALLOC) && b_alloc(br_tail(qcc->mbuf))) {
		qcc->flags &= ~QC_CF_MUX_MALLOC;

		if (qcc->flags & QC_CF_DEM_MROOM) {
			qcc->flags &= ~QC_CF_DEM_MROOM;
			qcc_restart_reading(qcc, 1);
		}
		return 1;
	}

#if 0
	if ((qcc->flags & QC_CF_DEM_SALLOC) &&
	    (qcs = qcc_st_by_id(qcc, qcc->dsi)) && qcs->cs &&
	    b_alloc_margin(&qcs->rxbuf, 0)) {
		qcc->flags &= ~QC_CF_DEM_SALLOC;
		qcc_restart_reading(qcc, 1);
		return 1;
	}
#endif

	return 0;
}

struct buffer *qc_get_buf(struct qcc *qcc, struct buffer *bptr)
{
	struct buffer *buf = NULL;

	if (likely(!LIST_INLIST(&qcc->buf_wait.list)) &&
	    unlikely((buf = b_alloc(bptr)) == NULL)) {
		qcc->buf_wait.target = qcc;
		qcc->buf_wait.wakeup_cb = qc_buf_available;
		LIST_APPEND(&ti->buffer_wq, &qcc->buf_wait.list);
	}

	return buf;
}

__maybe_unused
static inline void qc_release_buf(struct qcc *qcc, struct buffer *bptr)
{
	if (bptr->size) {
		b_free(bptr);
		offer_buffers(NULL, 1);
	}
}

static inline void qc_release_mbuf(struct qcc *qcc)
{
	struct buffer *buf;
	unsigned int count = 0;

	while (b_size(buf = br_head_pick(qcc->mbuf))) {
		b_free(buf);
		count++;
	}
	if (count)
		offer_buffers(NULL, count);
}

/* returns the number of streams in use on a connection to figure if it's
 * idle or not. We check nb_cs and not nb_streams as the caller will want
 * to know if it was the last one after a detach().
 */
static int qc_used_streams(struct connection *conn)
{
	struct qcc *qcc = conn->ctx;

	return qcc->nb_cs;
}

/* returns the number of concurrent streams available on the connection with <dir>
 * as direction
 */
static int qc_avail_streams(struct connection *conn, enum qcs_dir dir)
{
	struct qcc *qcc = conn->ctx;
	enum qcs_type qcs_type;

	if (qcc->st0 >= QC_CS_ERROR)
		return 0;

	qcs_type = qcs_type_from_dir(qcc, dir);

	return qcc->strms[qcs_type].max_streams - qcc->strms[qcs_type].nb_streams;
}


/* returns the number of concurrent bidirectional streams available on the
 * connection.
 */
static int qc_avail_streams_bidi(struct connection *conn)
{
	return qc_avail_streams(conn, QCS_BIDI);
}

/* returns the number of concurrent unidirectional streams available on the
 * connection.
 */
static int qc_avail_streams_uni(struct connection *conn)
{
	return qc_avail_streams(conn, QCS_UNI);
}

/*****************************************************************/
/* functions below are dedicated to the mux setup and management */
/*****************************************************************/

/* Update the mux transport parameter after having received remote transpot parameters */
void quic_mux_transport_params_update(struct qcc *qcc)
{
	if (objt_listener(qcc->conn->target)) {
		struct quic_transport_params *clt_params;

		/* Client parameters, params used to TX. */
		clt_params = &qcc->conn->qc->tx.params;

		qcc->tx.max_data = clt_params->initial_max_data;
		/* Client initiated streams must respect the server flow control. */
		qcc->strms[QCS_CLT_BIDI].rx.max_data = clt_params->initial_max_stream_data_bidi_local;
		qcc->strms[QCS_CLT_UNI].rx.max_data = clt_params->initial_max_stream_data_uni;

		/* Server initiated streams must respect the server flow control. */
		qcc->strms[QCS_SRV_BIDI].max_streams = clt_params->initial_max_streams_bidi;
		qcc->strms[QCS_SRV_BIDI].tx.max_data = clt_params->initial_max_stream_data_bidi_remote;

		qcc->strms[QCS_SRV_UNI].max_streams = clt_params->initial_max_streams_uni;
		qcc->strms[QCS_SRV_UNI].tx.max_data = clt_params->initial_max_stream_data_uni;
	}
	else {
		struct quic_transport_params *srv_params;

		/* server parameters, TX params. */
		srv_params = &qcc->conn->qc->tx.params;

		qcc->tx.max_data = srv_params->initial_max_data;
		/* Client initiated streams must respect the server flow control. */
		qcc->strms[QCS_CLT_BIDI].max_streams = srv_params->initial_max_streams_bidi;
		qcc->strms[QCS_CLT_BIDI].tx.max_data = srv_params->initial_max_stream_data_bidi_remote;

		qcc->strms[QCS_CLT_UNI].max_streams = srv_params->initial_max_streams_uni;
		qcc->strms[QCS_CLT_UNI].tx.max_data = srv_params->initial_max_stream_data_uni;

		/* Server initiated streams must respect the server flow control. */
		qcc->strms[QCS_SRV_BIDI].rx.max_data = srv_params->initial_max_stream_data_bidi_local;
		qcc->strms[QCS_SRV_UNI].rx.max_data = srv_params->initial_max_stream_data_uni;
	}

	/* Now that we have all the flow control information, we can finalize the application
	 * context.
	 */
	qcc->app_ops->finalize(qcc->ctx);
}

/* Initialize the mux once it's attached. For outgoing connections, the context
 * is already initialized before installing the mux, so we detect incoming
 * connections from the fact that the context is still NULL (even during mux
 * upgrades). <input> is always used as Input buffer and may contain data. It is
 * the caller responsibility to not reuse it anymore. Returns < 0 on error.
 */
static int qc_init(struct connection *conn, struct proxy *prx,
                   struct session *sess, struct buffer *input)
{
	struct qcc *qcc;
	struct task *t = NULL;
	void *conn_ctx = conn->ctx;

	TRACE_ENTER(QC_EV_QCC_NEW);

	qcc = pool_alloc(pool_head_qcc);
	if (!qcc)
		goto fail_no_qcc;

	if (conn_is_back(conn)) {
		qcc->flags = QC_CF_IS_BACK;
		qcc->shut_timeout = qcc->timeout = prx->timeout.server;
		if (tick_isset(prx->timeout.serverfin))
			qcc->shut_timeout = prx->timeout.serverfin;

		qcc->px_counters = EXTRA_COUNTERS_GET(prx->extra_counters_be,
		                                      &qc_stats_module);
	} else {
		qcc->flags = QC_CF_NONE;
		qcc->shut_timeout = qcc->timeout = prx->timeout.client;
		if (tick_isset(prx->timeout.clientfin))
			qcc->shut_timeout = prx->timeout.clientfin;

		qcc->px_counters = EXTRA_COUNTERS_GET(prx->extra_counters_fe,
		                                      &qc_stats_module);
	}

	qcc->proxy = prx;
	qcc->task = NULL;
	if (tick_isset(qcc->timeout)) {
		t = task_new(tid_bit);
		if (!t)
			goto fail;

		qcc->task = t;
		t->process = qc_timeout_task;
		t->context = qcc;
		t->expire = tick_add(now_ms, qcc->timeout);
	}

	qcc->wait_event.tasklet = tasklet_new();
	if (!qcc->wait_event.tasklet)
		goto fail;

	qcc->wait_event.tasklet->process = qc_io_cb;
	qcc->wait_event.tasklet->context = qcc;
	qcc->wait_event.events = 0;

	/* Initialize the context. */
	qcc->st0 = QC_CS_NOERR;
	qcc->conn = conn;
	qcc->conn->qc->qcc = qcc;

	/* Application layer initialization. */
	qcc->app_ops = &h3_ops;
	if (!qcc->app_ops->init(qcc))
		goto fail;

	/* The transports parameters which control the data sent have been stored
	 * in ->tx.params. The ones which control the received data are stored in
	 * in ->rx.params.
	 */
	if (objt_listener(qcc->conn->target)) {
		struct quic_transport_params *srv_params;

		/* Server parameters, params used for RX flow control. */
		srv_params = &conn->qc->rx.params;

		qcc->rx.max_data = srv_params->initial_max_data;
		qcc->tx.max_data = 0;
		/* Client initiated streams must respect the server flow control. */
		qcc->strms[QCS_CLT_BIDI].max_streams = srv_params->initial_max_streams_bidi;
		qcc->strms[QCS_CLT_BIDI].nb_streams  = 0;
		qcc->strms[QCS_CLT_BIDI].largest_id  = -1;
		qcc->strms[QCS_CLT_BIDI].rx.max_data = 0;
		qcc->strms[QCS_CLT_BIDI].tx.max_data = srv_params->initial_max_stream_data_bidi_remote;

		qcc->strms[QCS_CLT_UNI].max_streams = srv_params->initial_max_streams_uni;
		qcc->strms[QCS_CLT_UNI].nb_streams = 0;
		qcc->strms[QCS_CLT_UNI].largest_id = -1;
		qcc->strms[QCS_CLT_UNI].rx.max_data = 0;
		qcc->strms[QCS_CLT_UNI].tx.max_data = srv_params->initial_max_stream_data_uni;

		/* Server initiated streams must respect the server flow control. */
		qcc->strms[QCS_SRV_BIDI].max_streams = 0;
		qcc->strms[QCS_SRV_BIDI].nb_streams  = 0;
		qcc->strms[QCS_SRV_BIDI].largest_id  = -1;
		qcc->strms[QCS_SRV_BIDI].rx.max_data = srv_params->initial_max_stream_data_bidi_local;
		qcc->strms[QCS_SRV_BIDI].tx.max_data = 0;

		qcc->strms[QCS_SRV_UNI].max_streams = 0;
		qcc->strms[QCS_SRV_UNI].nb_streams = 0;
		qcc->strms[QCS_SRV_UNI].largest_id = -1;
		qcc->strms[QCS_SRV_UNI].rx.max_data = srv_params->initial_max_stream_data_uni;
		qcc->strms[QCS_SRV_UNI].tx.max_data = 0;
	}
	else {
		struct quic_transport_params *clt_params;

		/* client parameters, RX params. */
		clt_params = &conn->qc->rx.params;

		qcc->rx.max_data = clt_params->initial_max_data;
		qcc->tx.max_data = 0;
		/* Client initiated streams must respect the server flow control. */
		qcc->strms[QCS_CLT_BIDI].max_streams = 0;
		qcc->strms[QCS_CLT_BIDI].nb_streams  = 0;
		qcc->strms[QCS_CLT_BIDI].largest_id  = -1;
		qcc->strms[QCS_CLT_BIDI].rx.max_data = clt_params->initial_max_stream_data_bidi_local;
		qcc->strms[QCS_CLT_BIDI].tx.max_data = 0;

		qcc->strms[QCS_CLT_UNI].max_streams = 0;
		qcc->strms[QCS_CLT_UNI].nb_streams = 0;
		qcc->strms[QCS_CLT_UNI].largest_id = -1;
		qcc->strms[QCS_CLT_UNI].rx.max_data = clt_params->initial_max_stream_data_uni;
		qcc->strms[QCS_CLT_UNI].tx.max_data = 0;

		/* Server initiated streams must respect the server flow control. */
		qcc->strms[QCS_SRV_BIDI].max_streams = clt_params->initial_max_streams_bidi;
		qcc->strms[QCS_SRV_BIDI].nb_streams  = 0;
		qcc->strms[QCS_SRV_BIDI].largest_id  = -1;
		qcc->strms[QCS_SRV_BIDI].rx.max_data = 0;
		qcc->strms[QCS_SRV_BIDI].tx.max_data = clt_params->initial_max_stream_data_bidi_remote;

		qcc->strms[QCS_SRV_UNI].max_streams = clt_params->initial_max_streams_uni;
		qcc->strms[QCS_SRV_UNI].nb_streams = 0;
		qcc->strms[QCS_SRV_UNI].largest_id = -1;
		qcc->strms[QCS_SRV_UNI].rx.max_data = 0;
		qcc->strms[QCS_SRV_UNI].tx.max_data = clt_params->initial_max_stream_data_uni;

	}

	/* Initialize the streams counters. */
	qcc->nb_cs = 0;
	qcc->stream_cnt = 0;

	br_init(qcc->mbuf, sizeof(qcc->mbuf) / sizeof(qcc->mbuf[0]));
	qcc->streams_by_id = EB_ROOT_UNIQUE;
	LIST_INIT(&qcc->send_list);
	LIST_INIT(&qcc->fctl_list);
	LIST_INIT(&qcc->blocked_list);
	LIST_INIT(&qcc->buf_wait.list);
	MT_LIST_INIT(&qcc->qcs_rxbuf_wlist);

	conn->ctx = qcc;

	if (t)
		task_queue(t);

	if (qcc->flags & QC_CF_IS_BACK) {
		/* FIXME: For outgoing connections we need to immediately allocate streams.
		 * This highly depends on the QUIC application needs.
		 */
	}

	HA_ATOMIC_ADD(&qcc->px_counters->open_conns, 1);
	HA_ATOMIC_ADD(&qcc->px_counters->total_conns, 1);

	/* prepare to read something */
	qcc_restart_reading(qcc, 1);
	TRACE_LEAVE(QC_EV_QCC_NEW, conn);
	return 0;

  fail:
	task_destroy(t);
	if (qcc->wait_event.tasklet)
		tasklet_free(qcc->wait_event.tasklet);
	pool_free(pool_head_qcc, qcc);
  fail_no_qcc:
	conn->ctx = conn_ctx; /* restore saved ctx */
	TRACE_DEVEL("leaving in error", QC_EV_QCC_NEW|QC_EV_QCC_END|QC_EV_QCC_ERR);
	return -1;
}

/* returns the stream associated with id <id> or NULL if not found */
__maybe_unused
static inline struct qcs *qcc_st_by_id(struct qcc *qcc, int id)
{
	struct eb64_node *node;

	node = eb64_lookup(&qcc->streams_by_id, id);
	if (!node)
		return (struct qcs *)qc_closed_stream;

	return container_of(node, struct qcs, by_id);
}

/* release function. This one should be called to free all resources allocated
 * to the mux.
 */
static void qc_release(struct qcc *qcc)
{
	struct connection *conn = NULL;

	TRACE_ENTER(QC_EV_QCC_END);

	if (qcc) {
		/* The connection must be aattached to this mux to be released */
		if (qcc->conn && qcc->conn->ctx == qcc)
			conn = qcc->conn;

		TRACE_DEVEL("freeing qcc", QC_EV_QCC_END, conn);

		if (LIST_INLIST(&qcc->buf_wait.list))
			LIST_DELETE(&qcc->buf_wait.list);

		qc_release_mbuf(qcc);

		if (qcc->task) {
			qcc->task->context = NULL;
			task_wakeup(qcc->task, TASK_WOKEN_OTHER);
			qcc->task = NULL;
		}
		if (qcc->wait_event.tasklet)
			tasklet_free(qcc->wait_event.tasklet);
		if (conn && qcc->wait_event.events != 0)
			conn->xprt->unsubscribe(conn, conn->xprt_ctx, qcc->wait_event.events,
						&qcc->wait_event);

		HA_ATOMIC_SUB(&qcc->px_counters->open_conns, 1);

		pool_free(pool_head_qcc, qcc);
	}

	if (conn) {
		conn->mux = NULL;
		conn->ctx = NULL;
		TRACE_DEVEL("freeing conn", QC_EV_QCC_END, conn);

		conn_stop_tracking(conn);
		conn_full_close(conn);
		if (conn->destroy_cb)
			conn->destroy_cb(conn);
		conn_free(conn);
	}

	TRACE_LEAVE(QC_EV_QCC_END);
}


/******************************************************/
/* functions below are for the QUIC protocol processing */
/******************************************************/

/* attempt to notify the data layer of recv availability */
__maybe_unused
static void qcs_notify_recv(struct qcs *qcs)
{
	if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) {
		TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
		tasklet_wakeup(qcs->subs->tasklet);
		qcs->subs->events &= ~SUB_RETRY_RECV;
		if (!qcs->subs->events)
			qcs->subs = NULL;
	}
}

/* attempt to notify the data layer of send availability */
__maybe_unused
static void qcs_notify_send(struct qcs *qcs)
{
	if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) {
		TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
		qcs->flags |= QC_SF_NOTIFIED;
		tasklet_wakeup(qcs->subs->tasklet);
		qcs->subs->events &= ~SUB_RETRY_SEND;
		if (!qcs->subs->events)
			qcs->subs = NULL;
	}
	else if (qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW)) {
		TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
		tasklet_wakeup(qcs->shut_tl);
	}
}

/* alerts the data layer, trying to wake it up by all means, following
 * this sequence :
 *   - if the qcs' data layer is subscribed to recv, then it's woken up for recv
 *   - if its subscribed to send, then it's woken up for send
 *   - if it was subscribed to neither, its ->wake() callback is called
 * It is safe to call this function with a closed stream which doesn't have a
 * conn_stream anymore.
 */
__maybe_unused
static void qcs_alert(struct qcs *qcs)
{
	TRACE_ENTER(QC_EV_QCS_WAKE, qcs->qcc->conn, qcs);

	if (qcs->subs ||
	    (qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW))) {
		qcs_notify_recv(qcs);
		qcs_notify_send(qcs);
	}
	else if (qcs->cs && qcs->cs->data_cb->wake != NULL) {
		TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn, qcs);
		qcs->cs->data_cb->wake(qcs->cs);
	}

	TRACE_LEAVE(QC_EV_QCS_WAKE, qcs->qcc->conn, qcs);
}

/* marks stream <qcs> as CLOSED and decrement the number of active streams for
 * its connection if the stream was not yet closed. Please use this exclusively
 * before closing a stream to ensure stream count is well maintained.
 */
static inline void qcs_close(struct qcs *qcs)
{
	TRACE_ENTER(QC_EV_QCS_END, qcs->qcc->conn, qcs);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCS_END, qcs->qcc->conn, qcs);
}

/* detaches an QUIC stream from its QCC and releases it to the QCS pool. */
/* qcs_destroy should only ever be called by the thread that owns the stream,
 * that means that a tasklet should be used if we want to destroy the qcs
 * from another thread
 */
static void qcs_destroy(struct qcs *qcs)
{
	struct connection *conn = qcs->qcc->conn;

	TRACE_ENTER(QC_EV_QCS_END, conn, qcs);

	qcs_close(qcs);
	eb64_delete(&qcs->by_id);
	if (b_size(&qcs->rx.buf)) {
		b_free(&qcs->rx.buf);
		offer_buffers(NULL, 1);
	}

	if (qcs->subs)
		qcs->subs->events = 0;

	/* There's no need to explicitly call unsubscribe here, the only
	 * reference left would be in the qcc send_list/fctl_list, and if
	 * we're in it, we're getting out anyway
	 */
	LIST_DEL_INIT(&qcs->list);

	/* ditto, calling tasklet_free() here should be ok */
	tasklet_free(qcs->shut_tl);
	pool_free(pool_head_qcs, qcs);

	TRACE_LEAVE(QC_EV_QCS_END, conn);
}

/* allocates a new bidirection stream <id> for connection <qcc> and adds it into qcc's
 * stream tree. In case of error, nothing is added and NULL is returned. The
 * causes of errors can be any failed memory allocation. The caller is
 * responsible for checking if the connection may support an extra stream
 * prior to calling this function.
 */
struct qcs *bidi_qcs_new(struct qcc *qcc, uint64_t id)
{
	struct qcs *qcs;
	enum qcs_type qcs_type;

	TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);

	qcs = pool_alloc(pool_head_qcs);
	if (!qcs)
		goto out;

	qcs->shut_tl = tasklet_new();
	if (!qcs->shut_tl) {
		pool_free(pool_head_qcs, qcs);
		goto out;
	}

	qcs_type = qcs_id_type(id);
	qcs->qcc         = qcc;
	qcs->cs          = NULL;
	qcs->id = qcs->by_id.key = id;
	qcs->frms        = EB_ROOT_UNIQUE;
	qcs->flags       = QC_SF_NONE;

	qcs->rx.buf      = BUF_NULL;
	qcs->rx.st       = QC_RX_SS_IDLE;
	qcs->rx.bytes    = qcs->rx.offset = 0;
	qcs->rx.max_data = qcc->strms[qcs_type].rx.max_data;

	qcs->rx.buf      = BUF_NULL;
	qcs->tx.st       = QC_TX_SS_IDLE;
	qcs->tx.bytes    = qcs->tx.offset = 0;
	qcs->tx.max_data = qcc->strms[qcs_type].tx.max_data;

	eb64_insert(&qcc->streams_by_id, &qcs->by_id);
	qcc->strms[qcs_type].nb_streams++;
	qcc->stream_cnt++;
	qcs->subs = NULL;
	LIST_INIT(&qcs->list);
	qcs->shut_tl->process = qc_deferred_shut;
	qcs->shut_tl->context = qcs;

	HA_ATOMIC_ADD(&qcc->px_counters->open_streams, 1);
	HA_ATOMIC_ADD(&qcc->px_counters->total_streams, 1);

	TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn, qcs);
	return qcs;

 out:
	TRACE_DEVEL("leaving in error", QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn);
	return NULL;
}

/* Release <qcs> outgoing uni-stream */
void qcs_release(struct qcs *qcs)
{
	eb64_delete(&qcs->by_id);
	pool_free(pool_head_qcs, qcs);
}

/* Allocates a locally initiated unidirectional stream. */
struct qcs *luqs_new(struct qcc *qcc)
{
	struct qcs *qcs;
	uint64_t next_id;
	enum qcs_type qcs_type;

	TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);

	qcs = NULL;
	/* QCS_ID_DIR_BIT bit is set for unidirectional stream. */
	if (objt_listener(qcc->conn->target))
	    qcs_type = QCS_ID_SRV_INTIATOR_BIT | QCS_ID_DIR_BIT;
	else
	    qcs_type = QCS_ID_DIR_BIT;

	next_id = qcs_next_id(qcc, qcs_type);
	if (next_id == (uint64_t)-1) {
		TRACE_PROTO("No more stream available", QC_EV_QCS_NEW, qcc->conn);
		goto out;
	}

	qcs = pool_alloc(pool_head_qcs);
	if (!qcs)
		goto out;

	qcs->qcc = qcc;
	qcs->cs = NULL;
	qcs->id = qcs->by_id.key = next_id;
	qcs->frms = EB_ROOT_UNIQUE;
	qcs->flags = QC_SF_NONE;

	qcs->tx.st = QC_TX_SS_IDLE;
	qcs->tx.max_data = qcc->strms[qcs_type].tx.max_data;
	qcs->tx.offset = qcs->tx.bytes = 0;
	qcs->tx.buf = BUF_NULL;

	qcs->subs = NULL;
	LIST_INIT(&qcs->list);
	eb64_insert(&qcc->streams_by_id, &qcs->by_id);

	TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn);
	return qcs;

 out:
	if (qcs)
		pool_free(pool_head_qcs, qcs);
	TRACE_DEVEL("leaving in error", QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn);
	return NULL;
}

/* Allocates a remotely initiated unidirectional stream. */
struct qcs *ruqs_new(struct qcc *qcc, uint64_t id)
{
	struct qcs *qcs;
	enum qcs_type qcs_type;

	TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);
	qcs = pool_alloc(pool_head_qcs);
	if (!qcs)
		goto out;

	qcs_type = qcs_id_type(id);

	qcs->qcc = qcc;
	qcs->cs = NULL;

	qcs->qcc = qcc;
	qcs->id = qcs->by_id.key = id;
	qcs->frms = EB_ROOT_UNIQUE;
	qcs->flags = QC_SF_NONE;

	qcs->rx.st = QC_RX_SS_IDLE;
	qcs->rx.max_data = qcc->strms[qcs_type].rx.max_data;
	qcs->rx.offset = qcs->rx.bytes = 0;
	qcs->rx.buf = BUF_NULL;

	qcs->subs = NULL;
	LIST_INIT(&qcs->list);
	eb64_insert(&qcc->streams_by_id, &qcs->by_id);

	TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn);
	return qcs;

 out:
	TRACE_DEVEL("leaving in error", QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn);
	return NULL;
}

/* attempt to notify the data layer of recv availability */
void ruqs_notify_recv(struct qcs *qcs)
{
	if (qcs->subs && qcs->subs->events & SUB_RETRY_RECV) {
		TRACE_POINT(QC_EV_STRM_WAKE, qcs->qcc->conn);
		tasklet_wakeup(qcs->subs->tasklet);
		qcs->subs->events &= ~SUB_RETRY_RECV;
		if (!qcs->subs->events)
			qcs->subs = NULL;
	}
}

/* Allocates a new stream associated to conn_stream <cs> on the qcc connection
 * with dir as direction and returns it, or NULL in case of memory allocation
 * error or if the highest possible stream ID was reached.
 */
static struct qcs *qcc_bck_stream_new(struct qcc *qcc, int dir,
                                      struct conn_stream *cs, struct session *sess)
{
	struct qcs *qcs = NULL;
	enum qcs_type qcs_type;

	TRACE_ENTER(QC_EV_QCS_NEW, qcc->conn);

	qcs_type = qcs_type_from_dir(qcc, dir);
	if (qcc->strms[qcs_type].largest_id + 1 >= qcc->strms[qcs_type].max_streams)
		goto out;

	/* Defer choosing the ID until we send the first message to create the stream */
	qcs = bidi_qcs_new(qcc, qcc->strms[qcs_type].largest_id + 1);
	if (!qcs)
		goto out;

	qcs->cs = cs;
	qcs->sess = sess;
	cs->ctx = qcs;
	qcc->nb_cs++;

 out:
	if (likely(qcs))
		TRACE_LEAVE(QC_EV_QCS_NEW, qcc->conn, qcs);
	else
		TRACE_LEAVE(QC_EV_QCS_NEW|QC_EV_QCS_ERR|QC_EV_QCS_END, qcc->conn, qcs);
	return qcs;
}

/* Allocates a new bidirectional stream associated to conn_stream <cs> on the <qcc> connection
 * and returns it, or NULL in case of memory allocation error or if the highest
 * possible stream ID was reached.
 */
__maybe_unused
static struct qcs *qcc_bck_stream_new_bidi(struct qcc *qcc,
                                           struct conn_stream *cs, struct session *sess)
{
	return qcc_bck_stream_new(qcc, QCS_BIDI, cs, sess);
}

/* Allocates a new unidirectional stream associated to conn_stream <cs> on the <qcc> connection
 * and returns it, or NULL in case of memory allocation error or if the highest
 * possible stream ID was reached.
 */
__maybe_unused
static struct qcs *qcc_bck_stream_new_uni(struct qcc *qcc,
                                          struct conn_stream *cs, struct session *sess)
{
	return qcc_bck_stream_new(qcc, QCS_UNI, cs, sess);
}


/* wake a specific stream and assign its conn_stream some CS_FL_* flags among
 * CS_FL_ERR_PENDING and CS_FL_ERROR if needed. The stream's state
 * is automatically updated accordingly. If the stream is orphaned, it is
 * destroyed.
 */
static void qcs_wake_one_stream(struct qcs *qcs)
{
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_QCS_WAKE, qcc->conn, qcs);
	if (!qcs->cs) {
		/* this stream was already orphaned */
		qcs_destroy(qcs);
		TRACE_DEVEL("leaving with no qcs", QC_EV_QCS_WAKE, qcc->conn);
		return;
	}
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCS_WAKE, qcc->conn);
}

/* wake the streams attached to the connection, whose id is greater than <last>
 * or unassigned.
 */
static void qc_wake_some_streams(struct qcc *qcc, int last)
{
	struct eb64_node *node;
	struct qcs *qcs;

	TRACE_ENTER(QC_EV_QCS_WAKE, qcc->conn);

	/* Wake all streams with ID > last */
	node = eb64_lookup_ge(&qcc->streams_by_id, last + 1);
	while (node) {
		qcs = container_of(node, struct qcs, by_id);
		node = eb64_next(node);
		qcs_wake_one_stream(qcs);
	}

	/* Wake all streams with unassigned ID (ID == 0) */
	node = eb64_lookup(&qcc->streams_by_id, 0);
	while (node) {
		qcs = container_of(node, struct qcs, by_id);
		if (qcs->id > 0)
			break;
		node = eb64_next(node);
		qcs_wake_one_stream(qcs);
	}

	TRACE_LEAVE(QC_EV_QCS_WAKE, qcc->conn);
}

/* Wake up all blocked streams whose window size has become positive after the
 * mux's initial window was adjusted. This should be done after having processed
 * SETTINGS frames which have updated the mux's initial window size.
 */
__maybe_unused
static void qcc_unblock_sfctl(struct qcc *qcc)
{
	TRACE_ENTER(QC_EV_QCC_WAKE, qcc->conn);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCC_WAKE, qcc->conn);
}

/* process Rx frames to be demultiplexed */
__maybe_unused
static void qc_process_demux(struct qcc *qcc)
{
	TRACE_ENTER(QC_EV_QCC_WAKE, qcc->conn);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCC_WAKE, qcc->conn);
}

/* resume each qcs eligible for sending in list head <head> */
__maybe_unused
static void qc_resume_each_sending_qcs(struct qcc *qcc, struct list *head)
{
	struct qcs *qcs, *qcs_back;

	TRACE_ENTER(QC_EV_QCC_SEND|QC_EV_QCS_WAKE, qcc->conn);

	list_for_each_entry_safe(qcs, qcs_back, head, list) {
		if (qcc_wnd(qcc) <= 0 ||
		    qcc->flags & QC_CF_MUX_BLOCK_ANY ||
		    qcc->st0 >= QC_CS_ERROR)
			break;

		qcs->flags &= ~QC_SF_BLK_ANY;

		if (qcs->flags & QC_SF_NOTIFIED)
			continue;

		/* If the sender changed his mind and unsubscribed, let's just
		 * remove the stream from the send_list.
		 */
		if (!(qcs->flags & (QC_SF_WANT_SHUTR|QC_SF_WANT_SHUTW)) &&
		    (!qcs->subs || !(qcs->subs->events & SUB_RETRY_SEND))) {
			LIST_DEL_INIT(&qcs->list);
			continue;
		}

		if (qcs->subs && qcs->subs->events & SUB_RETRY_SEND) {
			qcs->flags |= QC_SF_NOTIFIED;
			tasklet_wakeup(qcs->subs->tasklet);
			qcs->subs->events &= ~SUB_RETRY_SEND;
			if (!qcs->subs->events)
				qcs->subs = NULL;
		}
		else if (qcs->flags & (QC_SF_WANT_SHUTR|QC_SF_WANT_SHUTW)) {
			tasklet_wakeup(qcs->shut_tl);
		}
	}

	TRACE_LEAVE(QC_EV_QCC_SEND|QC_EV_QCS_WAKE, qcc->conn);
}

/* process Tx frames from streams to be multiplexed. Returns > 0 if it reached
 * the end.
 */
__maybe_unused
static int qc_process_mux(struct qcc *qcc)
{
	TRACE_ENTER(QC_EV_QCC_WAKE, qcc->conn);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCC_WAKE, qcc->conn);
	return 0;
}


/* Attempt to read data, and subscribe if none available.
 * The function returns 1 if data has been received, otherwise zero.
 */
__maybe_unused
static int qc_recv(struct qcc *qcc)
{
	TRACE_ENTER(QC_EV_QCC_RECV, qcc->conn);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCC_RECV, qcc->conn);
	return 0;
}

/* Try to send data if possible.
 * The function returns 1 if data have been sent, otherwise zero.
 */
static int qc_send(struct qcc *qcc)
{
	TRACE_ENTER(QC_EV_QCC_SEND, qcc->conn);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCC_SEND, qcc->conn);
	return 0;
}

/* this is the tasklet referenced in qcc->wait_event.tasklet */
static struct task *qc_io_cb(struct task *t, void *ctx, unsigned int status)
{
	struct connection *conn;
	struct tasklet *tl = (struct tasklet *)t;
	int conn_in_list;
	struct qcc *qcc;
	int ret = 0;


	HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
	if (t->context == NULL) {
		/* The connection has been taken over by another thread,
		 * we're no longer responsible for it, so just free the
		 * tasklet, and do nothing.
		 */
		HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
		tasklet_free(tl);
		goto leave;
	}
	qcc = ctx;
	conn = qcc->conn;

	TRACE_ENTER(QC_EV_QCC_WAKE, conn);

	conn_in_list = conn->flags & CO_FL_LIST_MASK;

	/* Remove the connection from the list, to be sure nobody attempts
	 * to use it while we handle the I/O events
	 */
	if (conn_in_list)
		conn_delete_from_tree(&conn->hash_node->node);

	HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);

	if (!(qcc->wait_event.events & SUB_RETRY_SEND))
		ret = qc_send(qcc);
#if 0
	if (!(qcc->wait_event.events & SUB_RETRY_RECV))
		ret |= qc_recv(qcc);
#endif
	// TODO redefine the proper condition here
	//if (ret || qcc->rx.inmux)
		ret = qc_process(qcc);

	/* If we were in an idle list, we want to add it back into it,
	 * unless qc_process() returned -1, which mean it has destroyed
	 * the connection (testing !ret is enough, if qc_process() wasn't
	 * called then ret will be 0 anyway.
	 */
	if (!ret && conn_in_list) {
		struct server *srv = objt_server(conn->target);

		HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
		if (conn_in_list == CO_FL_SAFE_LIST)
			ebmb_insert(&srv->per_thr[tid].safe_conns,
			            &conn->hash_node->node, sizeof(conn->hash_node->hash));
		else
			ebmb_insert(&srv->per_thr[tid].idle_conns,
			            &conn->hash_node->node, sizeof(conn->hash_node->hash));
		HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
	}

leave:
	TRACE_LEAVE(QC_EV_QCC_WAKE);
	return NULL;
}

static int qcs_push_frame(struct qcs *qcs, struct buffer *payload, int fin, uint64_t offset)
{
	struct quic_frame *frm;
	struct buffer buf = BUF_NULL;
	int total = 0;

	qc_get_buf(qcs->qcc, &buf);
	total = b_xfer(&buf, payload, b_data(payload));

	frm = pool_zalloc(pool_head_quic_frame);
	if (!frm)
		goto err;

	frm->type = QUIC_FT_STREAM_8;
	if (fin)
		frm->type |= QUIC_STREAM_FRAME_TYPE_FIN_BIT;
	if (offset) {
		frm->type |= QUIC_STREAM_FRAME_TYPE_OFF_BIT;
		frm->stream.offset = offset;
	}
	frm->stream.id = qcs->by_id.key;
	if (total) {
		frm->type |= QUIC_STREAM_FRAME_TYPE_LEN_BIT;
		frm->stream.len = total;
		frm->stream.data = (unsigned char *)b_head(&buf);
	}

	struct quic_enc_level *qel = &qcs->qcc->conn->qc->els[QUIC_TLS_ENC_LEVEL_APP];
	MT_LIST_APPEND(&qel->pktns->tx.frms, &frm->mt_list);
	fprintf(stderr, "%s: total=%d fin=%d offset=%lu\n", __func__, total, fin, offset);
	return total;

 err:
	return -1;
}

/* callback called on any event by the connection handler.
 * It applies changes and returns zero, or < 0 if it wants immediate
 * destruction of the connection (which normally doesn not happen in quic).
 */
static int qc_process(struct qcc *qcc)
{
	struct connection *conn = qcc->conn;
	struct qcs *qcs;
	struct eb64_node *node;

	TRACE_ENTER(QC_EV_QCC_WAKE, conn);

	/* TODO simple loop through all streams and check if there is frames to
	 * send
	 */
	node = eb64_first(&qcc->streams_by_id);
	while (node) {
		struct buffer *buf;
		qcs = container_of(node, struct qcs, by_id);
		for (buf = br_head(qcs->tx.mbuf); b_data(buf); buf = br_del_head(qcs->tx.mbuf)) {
			if (b_data(buf)) {
				int ret;
				ret = qcs_push_frame(qcs, buf, 0, qcs->tx.offset);
				if (ret <= 0)
					ABORT_NOW();

				qcs->tx.offset += ret;
				qcs->qcc->wait_event.events &= ~SUB_RETRY_SEND;
			}
			b_free(buf);
		}
		node = eb64_next(node);
	}

	TRACE_LEAVE(QC_EV_QCC_WAKE, conn);
	return 0;
}

/* wake-up function called by the connection layer (mux_ops.wake) */
static int qc_wake(struct connection *conn)
{
	struct qcc *qcc = conn->ctx;
	int ret;

	TRACE_ENTER(QC_EV_QCC_WAKE, conn);
	ret = qc_process(qcc);
	if (ret >= 0)
		qc_wake_some_streams(qcc, 0);
	TRACE_LEAVE(QC_EV_QCC_WAKE);
	return ret;
}

/* Connection timeout management. The principle is that if there's no receipt
 * nor sending for a certain amount of time, the connection is closed. If the
 * MUX buffer still has lying data or is not allocatable, the connection is
 * immediately killed. If it's allocatable and empty, we attempt to send a
 * GOAWAY frame.
 */
static struct task *qc_timeout_task(struct task *t, void *context, unsigned int state)
{
	TRACE_ENTER(QC_EV_QCC_WAKE);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_QCC_WAKE);
	return NULL;
}


/*******************************************/
/* functions below are used by the streams */
/*******************************************/

/*
 * Attach a new stream to a connection
 * (Used for outgoing connections)
 */
static struct conn_stream *qc_attach(struct connection *conn, struct session *sess)
{
	struct conn_stream *cs;
	struct qcs *qcs;
	struct qcc *qcc = conn->ctx;

	TRACE_ENTER(QC_EV_QCS_NEW, conn);
	cs = cs_new(conn, conn->target);
	if (!cs) {
		TRACE_DEVEL("leaving on CS allocation failure", QC_EV_QCS_NEW|QC_EV_QCS_ERR, conn);
		return NULL;
	}
	qcs = qcc_bck_stream_new(qcc, QCS_BIDI, cs, sess);
	if (!qcs) {
		TRACE_DEVEL("leaving on stream creation failure", QC_EV_QCS_NEW|QC_EV_QCS_ERR, conn);
		cs_free(cs);
		return NULL;
	}
	TRACE_LEAVE(QC_EV_QCS_NEW, conn, qcs);
	return cs;
}

/* Retrieves the first valid conn_stream from this connection, or returns NULL.
 * We have to scan because we may have some orphan streams. It might be
 * beneficial to scan backwards from the end to reduce the likeliness to find
 * orphans.
 */
static const struct conn_stream *qc_get_first_cs(const struct connection *conn)
{
	struct qcc *qcc = conn->ctx;
	struct qcs *qcs;
	struct eb64_node *node;

	node = eb64_first(&qcc->streams_by_id);
	while (node) {
		qcs = container_of(node, struct qcs, by_id);
		if (qcs->cs)
			return qcs->cs;
		node = eb64_next(node);
	}
	return NULL;
}

static int qc_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *output)
{
	int ret = 0;
	struct qcc *qcc = conn->ctx;

	switch (mux_ctl) {
	case MUX_STATUS:
		/* Only consider the mux to be ready if we had no error. */
		if (qcc->st0 < QC_CS_ERROR)
			ret |= MUX_STATUS_READY;
		return ret;
	case MUX_EXIT_STATUS:
		return MUX_ES_UNKNOWN;
	default:
		return -1;
	}
}

/*
 * Destroy the mux and the associated connection, if it is no longer used
 */
static void qc_destroy(void *ctx)
{
	struct qcc *qcc = ctx;

	TRACE_ENTER(QC_EV_QCC_END, qcc->conn);
	if (eb_is_empty(&qcc->streams_by_id) || !qcc->conn || qcc->conn->ctx != qcc)
		qc_release(qcc);
	TRACE_LEAVE(QC_EV_QCC_END);
}

/*
 * Detach the stream from the connection and possibly release the connection.
 */
static void qc_detach(struct conn_stream *cs)
{
	struct qcs *qcs = cs->ctx;

	TRACE_ENTER(QC_EV_STRM_END, qcs ? qcs->qcc->conn : NULL, qcs);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_STRM_END, qcs ? qcs->qcc->conn : NULL);
}

/* Performs a synchronous or asynchronous shutr(). */
static void qc_do_shutr(struct qcs *qcs)
{
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_STRM_SHUT, qcc->conn, qcs);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_STRM_SHUT, qcc->conn, qcs);
	return;
}

/* Performs a synchronous or asynchronous shutw(). */
static void qc_do_shutw(struct qcs *qcs)
{
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_STRM_SHUT, qcc->conn, qcs);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_STRM_SHUT, qcc->conn, qcs);
	return;
}

/* This is the tasklet referenced in qcs->shut_tl, it is used for
 * deferred shutdowns when the qc_detach() was done but the mux buffer was full
 * and prevented the last frame from being emitted.
 */
static struct task *qc_deferred_shut(struct task *t, void *ctx, unsigned int state)
{
	struct qcs *qcs = ctx;
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_STRM_SHUT, qcc->conn, qcs);

	if (qcs->flags & QC_SF_NOTIFIED) {
		/* some data processing remains to be done first */
		goto end;
	}

	if (qcs->flags & QC_SF_WANT_SHUTW)
		qc_do_shutw(qcs);

	if (qcs->flags & QC_SF_WANT_SHUTR)
		qc_do_shutr(qcs);

	if (!(qcs->flags & (QC_SF_WANT_SHUTR|QC_SF_WANT_SHUTW))) {
		/* We're done trying to send, remove ourself from the send_list */
		LIST_DEL_INIT(&qcs->list);

		if (!qcs->cs) {
			qcs_destroy(qcs);
			if (qcc_is_dead(qcc))
				qc_release(qcc);
		}
	}

 end:
	TRACE_LEAVE(QC_EV_STRM_SHUT);
	return NULL;
}

/* shutr() called by the conn_stream (mux_ops.shutr) */
static void qc_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
{

	struct qcs *qcs = cs->ctx;

	TRACE_ENTER(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
	if (cs->flags & CS_FL_KILL_CONN)
		qcs->flags |= QC_SF_KILL_CONN;

	if (mode)
		qc_do_shutr(qcs);

	TRACE_LEAVE(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
}

/* shutw() called by the conn_stream (mux_ops.shutw) */
static void qc_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
{
	struct qcs *qcs = cs->ctx;

	TRACE_ENTER(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
	if (cs->flags & CS_FL_KILL_CONN)
		qcs->flags |= QC_SF_KILL_CONN;

	qc_do_shutw(qcs);
	TRACE_LEAVE(QC_EV_STRM_SHUT, qcs->qcc->conn, qcs);
}

/* Called from the upper layer, to subscribe <es> to events <event_type>. The
 * event subscriber <es> is not allowed to change from a previous call as long
 * as at least one event is still subscribed. The <event_type> must only be a
 * combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0.
 */
static int qc_subscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
{
	struct qcs *qcs = cs->ctx;
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcc->conn, qcs);

	BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
	BUG_ON(qcs->subs && qcs->subs != es);

	es->events |= event_type;
	qcs->subs = es;

	if (event_type & SUB_RETRY_RECV)
		TRACE_DEVEL("subscribe(recv)", QC_EV_STRM_RECV, qcc->conn, qcs);

	if (event_type & SUB_RETRY_SEND) {
		TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcc->conn, qcs);
		if (!(qcs->flags & QC_SF_BLK_SFCTL) &&
		    !LIST_INLIST(&qcs->list)) {
			if (qcs->flags & QC_SF_BLK_MFCTL)
				LIST_APPEND(&qcc->fctl_list, &qcs->list);
			else
				LIST_APPEND(&qcc->send_list, &qcs->list);
		}
	}
	TRACE_LEAVE(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcc->conn, qcs);
	return 0;
}

/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
 * The <es> pointer is not allowed to differ from the one passed to the
 * subscribe() call. It always returns zero.
 */
static int qc_unsubscribe(struct conn_stream *cs, int event_type, struct wait_event *es)
{
	struct qcs *qcs = cs->ctx;

	TRACE_ENTER(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcs->qcc->conn, qcs);

	BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
	BUG_ON(qcs->subs && qcs->subs != es);

	es->events &= ~event_type;
	if (!es->events)
		qcs->subs = NULL;

	if (event_type & SUB_RETRY_RECV)
		TRACE_DEVEL("unsubscribe(recv)", QC_EV_STRM_RECV, qcs->qcc->conn, qcs);

	if (event_type & SUB_RETRY_SEND) {
		TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcs->qcc->conn, qcs);
		qcs->flags &= ~QC_SF_NOTIFIED;
		if (!(qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW)))
			LIST_DEL_INIT(&qcs->list);
	}

	TRACE_LEAVE(QC_EV_STRM_SEND|QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
	return 0;
}


/* Called from the upper layer, to subscribe <es> to events <event_type>. The
 * event subscriber <es> is not allowed to change from a previous call as long
 * as at least one event is still subscribed. The <event_type> must only be a
 * SUB_RETRY_RECV. It always returns 0.
 */
static int ruqs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es)
{
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_STRM_RECV, qcc->conn, qcs);

	BUG_ON(event_type & ~SUB_RETRY_RECV);
	BUG_ON(qcs->subs && qcs->subs != es);

	es->events |= event_type;
	qcs->subs = es;

	if (event_type & SUB_RETRY_RECV)
		TRACE_DEVEL("subscribe(recv)", QC_EV_STRM_RECV, qcc->conn, qcs);

	TRACE_LEAVE(QC_EV_STRM_RECV, qcc->conn, qcs);
	return 0;
}

/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
 * The <es> pointer is not allowed to differ from the one passed to the
 * subscribe() call. It always returns zero.
 */
static int ruqs_unsubscribe(struct qcs *qcs, int event_type, struct wait_event *es)
{
	TRACE_ENTER(QC_EV_STRM_RECV, qcs->qcc->conn, qcs);

	BUG_ON(event_type & ~SUB_RETRY_RECV);
	BUG_ON(qcs->subs && qcs->subs != es);

	es->events &= ~event_type;
	if (!es->events)
		qcs->subs = NULL;

	if (event_type & SUB_RETRY_RECV)
		TRACE_DEVEL("unsubscribe(recv)", QC_EV_STRM_RECV, qcs->qcc->conn, qcs);

	TRACE_LEAVE(QC_EV_STRM_RECV, qcs->qcc->conn, qcs);
	return 0;
}

/* Called from the upper layer, to subscribe <es> to events <event_type>. The
 * event subscriber <es> is not allowed to change from a previous call as long
 * as at least one event is still subscribed. The <event_type> must only be
 * SUB_RETRY_SEND. It always returns 0.
 */
static int luqs_subscribe(struct qcs *qcs, int event_type, struct wait_event *es)
{
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_STRM_SEND, qcc->conn, qcs);

	BUG_ON(event_type & ~SUB_RETRY_SEND);
	BUG_ON(qcs->subs && qcs->subs != es);

	es->events |= event_type;
	qcs->subs = es;

	if (event_type & SUB_RETRY_SEND) {
		TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcc->conn, qcs);
		if (!(qcs->flags & QC_SF_BLK_SFCTL) &&
		    !LIST_INLIST(&qcs->list)) {
			if (qcs->flags & QC_SF_BLK_MFCTL)
				LIST_APPEND(&qcc->fctl_list, &qcs->list);
			else
				LIST_APPEND(&qcc->send_list, &qcs->list);
		}
	}

	TRACE_LEAVE(QC_EV_STRM_SEND, qcc->conn, qcs);
	return 0;
}

/* Called from the upper layer, to unsubscribe <es> from events <event_type>.
 * The <es> pointer is not allowed to differ from the one passed to the
 * subscribe() call. It always returns zero.
 */
static int luqs_unsubscribe(struct qcs *qcs, int event_type, struct wait_event *es)
{
	struct qcc *qcc = qcs->qcc;

	TRACE_ENTER(QC_EV_STRM_SEND, qcc->conn, qcs);

	BUG_ON(event_type & ~SUB_RETRY_SEND);
	BUG_ON(qcs->subs && qcs->subs != es);

	es->events &= ~event_type;
	if (!es->events)
		qcs->subs = NULL;

	if (event_type & SUB_RETRY_SEND) {
		TRACE_DEVEL("subscribe(send)", QC_EV_STRM_SEND, qcc->conn, qcs);
		qcs->flags &= ~QC_SF_NOTIFIED;
		if (!(qcs->flags & (QC_SF_WANT_SHUTR | QC_SF_WANT_SHUTW)))
			LIST_DEL_INIT(&qcs->list);
	}

	TRACE_LEAVE(QC_EV_STRM_SEND, qcc->conn, qcs);
	return 0;
}

/* Called from the upper layer, to receive data */
static size_t qc_rcv_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
{
	struct qcs *qcs = cs->ctx;
	struct qcc *qcc = qcs->qcc;
	int ret;

	ret = 0;
	TRACE_ENTER(QC_EV_STRM_RECV, qcc->conn, qcs);
	/* XXX TO DO XXX */
	TRACE_LEAVE(QC_EV_STRM_RECV, qcc->conn, qcs);
	return ret;
}

/* Called from the upper layer, to send data from buffer <buf> for no more than
 * <count> bytes. Returns the number of bytes effectively sent. Some status
 * flags may be updated on the conn_stream.
 */
static size_t qc_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t count, int flags)
{
	struct qcs *qcs = cs->ctx;
	size_t total = 0;

	TRACE_ENTER(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn, qcs);

	if (count) {
		if (!(qcs->qcc->wait_event.events & SUB_RETRY_SEND))
			tasklet_wakeup(qcs->qcc->wait_event.tasklet);
	}

	TRACE_LEAVE(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn, qcs);
	return total;
}

/* Called from the upper layer, to send data from buffer <buf> for no more than
 * <count> bytes. Returns the number of bytes effectively sent. Some status
 * flags may be updated on the outgoing uni-stream.
 */
__maybe_unused
static size_t _qcs_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int flags)
{
	size_t total = 0;
	struct qcc *qcc = qcs->qcc;
	struct buffer *res;
	struct quic_tx_frm *frm;

	TRACE_ENTER(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);

	if (!count)
		goto out;

	res = br_tail(qcc->mbuf);
	if (!qc_get_buf(qcc, res)) {
		qcc->flags |= QC_CF_MUX_MALLOC;
		goto out;
	}

	while (count) {
		size_t try, room;

		room = b_room(res);
		if (!room) {
			if ((res = br_tail_add(qcc->mbuf)) != NULL)
				continue;

			qcc->flags |= QC_CF_MUX_MALLOC;
			break;
		}

		try = count;
		if (try > room)
			try = room;

		total += b_xfer(res, buf, try);
		count -= try;
	}

	if (total) {

		frm = pool_alloc(pool_head_quic_tx_frm);
		if (!frm) { /* XXX XXX */ }
	}

 out:
	TRACE_LEAVE(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
	return total;

 err:
	TRACE_DEVEL("leaving on stream error", QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
	return total;
}

/* Called from the upper layer, to send data from buffer <buf> for no more than
 * <count> bytes. Returns the number of bytes effectively sent. Some status
 * flags may be updated on the mux.
 */
size_t luqs_snd_buf(struct qcs *qcs, struct buffer *buf, size_t count, int flags)
{
	size_t room, total = 0;
	struct qcc *qcc = qcs->qcc;
	struct buffer *res;

	TRACE_ENTER(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
	if (!count)
		goto out;

	res = &qcs->tx.buf;
	if (!qc_get_buf(qcc, res)) {
		qcc->flags |= QC_CF_MUX_MALLOC;
		goto out;
	}

	room = b_room(res);
	if (!room)
		goto out;

	if (count > room)
		count = room;

	total += b_xfer(res, buf, count);

 out:
	TRACE_LEAVE(QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
	return total;

 err:
	TRACE_DEVEL("leaving on stream error", QC_EV_QCS_SEND|QC_EV_STRM_SEND, qcs->qcc->conn);
	return total;
}

/* for debugging with CLI's "show fd" command */
static int qc_show_fd(struct buffer *msg, struct connection *conn)
{
	struct qcc *qcc = conn->ctx;
	struct qcs *qcs = NULL;
	struct eb64_node *node;
	int fctl_cnt = 0;
	int send_cnt = 0;
	int tree_cnt = 0;
	int orph_cnt = 0;
	struct buffer *hmbuf, *tmbuf;

	if (!qcc)
		return 0;

	list_for_each_entry(qcs, &qcc->fctl_list, list)
		fctl_cnt++;

	list_for_each_entry(qcs, &qcc->send_list, list)
		send_cnt++;

	qcs = NULL;
	node = eb64_first(&qcc->streams_by_id);
	while (node) {
		qcs = container_of(node, struct qcs, by_id);
		tree_cnt++;
		if (!qcs->cs)
			orph_cnt++;
		node = eb64_next(node);
	}

	hmbuf = br_head(qcc->mbuf);
	tmbuf = br_tail(qcc->mbuf);
	chunk_appendf(msg, " qcc.st0=%s .flg=0x%04x"
	              " clt.nb_streams_bidi=%llu srv.nb_streams_bidi=%llu"
	              " clt.nb_streams_uni=%llu srv.nb_streams_uni=%llu"
	              " .nbcs=%u .fctl_cnt=%d .send_cnt=%d .tree_cnt=%d"
	              " .orph_cnt=%d .sub=%d"
	              " .mbuf=[%u..%u|%u],h=[%u@%p+%u/%u],t=[%u@%p+%u/%u]",
		      qcc_st_to_str(qcc->st0), qcc->flags,
		      (unsigned long long)qcc->strms[QCS_CLT_BIDI].nb_streams,
		      (unsigned long long)qcc->strms[QCS_SRV_BIDI].nb_streams,
		      (unsigned long long)qcc->strms[QCS_CLT_UNI].nb_streams,
		      (unsigned long long)qcc->strms[QCS_SRV_UNI].nb_streams,
		      qcc->nb_cs, fctl_cnt, send_cnt, tree_cnt, orph_cnt,
		      qcc->wait_event.events,
		      br_head_idx(qcc->mbuf), br_tail_idx(qcc->mbuf), br_size(qcc->mbuf),
		      (unsigned int)b_data(hmbuf), b_orig(hmbuf),
		      (unsigned int)b_head_ofs(hmbuf), (unsigned int)b_size(hmbuf),
		      (unsigned int)b_data(tmbuf), b_orig(tmbuf),
		      (unsigned int)b_head_ofs(tmbuf), (unsigned int)b_size(tmbuf));

	if (qcs) {
		chunk_appendf(msg, " last_qcs=%p .id=%llu rx.st=%s tx.st=%s .flg=0x%04x .rxbuf=%u@%p+%u/%u .cs=%p",
			      qcs, (unsigned long long)qcs->id,
			      qcs_rx_st_to_str(qcs->rx.st), qcs_tx_st_to_str(qcs->tx.st), qcs->flags,
			      (unsigned int)b_data(&qcs->rx.buf), b_orig(&qcs->rx.buf),
			      (unsigned int)b_head_ofs(&qcs->rx.buf), (unsigned int)b_size(&qcs->rx.buf),
			      qcs->cs);
		if (qcs->cs)
			chunk_appendf(msg, " .cs.flg=0x%08x .cs.data=%p",
				      qcs->cs->flags, qcs->cs->data);
	}

	return 0;
}

/* Migrate the the connection to the current thread.
 * Return 0 if successful, non-zero otherwise.
 * Expected to be called with the old thread lock held.
 */
static int qc_takeover(struct connection *conn, int orig_tid)
{
	struct qcc *qcc = conn->ctx;
	struct task *task;

	if (fd_takeover(conn->handle.fd, conn) != 0)
		return -1;

	if (conn->xprt->takeover && conn->xprt->takeover(conn, conn->xprt_ctx, orig_tid) != 0) {
		/* We failed to takeover the xprt, even if the connection may
		 * still be valid, flag it as error'd, as we have already
		 * taken over the fd, and wake the tasklet, so that it will
		 * destroy it.
		 */
		conn->flags |= CO_FL_ERROR;
		tasklet_wakeup_on(qcc->wait_event.tasklet, orig_tid);
		return -1;
	}

	if (qcc->wait_event.events)
		qcc->conn->xprt->unsubscribe(qcc->conn, qcc->conn->xprt_ctx,
		    qcc->wait_event.events, &qcc->wait_event);
	/* To let the tasklet know it should free itself, and do nothing else,
	 * set its context to NULL.
	 */
	qcc->wait_event.tasklet->context = NULL;
	tasklet_wakeup_on(qcc->wait_event.tasklet, orig_tid);

	task = qcc->task;
	if (task) {
		task->context = NULL;
		qcc->task = NULL;
		__ha_barrier_store();
		task_kill(task);

		qcc->task = task_new(tid_bit);
		if (!qcc->task) {
			qc_release(qcc);
			return -1;
		}

		qcc->task->process = qc_timeout_task;
		qcc->task->context = qcc;
	}

	qcc->wait_event.tasklet = tasklet_new();
	if (!qcc->wait_event.tasklet) {
		qc_release(qcc);
		return -1;
	}

	qcc->wait_event.tasklet->process = qc_io_cb;
	qcc->wait_event.tasklet->context = qcc;
	qcc->conn->xprt->subscribe(qcc->conn, qcc->conn->xprt_ctx,
		                   SUB_RETRY_RECV, &qcc->wait_event);

	return 0;
}

/****************************************/
/* MUX initialization and instantiation */
/***************************************/

/* The mux operations */
static const struct mux_ops qc_ops = {
	.init = qc_init,
	.wake = qc_wake,
	.snd_buf = qc_snd_buf,
	.rcv_buf = qc_rcv_buf,
	.subscribe = qc_subscribe,
	.unsubscribe = qc_unsubscribe,
	.ruqs_subscribe = ruqs_subscribe,
	.ruqs_unsubscribe = ruqs_unsubscribe,
	.luqs_subscribe = luqs_subscribe,
	.luqs_unsubscribe = luqs_unsubscribe,
	.attach = qc_attach,
	.get_first_cs = qc_get_first_cs,
	.detach = qc_detach,
	.destroy = qc_destroy,
	.avail_streams_bidi = qc_avail_streams_bidi,
	.avail_streams_uni = qc_avail_streams_uni,
	.used_streams = qc_used_streams,
	.shutr = qc_shutr,
	.shutw = qc_shutw,
	.ctl = qc_ctl,
	.show_fd = qc_show_fd,
	.takeover = qc_takeover,
	.flags = MX_FL_CLEAN_ABRT|MX_FL_HTX|MX_FL_HOL_RISK,
	.name = "QUIC",
};

static struct mux_proto_list mux_proto_quic =
	{ .token = IST("quic"), .mode = PROTO_MODE_HTTP, .side = PROTO_SIDE_BOTH, .mux = &qc_ops };

INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_quic);

