diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2024-03-14 21:30:55 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2024-03-14 21:30:55 +0100 |
commit | dcf85f8b41547667293ee55218007407b40c4686 (patch) | |
tree | fbf2c1bda7d0564ea9dfa9465f57fd3444dc41f7 | |
parent | 0f9500cc636e82b2b5841be1f69097c5cadf5055 (diff) | |
download | gnunet-dcf85f8b41547667293ee55218007407b40c4686.tar.gz gnunet-dcf85f8b41547667293ee55218007407b40c4686.zip |
TRANSPORT(tcp): Do not try to create another queue that is already in construction.
-rw-r--r-- | src/service/transport/gnunet-communicator-tcp.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/service/transport/gnunet-communicator-tcp.c b/src/service/transport/gnunet-communicator-tcp.c index 0ab8c0c82..c1e1c66c8 100644 --- a/src/service/transport/gnunet-communicator-tcp.c +++ b/src/service/transport/gnunet-communicator-tcp.c | |||
@@ -457,6 +457,11 @@ struct Queue | |||
457 | gcry_cipher_hd_t out_cipher; | 457 | gcry_cipher_hd_t out_cipher; |
458 | 458 | ||
459 | /** | 459 | /** |
460 | * Key in hash map | ||
461 | */ | ||
462 | struct GNUNET_HashCode key; | ||
463 | |||
464 | /** | ||
460 | * Shared secret for HMAC verification on incoming data. | 465 | * Shared secret for HMAC verification on incoming data. |
461 | */ | 466 | */ |
462 | struct GNUNET_HashCode in_hmac; | 467 | struct GNUNET_HashCode in_hmac; |
@@ -820,7 +825,7 @@ static struct GNUNET_TRANSPORT_CommunicatorHandle *ch; | |||
820 | /** | 825 | /** |
821 | * Queues (map from peer identity to `struct Queue`) | 826 | * Queues (map from peer identity to `struct Queue`) |
822 | */ | 827 | */ |
823 | static struct GNUNET_CONTAINER_MultiPeerMap *queue_map; | 828 | static struct GNUNET_CONTAINER_MultiHashMap *queue_map; |
824 | 829 | ||
825 | /** | 830 | /** |
826 | * ListenTasks (map from socket to `struct ListenTask`) | 831 | * ListenTasks (map from socket to `struct ListenTask`) |
@@ -997,10 +1002,10 @@ queue_destroy (struct Queue *queue) | |||
997 | } | 1002 | } |
998 | GNUNET_assert ( | 1003 | GNUNET_assert ( |
999 | GNUNET_YES == | 1004 | GNUNET_YES == |
1000 | GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue)); | 1005 | GNUNET_CONTAINER_multihashmap_remove (queue_map, &queue->key, queue)); |
1001 | GNUNET_STATISTICS_set (stats, | 1006 | GNUNET_STATISTICS_set (stats, |
1002 | "# queues active", | 1007 | "# queues active", |
1003 | GNUNET_CONTAINER_multipeermap_size (queue_map), | 1008 | GNUNET_CONTAINER_multihashmap_size (queue_map), |
1004 | GNUNET_NO); | 1009 | GNUNET_NO); |
1005 | if (NULL != queue->read_task) | 1010 | if (NULL != queue->read_task) |
1006 | { | 1011 | { |
@@ -2669,14 +2674,14 @@ boot_queue (struct Queue *queue) | |||
2669 | { | 2674 | { |
2670 | queue->nt = | 2675 | queue->nt = |
2671 | GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len); | 2676 | GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len); |
2672 | (void) GNUNET_CONTAINER_multipeermap_put ( | 2677 | (void) GNUNET_CONTAINER_multihashmap_put ( |
2673 | queue_map, | 2678 | queue_map, |
2674 | &queue->target, | 2679 | &queue->key, |
2675 | queue, | 2680 | queue, |
2676 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2681 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2677 | GNUNET_STATISTICS_set (stats, | 2682 | GNUNET_STATISTICS_set (stats, |
2678 | "# queues active", | 2683 | "# queues active", |
2679 | GNUNET_CONTAINER_multipeermap_size (queue_map), | 2684 | GNUNET_CONTAINER_multihashmap_size (queue_map), |
2680 | GNUNET_NO); | 2685 | GNUNET_NO); |
2681 | queue->timeout = | 2686 | queue->timeout = |
2682 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2687 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
@@ -3315,6 +3320,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
3315 | struct sockaddr_in6 *v6; | 3320 | struct sockaddr_in6 *v6; |
3316 | unsigned int is_natd = GNUNET_NO; | 3321 | unsigned int is_natd = GNUNET_NO; |
3317 | struct GNUNET_HashCode key; | 3322 | struct GNUNET_HashCode key; |
3323 | struct GNUNET_HashCode queue_map_key; | ||
3324 | struct GNUNET_HashContext *hsh; | ||
3325 | struct Queue *queue; | ||
3318 | 3326 | ||
3319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3320 | "Connecting to %s at %s\n", | 3328 | "Connecting to %s at %s\n", |
@@ -3341,6 +3349,18 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
3341 | "in %s\n", | 3349 | "in %s\n", |
3342 | GNUNET_a2s (in, in_len)); | 3350 | GNUNET_a2s (in, in_len)); |
3343 | 3351 | ||
3352 | hsh = GNUNET_CRYPTO_hash_context_start(); | ||
3353 | GNUNET_CRYPTO_hash_context_read (hsh, address, strlen (address)); | ||
3354 | GNUNET_CRYPTO_hash_context_read (hsh, peer, sizeof (*peer)); | ||
3355 | GNUNET_CRYPTO_hash_context_finish (hsh, &queue_map_key); | ||
3356 | queue = GNUNET_CONTAINER_multihashmap_get(queue_map, &queue_map_key); | ||
3357 | |||
3358 | if (NULL != queue) | ||
3359 | { | ||
3360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3361 | "Queue for %s already exists or is in construction\n", address); | ||
3362 | return GNUNET_SYSERR; | ||
3363 | } | ||
3344 | switch (in->sa_family) | 3364 | switch (in->sa_family) |
3345 | { | 3365 | { |
3346 | case AF_INET: | 3366 | case AF_INET: |
@@ -3422,7 +3442,6 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
3422 | else | 3442 | else |
3423 | { | 3443 | { |
3424 | struct GNUNET_NETWORK_Handle *sock; | 3444 | struct GNUNET_NETWORK_Handle *sock; |
3425 | struct Queue *queue; | ||
3426 | 3445 | ||
3427 | sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, | 3446 | sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, |
3428 | IPPROTO_TCP); | 3447 | IPPROTO_TCP); |
@@ -3449,6 +3468,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
3449 | 3468 | ||
3450 | queue = GNUNET_new (struct Queue); | 3469 | queue = GNUNET_new (struct Queue); |
3451 | queue->target = *peer; | 3470 | queue->target = *peer; |
3471 | queue->key = queue_map_key; | ||
3452 | queue->address = in; | 3472 | queue->address = in; |
3453 | queue->address_len = in_len; | 3473 | queue->address_len = in_len; |
3454 | queue->sock = sock; | 3474 | queue->sock = sock; |
@@ -3522,7 +3542,7 @@ get_lt_delete_it (void *cls, | |||
3522 | */ | 3542 | */ |
3523 | static int | 3543 | static int |
3524 | get_queue_delete_it (void *cls, | 3544 | get_queue_delete_it (void *cls, |
3525 | const struct GNUNET_PeerIdentity *target, | 3545 | const struct GNUNET_HashCode *target, |
3526 | void *value) | 3546 | void *value) |
3527 | { | 3547 | { |
3528 | struct Queue *queue = value; | 3548 | struct Queue *queue = value; |
@@ -3563,8 +3583,8 @@ do_shutdown (void *cls) | |||
3563 | GNUNET_CONTAINER_multihashmap_destroy (pending_reversals); | 3583 | GNUNET_CONTAINER_multihashmap_destroy (pending_reversals); |
3564 | GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL); | 3584 | GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL); |
3565 | GNUNET_CONTAINER_multihashmap_destroy (lt_map); | 3585 | GNUNET_CONTAINER_multihashmap_destroy (lt_map); |
3566 | GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); | 3586 | GNUNET_CONTAINER_multihashmap_iterate (queue_map, &get_queue_delete_it, NULL); |
3567 | GNUNET_CONTAINER_multipeermap_destroy (queue_map); | 3587 | GNUNET_CONTAINER_multihashmap_destroy (queue_map); |
3568 | if (NULL != ch) | 3588 | if (NULL != ch) |
3569 | { | 3589 | { |
3570 | GNUNET_TRANSPORT_communicator_address_remove_all (ch); | 3590 | GNUNET_TRANSPORT_communicator_address_remove_all (ch); |
@@ -3835,7 +3855,7 @@ init_socket (struct sockaddr *addr, | |||
3835 | "map entry created\n"); | 3855 | "map entry created\n"); |
3836 | 3856 | ||
3837 | if (NULL == queue_map) | 3857 | if (NULL == queue_map) |
3838 | queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 3858 | queue_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
3839 | 3859 | ||
3840 | if (NULL == ch) | 3860 | if (NULL == ch) |
3841 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, | 3861 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, |