aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarshall <stmr@umich.edu>2023-07-20 23:28:15 -0400
committermarshall <stmr@umich.edu>2023-07-20 23:45:15 -0400
commitb97fab0cbafd25b81953e041ec0fa2ba1145bc32 (patch)
treead0b379962112e9e86820a5f00fa9bf7da5821b1
parent6d6d6cffb00bbc55bdc4e2864b45e305bf59a5ff (diff)
downloadgnunet-b97fab0cbafd25b81953e041ec0fa2ba1145bc32.tar.gz
gnunet-b97fab0cbafd25b81953e041ec0fa2ba1145bc32.zip
transport (quic): prepare to send pid
-rw-r--r--src/transport/gnunet-communicator-quic.c113
1 files changed, 88 insertions, 25 deletions
diff --git a/src/transport/gnunet-communicator-quic.c b/src/transport/gnunet-communicator-quic.c
index 3ae120513..fd36f2fe4 100644
--- a/src/transport/gnunet-communicator-quic.c
+++ b/src/transport/gnunet-communicator-quic.c
@@ -53,6 +53,16 @@ static unsigned long long rekey_max_bytes;
53static quiche_config *config = NULL; 53static quiche_config *config = NULL;
54 54
55/** 55/**
56 * Our peer identity
57*/
58struct GNUNET_PeerIdentity my_identity;
59
60/**
61 * Our private key.
62 */
63static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
64
65/**
56 * Information we track per peer we have recently been in contact with. 66 * Information we track per peer we have recently been in contact with.
57 * 67 *
58 * (Since quiche handles crypto, handshakes, etc. we don't differentiate 68 * (Since quiche handles crypto, handshakes, etc. we don't differentiate
@@ -187,6 +197,12 @@ struct QUIC_header
187}; 197};
188 198
189/** 199/**
200 * TODOS:
201 * 1. Mandate timeouts
202 * 2. Setup stats handler properly
203*/
204
205/**
190 * Given a PeerAddress, receive data from streams after doing connection logic. 206 * Given a PeerAddress, receive data from streams after doing connection logic.
191 * ASSUMES: connection is established to peer 207 * ASSUMES: connection is established to peer
192*/ 208*/
@@ -403,9 +419,7 @@ reschedule_peer_timeout (struct PeerAddress *peer)
403static void 419static void
404peer_destroy (struct PeerAddress *peer) 420peer_destroy (struct PeerAddress *peer)
405{ 421{
406
407 peer->peer_destroy_called = GNUNET_YES; 422 peer->peer_destroy_called = GNUNET_YES;
408
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
410 "Disconnecting peer for peer `%s'\n", 424 "Disconnecting peer for peer `%s'\n",
411 GNUNET_i2s (&peer->target)); 425 GNUNET_i2s (&peer->target));
@@ -432,6 +446,27 @@ peer_destroy (struct PeerAddress *peer)
432 446
433 447
434/** 448/**
449 * Iterator over all peers to clean up.
450 *
451 * @param cls NULL
452 * @param target unused
453 * @param value the queue to destroy
454 * @return #GNUNET_OK to continue to iterate
455 */
456static int
457get_peer_delete_it (void *cls,
458 const struct GNUNET_PeerIdentity *target,
459 void *value)
460{
461 struct PeerAddress *peer = value;
462 (void) cls;
463 (void) target;
464 peer_destroy (peer);
465 return GNUNET_OK;
466}
467
468
469/**
435 * Signature of functions implementing the sending functionality of a 470 * Signature of functions implementing the sending functionality of a
436 * message queue. 471 * message queue.
437 * 472 *
@@ -884,6 +919,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
884 struct sockaddr *in; 919 struct sockaddr *in;
885 socklen_t in_len; 920 socklen_t in_len;
886 uint8_t scid[LOCAL_CONN_ID_LEN]; 921 uint8_t scid[LOCAL_CONN_ID_LEN];
922 size_t send_len;
887 923
888 struct quic_conn *q_conn; 924 struct quic_conn *q_conn;
889 char *bindto; 925 char *bindto;
@@ -919,6 +955,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
919 peer->address_len = in_len; 955 peer->address_len = in_len;
920 peer->target = *peer_id; 956 peer->target = *peer_id;
921 peer->nt = GNUNET_NT_scanner_get_type (is, in, in_len); 957 peer->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
958 /**
959 * TODO: use addr_map
960 */
922 (void) GNUNET_CONTAINER_multipeermap_put ( 961 (void) GNUNET_CONTAINER_multipeermap_put (
923 peers, 962 peers,
924 &peer->target, 963 &peer->target,
@@ -952,14 +991,17 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
952 local_in_len, peer->address, peer->address_len, 991 local_in_len, peer->address, peer->address_len,
953 config); 992 config);
954 peer->conn = q_conn; 993 peer->conn = q_conn;
955 // quiche_conn_send (peer->conn->conn, ) 994 /**
995 * Send our pid
996 */
997 // quiche_conn_send (peer->conn->conn, );
956 /** 998 /**
957 * Insert connection into hashmap 999 * Insert connection into hashmap
958 */ 1000 */
959 struct GNUNET_HashCode key; 1001 // struct GNUNET_HashCode key;
960 GNUNET_CRYPTO_hash (q_conn->cid, LOCAL_CONN_ID_LEN, &key); 1002 // GNUNET_CRYPTO_hash (q_conn->cid, LOCAL_CONN_ID_LEN, &key);
961 GNUNET_CONTAINER_multihashmap_put (conn_map, &key, q_conn, 1003 // GNUNET_CONTAINER_multihashmap_put (conn_map, &key, q_conn,
962 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1004 // GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
963 setup_peer_mq (peer); 1005 setup_peer_mq (peer);
964 if (NULL == timeout_task) 1006 if (NULL == timeout_task)
965 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); 1007 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
@@ -978,10 +1020,20 @@ do_shutdown (void *cls)
978{ 1020{
979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1021 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
980 "do_shutdown\n"); 1022 "do_shutdown\n");
981 1023 GNUNET_CONTAINER_multipeermap_iterate (peers, &get_peer_delete_it, NULL);
982 GNUNET_CONTAINER_multihashmap_destroy (conn_map); 1024 GNUNET_CONTAINER_multipeermap_destroy (peers);
1025 /**
1026 * TODO: remove peers, just use addr_map
1027 */
1028 // GNUNET_CONTAINER_multihashmap_iterate (addr_map, &get_peer_delete_it, NULL);
1029 // GNUNET_CONTAINER_multihashmap_destroy (addr_map);
983 quiche_config_free (config); 1030 quiche_config_free (config);
984 1031
1032 if (NULL != timeout_task)
1033 {
1034 GNUNET_SCHEDULER_cancel (timeout_task);
1035 timeout_task = NULL;
1036 }
985 if (NULL != read_task) 1037 if (NULL != read_task)
986 { 1038 {
987 GNUNET_SCHEDULER_cancel (read_task); 1039 GNUNET_SCHEDULER_cancel (read_task);
@@ -1003,6 +1055,11 @@ do_shutdown (void *cls)
1003 GNUNET_TRANSPORT_application_done (ah); 1055 GNUNET_TRANSPORT_application_done (ah);
1004 ah = NULL; 1056 ah = NULL;
1005 } 1057 }
1058 if (NULL != my_private_key)
1059 {
1060 GNUNET_free (my_private_key);
1061 my_private_key = NULL;
1062 }
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1007 "do_shutdown finished\n"); 1064 "do_shutdown finished\n");
1008} 1065}
@@ -1019,19 +1076,13 @@ sock_read (void *cls)
1019 ssize_t rcvd; 1076 ssize_t rcvd;
1020 (void) cls; 1077 (void) cls;
1021 1078
1022 // struct quic_conn *conn;
1023 // struct GNUNET_HashCode conn_key;
1024 ssize_t process_pkt; 1079 ssize_t process_pkt;
1025
1026 struct QUIC_header quic_header; 1080 struct QUIC_header quic_header;
1027 uint8_t new_cid[LOCAL_CONN_ID_LEN]; 1081 uint8_t new_cid[LOCAL_CONN_ID_LEN];
1028 1082
1029 struct PeerAddress *peer; 1083 struct PeerAddress *peer;
1030 struct GNUNET_HashCode addr_key; 1084 struct GNUNET_HashCode addr_key;
1031 1085
1032 /**
1033 * May be unnecessary if quiche_header_info writes to len fields
1034 */
1035 quic_header.scid_len = sizeof(quic_header.scid); 1086 quic_header.scid_len = sizeof(quic_header.scid);
1036 quic_header.dcid_len = sizeof(quic_header.dcid); 1087 quic_header.dcid_len = sizeof(quic_header.dcid);
1037 quic_header.odcid_len = sizeof(quic_header.odcid); 1088 quic_header.odcid_len = sizeof(quic_header.odcid);
@@ -1237,7 +1288,7 @@ sock_read (void *cls)
1237 * TODO: Should we use a list instead of hashmap? 1288 * TODO: Should we use a list instead of hashmap?
1238 * Overhead for hashing function, O(1) retrieval vs O(n) iteration with n=30? 1289 * Overhead for hashing function, O(1) retrieval vs O(n) iteration with n=30?
1239 * 1290 *
1240 * TODO: Is iteration necessary as in the server example? 1291 * TODO: Is iteration necessary as in the quiche server example?
1241 */ 1292 */
1242 quiche_stats stats; 1293 quiche_stats stats;
1243 quiche_path_stats path_stats; 1294 quiche_path_stats path_stats;
@@ -1376,6 +1427,27 @@ run (void *cls,
1376 my_port = 0; 1427 my_port = 0;
1377 } 1428 }
1378 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 1429 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
1430 /**
1431 * Setup QUICHE configuration
1432 */
1433 config = quiche_config_new (QUICHE_PROTOCOL_VERSION);
1434 quiche_config_verify_peer (config, false);
1435 // conn_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
1436 addr_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
1437 /**
1438 * Get our public key for initial packet
1439 */
1440 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
1441 if (NULL == my_private_key)
1442 {
1443 GNUNET_log (
1444 GNUNET_ERROR_TYPE_ERROR,
1445 _ (
1446 "Transport service is lacking key configuration settings. Exiting.\n"));
1447 GNUNET_SCHEDULER_shutdown ();
1448 return;
1449 }
1450 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
1379 /* start reading */ 1451 /* start reading */
1380 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1452 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1381 udp_sock, 1453 udp_sock,
@@ -1417,15 +1489,6 @@ run (void *cls,
1417int 1489int
1418main (int argc, char *const *argv) 1490main (int argc, char *const *argv)
1419{ 1491{
1420 /**
1421 * Setup QUICHE configuration
1422 */
1423 config = quiche_config_new (QUICHE_PROTOCOL_VERSION);
1424
1425 quiche_config_verify_peer (config, false);
1426 conn_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
1427 addr_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
1428
1429 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1492 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1430 GNUNET_GETOPT_OPTION_END 1493 GNUNET_GETOPT_OPTION_END
1431 }; 1494 };