diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-17 17:18:53 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-17 17:18:53 +0100 |
commit | f9b01d9c8eeac932db6357426f8a70bf525a4e07 (patch) | |
tree | f3023b6cfe959a38ed5d9ab131fc8e1c62d136ea /src/cadet/gnunet-service-cadet_connection.c | |
parent | 100e16ba31dac7138413bda3389d30b3575a8b8e (diff) | |
download | gnunet-f9b01d9c8eeac932db6357426f8a70bf525a4e07.tar.gz gnunet-f9b01d9c8eeac932db6357426f8a70bf525a4e07.zip |
use new shortmap to simplify CADET logic a bit
Diffstat (limited to 'src/cadet/gnunet-service-cadet_connection.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 80 |
1 files changed, 37 insertions, 43 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 2c21a1686..500511ce4 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -322,7 +322,7 @@ extern struct GNUNET_PeerIdentity my_full_id; | |||
322 | /** | 322 | /** |
323 | * Connections known, indexed by cid (CadetConnection). | 323 | * Connections known, indexed by cid (CadetConnection). |
324 | */ | 324 | */ |
325 | static struct GNUNET_CONTAINER_MultiHashMap *connections; | 325 | static struct GNUNET_CONTAINER_MultiShortmap *connections; |
326 | 326 | ||
327 | /** | 327 | /** |
328 | * How many connections are we willing to maintain. | 328 | * How many connections are we willing to maintain. |
@@ -475,7 +475,8 @@ fc_init (struct CadetFlowControl *fc) | |||
475 | static struct CadetConnection * | 475 | static struct CadetConnection * |
476 | connection_get (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 476 | connection_get (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
477 | { | 477 | { |
478 | return GNUNET_CONTAINER_multihashmap_get (connections, GC_h2hc (&cid->connection_of_tunnel)); | 478 | return GNUNET_CONTAINER_multishortmap_get (connections, |
479 | &cid->connection_of_tunnel); | ||
479 | } | 480 | } |
480 | 481 | ||
481 | 482 | ||
@@ -912,7 +913,7 @@ check_neighbours (const struct CadetConnection *c) | |||
912 | */ | 913 | */ |
913 | static int | 914 | static int |
914 | check_connection (void *cls, | 915 | check_connection (void *cls, |
915 | const struct GNUNET_HashCode *key, | 916 | const struct GNUNET_ShortHashCode *key, |
916 | void *value) | 917 | void *value) |
917 | { | 918 | { |
918 | struct CadetConnection *c = value; | 919 | struct CadetConnection *c = value; |
@@ -932,9 +933,9 @@ GCC_check_connections () | |||
932 | return; | 933 | return; |
933 | if (NULL == connections) | 934 | if (NULL == connections) |
934 | return; | 935 | return; |
935 | GNUNET_CONTAINER_multihashmap_iterate (connections, | 936 | GNUNET_CONTAINER_multishortmap_iterate (connections, |
936 | &check_connection, | 937 | &check_connection, |
937 | NULL); | 938 | NULL); |
938 | } | 939 | } |
939 | 940 | ||
940 | 941 | ||
@@ -1109,7 +1110,7 @@ send_broken_unknown (const struct GNUNET_CADET_ConnectionTunnelIdentifier *conne | |||
1109 | 1110 | ||
1110 | GCC_check_connections (); | 1111 | GCC_check_connections (); |
1111 | LOG (GNUNET_ERROR_TYPE_INFO, "--> BROKEN on unknown connection %s\n", | 1112 | LOG (GNUNET_ERROR_TYPE_INFO, "--> BROKEN on unknown connection %s\n", |
1112 | GNUNET_h2s (GC_h2hc (&connection_id->connection_of_tunnel))); | 1113 | GNUNET_sh2s (&connection_id->connection_of_tunnel)); |
1113 | 1114 | ||
1114 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); | 1115 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); |
1115 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | 1116 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
@@ -1855,9 +1856,13 @@ log_message (const struct GNUNET_MessageHeader *message, | |||
1855 | default: | 1856 | default: |
1856 | arrow = "--"; | 1857 | arrow = "--"; |
1857 | } | 1858 | } |
1858 | LOG (GNUNET_ERROR_TYPE_INFO, "<%s %s on conn %s from %s, %6u bytes\n", | 1859 | LOG (GNUNET_ERROR_TYPE_INFO, |
1859 | arrow, GC_m2s (type), GNUNET_h2s (GC_h2hc (&conn_id->connection_of_tunnel)), | 1860 | "<%s %s on conn %s from %s, %6u bytes\n", |
1860 | GCP_2s(peer), (unsigned int) size); | 1861 | arrow, |
1862 | GC_m2s (type), | ||
1863 | GNUNET_sh2s (&conn_id->connection_of_tunnel), | ||
1864 | GCP_2s(peer), | ||
1865 | (unsigned int) size); | ||
1861 | } | 1866 | } |
1862 | 1867 | ||
1863 | /******************************************************************************/ | 1868 | /******************************************************************************/ |
@@ -2354,7 +2359,7 @@ GCC_handle_poll (struct CadetPeer *peer, | |||
2354 | GNUNET_NO); | 2359 | GNUNET_NO); |
2355 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2360 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2356 | "POLL message on unknown connection %s!\n", | 2361 | "POLL message on unknown connection %s!\n", |
2357 | GNUNET_h2s (GC_h2hc (&msg->cid.connection_of_tunnel))); | 2362 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
2358 | send_broken_unknown (&msg->cid, | 2363 | send_broken_unknown (&msg->cid, |
2359 | &my_full_id, | 2364 | &my_full_id, |
2360 | NULL, | 2365 | NULL, |
@@ -2428,7 +2433,7 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2428 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2433 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2429 | "%s on unknown connection %s\n", | 2434 | "%s on unknown connection %s\n", |
2430 | GC_m2s (ntohs (message->type)), | 2435 | GC_m2s (ntohs (message->type)), |
2431 | GNUNET_h2s (GC_h2hc (&cid->connection_of_tunnel))); | 2436 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
2432 | GNUNET_break_op (0); | 2437 | GNUNET_break_op (0); |
2433 | send_broken_unknown (cid, | 2438 | send_broken_unknown (cid, |
2434 | &my_full_id, | 2439 | &my_full_id, |
@@ -2680,7 +2685,8 @@ GCC_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
2680 | } | 2685 | } |
2681 | create_connection_time = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, | 2686 | create_connection_time = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, |
2682 | refresh_connection_time); | 2687 | refresh_connection_time); |
2683 | connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); | 2688 | connections = GNUNET_CONTAINER_multishortmap_create (1024, |
2689 | GNUNET_YES); | ||
2684 | } | 2690 | } |
2685 | 2691 | ||
2686 | 2692 | ||
@@ -2695,7 +2701,7 @@ GCC_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
2695 | */ | 2701 | */ |
2696 | static int | 2702 | static int |
2697 | shutdown_iterator (void *cls, | 2703 | shutdown_iterator (void *cls, |
2698 | const struct GNUNET_HashCode *key, | 2704 | const struct GNUNET_ShortHashCode *key, |
2699 | void *value) | 2705 | void *value) |
2700 | { | 2706 | { |
2701 | struct CadetConnection *c = value; | 2707 | struct CadetConnection *c = value; |
@@ -2714,10 +2720,10 @@ GCC_shutdown (void) | |||
2714 | { | 2720 | { |
2715 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connections\n"); | 2721 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connections\n"); |
2716 | GCC_check_connections (); | 2722 | GCC_check_connections (); |
2717 | GNUNET_CONTAINER_multihashmap_iterate (connections, | 2723 | GNUNET_CONTAINER_multishortmap_iterate (connections, |
2718 | &shutdown_iterator, | 2724 | &shutdown_iterator, |
2719 | NULL); | 2725 | NULL); |
2720 | GNUNET_CONTAINER_multihashmap_destroy (connections); | 2726 | GNUNET_CONTAINER_multishortmap_destroy (connections); |
2721 | connections = NULL; | 2727 | connections = NULL; |
2722 | } | 2728 | } |
2723 | 2729 | ||
@@ -2748,9 +2754,10 @@ GCC_new (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
2748 | c = GNUNET_new (struct CadetConnection); | 2754 | c = GNUNET_new (struct CadetConnection); |
2749 | c->id = *cid; | 2755 | c->id = *cid; |
2750 | GNUNET_assert (GNUNET_OK == | 2756 | GNUNET_assert (GNUNET_OK == |
2751 | GNUNET_CONTAINER_multihashmap_put (connections, | 2757 | GNUNET_CONTAINER_multishortmap_put (connections, |
2752 | GCC_get_h (c), c, | 2758 | &c->id.connection_of_tunnel, |
2753 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2759 | c, |
2760 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2754 | fc_init (&c->fwd_fc); | 2761 | fc_init (&c->fwd_fc); |
2755 | fc_init (&c->bck_fc); | 2762 | fc_init (&c->bck_fc); |
2756 | c->fwd_fc.c = c; | 2763 | c->fwd_fc.c = c; |
@@ -2851,9 +2858,9 @@ GCC_destroy (struct CadetConnection *c) | |||
2851 | if (GNUNET_NO == c->was_removed) | 2858 | if (GNUNET_NO == c->was_removed) |
2852 | { | 2859 | { |
2853 | GNUNET_break (GNUNET_YES == | 2860 | GNUNET_break (GNUNET_YES == |
2854 | GNUNET_CONTAINER_multihashmap_remove (connections, | 2861 | GNUNET_CONTAINER_multishortmap_remove (connections, |
2855 | GCC_get_h (c), | 2862 | &c->id.connection_of_tunnel, |
2856 | c)); | 2863 | c)); |
2857 | } | 2864 | } |
2858 | GNUNET_STATISTICS_update (stats, | 2865 | GNUNET_STATISTICS_update (stats, |
2859 | "# connections", | 2866 | "# connections", |
@@ -2879,20 +2886,6 @@ GCC_get_id (const struct CadetConnection *c) | |||
2879 | 2886 | ||
2880 | 2887 | ||
2881 | /** | 2888 | /** |
2882 | * Get the connection ID. | ||
2883 | * | ||
2884 | * @param c Connection to get the ID from. | ||
2885 | * | ||
2886 | * @return ID of the connection. | ||
2887 | */ | ||
2888 | const struct GNUNET_HashCode * | ||
2889 | GCC_get_h (const struct CadetConnection *c) | ||
2890 | { | ||
2891 | return GC_h2hc (&c->id.connection_of_tunnel); | ||
2892 | } | ||
2893 | |||
2894 | |||
2895 | /** | ||
2896 | * Get the connection path. | 2889 | * Get the connection path. |
2897 | * | 2890 | * |
2898 | * @param c Connection to get the path from. | 2891 | * @param c Connection to get the path from. |
@@ -3092,9 +3085,9 @@ GCC_neighbor_disconnected (struct CadetConnection *c, struct CadetPeer *peer) | |||
3092 | GNUNET_assert (GNUNET_NO == c->was_removed); | 3085 | GNUNET_assert (GNUNET_NO == c->was_removed); |
3093 | c->was_removed = GNUNET_YES; | 3086 | c->was_removed = GNUNET_YES; |
3094 | GNUNET_break (GNUNET_YES == | 3087 | GNUNET_break (GNUNET_YES == |
3095 | GNUNET_CONTAINER_multihashmap_remove (connections, | 3088 | GNUNET_CONTAINER_multishortmap_remove (connections, |
3096 | GCC_get_h (c), | 3089 | &c->id.connection_of_tunnel, |
3097 | c)); | 3090 | c)); |
3098 | /* Cancel queue in the direction that just died. */ | 3091 | /* Cancel queue in the direction that just died. */ |
3099 | connection_cancel_queues (c, ! fwd); | 3092 | connection_cancel_queues (c, ! fwd); |
3100 | GCC_stop_poll (c, ! fwd); | 3093 | GCC_stop_poll (c, ! fwd); |
@@ -3559,10 +3552,11 @@ GCC_2s (const struct CadetConnection *c) | |||
3559 | static char buf[128]; | 3552 | static char buf[128]; |
3560 | 3553 | ||
3561 | SPRINTF (buf, "%s (->%s)", | 3554 | SPRINTF (buf, "%s (->%s)", |
3562 | GNUNET_h2s (GC_h2hc (&GCC_get_id (c)->connection_of_tunnel)), GCT_2s (c->t)); | 3555 | GNUNET_sh2s (&GCC_get_id (c)->connection_of_tunnel), |
3556 | GCT_2s (c->t)); | ||
3563 | return buf; | 3557 | return buf; |
3564 | } | 3558 | } |
3565 | return GNUNET_h2s (GC_h2hc (&c->id.connection_of_tunnel)); | 3559 | return GNUNET_sh2s (&c->id.connection_of_tunnel); |
3566 | } | 3560 | } |
3567 | 3561 | ||
3568 | 3562 | ||