1111#include "src/transport/xqc_conn.h"
1212
1313
14- typedef struct xqc_hq_conn_s {
15- xqc_hq_conn_callbacks_t * hqc_cbs ;
16-
17- xqc_connection_t * conn ;
18-
19- xqc_log_t * log ;
20-
21- void * user_data ;
22-
23- } xqc_hq_conn_s ;
24-
25-
2614xqc_hq_conn_t *
2715xqc_hq_conn_create (xqc_connection_t * conn , const xqc_cid_t * cid , void * user_data )
2816{
@@ -31,7 +19,12 @@ xqc_hq_conn_create(xqc_connection_t *conn, const xqc_cid_t *cid, void *user_data
3119 return NULL ;
3220 }
3321
34- if (xqc_hq_ctx_get_conn_callbacks (& hqc -> hqc_cbs ) != XQC_OK ) {
22+ xqc_hq_callbacks_t * hq_cbs = NULL ;
23+ xqc_int_t ret ;
24+
25+ ret = xqc_hq_ctx_get_callbacks (conn -> engine , conn -> alpn , conn -> alpn_len , & hq_cbs );
26+
27+ if (ret != XQC_OK || hq_cbs == NULL ) {
3528 PRINT_LOG ("|create hq conn failed" );
3629 xqc_free (hqc );
3730 return NULL ;
@@ -40,6 +33,10 @@ xqc_hq_conn_create(xqc_connection_t *conn, const xqc_cid_t *cid, void *user_data
4033 hqc -> user_data = user_data ;
4134 hqc -> log = conn -> log ;
4235 hqc -> conn = conn ;
36+ hqc -> hqc_cbs = hq_cbs -> hqc_cbs ;
37+ hqc -> hqr_cbs = hq_cbs -> hqr_cbs ;
38+
39+ xqc_conn_set_alp_user_data (conn , hqc );
4340
4441 return hqc ;
4542}
@@ -53,22 +50,7 @@ xqc_hq_conn_destroy(xqc_hq_conn_t *hqc)
5350 }
5451}
5552
56-
57- xqc_hq_conn_t *
58- xqc_hq_conn_create_passive (xqc_connection_t * conn , const xqc_cid_t * cid )
59- {
60- xqc_hq_conn_t * hqc = xqc_hq_conn_create (conn , cid , NULL );
61- if (NULL == hqc ) {
62- PRINT_LOG ("|create hq conn failed" );
63- return NULL ;
64- }
65-
66- xqc_conn_set_alp_user_data (conn , hqc );
67- return hqc ;
68- }
69-
70-
71- xqc_hq_conn_t *
53+ const xqc_cid_t *
7254xqc_hq_connect (xqc_engine_t * engine , const xqc_conn_settings_t * conn_settings ,
7355 const unsigned char * token , unsigned token_len , const char * server_host , int no_crypto_flag ,
7456 const xqc_conn_ssl_config_t * conn_ssl_config , const struct sockaddr * peer_addr ,
@@ -78,18 +60,8 @@ xqc_hq_connect(xqc_engine_t *engine, const xqc_conn_settings_t *conn_settings,
7860 const xqc_cid_t * cid = xqc_connect (engine , conn_settings , token , token_len , server_host ,
7961 no_crypto_flag , conn_ssl_config , peer_addr , peer_addrlen ,
8062 xqc_hq_alpn [conn_settings -> proto_version ], user_data );
81- if (cid == NULL ) {
82- return NULL ;
83- }
84-
85- xqc_hq_conn_t * hqc = xqc_hq_conn_create (xqc_engine_conns_hash_find (engine , cid , 's' ),
86- cid , user_data );
87- if (NULL == hqc ) {
88- xqc_conn_close (engine , cid );
89- return NULL ;
90- }
9163
92- return hqc ;
64+ return cid ;
9365}
9466
9567
@@ -125,12 +97,9 @@ xqc_hq_conn_create_notify(xqc_connection_t *conn, const xqc_cid_t *cid,
12597 return - XQC_EMALLOC ;
12698 }
12799
128- /* set hqc as conn's application-layer-protocol user_data */
129- xqc_conn_set_alp_user_data (conn , hqc );
130-
131- if (hqc -> hqc_cbs -> conn_create_notify ) {
100+ if (hqc -> hqc_cbs .conn_create_notify ) {
132101 /* NOTICE: if hqc is created passively, hqc->user_data is NULL */
133- return hqc -> hqc_cbs -> conn_create_notify (hqc , cid , hqc -> user_data );
102+ return hqc -> hqc_cbs . conn_create_notify (hqc , cid , hqc -> user_data );
134103 }
135104
136105 return XQC_OK ;
@@ -143,8 +112,8 @@ xqc_hq_conn_close_notify(xqc_connection_t *conn, const xqc_cid_t *cid,
143112 xqc_int_t ret = XQC_OK ;
144113
145114 xqc_hq_conn_t * hqc = (xqc_hq_conn_t * )conn_proto_data ;
146- if (hqc -> hqc_cbs -> conn_close_notify ) {
147- ret = hqc -> hqc_cbs -> conn_close_notify (hqc , cid , hqc -> user_data );
115+ if (hqc -> hqc_cbs . conn_close_notify ) {
116+ ret = hqc -> hqc_cbs . conn_close_notify (hqc , cid , hqc -> user_data );
148117 if (ret != XQC_OK ) {
149118 return ret ;
150119 }
0 commit comments