aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c152
1 files changed, 61 insertions, 91 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index f31ff63ba..b30289ac0 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -661,8 +661,8 @@ is_client_subscribed (uint16_t message_type, struct MeshClient *c)
661{ 661{
662 GNUNET_HashCode hc; 662 GNUNET_HashCode hc;
663 663
664 GNUNET_CRYPTO_hash(&message_type, sizeof(uint16_t), &hc); 664 GNUNET_CRYPTO_hash (&message_type, sizeof (uint16_t), &hc);
665 return GNUNET_CONTAINER_multihashmap_contains(c->types, &hc); 665 return GNUNET_CONTAINER_multihashmap_contains (c->types, &hc);
666} 666}
667 667
668 668
@@ -817,9 +817,8 @@ static int
817announce_application (void *cls, const GNUNET_HashCode * key, void *value) 817announce_application (void *cls, const GNUNET_HashCode * key, void *value)
818{ 818{
819 /* FIXME are hashes in multihash map equal on all aquitectures? */ 819 /* FIXME are hashes in multihash map equal on all aquitectures? */
820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: putting in DHT %s\n",
821 "MESH: putting in DHT %s\n", 821 GNUNET_h2s_full (key));
822 GNUNET_h2s_full(key));
823 GNUNET_DHT_put (dht_handle, key, 10U, GNUNET_DHT_RO_RECORD_ROUTE, 822 GNUNET_DHT_put (dht_handle, key, 10U, GNUNET_DHT_RO_RECORD_ROUTE,
824 GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity), 823 GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity),
825 (const char *) &my_full_id, 824 (const char *) &my_full_id,
@@ -851,9 +850,8 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
851 return; 850 return;
852 } 851 }
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for apps\n"); 852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for apps\n");
854 GNUNET_CONTAINER_multihashmap_iterate(applications, 853 GNUNET_CONTAINER_multihashmap_iterate (applications, &announce_application,
855 &announce_application, 854 NULL);
856 NULL);
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);
@@ -884,7 +882,7 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
884 &my_full_id.hashPubKey, /* Key to use */ 882 &my_full_id.hashPubKey, /* Key to use */
885 10U, /* Replication level */ 883 10U, /* Replication level */
886 GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options */ 884 GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options */
887 GNUNET_BLOCK_TYPE_TEST, /* Block type */ 885 GNUNET_BLOCK_TYPE_TEST, /* Block type */
888 0, /* Size of the data */ 886 0, /* Size of the data */
889 NULL, /* Data itself */ 887 NULL, /* Data itself */
890 GNUNET_TIME_absolute_get_forever (), /* Data expiration */ 888 GNUNET_TIME_absolute_get_forever (), /* Data expiration */
@@ -1682,7 +1680,7 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
1682 } 1680 }
1683 1681
1684 /* Message for us? */ 1682 /* Message for us? */
1685 if (0 == memcmp (&msg->oid, &my_full_id, sizeof(struct GNUNET_PeerIdentity))) 1683 if (0 == memcmp (&msg->oid, &my_full_id, sizeof (struct GNUNET_PeerIdentity)))
1686 { 1684 {
1687 struct GNUNET_MESH_PeerControl pc; 1685 struct GNUNET_MESH_PeerControl pc;
1688 1686
@@ -1772,7 +1770,7 @@ delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value)
1772static int 1770static int
1773deregister_app (void *cls, const GNUNET_HashCode * key, void *value) 1771deregister_app (void *cls, const GNUNET_HashCode * key, void *value)
1774{ 1772{
1775 GNUNET_CONTAINER_multihashmap_remove(applications, key, value); 1773 GNUNET_CONTAINER_multihashmap_remove (applications, key, value);
1776 return GNUNET_OK; 1774 return GNUNET_OK;
1777} 1775}
1778 1776
@@ -1880,12 +1878,10 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
1880 GNUNET_DHT_get_stop (peer_info->dhtget); 1878 GNUNET_DHT_get_stop (peer_info->dhtget);
1881 GNUNET_PEER_resolve (peer_info->id, &pi); 1879 GNUNET_PEER_resolve (peer_info->id, &pi);
1882 peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ 1880 peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
1883 GNUNET_TIME_UNIT_FOREVER_REL, 1881 GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_TEST, /* type */
1884 GNUNET_BLOCK_TYPE_TEST, /* type */ 1882 &pi.hashPubKey, /*key to search */
1885 &pi.hashPubKey, /*key to search */ 1883 4, /* replication level */
1886 4, /* replication level */ 1884 GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */
1887 GNUNET_DHT_RO_RECORD_ROUTE,
1888 NULL, /* bloom filter */
1889 0, /* mutator */ 1885 0, /* mutator */
1890 NULL, /* xquery */ 1886 NULL, /* xquery */
1891 0, /* xquery bits */ 1887 0, /* xquery bits */
@@ -1966,7 +1962,7 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
1966 return; 1962 return;
1967 } 1963 }
1968 GNUNET_assert (NULL != t->client); 1964 GNUNET_assert (NULL != t->client);
1969 GNUNET_DHT_get_stop(t->client->dht_get_type); 1965 GNUNET_DHT_get_stop (t->client->dht_get_type);
1970 t->client->dht_get_type = NULL; 1966 t->client->dht_get_type = NULL;
1971 peer_info = get_peer_info (pi); 1967 peer_info = get_peer_info (pi);
1972 GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, peer_info, 1968 GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, peer_info,
@@ -1976,13 +1972,9 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
1976 /* we don't have a route to the peer, let's try a direct lookup */ 1972 /* we don't have a route to the peer, let's try a direct lookup */
1977 if (NULL == peer_info->dhtget) 1973 if (NULL == peer_info->dhtget)
1978 { 1974 {
1979 peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ 1975 peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
1980 GNUNET_TIME_UNIT_FOREVER_REL, 1976 GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_TEST, &pi->hashPubKey, 10U, /* replication level */
1981 GNUNET_BLOCK_TYPE_TEST, 1977 GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */
1982 &pi->hashPubKey,
1983 10U, /* replication level */
1984 GNUNET_DHT_RO_RECORD_ROUTE,
1985 NULL, /* bloom filter */
1986 0, /* mutator */ 1978 0, /* mutator */
1987 NULL, /* xquery */ 1979 NULL, /* xquery */
1988 0, /* xquery bits */ 1980 0, /* xquery bits */
@@ -2050,8 +2042,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n"); 2042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n");
2051 if (NULL != c->tunnels) 2043 if (NULL != c->tunnels)
2052 { 2044 {
2053 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, 2045 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry,
2054 &delete_tunnel_entry,
2055 c); 2046 c);
2056 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); 2047 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
2057 } 2048 }
@@ -2059,19 +2050,19 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2059 /* deregister clients applications */ 2050 /* deregister clients applications */
2060 if (NULL != c->apps) 2051 if (NULL != c->apps)
2061 { 2052 {
2062 GNUNET_CONTAINER_multihashmap_iterate(c->apps, &deregister_app, NULL); 2053 GNUNET_CONTAINER_multihashmap_iterate (c->apps, &deregister_app, NULL);
2063 GNUNET_CONTAINER_multihashmap_destroy(c->apps); 2054 GNUNET_CONTAINER_multihashmap_destroy (c->apps);
2064 } 2055 }
2065 if (0 == GNUNET_CONTAINER_multihashmap_size(applications) && 2056 if (0 == GNUNET_CONTAINER_multihashmap_size (applications) &&
2066 GNUNET_SCHEDULER_NO_TASK != announce_applications_task) 2057 GNUNET_SCHEDULER_NO_TASK != announce_applications_task)
2067 { 2058 {
2068 GNUNET_SCHEDULER_cancel (announce_applications_task); 2059 GNUNET_SCHEDULER_cancel (announce_applications_task);
2069 announce_applications_task = GNUNET_SCHEDULER_NO_TASK; 2060 announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
2070 } 2061 }
2071 if (NULL != c->types) 2062 if (NULL != c->types)
2072 GNUNET_CONTAINER_multihashmap_destroy(c->types); 2063 GNUNET_CONTAINER_multihashmap_destroy (c->types);
2073 if (NULL != c->dht_get_type) 2064 if (NULL != c->dht_get_type)
2074 GNUNET_DHT_get_stop(c->dht_get_type); 2065 GNUNET_DHT_get_stop (c->dht_get_type);
2075 GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); 2066 GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c);
2076 next = c->next; 2067 next = c->next;
2077 GNUNET_free (c); 2068 GNUNET_free (c);
@@ -2126,27 +2117,21 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2126 GNUNET_MESH_ApplicationType at; 2117 GNUNET_MESH_ApplicationType at;
2127 GNUNET_HashCode hc; 2118 GNUNET_HashCode hc;
2128 2119
2129 c->apps = GNUNET_CONTAINER_multihashmap_create(napps); 2120 c->apps = GNUNET_CONTAINER_multihashmap_create (napps);
2130 for (i = 0; i < napps; i++) 2121 for (i = 0; i < napps; i++)
2131 { 2122 {
2132 at = ntohl(a[i]); 2123 at = ntohl (a[i]);
2133 GNUNET_CRYPTO_hash(&at, sizeof(at), &hc); 2124 GNUNET_CRYPTO_hash (&at, sizeof (at), &hc);
2134 /* store in clients hashmap */ 2125 /* store in clients hashmap */
2135 GNUNET_CONTAINER_multihashmap_put( 2126 GNUNET_CONTAINER_multihashmap_put (c->apps, &hc, c,
2136 c->apps, 2127 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2137 &hc,
2138 c,
2139 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2140 /* store in global hashmap, for announcements */ 2128 /* store in global hashmap, for announcements */
2141 GNUNET_CONTAINER_multihashmap_put( 2129 GNUNET_CONTAINER_multihashmap_put (applications, &hc, c,
2142 applications, 2130 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2143 &hc,
2144 c,
2145 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2146 } 2131 }
2147 if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task) 2132 if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task)
2148 announce_applications_task = GNUNET_SCHEDULER_add_now ( 2133 announce_applications_task =
2149 &announce_applications, NULL); 2134 GNUNET_SCHEDULER_add_now (&announce_applications, NULL);
2150 2135
2151 } 2136 }
2152 if (ntypes > 0) 2137 if (ntypes > 0)
@@ -2154,24 +2139,19 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2154 uint16_t u16; 2139 uint16_t u16;
2155 GNUNET_HashCode hc; 2140 GNUNET_HashCode hc;
2156 2141
2157 t = (uint16_t *) &a[napps]; 2142 t = (uint16_t *) & a[napps];
2158 c->types = GNUNET_CONTAINER_multihashmap_create(ntypes); 2143 c->types = GNUNET_CONTAINER_multihashmap_create (ntypes);
2159 for (i =0; i < ntypes; i++) 2144 for (i = 0; i < ntypes; i++)
2160 { 2145 {
2161 u16 = ntohs(t[i]); 2146 u16 = ntohs (t[i]);
2162 GNUNET_CRYPTO_hash(&u16, sizeof(u16), &hc); 2147 GNUNET_CRYPTO_hash (&u16, sizeof (u16), &hc);
2148
2163 /* store in clients hashmap */ 2149 /* store in clients hashmap */
2164 GNUNET_CONTAINER_multihashmap_put( 2150 GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c,
2165 c->types, 2151 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2166 &hc,
2167 c,
2168 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2169 /* store in global hashmap */ 2152 /* store in global hashmap */
2170 GNUNET_CONTAINER_multihashmap_put( 2153 GNUNET_CONTAINER_multihashmap_put (types, &hc, c,
2171 types, 2154 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2172 &hc,
2173 c,
2174 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2175 } 2155 }
2176 } 2156 }
2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2383,9 +2363,7 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
2383 /* Start DHT search if needed */ 2363 /* Start DHT search if needed */
2384 if (MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget) 2364 if (MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget)
2385 { 2365 {
2386 peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, 2366 peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_TEST, &peer_msg->peer.hashPubKey, 4, /* replication level */
2387 GNUNET_BLOCK_TYPE_TEST,
2388 &peer_msg->peer.hashPubKey, 4, /* replication level */
2389 GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */ 2367 GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */
2390 0, /* mutator */ 2368 0, /* mutator */
2391 NULL, /* xquery */ 2369 NULL, /* xquery */
@@ -2517,26 +2495,27 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2517 type = ntohl (connect_msg->type); 2495 type = ntohl (connect_msg->type);
2518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", type); 2496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", type);
2519 GNUNET_CRYPTO_hash (&type, sizeof (GNUNET_MESH_ApplicationType), &hash); 2497 GNUNET_CRYPTO_hash (&type, sizeof (GNUNET_MESH_ApplicationType), &hash);
2520 if (GNUNET_CONTAINER_multihashmap_contains(applications, &hash) == GNUNET_YES) 2498 if (GNUNET_CONTAINER_multihashmap_contains (applications, &hash) ==
2499 GNUNET_YES)
2521 { 2500 {
2522 /* Yes! Fast forward, add ourselves to the tunnel and send the 2501 /* Yes! Fast forward, add ourselves to the tunnel and send the
2523 * good news to the client 2502 * good news to the client
2524 */ 2503 */
2525 struct GNUNET_MESH_PeerControl pc; 2504 struct GNUNET_MESH_PeerControl pc;
2526 2505
2527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: available locally\n"); 2506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: available locally\n");
2528 pc.peer = my_full_id; 2507 pc.peer = my_full_id;
2529 GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey, 2508 GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey,
2530 get_peer_info (&pc.peer), 2509 get_peer_info (&pc.peer),
2531 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2510 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2532 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 2511 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
2533 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); 2512 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
2534 pc.tunnel_id = htonl (t->local_tid); 2513 pc.tunnel_id = htonl (t->local_tid);
2535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n"); 2514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client\n");
2536 GNUNET_SERVER_notification_context_unicast (nc, /* context */ 2515 GNUNET_SERVER_notification_context_unicast (nc, /* context */
2537 client, /* dest */ 2516 client, /* dest */
2538 &pc.header, /* msg */ 2517 &pc.header, /* msg */
2539 GNUNET_NO); /* can drop? */ 2518 GNUNET_NO); /* can drop? */
2540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n"); 2519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Done\n");
2541 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2520 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2542 return; 2521 return;
@@ -2546,22 +2525,13 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2546 { 2525 {
2547 GNUNET_DHT_get_stop (c->dht_get_type); 2526 GNUNET_DHT_get_stop (c->dht_get_type);
2548 } 2527 }
2549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n",
2550 "MESH: looking in DHT for %s\n", 2529 GNUNET_h2s_full (&hash));
2551 GNUNET_h2s_full(&hash));
2552 c->dht_get_type = 2530 c->dht_get_type =
2553 GNUNET_DHT_get_start (dht_handle, 2531 GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL,
2554 GNUNET_TIME_UNIT_FOREVER_REL, 2532 GNUNET_BLOCK_TYPE_TEST, &hash, 10U,
2555 GNUNET_BLOCK_TYPE_TEST, 2533 GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, NULL, 0,
2556 &hash, 2534 &dht_get_type_handler, t);
2557 10U,
2558 GNUNET_DHT_RO_RECORD_ROUTE,
2559 NULL,
2560 0,
2561 NULL,
2562 0,
2563 &dht_get_type_handler,
2564 t);
2565 2535
2566 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2536 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2567 return; 2537 return;
@@ -2639,7 +2609,7 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
2639 /* Work around const limitation */ 2609 /* Work around const limitation */
2640 memcpy (&copy, data_msg, sizeof (struct GNUNET_MESH_Unicast)); 2610 memcpy (&copy, data_msg, sizeof (struct GNUNET_MESH_Unicast));
2641 copy.oid = my_full_id; 2611 copy.oid = my_full_id;
2642 copy.tid = htonl(t->id.tid); 2612 copy.tid = htonl (t->id.tid);
2643 handle_mesh_data_unicast (NULL, &my_full_id, &copy.header, NULL); 2613 handle_mesh_data_unicast (NULL, &my_full_id, &copy.header, NULL);
2644 return; 2614 return;
2645 } 2615 }
@@ -2858,7 +2828,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2858 { 2828 {
2859 for (c = clients; NULL != c; c = c->next) 2829 for (c = clients; NULL != c; c = c->next)
2860 if (NULL != c->dht_get_type) 2830 if (NULL != c->dht_get_type)
2861 GNUNET_DHT_get_stop(c->dht_get_type); 2831 GNUNET_DHT_get_stop (c->dht_get_type);
2862 GNUNET_DHT_disconnect (dht_handle); 2832 GNUNET_DHT_disconnect (dht_handle);
2863 dht_handle = NULL; 2833 dht_handle = NULL;
2864 } 2834 }