diff options
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 6ca5b3bec..9734fe4d9 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -82,11 +82,11 @@ mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
82 | 300) | 82 | 300) |
83 | #define APP_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ | 83 | #define APP_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ |
84 | GNUNET_TIME_UNIT_SECONDS,\ | 84 | GNUNET_TIME_UNIT_SECONDS,\ |
85 | 60) | 85 | 5) |
86 | 86 | ||
87 | #define ID_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ | 87 | #define ID_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ |
88 | GNUNET_TIME_UNIT_SECONDS,\ | 88 | GNUNET_TIME_UNIT_SECONDS,\ |
89 | 300) | 89 | 5) |
90 | 90 | ||
91 | 91 | ||
92 | 92 | ||
@@ -833,10 +833,12 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
833 | announce_applications_task = GNUNET_SCHEDULER_NO_TASK; | 833 | announce_applications_task = GNUNET_SCHEDULER_NO_TASK; |
834 | return; | 834 | return; |
835 | } | 835 | } |
836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for %u apps\n", | ||
837 | n_apps); | ||
836 | p = (unsigned int *) &buffer[8]; | 838 | p = (unsigned int *) &buffer[8]; |
837 | for (i = 0; i < n_apps; i++) | 839 | for (i = 0; i < n_apps; i++) |
838 | { | 840 | { |
839 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %d\n", | 841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Starting PUT for app %u\n", |
840 | applications[i]); | 842 | applications[i]); |
841 | *p = htonl (applications[i]); | 843 | *p = htonl (applications[i]); |
842 | GNUNET_CRYPTO_hash (buffer, 12, &hash); | 844 | GNUNET_CRYPTO_hash (buffer, 12, &hash); |
@@ -847,7 +849,7 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
847 | APP_ANNOUNCE_TIME), | 849 | APP_ANNOUNCE_TIME), |
848 | APP_ANNOUNCE_TIME, | 850 | APP_ANNOUNCE_TIME, |
849 | #if MESH_DEBUG | 851 | #if MESH_DEBUG |
850 | &mesh_debug, "MESH: DHT_put for apps completed\n"); | 852 | &mesh_debug, "DHT_put for apps completed\n"); |
851 | #else | 853 | #else |
852 | NULL, NULL); | 854 | NULL, NULL); |
853 | #endif | 855 | #endif |
@@ -2018,7 +2020,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
2018 | c = c->next; | 2020 | c = c->next; |
2019 | continue; | 2021 | continue; |
2020 | } | 2022 | } |
2021 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " matching client found, cleaning\n"); | 2023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n"); |
2022 | GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, c); | 2024 | GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, c); |
2023 | GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); | 2025 | GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); |
2024 | if (0 != c->app_counter) | 2026 | if (0 != c->app_counter) |
@@ -2072,8 +2074,10 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
2072 | { | 2074 | { |
2073 | struct GNUNET_MESH_ClientConnect *cc_msg; | 2075 | struct GNUNET_MESH_ClientConnect *cc_msg; |
2074 | struct MeshClient *c; | 2076 | struct MeshClient *c; |
2077 | GNUNET_MESH_ApplicationType *a; | ||
2075 | unsigned int size; | 2078 | unsigned int size; |
2076 | uint16_t types; | 2079 | uint16_t types; |
2080 | uint16_t *t; | ||
2077 | uint16_t apps; | 2081 | uint16_t apps; |
2078 | uint16_t i; | 2082 | uint16_t i; |
2079 | uint16_t j; | 2083 | uint16_t j; |
@@ -2096,45 +2100,52 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
2096 | /* Create new client structure */ | 2100 | /* Create new client structure */ |
2097 | c = GNUNET_malloc (sizeof (struct MeshClient)); | 2101 | c = GNUNET_malloc (sizeof (struct MeshClient)); |
2098 | c->handle = client; | 2102 | c->handle = client; |
2099 | if (types != 0) | 2103 | a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; |
2100 | { | 2104 | if (apps > 0) |
2101 | c->type_counter = types; | ||
2102 | c->types = GNUNET_malloc (types * sizeof (uint16_t)); | ||
2103 | memcpy (c->types, &message[1], types * sizeof (uint16_t)); | ||
2104 | } | ||
2105 | if (apps != 0) | ||
2106 | { | 2105 | { |
2107 | c->app_counter = apps; | 2106 | c->app_counter = apps; |
2108 | c->apps = GNUNET_malloc (apps * sizeof (GNUNET_MESH_ApplicationType)); | 2107 | c->apps = GNUNET_malloc (apps * sizeof(GNUNET_MESH_ApplicationType)); |
2109 | memcpy (c->apps, &message[1] + types * sizeof (uint16_t), | 2108 | for (i = 0; i < apps; i++) |
2110 | apps * sizeof (GNUNET_MESH_ApplicationType)); | ||
2111 | } | ||
2112 | for (i = 0; i < apps; i++) | ||
2113 | { | ||
2114 | known = GNUNET_NO; | ||
2115 | for (j = 0; i < n_apps; j++) | ||
2116 | { | 2109 | { |
2117 | if (c->apps[i] == applications[j]) | 2110 | c->apps[i] = ntohl(a[i]); |
2111 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: app %u\n", c->apps[i]); | ||
2112 | known = GNUNET_NO; | ||
2113 | for (j = 0; i < n_apps; j++) | ||
2118 | { | 2114 | { |
2119 | known = GNUNET_YES; | 2115 | if (c->apps[i] == applications[j]) |
2120 | applications_rc[j]++; | 2116 | { |
2121 | break; | 2117 | known = GNUNET_YES; |
2118 | applications_rc[j]++; | ||
2119 | break; | ||
2120 | } | ||
2122 | } | 2121 | } |
2123 | } | 2122 | if (!known) |
2124 | if (!known) | ||
2125 | { | ||
2126 | /* Register previously unknown application */ | ||
2127 | GNUNET_array_append (applications, n_apps, c->apps[i]); | ||
2128 | n_apps--; | ||
2129 | GNUNET_array_append (applications_rc, n_apps, 1); | ||
2130 | if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task) | ||
2131 | { | 2123 | { |
2132 | announce_applications_task = | 2124 | /* Register previously unknown application */ |
2133 | GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, | 2125 | GNUNET_array_append (applications, n_apps, c->apps[i]); |
2134 | &announce_applications, NULL); | 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 | } | 2135 | } |
2136 | } | 2136 | } |
2137 | } | 2137 | } |
2138 | if (types > 0) | ||
2139 | { | ||
2140 | t = (uint16_t *) &a[apps]; | ||
2141 | c->type_counter = types; | ||
2142 | c->types = GNUNET_malloc (types * sizeof (uint16_t)); | ||
2143 | for (i =0; i < types; i++) | ||
2144 | { | ||
2145 | c->types[i] = ntohs(t[i]); | ||
2146 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: type %hu\n", c->types[i]); | ||
2147 | } | ||
2148 | } | ||
2138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2139 | "MESH: client has %u+%u subscriptions\n", c->type_counter, | 2150 | "MESH: client has %u+%u subscriptions\n", c->type_counter, |
2140 | c->app_counter); | 2151 | c->app_counter); |
@@ -2439,6 +2450,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2439 | uint32_t *p; | 2450 | uint32_t *p; |
2440 | unsigned int i; | 2451 | unsigned int i; |
2441 | 2452 | ||
2453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: got connect by type request\n"); | ||
2442 | /* Sanity check for client registration */ | 2454 | /* Sanity check for client registration */ |
2443 | if (NULL == (c = retrieve_client (client))) | 2455 | if (NULL == (c = retrieve_client (client))) |
2444 | { | 2456 | { |
@@ -2449,7 +2461,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2449 | 2461 | ||
2450 | connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message; | 2462 | connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message; |
2451 | /* Sanity check for message size */ | 2463 | /* Sanity check for message size */ |
2452 | if (sizeof (struct GNUNET_MESH_PeerControl) != | 2464 | if (sizeof (struct GNUNET_MESH_ConnectPeerByType) != |
2453 | ntohs (connect_msg->header.size)) | 2465 | ntohs (connect_msg->header.size)) |
2454 | { | 2466 | { |
2455 | GNUNET_break (0); | 2467 | GNUNET_break (0); |
@@ -2477,6 +2489,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2477 | 2489 | ||
2478 | /* Do WE have the service? */ | 2490 | /* Do WE have the service? */ |
2479 | type = ntohl (connect_msg->type); | 2491 | type = ntohl (connect_msg->type); |
2492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: type requested: %u\n", type); | ||
2480 | for (i = 0; i < n_apps; i++) | 2493 | for (i = 0; i < n_apps; i++) |
2481 | { | 2494 | { |
2482 | if (applications[i] == type) | 2495 | if (applications[i] == type) |
@@ -2486,6 +2499,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2486 | */ | 2499 | */ |
2487 | struct GNUNET_MESH_PeerControl pc; | 2500 | struct GNUNET_MESH_PeerControl pc; |
2488 | 2501 | ||
2502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: available locally\n"); | ||
2489 | pc.peer = my_full_id; | 2503 | pc.peer = my_full_id; |
2490 | GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey, | 2504 | GNUNET_CONTAINER_multihashmap_put (t->peers, &pc.peer.hashPubKey, |
2491 | get_peer_info (&pc.peer), | 2505 | get_peer_info (&pc.peer), |
@@ -2493,7 +2507,13 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2493 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); | 2507 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); |
2494 | pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); | 2508 | pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); |
2495 | pc.tunnel_id = htonl (t->local_tid); | 2509 | pc.tunnel_id = htonl (t->local_tid); |
2496 | GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO); | 2510 | pc.peer = my_full_id; |
2511 | GNUNET_SERVER_notification_context_unicast (nc, /* context */ | ||
2512 | client, /* dest */ | ||
2513 | &pc.header, /* msg */ | ||
2514 | GNUNET_NO); /* can drop? */ | ||
2515 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2516 | return; | ||
2497 | } | 2517 | } |
2498 | } | 2518 | } |
2499 | /* Ok, lets find a peer offering the service */ | 2519 | /* Ok, lets find a peer offering the service */ |