aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authormarshall <stmr@umich.edu>2023-06-28 08:48:30 -0400
committermarshall <stmr@umich.edu>2023-07-18 11:12:18 -0400
commit37d91f07a844688710a680947023e6fc81ed8688 (patch)
treeadf8a33a6e681b2b50407b3ff1f7ba4102ff9b2b /src/transport
parent63a18f014bfff83463b85498ca299e5e9a5edefc (diff)
downloadgnunet-37d91f07a844688710a680947023e6fc81ed8688.tar.gz
gnunet-37d91f07a844688710a680947023e6fc81ed8688.zip
transport (quic): get random block for cid
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-communicator-quic.c100
1 files changed, 61 insertions, 39 deletions
diff --git a/src/transport/gnunet-communicator-quic.c b/src/transport/gnunet-communicator-quic.c
index dc6cca01c..71aee3826 100644
--- a/src/transport/gnunet-communicator-quic.c
+++ b/src/transport/gnunet-communicator-quic.c
@@ -105,21 +105,6 @@ gen_streamid ()
105 105
106 106
107/** 107/**
108 * Generate a new connection ID
109*/
110static uint8_t*
111gen_cid (uint8_t *cid, size_t cid_len)
112{
113 /**
114 * NOTE: come back and fix
115 */
116 int rand_cid;
117 rand_cid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
118 UINT8_MAX);
119}
120
121
122/**
123 * Given a quiche connection and buffer, recv data from streams and store into buffer 108 * Given a quiche connection and buffer, recv data from streams and store into buffer
124 * ASSUMES: connection is established to peer 109 * ASSUMES: connection is established to peer
125*/ 110*/
@@ -256,35 +241,37 @@ create_conn (uint8_t *scid, size_t scid_len,
256} 241}
257 242
258 243
259/** 244static void
260 * Check for closed connections, print stats 245flush_egress (struct quic_conn *conn)
261*/
262static int
263check_conn_closed (void *cls,
264 const struct GNUNET_HashCode *key,
265 void *value)
266{ 246{
267 struct quic_conn *conn = value; 247 static uint8_t out[MAX_DATAGRAM_SIZE];
248 quiche_send_info send_info;
268 249
269 if (quiche_conn_is_closed (conn->conn)) 250 ssize_t written;
251 ssize_t sent;
252
253 while (1)
270 { 254 {
271 quiche_stats stats; 255 written = quiche_conn_send (conn->conn, out, sizeof(out), &send_info);
272 quiche_path_stats path_stats;
273 256
274 quiche_conn_stats (conn->conn, &stats); 257 if (0 > written)
275 quiche_conn_path_stats (conn->conn, 0, &path_stats); 258 {
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "quiche failed to create packet\n");
260 return;
261 }
276 262
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 263 sent = GNUNET_NETWORK_socket_sendto (udp_sock, out, written,
278 "connection closed. quiche stats: sent=%zu, recv=%zu\n", 264 (struct sockaddr *) &send_info.to,
279 stats.sent, stats.recv); 265 &send_info.to_len);
280 GNUNET_CONTAINER_multihashmap_remove (conn_map, key, value); 266 if (sent != written)
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 267 {
282 "removed closed connection from connection map\n"); 268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
269 "quiche failed to send data to peer\n");
270 return;
271 }
283 272
284 quiche_conn_free (conn->conn); 273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sent %zd bytes\n", sent);
285 GNUNET_free (conn);
286 } 274 }
287 return GNUNET_OK;
288} 275}
289 276
290 277
@@ -298,6 +285,9 @@ do_shutdown (void *cls)
298{ 285{
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "do_shutdown\n"); 287 "do_shutdown\n");
288
289 GNUNET_CONTAINER_multihashmap_destroy (conn_map);
290
301 if (NULL != read_task) 291 if (NULL != read_task)
302 { 292 {
303 GNUNET_SCHEDULER_cancel (read_task); 293 GNUNET_SCHEDULER_cancel (read_task);
@@ -588,7 +578,8 @@ sock_read (void *cls)
588 quic_header.token, &quic_header.token_len); 578 quic_header.token, &quic_header.token_len);
589 579
590 uint8_t new_cid[LOCAL_CONN_ID_LEN]; 580 uint8_t new_cid[LOCAL_CONN_ID_LEN];
591 gen_cid (new_cid, LOCAL_CONN_ID_LEN); 581 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, new_cid,
582 LOCAL_CONN_ID_LEN);
592 583
593 ssize_t written = quiche_retry (quic_header.scid, quic_header.scid_len, 584 ssize_t written = quiche_retry (quic_header.scid, quic_header.scid_len,
594 quic_header.dcid, quic_header.dcid_len, 585 quic_header.dcid, quic_header.dcid_len,
@@ -668,7 +659,38 @@ sock_read (void *cls)
668 /** 659 /**
669 * Connection cleanup, check for closed connections, delete entries, print stats 660 * Connection cleanup, check for closed connections, delete entries, print stats
670 */ 661 */
671 GNUNET_CONTAINER_multihashmap_iterate (conn_map, &check_conn_closed, NULL); 662 /**
663 * TODO: Should we use a list instead of hashmap?
664 * Overhead for hashing function, O(1) retrieval vs O(n) iteration with n=30?
665 *
666 * TODO: Is iteration necessary as in the server example?
667 */
668 quiche_stats stats;
669 quiche_path_stats path_stats;
670
671 flush_egress (conn);
672
673 if (quiche_conn_is_closed (conn->conn))
674 {
675 quiche_conn_stats (conn->conn, &stats);
676 quiche_conn_path_stats (conn->conn, 0, &path_stats);
677
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
679 "connection closed. quiche stats: sent=%zu, recv=%zu\n",
680 stats.sent, stats.recv);
681 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (conn_map, &conn_key,
682 conn->conn))
683 {
684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
685 "failed to remove quic connection from map\n");
686 return;
687 }
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "removed closed connection from connection map\n");
690
691 quiche_conn_free (conn->conn);
692 GNUNET_free (conn);
693 }
672} 694}
673 695
674 696