diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-09 12:04:29 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-09 12:04:29 +0000 |
commit | f0ac323a4bae4dd87c96bf6d2e9980ec9952df8b (patch) | |
tree | 68ca26106ee56638677e72a44164202f336d0667 /src/mesh | |
parent | 90a2ece34b60543d6dfd7cbcf0c61e215e43b7e0 (diff) | |
download | gnunet-f0ac323a4bae4dd87c96bf6d2e9980ec9952df8b.tar.gz gnunet-f0ac323a4bae4dd87c96bf6d2e9980ec9952df8b.zip |
Changed mesh service's storage to multihashmap, fixed bugs
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 322 | ||||
-rw-r--r-- | src/mesh/test_mesh_local.c | 4 |
2 files changed, 165 insertions, 161 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 9734fe4d9..a7e7e95e2 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -60,6 +60,8 @@ | |||
60 | #if MESH_DEBUG | 60 | #if MESH_DEBUG |
61 | /** | 61 | /** |
62 | * GNUNET_SCHEDULER_Task for printing a message after some operation is done | 62 | * GNUNET_SCHEDULER_Task for printing a message after some operation is done |
63 | * @param cls string to print | ||
64 | * @param tc task context | ||
63 | */ | 65 | */ |
64 | static void | 66 | static void |
65 | mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 67 | mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -70,7 +72,7 @@ mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
70 | { | 72 | { |
71 | return; | 73 | return; |
72 | } | 74 | } |
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s", s); | 75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", s); |
74 | } | 76 | } |
75 | #endif | 77 | #endif |
76 | 78 | ||
@@ -372,14 +374,12 @@ struct MeshClient | |||
372 | /** | 374 | /** |
373 | * Applications that this client has claimed to provide | 375 | * Applications that this client has claimed to provide |
374 | */ | 376 | */ |
375 | GNUNET_MESH_ApplicationType *apps; | 377 | struct GNUNET_CONTAINER_MultiHashMap *apps; |
376 | unsigned int app_counter; | ||
377 | 378 | ||
378 | /** | 379 | /** |
379 | * Messages that this client has declared interest in | 380 | * Messages that this client has declared interest in |
380 | */ | 381 | */ |
381 | uint16_t *types; | 382 | struct GNUNET_CONTAINER_MultiHashMap *types; |
382 | unsigned int type_counter; | ||
383 | 383 | ||
384 | /** | 384 | /** |
385 | * Used for seachching peers offering a service | 385 | * Used for seachching peers offering a service |
@@ -446,17 +446,12 @@ static MESH_TunnelNumber next_tid; | |||
446 | /** | 446 | /** |
447 | * All application types provided by this peer | 447 | * All application types provided by this peer |
448 | */ | 448 | */ |
449 | static GNUNET_MESH_ApplicationType *applications; | 449 | static struct GNUNET_CONTAINER_MultiHashMap *applications; |
450 | |||
451 | /** | ||
452 | * All application types provided by this peer (reference counter) | ||
453 | */ | ||
454 | static unsigned int *applications_rc; | ||
455 | 450 | ||
456 | /** | 451 | /** |
457 | * Number of applications provided by this peer | 452 | * All message types clients of this peer are interested in |
458 | */ | 453 | */ |
459 | static unsigned int n_apps; | 454 | static struct GNUNET_CONTAINER_MultiHashMap *types; |
460 | 455 | ||
461 | /** | 456 | /** |
462 | * Task to periodically announce provided applications | 457 | * Task to periodically announce provided applications |
@@ -664,14 +659,10 @@ retrieve_client (struct GNUNET_SERVER_Client *client) | |||
664 | static int /* FIXME inline? */ | 659 | static int /* FIXME inline? */ |
665 | is_client_subscribed (uint16_t message_type, struct MeshClient *c) | 660 | is_client_subscribed (uint16_t message_type, struct MeshClient *c) |
666 | { | 661 | { |
667 | unsigned int i; | 662 | GNUNET_HashCode hc; |
668 | 663 | ||
669 | for (i = 0; i < c->type_counter; i++) | 664 | GNUNET_CRYPTO_hash(&message_type, sizeof(uint16_t), &hc); |
670 | { | 665 | return GNUNET_CONTAINER_multihashmap_contains(c->types, &hc); |
671 | if (c->types[i] == message_type) | ||
672 | return GNUNET_YES; | ||
673 | } | ||
674 | return GNUNET_NO; | ||
675 | } | 666 | } |
676 | 667 | ||
677 | 668 | ||
@@ -815,6 +806,35 @@ destroy_tunnel (struct MeshTunnel *t) | |||
815 | /******************************************************************************/ | 806 | /******************************************************************************/ |
816 | 807 | ||
817 | /** | 808 | /** |
809 | * Announce iterator over for each application provided by the peer | ||
810 | * | ||
811 | * @param cls closure | ||
812 | * @param key current key code | ||
813 | * @param value value in the hash map | ||
814 | * @return GNUNET_YES if we should continue to | ||
815 | * iterate, | ||
816 | * GNUNET_NO if not. | ||
817 | */ | ||
818 | static int | ||
819 | announce_application (void *cls, const GNUNET_HashCode * key, void *value) | ||
820 | { | ||
821 | /* FIXME are hashes in multihash map equal on all aquitectures? */ | ||
822 | GNUNET_DHT_put (dht_handle, key, 10U, GNUNET_DHT_RO_RECORD_ROUTE, | ||
823 | GNUNET_BLOCK_TYPE_ANY, sizeof (struct GNUNET_PeerIdentity), | ||
824 | (const char *) &my_full_id, | ||
825 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | ||
826 | APP_ANNOUNCE_TIME), | ||
827 | APP_ANNOUNCE_TIME, | ||
828 | #if MESH_DEBUG | ||
829 | &mesh_debug, "DHT_put for app completed"); | ||
830 | #else | ||
831 | NULL, NULL); | ||
832 | #endif | ||
833 | return GNUNET_OK; | ||
834 | } | ||
835 | |||
836 | |||
837 | /** | ||
818 | * Periodically announce what applications are provided by local clients | 838 | * Periodically announce what applications are provided by local clients |
819 | * | 839 | * |
820 | * @param cls closure | 840 | * @param cls closure |
@@ -823,40 +843,19 @@ destroy_tunnel (struct MeshTunnel *t) | |||
823 | static void | 843 | static void |
824 | announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 844 | announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
825 | { | 845 | { |
826 | GNUNET_HashCode hash; | ||
827 | uint8_t buffer[12] = "MESH_APP"; | ||
828 | uint32_t *p; | ||
829 | uint32_t i; | ||
830 | |||
831 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 846 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
832 | { | 847 | { |
833 | announce_applications_task = GNUNET_SCHEDULER_NO_TASK; | 848 | announce_applications_task = GNUNET_SCHEDULER_NO_TASK; |
834 | return; | 849 | return; |
835 | } | 850 | } |
836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for %u apps\n", | 851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for apps\n"); |
837 | n_apps); | 852 | GNUNET_CONTAINER_multihashmap_iterate(applications, |
838 | p = (unsigned int *) &buffer[8]; | 853 | &announce_application, |
839 | for (i = 0; i < n_apps; i++) | 854 | NULL); |
840 | { | ||
841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %u\n", | ||
842 | applications[i]); | ||
843 | *p = htonl (applications[i]); | ||
844 | GNUNET_CRYPTO_hash (buffer, 12, &hash); | ||
845 | GNUNET_DHT_put (dht_handle, &hash, 10U, GNUNET_DHT_RO_RECORD_ROUTE, | ||
846 | GNUNET_BLOCK_TYPE_ANY, sizeof (struct GNUNET_PeerIdentity), | ||
847 | (const char *) &my_full_id, | ||
848 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | ||
849 | APP_ANNOUNCE_TIME), | ||
850 | APP_ANNOUNCE_TIME, | ||
851 | #if MESH_DEBUG | ||
852 | &mesh_debug, "DHT_put for apps completed\n"); | ||
853 | #else | ||
854 | NULL, NULL); | ||
855 | #endif | ||
856 | } | ||
857 | announce_applications_task = | 855 | announce_applications_task = |
858 | GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, &announce_applications, | 856 | GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, &announce_applications, |
859 | cls); | 857 | cls); |
858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Finished PUT for apps\n"); | ||
860 | return; | 859 | return; |
861 | } | 860 | } |
862 | 861 | ||
@@ -889,7 +888,7 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
889 | GNUNET_TIME_absolute_get_forever (), /* Data expiration */ | 888 | GNUNET_TIME_absolute_get_forever (), /* Data expiration */ |
890 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ | 889 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ |
891 | #if MESH_DEBUG | 890 | #if MESH_DEBUG |
892 | &mesh_debug, "DHT_put for id completed\n"); | 891 | &mesh_debug, "DHT_put for id completed"); |
893 | #else | 892 | #else |
894 | NULL, /* Continuation */ | 893 | NULL, /* Continuation */ |
895 | NULL); /* Continuation closure */ | 894 | NULL); /* Continuation closure */ |
@@ -1760,6 +1759,21 @@ delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) | |||
1760 | return r; | 1759 | return r; |
1761 | } | 1760 | } |
1762 | 1761 | ||
1762 | |||
1763 | /** | ||
1764 | * deregister_app: iterator for removing each application registered by a client | ||
1765 | * @param cls closure | ||
1766 | * @param key the hash of the application id (used to access the hashmap) | ||
1767 | * @param value the value stored at the key (client) | ||
1768 | * @return GNUNET_OK on success | ||
1769 | */ | ||
1770 | static int | ||
1771 | deregister_app (void *cls, const GNUNET_HashCode * key, void *value) | ||
1772 | { | ||
1773 | GNUNET_CONTAINER_multihashmap_remove(applications, key, value); | ||
1774 | return GNUNET_OK; | ||
1775 | } | ||
1776 | |||
1763 | #if LATER | 1777 | #if LATER |
1764 | /** | 1778 | /** |
1765 | * notify_client_connection_failure: notify a client that the connection to the | 1779 | * notify_client_connection_failure: notify a client that the connection to the |
@@ -1863,8 +1877,13 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
1863 | // Find ourselves some alternate initial path to the destination: retry | 1877 | // Find ourselves some alternate initial path to the destination: retry |
1864 | GNUNET_DHT_get_stop (peer_info->dhtget); | 1878 | GNUNET_DHT_get_stop (peer_info->dhtget); |
1865 | GNUNET_PEER_resolve (peer_info->id, &pi); | 1879 | GNUNET_PEER_resolve (peer_info->id, &pi); |
1866 | peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_ANY, &pi.hashPubKey, 4, /* replication level */ | 1880 | peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ |
1867 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */ | 1881 | GNUNET_TIME_UNIT_FOREVER_REL, |
1882 | GNUNET_BLOCK_TYPE_ANY, /* type */ | ||
1883 | &pi.hashPubKey, /*key to search */ | ||
1884 | 4, /* replication level */ | ||
1885 | GNUNET_DHT_RO_RECORD_ROUTE, | ||
1886 | NULL, /* bloom filter */ | ||
1868 | 0, /* mutator */ | 1887 | 0, /* mutator */ |
1869 | NULL, /* xquery */ | 1888 | NULL, /* xquery */ |
1870 | 0, /* xquery bits */ | 1889 | 0, /* xquery bits */ |
@@ -2007,8 +2026,6 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
2007 | { | 2026 | { |
2008 | struct MeshClient *c; | 2027 | struct MeshClient *c; |
2009 | struct MeshClient *next; | 2028 | struct MeshClient *next; |
2010 | unsigned int i; | ||
2011 | unsigned int j; | ||
2012 | 2029 | ||
2013 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client disconnected\n"); | 2030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client disconnected\n"); |
2014 | c = clients; | 2031 | c = clients; |
@@ -2023,33 +2040,16 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
2023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n"); | 2040 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n"); |
2024 | GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, c); | 2041 | GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, c); |
2025 | GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); | 2042 | GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); |
2026 | if (0 != c->app_counter) | 2043 | |
2044 | /* deregister clients applications */ | ||
2045 | GNUNET_CONTAINER_multihashmap_iterate(c->apps, &deregister_app, NULL); | ||
2046 | GNUNET_CONTAINER_multihashmap_destroy(c->apps); | ||
2047 | if (0 == GNUNET_CONTAINER_multihashmap_size(applications)) | ||
2027 | { | 2048 | { |
2028 | /* deregister clients applications */ | 2049 | GNUNET_SCHEDULER_cancel (announce_applications_task); |
2029 | for (i = 0; i < c->app_counter; i++) | ||
2030 | { | ||
2031 | for (j = 0; j < n_apps; j++) | ||
2032 | { | ||
2033 | if (c->apps[i] == applications[j] && 0 == --applications_rc[j]) | ||
2034 | { | ||
2035 | applications[j] = applications[n_apps - 1]; | ||
2036 | GNUNET_array_grow (applications, n_apps, n_apps - 1); | ||
2037 | n_apps++; | ||
2038 | applications_rc[j] = applications_rc[n_apps - 1]; | ||
2039 | GNUNET_array_grow (applications_rc, n_apps, n_apps - 1); | ||
2040 | |||
2041 | } | ||
2042 | break; | ||
2043 | } | ||
2044 | } | ||
2045 | GNUNET_free (c->apps); | ||
2046 | if (0 == n_apps) | ||
2047 | { | ||
2048 | GNUNET_SCHEDULER_cancel (announce_applications_task); | ||
2049 | } | ||
2050 | } | 2050 | } |
2051 | if (0 != c->type_counter) | 2051 | |
2052 | GNUNET_free (c->types); | 2052 | GNUNET_CONTAINER_multihashmap_destroy(c->types); |
2053 | GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); | 2053 | GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); |
2054 | next = c->next; | 2054 | next = c->next; |
2055 | GNUNET_free (c); | 2055 | GNUNET_free (c); |
@@ -2076,21 +2076,19 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
2076 | struct MeshClient *c; | 2076 | struct MeshClient *c; |
2077 | GNUNET_MESH_ApplicationType *a; | 2077 | GNUNET_MESH_ApplicationType *a; |
2078 | unsigned int size; | 2078 | unsigned int size; |
2079 | uint16_t types; | 2079 | uint16_t ntypes; |
2080 | uint16_t *t; | 2080 | uint16_t *t; |
2081 | uint16_t apps; | 2081 | uint16_t napps; |
2082 | uint16_t i; | 2082 | uint16_t i; |
2083 | uint16_t j; | ||
2084 | int known; | ||
2085 | 2083 | ||
2086 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: new client connected\n"); | 2084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: new client connected\n"); |
2087 | /* Check data sanity */ | 2085 | /* Check data sanity */ |
2088 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); | 2086 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); |
2089 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; | 2087 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; |
2090 | types = ntohs (cc_msg->types); | 2088 | ntypes = ntohs (cc_msg->types); |
2091 | apps = ntohs (cc_msg->applications); | 2089 | napps = ntohs (cc_msg->applications); |
2092 | if (size != | 2090 | if (size != |
2093 | types * sizeof (uint16_t) + apps * sizeof (GNUNET_MESH_ApplicationType)) | 2091 | ntypes * sizeof (uint16_t) + napps * sizeof (GNUNET_MESH_ApplicationType)) |
2094 | { | 2092 | { |
2095 | GNUNET_break (0); | 2093 | GNUNET_break (0); |
2096 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2094 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -2101,54 +2099,61 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
2101 | c = GNUNET_malloc (sizeof (struct MeshClient)); | 2099 | c = GNUNET_malloc (sizeof (struct MeshClient)); |
2102 | c->handle = client; | 2100 | c->handle = client; |
2103 | a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; | 2101 | a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; |
2104 | if (apps > 0) | 2102 | if (napps > 0) |
2105 | { | 2103 | { |
2106 | c->app_counter = apps; | 2104 | GNUNET_MESH_ApplicationType at; |
2107 | c->apps = GNUNET_malloc (apps * sizeof(GNUNET_MESH_ApplicationType)); | 2105 | GNUNET_HashCode hc; |
2108 | for (i = 0; i < apps; i++) | 2106 | |
2107 | c->apps = GNUNET_CONTAINER_multihashmap_create(napps); | ||
2108 | for (i = 0; i < napps; i++) | ||
2109 | { | 2109 | { |
2110 | c->apps[i] = ntohl(a[i]); | 2110 | at = ntohl(a[i]); |
2111 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: app %u\n", c->apps[i]); | 2111 | GNUNET_CRYPTO_hash(&at, sizeof(at), &hc); |
2112 | known = GNUNET_NO; | 2112 | /* store in clients hashmap */ |
2113 | for (j = 0; i < n_apps; j++) | 2113 | GNUNET_CONTAINER_multihashmap_put( |
2114 | { | 2114 | c->apps, |
2115 | if (c->apps[i] == applications[j]) | 2115 | &hc, |
2116 | { | 2116 | c, |
2117 | known = GNUNET_YES; | 2117 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2118 | applications_rc[j]++; | 2118 | /* store in global hashmap, for announcements */ |
2119 | break; | 2119 | GNUNET_CONTAINER_multihashmap_put( |
2120 | } | 2120 | applications, |
2121 | } | 2121 | &hc, |
2122 | if (!known) | 2122 | c, |
2123 | { | 2123 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2124 | /* Register previously unknown application */ | ||
2125 | GNUNET_array_append (applications, n_apps, c->apps[i]); | ||
2126 | n_apps--; | ||
2127 | GNUNET_array_append (applications_rc, n_apps, 1); | ||
2128 | if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task) | ||
2129 | { | ||
2130 | announce_applications_task = | ||
2131 | GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, | ||
2132 | &announce_applications, NULL); | ||
2133 | } | ||
2134 | /* TODO: if any client was looking for *type*, notify peer found */ | ||
2135 | } | ||
2136 | } | 2124 | } |
2125 | if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task) | ||
2126 | announce_applications_task = GNUNET_SCHEDULER_add_now ( | ||
2127 | &announce_applications, NULL); | ||
2128 | |||
2137 | } | 2129 | } |
2138 | if (types > 0) | 2130 | if (ntypes > 0) |
2139 | { | 2131 | { |
2140 | t = (uint16_t *) &a[apps]; | 2132 | uint16_t u16; |
2141 | c->type_counter = types; | 2133 | GNUNET_HashCode hc; |
2142 | c->types = GNUNET_malloc (types * sizeof (uint16_t)); | 2134 | |
2143 | for (i =0; i < types; i++) | 2135 | t = (uint16_t *) &a[napps]; |
2136 | c->types = GNUNET_CONTAINER_multihashmap_create(ntypes); | ||
2137 | for (i =0; i < ntypes; i++) | ||
2144 | { | 2138 | { |
2145 | c->types[i] = ntohs(t[i]); | 2139 | u16 = ntohs(t[i]); |
2146 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: type %hu\n", c->types[i]); | 2140 | GNUNET_CRYPTO_hash(&u16, sizeof(u16), &hc); |
2141 | /* store in clients hashmap */ | ||
2142 | GNUNET_CONTAINER_multihashmap_put( | ||
2143 | c->types, | ||
2144 | &hc, | ||
2145 | c, | ||
2146 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2147 | /* store in global hashmap */ | ||
2148 | GNUNET_CONTAINER_multihashmap_put( | ||
2149 | types, | ||
2150 | &hc, | ||
2151 | c, | ||
2152 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2147 | } | 2153 | } |
2148 | } | 2154 | } |
2149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2150 | "MESH: client has %u+%u subscriptions\n", c->type_counter, | 2156 | "MESH: client has %u+%u subscriptions\n", napps, ntypes); |
2151 | c->app_counter); | ||
2152 | 2157 | ||
2153 | GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); | 2158 | GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); |
2154 | c->tunnels = GNUNET_CONTAINER_multihashmap_create (32); | 2159 | c->tunnels = GNUNET_CONTAINER_multihashmap_create (32); |
@@ -2446,9 +2451,6 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2446 | GNUNET_HashCode hash; | 2451 | GNUNET_HashCode hash; |
2447 | GNUNET_MESH_ApplicationType type; | 2452 | GNUNET_MESH_ApplicationType type; |
2448 | MESH_TunnelNumber tid; | 2453 | MESH_TunnelNumber tid; |
2449 | uint8_t buffer[12] = "MESH_APP"; | ||
2450 | uint32_t *p; | ||
2451 | unsigned int i; | ||
2452 | 2454 | ||
2453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got connect by type request\n"); | 2455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got connect by type request\n"); |
2454 | /* Sanity check for client registration */ | 2456 | /* Sanity check for client registration */ |
@@ -2490,45 +2492,48 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2490 | /* Do WE have the service? */ | 2492 | /* Do WE have the service? */ |
2491 | type = ntohl (connect_msg->type); | 2493 | type = ntohl (connect_msg->type); |
2492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", type); | 2494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", type); |
2493 | for (i = 0; i < n_apps; i++) | 2495 | GNUNET_CRYPTO_hash (&type, sizeof (GNUNET_MESH_ApplicationType), &hash); |
2496 | if (GNUNET_CONTAINER_multihashmap_contains(applications, &hash) == GNUNET_YES) | ||
2494 | { | 2497 | { |
2495 | if (applications[i] == type) | 2498 | /* Yes! Fast forward, add ourselves to the tunnel and send the |
2496 | { | 2499 | * good news to the client |
2497 | /* Yes! Fast forward, add ourselves to the tunnel and send the | 2500 | */ |
2498 | * good news to the client | 2501 | struct GNUNET_MESH_PeerControl pc; |
2499 | */ | 2502 | |
2500 | struct GNUNET_MESH_PeerControl pc; | 2503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: available locally\n"); |
2501 | 2504 | pc.peer = my_full_id; | |
2502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: available locally\n"); | 2505 | GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey, |
2503 | pc.peer = my_full_id; | 2506 | get_peer_info (&pc.peer), |
2504 | GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey, | 2507 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
2505 | get_peer_info (&pc.peer), | 2508 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); |
2506 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 2509 | pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); |
2507 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); | 2510 | pc.tunnel_id = htonl (t->local_tid); |
2508 | pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); | 2511 | pc.peer = my_full_id; |
2509 | pc.tunnel_id = htonl (t->local_tid); | 2512 | GNUNET_SERVER_notification_context_unicast (nc, /* context */ |
2510 | pc.peer = my_full_id; | 2513 | client, /* dest */ |
2511 | GNUNET_SERVER_notification_context_unicast (nc, /* context */ | 2514 | &pc.header, /* msg */ |
2512 | client, /* dest */ | 2515 | GNUNET_NO); /* can drop? */ |
2513 | &pc.header, /* msg */ | 2516 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2514 | GNUNET_NO); /* can drop? */ | 2517 | return; |
2515 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2516 | return; | ||
2517 | } | ||
2518 | } | 2518 | } |
2519 | /* Ok, lets find a peer offering the service */ | 2519 | /* Ok, lets find a peer offering the service */ |
2520 | p = (uint32_t *) & buffer[8]; | ||
2521 | *p = connect_msg->type; /* Already in Network Byte Order! */ | ||
2522 | GNUNET_CRYPTO_hash (buffer, 12, &hash); | ||
2523 | if (c->dht_get_type) | 2520 | if (c->dht_get_type) |
2524 | { | 2521 | { |
2525 | GNUNET_DHT_get_stop (c->dht_get_type); | 2522 | GNUNET_DHT_get_stop (c->dht_get_type); |
2526 | } | 2523 | } |
2527 | c->dht_get_type = | 2524 | c->dht_get_type = |
2528 | GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, | 2525 | GNUNET_DHT_get_start (dht_handle, |
2529 | GNUNET_BLOCK_TYPE_ANY, &hash, 10U, | 2526 | GNUNET_TIME_UNIT_FOREVER_REL, |
2530 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, NULL, 0, | 2527 | GNUNET_BLOCK_TYPE_ANY, |
2531 | &dht_get_type_handler, t); | 2528 | &hash, |
2529 | 10U, | ||
2530 | GNUNET_DHT_RO_RECORD_ROUTE, | ||
2531 | NULL, | ||
2532 | 0, | ||
2533 | NULL, | ||
2534 | 0, | ||
2535 | &dht_get_type_handler, | ||
2536 | t); | ||
2532 | 2537 | ||
2533 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2538 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2534 | return; | 2539 | return; |
@@ -2882,14 +2887,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2882 | 2887 | ||
2883 | tunnels = GNUNET_CONTAINER_multihashmap_create (32); | 2888 | tunnels = GNUNET_CONTAINER_multihashmap_create (32); |
2884 | peers = GNUNET_CONTAINER_multihashmap_create (32); | 2889 | peers = GNUNET_CONTAINER_multihashmap_create (32); |
2890 | applications = GNUNET_CONTAINER_multihashmap_create (32); | ||
2891 | types = GNUNET_CONTAINER_multihashmap_create (32); | ||
2885 | nc = GNUNET_SERVER_notification_context_create (server_handle, | 2892 | nc = GNUNET_SERVER_notification_context_create (server_handle, |
2886 | LOCAL_QUEUE_SIZE); | 2893 | LOCAL_QUEUE_SIZE); |
2887 | clients = NULL; | 2894 | clients = NULL; |
2888 | clients_tail = NULL; | 2895 | clients_tail = NULL; |
2889 | 2896 | ||
2890 | applications = NULL; | ||
2891 | applications_rc = NULL; | ||
2892 | n_apps = 0; | ||
2893 | announce_applications_task = 0; | 2897 | announce_applications_task = 0; |
2894 | 2898 | ||
2895 | /* Scheduled the task to clean up when shutdown is called */ | 2899 | /* Scheduled the task to clean up when shutdown is called */ |
diff --git a/src/mesh/test_mesh_local.c b/src/mesh/test_mesh_local.c index 6b5b2159b..a51eb133d 100644 --- a/src/mesh/test_mesh_local.c +++ b/src/mesh/test_mesh_local.c | |||
@@ -153,7 +153,7 @@ inbound_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, | |||
153 | * @param tunnel_ctx place where local state associated | 153 | * @param tunnel_ctx place where local state associated |
154 | * with the tunnel is stored | 154 | * with the tunnel is stored |
155 | */ | 155 | */ |
156 | static void | 156 | static void |
157 | inbound_end (void *cls, | 157 | inbound_end (void *cls, |
158 | const struct GNUNET_MESH_Tunnel * tunnel, | 158 | const struct GNUNET_MESH_Tunnel * tunnel, |
159 | void *tunnel_ctx) | 159 | void *tunnel_ctx) |
@@ -186,7 +186,7 @@ static void peer_conected ( | |||
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Method called whenever a peer has connected to the tunnel. | 188 | * Method called whenever a peer has connected to the tunnel. |
189 | * | 189 | * |
190 | * @param cls closure | 190 | * @param cls closure |
191 | * @param peer peer identity the tunnel was created to, NULL on timeout | 191 | * @param peer peer identity the tunnel was created to, NULL on timeout |
192 | * @param atsi performance data for the connection | 192 | * @param atsi performance data for the connection |