MAJOR: conn-stream: Share endpoint struct between the CS and the mux/applet

The conn-stream endpoint is now shared between the conn-stream and the
applet or the multiplexer. If the mux or the applet is created first, it is
responsible to also create the endpoint and share it with the conn-stream.
If the conn-stream is created first, it is the opposite.

When the endpoint is only owned by an applet or a mux, it is called an
orphan endpoint (there is no conn-stream). When it is only owned by a
conn-stream, it is called a detached endpoint (there is no mux/applet).

The last entity that owns an endpoint is responsible to release it. When a
mux or an applet is detached from a conn-stream, the conn-stream
relinquishes the endpoint to recreate a new one. This way, the endpoint
state is never lost for the mux or the applet.
diff --git a/src/mux_quic.c b/src/mux_quic.c
index f61602f..c64f8d0 100644
--- a/src/mux_quic.c
+++ b/src/mux_quic.c
@@ -117,9 +117,19 @@
 	qcs->cs = NULL;
 	qcs->flags = QC_SF_NONE;
 
+	qcs->endp = cs_endpoint_new();
+	if (!qcs->endp) {
+		pool_free(pool_head_qcs, qcs);
+		return NULL;
+	}
+	qcs->endp->target = qcs;
+	qcs->endp->ctx = qcc->conn;
+	qcs->endp->flags |= (CS_EP_T_MUX|CS_EP_ORPHAN|CS_EP_NOT_FIRST);
+
 	qcs->id = id;
 	/* store transport layer stream descriptor in qcc tree */
 	eb64_insert(&qcc->streams_by_id, &stream->by_id);
+
 	qcc->strms[type].nb_streams++;
 
 	/* If stream is local, use peer remote-limit, or else the opposite. */
@@ -160,6 +170,8 @@
 	/* stream desc must be removed from MUX tree before release it */
 	eb64_delete(&qcs->stream->by_id);
 	qc_stream_desc_release(qcs->stream, qcs->qcc->conn->handle.qc);
+	BUG_ON(qcs->endp && !(qcs->endp->flags & CS_EP_ORPHAN));
+	cs_endpoint_free(qcs->endp);
 	pool_free(pool_head_qcs, qcs);
 }