diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-05 08:54:30 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-05 08:54:30 +0000 |
commit | f5c36840ecd770e195cc87a1bca8fa3e54c2dd40 (patch) | |
tree | 23cb2ab815349c2c598318bd7da1ac4b7673b372 /src/mesh | |
parent | 90983fb515cb6b21016f8b1814e216c4651db6bc (diff) | |
download | gnunet-f5c36840ecd770e195cc87a1bca8fa3e54c2dd40.tar.gz gnunet-f5c36840ecd770e195cc87a1bca8fa3e54c2dd40.zip |
Adapted path generation to new DHT_RECORD_ROUTE behavior
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 5347a1b98..645b5470a 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -139,6 +139,11 @@ struct MeshPeerInfo | |||
139 | struct GNUNET_DHT_GetHandle *dhtget; | 139 | struct GNUNET_DHT_GetHandle *dhtget; |
140 | 140 | ||
141 | /** | 141 | /** |
142 | * Task to reissue the DHT get request a path for this peer | ||
143 | */ | ||
144 | GNUNET_SCHEDULER_TaskIdentifier dhtget_task; | ||
145 | |||
146 | /** | ||
142 | * Handles to stop queued transmissions for this peer | 147 | * Handles to stop queued transmissions for this peer |
143 | */ | 148 | */ |
144 | struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; | 149 | struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; |
@@ -346,6 +351,11 @@ struct MeshClient | |||
346 | */ | 351 | */ |
347 | struct GNUNET_DHT_GetHandle *dht_get_type; | 352 | struct GNUNET_DHT_GetHandle *dht_get_type; |
348 | 353 | ||
354 | /** | ||
355 | * Task to reissue the DHT get request for a type | ||
356 | */ | ||
357 | GNUNET_SCHEDULER_TaskIdentifier dht_get_type_task; | ||
358 | |||
349 | #if MESH_DEBUG | 359 | #if MESH_DEBUG |
350 | /** | 360 | /** |
351 | * ID of the client, for debug messages | 361 | * ID of the client, for debug messages |
@@ -764,7 +774,7 @@ path_remove_from_peer (struct MeshPeerInfo *peer, | |||
764 | path_info->peer = peer_d; | 774 | path_info->peer = peer_d; |
765 | path_info->t = peer->tunnels[i]; | 775 | path_info->t = peer->tunnels[i]; |
766 | peer_d->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */ | 776 | peer_d->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */ |
767 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 777 | GNUNET_TIME_UNIT_SECONDS, /* timeout */ |
768 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 778 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
769 | &id.hashPubKey, /*key to search */ | 779 | &id.hashPubKey, /*key to search */ |
770 | 4, /* replication level */ | 780 | 4, /* replication level */ |
@@ -859,7 +869,9 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
859 | GNUNET_PEER_Id id; | 869 | GNUNET_PEER_Id id; |
860 | int i; | 870 | int i; |
861 | 871 | ||
862 | p = path_new (0); | 872 | p = path_new (1); |
873 | p->peers[0] = myid; | ||
874 | GNUNET_PEER_change_rc(myid, 1); | ||
863 | i = get_path_length; | 875 | i = get_path_length; |
864 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); | 876 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); |
865 | for (i--; i >= 0; i--) | 877 | for (i--; i >= 0; i--) |
@@ -872,10 +884,9 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
872 | } | 884 | } |
873 | else | 885 | else |
874 | { | 886 | { |
875 | p->peers = | ||
876 | GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * (p->length + 1)); | ||
877 | p->peers[p->length] = id; | ||
878 | p->length++; | 887 | p->length++; |
888 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
889 | p->peers[p->length] = id; | ||
879 | } | 890 | } |
880 | } | 891 | } |
881 | i = put_path_length; | 892 | i = put_path_length; |
@@ -883,6 +894,14 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
883 | for (i--; i >= 0; i--) | 894 | for (i--; i >= 0; i--) |
884 | { | 895 | { |
885 | id = GNUNET_PEER_intern (&put_path[i]); | 896 | id = GNUNET_PEER_intern (&put_path[i]); |
897 | if (id == myid) | ||
898 | { | ||
899 | /* PUT path went through us, so discard the path up until now and start | ||
900 | * from here to get a much shorter (and loop-free) path. | ||
901 | */ | ||
902 | path_destroy (p); | ||
903 | p = path_new (0); | ||
904 | } | ||
886 | if (p->length > 0 && id == p->peers[p->length - 1]) | 905 | if (p->length > 0 && id == p->peers[p->length - 1]) |
887 | { | 906 | { |
888 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); | 907 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); |
@@ -890,10 +909,9 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | |||
890 | } | 909 | } |
891 | else | 910 | else |
892 | { | 911 | { |
893 | p->peers = | ||
894 | GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * (p->length + 1)); | ||
895 | p->peers[p->length] = id; | ||
896 | p->length++; | 912 | p->length++; |
913 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
914 | p->peers[p->length] = id; | ||
897 | } | 915 | } |
898 | } | 916 | } |
899 | #if MESH_DEBUG | 917 | #if MESH_DEBUG |
@@ -2132,9 +2150,9 @@ static void | |||
2132 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | 2150 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, |
2133 | const GNUNET_HashCode * key, | 2151 | const GNUNET_HashCode * key, |
2134 | const struct GNUNET_PeerIdentity *get_path, | 2152 | const struct GNUNET_PeerIdentity *get_path, |
2135 | unsigned int get_path_length, | 2153 | unsigned int get_path_length, |
2136 | const struct GNUNET_PeerIdentity *put_path, | 2154 | const struct GNUNET_PeerIdentity *put_path, |
2137 | unsigned int put_path_length, | 2155 | unsigned int put_path_length, |
2138 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 2156 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) |
2139 | { | 2157 | { |
2140 | struct MeshPathInfo *path_info = cls; | 2158 | struct MeshPathInfo *path_info = cls; |
@@ -2155,7 +2173,7 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
2155 | // Find ourselves some alternate initial path to the destination: retry | 2173 | // Find ourselves some alternate initial path to the destination: retry |
2156 | GNUNET_DHT_get_stop (path_info->peer->dhtget); | 2174 | GNUNET_DHT_get_stop (path_info->peer->dhtget); |
2157 | path_info->peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ | 2175 | path_info->peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ |
2158 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 2176 | GNUNET_TIME_UNIT_SECONDS, /* timeout */ |
2159 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 2177 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
2160 | &pi.hashPubKey, /*key to search */ | 2178 | &pi.hashPubKey, /*key to search */ |
2161 | 4, /* replication level */ | 2179 | 4, /* replication level */ |
@@ -2246,7 +2264,7 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
2246 | return; | 2264 | return; |
2247 | } | 2265 | } |
2248 | GNUNET_assert (NULL != t->client); | 2266 | GNUNET_assert (NULL != t->client); |
2249 | GNUNET_DHT_get_stop (t->client->dht_get_type); | 2267 | GNUNET_DHT_get_stop (t->client->dht_get_type); /* FIXME move to task? */ |
2250 | t->client->dht_get_type = NULL; | 2268 | t->client->dht_get_type = NULL; |
2251 | peer_info = peer_info_get (pi); | 2269 | peer_info = peer_info_get (pi); |
2252 | GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, peer_info, | 2270 | GNUNET_CONTAINER_multihashmap_put (t->peers, &pi->hashPubKey, peer_info, |
@@ -2261,7 +2279,7 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
2261 | /* we don't have a route to the peer, let's try a direct lookup */ | 2279 | /* we don't have a route to the peer, let's try a direct lookup */ |
2262 | peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, | 2280 | peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, |
2263 | /* handle */ | 2281 | /* handle */ |
2264 | GNUNET_TIME_UNIT_FOREVER_REL, | 2282 | GNUNET_TIME_UNIT_SECONDS, |
2265 | /* timeout */ | 2283 | /* timeout */ |
2266 | GNUNET_BLOCK_TYPE_TEST, | 2284 | GNUNET_BLOCK_TYPE_TEST, |
2267 | /* block type */ | 2285 | /* block type */ |
@@ -2327,6 +2345,18 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
2327 | } | 2345 | } |
2328 | 2346 | ||
2329 | 2347 | ||
2348 | /** | ||
2349 | * Task run during shutdown. | ||
2350 | * | ||
2351 | * @param cls unused | ||
2352 | * @param tc unused | ||
2353 | */ | ||
2354 | static void | ||
2355 | dht_get_type_restart (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2356 | { | ||
2357 | |||
2358 | } | ||
2359 | |||
2330 | /******************************************************************************/ | 2360 | /******************************************************************************/ |
2331 | /********************* MESH LOCAL HANDLES **************************/ | 2361 | /********************* MESH LOCAL HANDLES **************************/ |
2332 | /******************************************************************************/ | 2362 | /******************************************************************************/ |
@@ -2381,7 +2411,10 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
2381 | if (NULL != c->types) | 2411 | if (NULL != c->types) |
2382 | GNUNET_CONTAINER_multihashmap_destroy (c->types); | 2412 | GNUNET_CONTAINER_multihashmap_destroy (c->types); |
2383 | if (NULL != c->dht_get_type) | 2413 | if (NULL != c->dht_get_type) |
2414 | { | ||
2415 | GNUNET_SCHEDULER_cancel (c->dht_get_type_task); | ||
2384 | GNUNET_DHT_get_stop (c->dht_get_type); | 2416 | GNUNET_DHT_get_stop (c->dht_get_type); |
2417 | } | ||
2385 | GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); | 2418 | GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); |
2386 | next = c->next; | 2419 | next = c->next; |
2387 | GNUNET_free (c); | 2420 | GNUNET_free (c); |
@@ -2704,7 +2737,7 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, | |||
2704 | path_info->peer = peer_info; | 2737 | path_info->peer = peer_info; |
2705 | path_info->t = t; | 2738 | path_info->t = t; |
2706 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */ | 2739 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */ |
2707 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 2740 | GNUNET_TIME_UNIT_SECONDS, /* timeout */ |
2708 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 2741 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
2709 | &peer_msg->peer.hashPubKey, /*key to search */ | 2742 | &peer_msg->peer.hashPubKey, /*key to search */ |
2710 | 4, /* replication level */ | 2743 | 4, /* replication level */ |
@@ -2892,6 +2925,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2892 | /* Ok, lets find a peer offering the service */ | 2925 | /* Ok, lets find a peer offering the service */ |
2893 | if (c->dht_get_type) | 2926 | if (c->dht_get_type) |
2894 | { | 2927 | { |
2928 | GNUNET_SCHEDULER_cancel (c->dht_get_type_task); | ||
2895 | GNUNET_DHT_get_stop (c->dht_get_type); | 2929 | GNUNET_DHT_get_stop (c->dht_get_type); |
2896 | } | 2930 | } |
2897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", | 2931 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n", |
@@ -2901,6 +2935,9 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, | |||
2901 | GNUNET_BLOCK_TYPE_TEST, &hash, 10U, | 2935 | GNUNET_BLOCK_TYPE_TEST, &hash, 10U, |
2902 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, | 2936 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, |
2903 | &dht_get_type_handler, t); | 2937 | &dht_get_type_handler, t); |
2938 | c->dht_get_type_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | ||
2939 | &dht_get_type_restart, | ||
2940 | NULL); | ||
2904 | 2941 | ||
2905 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2942 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2906 | return; | 2943 | return; |
@@ -3228,7 +3265,10 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3228 | { | 3265 | { |
3229 | for (c = clients; NULL != c; c = c->next) | 3266 | for (c = clients; NULL != c; c = c->next) |
3230 | if (NULL != c->dht_get_type) | 3267 | if (NULL != c->dht_get_type) |
3268 | { | ||
3269 | GNUNET_SCHEDULER_cancel(c->dht_get_type_task); | ||
3231 | GNUNET_DHT_get_stop (c->dht_get_type); | 3270 | GNUNET_DHT_get_stop (c->dht_get_type); |
3271 | } | ||
3232 | GNUNET_DHT_disconnect (dht_handle); | 3272 | GNUNET_DHT_disconnect (dht_handle); |
3233 | dht_handle = NULL; | 3273 | dht_handle = NULL; |
3234 | } | 3274 | } |