aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-quic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-communicator-quic.c')
-rw-r--r--src/transport/gnunet-communicator-quic.c91
1 files changed, 37 insertions, 54 deletions
diff --git a/src/transport/gnunet-communicator-quic.c b/src/transport/gnunet-communicator-quic.c
index 626801821..d95d3dd57 100644
--- a/src/transport/gnunet-communicator-quic.c
+++ b/src/transport/gnunet-communicator-quic.c
@@ -140,11 +140,6 @@ struct PeerAddress
140}; 140};
141 141
142/** 142/**
143 * Peers (map from peer identity to `struct PeerAddress`)
144 */
145static struct GNUNET_CONTAINER_MultiPeerMap *peers;
146
147/**
148 * Expiration heap for peers (contains `struct PeerAddress`) 143 * Expiration heap for peers (contains `struct PeerAddress`)
149 */ 144 */
150static struct GNUNET_CONTAINER_Heap *peers_heap; 145static struct GNUNET_CONTAINER_Heap *peers_heap;
@@ -361,7 +356,6 @@ create_conn (uint8_t *scid, size_t scid_len,
361{ 356{
362 struct quic_conn *conn; 357 struct quic_conn *conn;
363 quiche_conn *q_conn; 358 quiche_conn *q_conn;
364 struct GNUNET_HashCode conn_key;
365 conn = GNUNET_new (struct quic_conn); 359 conn = GNUNET_new (struct quic_conn);
366 if (scid_len != LOCAL_CONN_ID_LEN) 360 if (scid_len != LOCAL_CONN_ID_LEN)
367 { 361 {
@@ -385,13 +379,6 @@ create_conn (uint8_t *scid, size_t scid_len,
385 return NULL; 379 return NULL;
386 } 380 }
387 conn->conn = q_conn; 381 conn->conn = q_conn;
388 // GNUNET_CRYPTO_hash (conn->cid, sizeof(conn->cid), &conn_key);
389 // /**
390 // * TODO: use UNIQUE_FAST instead?
391 // */
392 // GNUNET_CONTAINER_multihashmap_put (conn_map, &conn_key, conn,
393 // GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
394
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new quic connection created\n"); 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new quic connection created\n");
396 return conn; 383 return conn;
397} 384}
@@ -454,6 +441,8 @@ reschedule_peer_timeout (struct PeerAddress *peer)
454static void 441static void
455peer_destroy (struct PeerAddress *peer) 442peer_destroy (struct PeerAddress *peer)
456{ 443{
444 struct GNUNET_HashCode addr_key;
445
457 peer->peer_destroy_called = GNUNET_YES; 446 peer->peer_destroy_called = GNUNET_YES;
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "Disconnecting peer for peer `%s'\n", 448 "Disconnecting peer for peer `%s'\n",
@@ -463,14 +452,21 @@ peer_destroy (struct PeerAddress *peer)
463 GNUNET_TRANSPORT_communicator_mq_del (peer->d_qh); 452 GNUNET_TRANSPORT_communicator_mq_del (peer->d_qh);
464 peer->d_qh = NULL; 453 peer->d_qh = NULL;
465 } 454 }
466 GNUNET_assert (GNUNET_YES ==
467 GNUNET_CONTAINER_multipeermap_remove (peers,
468 &peer->target,
469 peer));
470 GNUNET_assert (peer == GNUNET_CONTAINER_heap_remove_node (peer->hn)); 455 GNUNET_assert (peer == GNUNET_CONTAINER_heap_remove_node (peer->hn));
456 /**
457 * Remove peer from hashmap
458 */
459 GNUNET_CRYPTO_hash (peer->address, peer->address_len, &addr_key);
460 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (addr_map, &addr_key,
461 peer))
462 {
463 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
464 "tried to remove non-existent peer from addr map\n");
465 return;
466 }
471 GNUNET_STATISTICS_set (stats, 467 GNUNET_STATISTICS_set (stats,
472 "# peers active", 468 "# peers active",
473 GNUNET_CONTAINER_multipeermap_size (peers), 469 GNUNET_CONTAINER_multihashmap_size (addr_map),
474 GNUNET_NO); 470 GNUNET_NO);
475 quiche_conn_free (peer->conn->conn); 471 quiche_conn_free (peer->conn->conn);
476 GNUNET_free (peer->address); 472 GNUNET_free (peer->address);
@@ -484,18 +480,18 @@ peer_destroy (struct PeerAddress *peer)
484 * Iterator over all peers to clean up. 480 * Iterator over all peers to clean up.
485 * 481 *
486 * @param cls NULL 482 * @param cls NULL
487 * @param target unused 483 * @param key peer->address
488 * @param value the queue to destroy 484 * @param value the peer to destroy
489 * @return #GNUNET_OK to continue to iterate 485 * @return #GNUNET_OK to continue to iterate
490 */ 486 */
491static int 487static int
492get_peer_delete_it (void *cls, 488get_peer_delete_it (void *cls,
493 const struct GNUNET_PeerIdentity *target, 489 const struct GNUNET_Hashcode *key,
494 void *value) 490 void *value)
495{ 491{
496 struct PeerAddress *peer = value; 492 struct PeerAddress *peer = value;
497 (void) cls; 493 (void) cls;
498 (void) target; 494 (void) key;
499 peer_destroy (peer); 495 peer_destroy (peer);
500 return GNUNET_OK; 496 return GNUNET_OK;
501} 497}
@@ -953,6 +949,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
953 const char *path; 949 const char *path;
954 struct sockaddr *in; 950 struct sockaddr *in;
955 socklen_t in_len; 951 socklen_t in_len;
952 struct GNUNET_HashCode addr_key;
956 uint8_t scid[LOCAL_CONN_ID_LEN]; 953 uint8_t scid[LOCAL_CONN_ID_LEN];
957 954
958 ssize_t send_len; 955 ssize_t send_len;
@@ -987,25 +984,21 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
987 in = udp_address_to_sockaddr (path, &in_len); 984 in = udp_address_to_sockaddr (path, &in_len);
988 985
989 /** 986 /**
990 * TODO: Check for existing peer (i.e. if we received a message from this address before) 987 * If we already have a queue with this peer, ignore
991 */ 988 */
992 989 GNUNET_CRYPTO_hash (&in, in_len, &addr_key);
990 peer = GNUNET_CONTAINER_multihashmap_get (addr_map, &addr_key);
991 if (NULL != peer)
992 {
993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
994 "ignoring transport service mq request, we already have an mq with this peer (address)\n");
995 return GNUNET_SYSERR;
996 }
993 peer = GNUNET_new (struct PeerAddress); 997 peer = GNUNET_new (struct PeerAddress);
994 peer->address = in; 998 peer->address = in;
995 peer->address_len = in_len; 999 peer->address_len = in_len;
996 peer->target = *peer_id; 1000 peer->target = *peer_id;
997 peer->nt = GNUNET_NT_scanner_get_type (is, in, in_len); 1001 peer->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
998 /**
999 * TODO: use addr_map
1000 */
1001 (void) GNUNET_CONTAINER_multipeermap_put (
1002 peers,
1003 &peer->target,
1004 peer,
1005 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1007 "Added %s to peers\n",
1008 GNUNET_i2s_full (&peer->target));
1009 peer->timeout = 1002 peer->timeout =
1010 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1003 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1011 peer->hn = GNUNET_CONTAINER_heap_insert (peers_heap, 1004 peer->hn = GNUNET_CONTAINER_heap_insert (peers_heap,
@@ -1013,7 +1006,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
1013 peer->timeout.abs_value_us); 1006 peer->timeout.abs_value_us);
1014 GNUNET_STATISTICS_set (stats, 1007 GNUNET_STATISTICS_set (stats,
1015 "# peers active", 1008 "# peers active",
1016 GNUNET_CONTAINER_multipeermap_size (peers), 1009 GNUNET_CONTAINER_multihashmap_size (addr_map),
1017 GNUNET_NO); 1010 GNUNET_NO);
1018 peer->foreign_addr = 1011 peer->foreign_addr =
1019 sockaddr_to_udpaddr_string (peer->address, peer->address_len); 1012 sockaddr_to_udpaddr_string (peer->address, peer->address_len);
@@ -1057,19 +1050,14 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const
1057 /** 1050 /**
1058 * Insert peer into hashmap 1051 * Insert peer into hashmap
1059 */ 1052 */
1060 struct GNUNET_HashCode key; 1053 GNUNET_CONTAINER_multihashmap_put (addr_map, &addr_key,
1061 GNUNET_CRYPTO_hash (peer->address, peer->address_len, &key); 1054 peer,
1062 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (addr_map, &key, peer, 1055 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1063 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1064 {
1065 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1066 "tried to add duplicate address into address map\n");
1067 peer_destroy (peer);
1068 GNUNET_free (local_addr);
1069 return GNUNET_SYSERR;
1070 }
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new peer to the addr map\n"); 1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new peer to the addr map\n");
1072 setup_peer_mq (peer); 1057 setup_peer_mq (peer);
1058 /**
1059 * TODO: destroy peers in hashmap
1060 */
1073 if (NULL == timeout_task) 1061 if (NULL == timeout_task)
1074 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); 1062 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
1075 GNUNET_free (local_addr); 1063 GNUNET_free (local_addr);
@@ -1087,13 +1075,8 @@ do_shutdown (void *cls)
1087{ 1075{
1088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1089 "do_shutdown\n"); 1077 "do_shutdown\n");
1090 GNUNET_CONTAINER_multipeermap_iterate (peers, &get_peer_delete_it, NULL); 1078 GNUNET_CONTAINER_multihashmap_iterate (addr_map, &get_peer_delete_it, NULL);
1091 GNUNET_CONTAINER_multipeermap_destroy (peers); 1079 GNUNET_CONTAINER_multihashmap_destroy (addr_map);
1092 /**
1093 * TODO: remove peers, just use addr_map
1094 */
1095 // GNUNET_CONTAINER_multihashmap_iterate (addr_map, &get_peer_delete_it, NULL);
1096 // GNUNET_CONTAINER_multihashmap_destroy (addr_map);
1097 quiche_config_free (config); 1080 quiche_config_free (config);
1098 1081
1099 if (NULL != timeout_task) 1082 if (NULL != timeout_task)