diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-29 15:10:19 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-29 15:10:19 +0000 |
commit | f7ce09a10eeed86d2ca47524b3e9e993b2bc548e (patch) | |
tree | c35ecbdc3fe18363ef6883989852336a427f8137 /src | |
parent | 5750bc7ad4ae2b31041d44b1b5211f62462e66ec (diff) | |
download | gnunet-f7ce09a10eeed86d2ca47524b3e9e993b2bc548e.tar.gz gnunet-f7ce09a10eeed86d2ca47524b3e9e993b2bc548e.zip |
caching transport handles
Diffstat (limited to 'src')
-rw-r--r-- | src/testbed/gnunet-service-testbed_hc.c | 41 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_oc.c | 141 |
2 files changed, 100 insertions, 82 deletions
diff --git a/src/testbed/gnunet-service-testbed_hc.c b/src/testbed/gnunet-service-testbed_hc.c index fdbff1192..6bc34ad0d 100644 --- a/src/testbed/gnunet-service-testbed_hc.c +++ b/src/testbed/gnunet-service-testbed_hc.c | |||
@@ -121,6 +121,11 @@ struct CacheEntry | |||
121 | * Number of operations this cache entry is being used | 121 | * Number of operations this cache entry is being used |
122 | */ | 122 | */ |
123 | unsigned int demand; | 123 | unsigned int demand; |
124 | |||
125 | /** | ||
126 | * The id of the peer this entry corresponds to | ||
127 | */ | ||
128 | unsigned int peer_id; | ||
124 | }; | 129 | }; |
125 | 130 | ||
126 | /** | 131 | /** |
@@ -184,13 +189,11 @@ cache_lookup_handles (const struct GNUNET_HashCode *pid, | |||
184 | { | 189 | { |
185 | struct CacheEntry *entry; | 190 | struct CacheEntry *entry; |
186 | 191 | ||
187 | GNUNET_assert ((NULL != th)); | 192 | GNUNET_assert (NULL != th); |
188 | entry = cache_lookup (pid); | 193 | entry = cache_lookup (pid); |
189 | if (NULL == entry) | 194 | if (NULL == entry) |
190 | return NULL; | 195 | return NULL; |
191 | if (0 == entry->demand) | 196 | if (NULL != entry->transport_handle) |
192 | GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); | ||
193 | if ((NULL != th) && (NULL != entry->transport_handle)) | ||
194 | *th = entry->transport_handle; | 197 | *th = entry->transport_handle; |
195 | return entry; | 198 | return entry; |
196 | } | 199 | } |
@@ -202,25 +205,30 @@ cache_remove (struct CacheEntry *entry) | |||
202 | /* We keep the entry in the hash table so that the HELLO can still be found | 205 | /* We keep the entry in the hash table so that the HELLO can still be found |
203 | in cache; we will however disconnect the core and transport handles */ | 206 | in cache; we will however disconnect the core and transport handles */ |
204 | GNUNET_assert (0 == entry->demand); | 207 | GNUNET_assert (0 == entry->demand); |
205 | GNUNET_assert (NULL != entry->cfg); | 208 | if ((NULL != entry->next) || (NULL != entry->prev)) |
206 | GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); | 209 | GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); |
210 | LOG_DEBUG ("Cleaning up handles from an entry in cache\n"); | ||
207 | if (NULL != entry->transport_handle) | 211 | if (NULL != entry->transport_handle) |
208 | { | 212 | { |
209 | GNUNET_assert (NULL != entry->transport_op); | 213 | GNUNET_assert (NULL != entry->transport_op); |
210 | GNUNET_TESTBED_operation_done (entry->transport_op); | 214 | GNUNET_TESTBED_operation_done (entry->transport_op); |
211 | entry->transport_op = NULL; | 215 | entry->transport_op = NULL; |
212 | } | 216 | } |
213 | GNUNET_CONFIGURATION_destroy (entry->cfg); | 217 | if (NULL != entry->cfg) |
214 | entry->cfg = NULL; | 218 | { |
219 | GNUNET_CONFIGURATION_destroy (entry->cfg); | ||
220 | entry->cfg = NULL; | ||
221 | } | ||
215 | } | 222 | } |
216 | 223 | ||
217 | 224 | ||
218 | static struct CacheEntry * | 225 | static struct CacheEntry * |
219 | add_entry (const struct GNUNET_HashCode *key) | 226 | add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id) |
220 | { | 227 | { |
221 | struct CacheEntry *entry; | 228 | struct CacheEntry *entry; |
222 | 229 | ||
223 | entry = GNUNET_malloc (sizeof (struct CacheEntry)); | 230 | entry = GNUNET_malloc (sizeof (struct CacheEntry)); |
231 | entry->peer_id = peer_id; | ||
224 | memcpy (&entry->key, key, sizeof (struct GNUNET_HashCode)); | 232 | memcpy (&entry->key, key, sizeof (struct GNUNET_HashCode)); |
225 | GNUNET_assert (GNUNET_OK == | 233 | GNUNET_assert (GNUNET_OK == |
226 | GNUNET_CONTAINER_multihashmap_put (cache, &entry->key, | 234 | GNUNET_CONTAINER_multihashmap_put (cache, &entry->key, |
@@ -261,7 +269,7 @@ opstart_get_handle_transport (void *cls) | |||
261 | struct CacheEntry *entry = cls; | 269 | struct CacheEntry *entry = cls; |
262 | 270 | ||
263 | GNUNET_assert (NULL != entry); | 271 | GNUNET_assert (NULL != entry); |
264 | LOG_DEBUG ("Opening a transport connection\n"); | 272 | LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id); |
265 | entry->transport_handle = GNUNET_TRANSPORT_connect (entry->cfg, | 273 | entry->transport_handle = GNUNET_TRANSPORT_connect (entry->cfg, |
266 | NULL, NULL, | 274 | NULL, NULL, |
267 | NULL, | 275 | NULL, |
@@ -315,9 +323,11 @@ cache_get_handle (unsigned int peer_id, | |||
315 | { | 323 | { |
316 | GNUNET_assert (NULL != entry); | 324 | GNUNET_assert (NULL != entry); |
317 | LOG_DEBUG ("Found existing transport handle in cache\n"); | 325 | LOG_DEBUG ("Found existing transport handle in cache\n"); |
326 | if (0 == entry->demand) | ||
327 | GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); | ||
318 | } | 328 | } |
319 | if (NULL == entry) | 329 | if (NULL == entry) |
320 | entry = add_entry (&key); | 330 | entry = add_entry (&key, peer_id); |
321 | if (NULL == entry->cfg) | 331 | if (NULL == entry->cfg) |
322 | entry->cfg = GNUNET_CONFIGURATION_dup (cfg); | 332 | entry->cfg = GNUNET_CONFIGURATION_dup (cfg); |
323 | entry->demand++; | 333 | entry->demand++; |
@@ -333,7 +343,6 @@ cache_get_handle (unsigned int peer_id, | |||
333 | { | 343 | { |
334 | case CGT_TRANSPORT_HANDLE: | 344 | case CGT_TRANSPORT_HANDLE: |
335 | GNUNET_assert (NULL == entry->transport_op); | 345 | GNUNET_assert (NULL == entry->transport_op); |
336 | LOG_DEBUG ("Creating an operation for opening transport handle"); | ||
337 | entry->transport_op = GNUNET_TESTBED_operation_create_ (entry, &opstart_get_handle_transport, | 346 | entry->transport_op = GNUNET_TESTBED_operation_create_ (entry, &opstart_get_handle_transport, |
338 | &oprelease_get_handle_transport); | 347 | &oprelease_get_handle_transport); |
339 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, | 348 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, |
@@ -366,6 +375,8 @@ cache_clear_iterator (void *cls, | |||
366 | GNUNET_break (0 == entry->demand); | 375 | GNUNET_break (0 == entry->demand); |
367 | LOG_DEBUG ("Clearing entry %u of %u\n", ++ncleared, cache_size); | 376 | LOG_DEBUG ("Clearing entry %u of %u\n", ++ncleared, cache_size); |
368 | GNUNET_CONTAINER_multihashmap_remove (cache, key, value); | 377 | GNUNET_CONTAINER_multihashmap_remove (cache, key, value); |
378 | if (0 == entry->demand) | ||
379 | cache_remove (entry); | ||
369 | GNUNET_free_non_null (entry->hello); | 380 | GNUNET_free_non_null (entry->hello); |
370 | GNUNET_break (NULL == entry->transport_handle); | 381 | GNUNET_break (NULL == entry->transport_handle); |
371 | GNUNET_break (NULL == entry->cfg); | 382 | GNUNET_break (NULL == entry->cfg); |
@@ -413,6 +424,7 @@ void | |||
413 | GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh) | 424 | GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh) |
414 | { | 425 | { |
415 | GNUNET_assert (NULL != cgh->entry); | 426 | GNUNET_assert (NULL != cgh->entry); |
427 | GNUNET_assert (0 < cgh->entry->demand); | ||
416 | cgh->entry->demand--; | 428 | cgh->entry->demand--; |
417 | if (GNUNET_NO == cgh->entry->cghq_head->notify_called) | 429 | if (GNUNET_NO == cgh->entry->cghq_head->notify_called) |
418 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cgh->entry->notify_task); | 430 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cgh->entry->notify_task); |
@@ -486,7 +498,8 @@ GST_cache_lookup_hello (const unsigned int peer_id) | |||
486 | entry = cache_lookup (&key); | 498 | entry = cache_lookup (&key); |
487 | if (NULL == entry) | 499 | if (NULL == entry) |
488 | return NULL; | 500 | return NULL; |
489 | LOG_DEBUG ("HELLO found for peer %u\n", peer_id); | 501 | if (NULL != entry->hello) |
502 | LOG_DEBUG ("HELLO found for peer %u\n", peer_id); | ||
490 | return entry->hello; | 503 | return entry->hello; |
491 | } | 504 | } |
492 | 505 | ||
@@ -508,7 +521,7 @@ GST_cache_add_hello (const unsigned int peer_id, | |||
508 | GNUNET_CRYPTO_hash (&peer_id, sizeof (peer_id), &key); | 521 | GNUNET_CRYPTO_hash (&peer_id, sizeof (peer_id), &key); |
509 | entry = GNUNET_CONTAINER_multihashmap_get (cache, &key); | 522 | entry = GNUNET_CONTAINER_multihashmap_get (cache, &key); |
510 | if (NULL == entry) | 523 | if (NULL == entry) |
511 | entry = add_entry (&key); | 524 | entry = add_entry (&key, peer_id); |
512 | GNUNET_free_non_null (entry->hello); | 525 | GNUNET_free_non_null (entry->hello); |
513 | entry->hello = GNUNET_copy_message (hello); | 526 | entry->hello = GNUNET_copy_message (hello); |
514 | } | 527 | } |
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c index c437f8225..75c7f4975 100644 --- a/src/testbed/gnunet-service-testbed_oc.c +++ b/src/testbed/gnunet-service-testbed_oc.c | |||
@@ -41,7 +41,12 @@ struct TryConnectContext | |||
41 | /** | 41 | /** |
42 | * The transport handle | 42 | * The transport handle |
43 | */ | 43 | */ |
44 | struct GNUNET_TRANSPORT_Handle *th; | 44 | struct GNUNET_TRANSPORT_Handle *th_; |
45 | |||
46 | /** | ||
47 | * The GetCacheHandle for the p1th transport handle | ||
48 | */ | ||
49 | struct GSTCacheGetHandle *cgh_th; | ||
45 | 50 | ||
46 | /** | 51 | /** |
47 | * the try connect handle | 52 | * the try connect handle |
@@ -97,6 +102,11 @@ struct OverlayConnectContext | |||
97 | struct GNUNET_TRANSPORT_Handle *p1th; | 102 | struct GNUNET_TRANSPORT_Handle *p1th; |
98 | 103 | ||
99 | /** | 104 | /** |
105 | * The GetCacheHandle for the p1th transport handle | ||
106 | */ | ||
107 | struct GSTGetCacheHandle *gch_p1th; | ||
108 | |||
109 | /** | ||
100 | * Core handles of the first peer; used to notify when second peer connects to it | 110 | * Core handles of the first peer; used to notify when second peer connects to it |
101 | */ | 111 | */ |
102 | struct GNUNET_CORE_Handle *ch; | 112 | struct GNUNET_CORE_Handle *ch; |
@@ -219,11 +229,6 @@ struct RemoteOverlayConnectCtx | |||
219 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; | 229 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; |
220 | 230 | ||
221 | /** | 231 | /** |
222 | * The local operation we create for this overlay connection | ||
223 | */ | ||
224 | struct GNUNET_TESTBED_Operation *lop; | ||
225 | |||
226 | /** | ||
227 | * The transport try connect context | 232 | * The transport try connect context |
228 | */ | 233 | */ |
229 | struct TryConnectContext tcc; | 234 | struct TryConnectContext tcc; |
@@ -415,9 +420,9 @@ cleanup_occ (struct OverlayConnectContext *occ) | |||
415 | GNUNET_TRANSPORT_disconnect (occ->p1th); | 420 | GNUNET_TRANSPORT_disconnect (occ->p1th); |
416 | occ->peer->reference_cnt--; | 421 | occ->peer->reference_cnt--; |
417 | } | 422 | } |
418 | if (NULL != occ->tcc.th) | 423 | if (NULL != occ->tcc.cgh_th) |
419 | { | 424 | { |
420 | GNUNET_TRANSPORT_disconnect (occ->tcc.th); | 425 | GST_cache_get_handle_done (occ->tcc.cgh_th); |
421 | GST_peer_list[occ->other_peer_id]->reference_cnt--; | 426 | GST_peer_list[occ->other_peer_id]->reference_cnt--; |
422 | } | 427 | } |
423 | if ((GNUNET_YES == occ->peer->destroy_flag) && | 428 | if ((GNUNET_YES == occ->peer->destroy_flag) && |
@@ -590,11 +595,12 @@ try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
590 | return; | 595 | return; |
591 | GNUNET_assert (NULL == tcc->tch); | 596 | GNUNET_assert (NULL == tcc->tch); |
592 | GNUNET_assert (NULL != tcc->pid); | 597 | GNUNET_assert (NULL != tcc->pid); |
593 | GNUNET_assert (NULL != tcc->th); | 598 | GNUNET_assert (NULL != tcc->th_); |
599 | GNUNET_assert (NULL != tcc->cgh_th); | ||
594 | LOG_DEBUG ("0x%llx: Trail %u to connect to peer %s\n", tcc->op_id, | 600 | LOG_DEBUG ("0x%llx: Trail %u to connect to peer %s\n", tcc->op_id, |
595 | tcc->retries, GNUNET_i2s (tcc->pid)); | 601 | tcc->retries, GNUNET_i2s (tcc->pid)); |
596 | tcc->tch = | 602 | tcc->tch = |
597 | GNUNET_TRANSPORT_try_connect (tcc->th, tcc->pid, &try_connect_cb, tcc); | 603 | GNUNET_TRANSPORT_try_connect (tcc->th_, tcc->pid, &try_connect_cb, tcc); |
598 | } | 604 | } |
599 | 605 | ||
600 | 606 | ||
@@ -690,7 +696,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
690 | LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n", occ->op_id, | 696 | LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n", occ->op_id, |
691 | GNUNET_i2s (&occ->peer_identity), other_peer_str); | 697 | GNUNET_i2s (&occ->peer_identity), other_peer_str); |
692 | occ->ohh = | 698 | occ->ohh = |
693 | GNUNET_TRANSPORT_offer_hello (occ->tcc.th, occ->hello, | 699 | GNUNET_TRANSPORT_offer_hello (occ->tcc.th_, occ->hello, |
694 | occ_hello_sent_cb, occ); | 700 | occ_hello_sent_cb, occ); |
695 | if (NULL == occ->ohh) | 701 | if (NULL == occ->ohh) |
696 | { | 702 | { |
@@ -709,6 +715,35 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
709 | 715 | ||
710 | 716 | ||
711 | /** | 717 | /** |
718 | * Callback from cache with needed handles set | ||
719 | * | ||
720 | * @param cls the closure passed to GST_cache_get_handle_transport() | ||
721 | * @param ch the handle to CORE. Can be NULL if it is not requested | ||
722 | * @param th the handle to TRANSPORT. Can be NULL if it is not requested | ||
723 | */ | ||
724 | static void | ||
725 | p2_transport_connect_cache_callback (void *cls, struct GNUNET_CORE_Handle *ch, | ||
726 | struct GNUNET_TRANSPORT_Handle *th) | ||
727 | { | ||
728 | struct OverlayConnectContext *occ = cls; | ||
729 | |||
730 | if (NULL == th) | ||
731 | { | ||
732 | GNUNET_asprintf (&occ->emsg, "0x%llx: Cannot connect to TRANSPORT of %s", | ||
733 | occ->op_id, GNUNET_i2s (&occ->other_peer_identity)); | ||
734 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | ||
735 | occ->timeout_task = | ||
736 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | ||
737 | return; | ||
738 | } | ||
739 | occ->tcc.th_ = th; | ||
740 | GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s", | ||
741 | occ->op_id, GNUNET_i2s (&occ->other_peer_identity)); | ||
742 | occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); | ||
743 | } | ||
744 | |||
745 | |||
746 | /** | ||
712 | * Connects to the transport of the other peer if it is a local peer and | 747 | * Connects to the transport of the other peer if it is a local peer and |
713 | * schedules the send hello task | 748 | * schedules the send hello task |
714 | * | 749 | * |
@@ -724,19 +759,13 @@ p2_transport_connect (struct OverlayConnectContext *occ) | |||
724 | if (NULL == occ->peer2_controller) | 759 | if (NULL == occ->peer2_controller) |
725 | { | 760 | { |
726 | GST_peer_list[occ->other_peer_id]->reference_cnt++; | 761 | GST_peer_list[occ->other_peer_id]->reference_cnt++; |
727 | occ->tcc.th = | 762 | occ->tcc.cgh_th = |
728 | GNUNET_TRANSPORT_connect (GST_peer_list[occ->other_peer_id]-> | 763 | GST_cache_get_handle_transport (occ->other_peer_id, |
729 | details.local.cfg, &occ->other_peer_identity, | 764 | GST_peer_list[occ->other_peer_id]-> |
730 | NULL, NULL, NULL, NULL); | 765 | details.local.cfg, |
731 | if (NULL == occ->tcc.th) | 766 | &p2_transport_connect_cache_callback, |
732 | { | 767 | occ); |
733 | GNUNET_asprintf (&occ->emsg, "0x%llx: Cannot connect to TRANSPORT of %s", | 768 | return; |
734 | occ->op_id, GNUNET_i2s (&occ->other_peer_identity)); | ||
735 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | ||
736 | occ->timeout_task = | ||
737 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | ||
738 | return; | ||
739 | } | ||
740 | } | 769 | } |
741 | GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s", | 770 | GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s", |
742 | occ->op_id, GNUNET_i2s (&occ->other_peer_identity)); | 771 | occ->op_id, GNUNET_i2s (&occ->other_peer_identity)); |
@@ -1282,11 +1311,6 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
1282 | static void | 1311 | static void |
1283 | cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) | 1312 | cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) |
1284 | { | 1313 | { |
1285 | if (NULL != rocc->lop) | ||
1286 | { | ||
1287 | GNUNET_TESTBED_operation_release_ (rocc->lop); | ||
1288 | return; | ||
1289 | } | ||
1290 | LOG_DEBUG ("0x%llx: Cleaning up rocc\n", rocc->op_id); | 1314 | LOG_DEBUG ("0x%llx: Cleaning up rocc\n", rocc->op_id); |
1291 | if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id) | 1315 | if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id) |
1292 | GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id); | 1316 | GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id); |
@@ -1298,7 +1322,8 @@ cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) | |||
1298 | GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch); | 1322 | GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch); |
1299 | if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task) | 1323 | if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task) |
1300 | GNUNET_SCHEDULER_cancel (rocc->tcc.task); | 1324 | GNUNET_SCHEDULER_cancel (rocc->tcc.task); |
1301 | GNUNET_TRANSPORT_disconnect (rocc->tcc.th); | 1325 | //GNUNET_TRANSPORT_disconnect (rocc->tcc.th_); |
1326 | GST_cache_get_handle_done (rocc->tcc.cgh_th); | ||
1302 | rocc->peer->reference_cnt--; | 1327 | rocc->peer->reference_cnt--; |
1303 | if ((GNUNET_YES == rocc->peer->destroy_flag) && | 1328 | if ((GNUNET_YES == rocc->peer->destroy_flag) && |
1304 | (0 == rocc->peer->reference_cnt)) | 1329 | (0 == rocc->peer->reference_cnt)) |
@@ -1410,7 +1435,7 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1410 | LOG_DEBUG ("0x%llx: Offering HELLO of peer %4s to local peer with id: %u\n", | 1435 | LOG_DEBUG ("0x%llx: Offering HELLO of peer %4s to local peer with id: %u\n", |
1411 | rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id); | 1436 | rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id); |
1412 | rocc->ohh = | 1437 | rocc->ohh = |
1413 | GNUNET_TRANSPORT_offer_hello (rocc->tcc.th, rocc->hello, | 1438 | GNUNET_TRANSPORT_offer_hello (rocc->tcc.th_, rocc->hello, |
1414 | rocc_hello_sent_cb, rocc); | 1439 | rocc_hello_sent_cb, rocc); |
1415 | if (NULL == rocc->ohh) | 1440 | if (NULL == rocc->ohh) |
1416 | rocc->attempt_connect_task_id = | 1441 | rocc->attempt_connect_task_id = |
@@ -1424,52 +1449,32 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1424 | 1449 | ||
1425 | 1450 | ||
1426 | /** | 1451 | /** |
1427 | * Callback which will be called when remote overlay connect operation is | 1452 | * Callback from cache with needed handles set |
1428 | * started | ||
1429 | * | 1453 | * |
1430 | * @param cls the remote overlay connect context | 1454 | * @param cls the closure passed to GST_cache_get_handle_transport() |
1455 | * @param ch the handle to CORE. Can be NULL if it is not requested | ||
1456 | * @param th the handle to TRANSPORT. Can be NULL if it is not requested | ||
1431 | */ | 1457 | */ |
1432 | static void | 1458 | static void |
1433 | opstart_remote_overlay_connect (void *cls) | 1459 | rocc_cache_get_handle_transport_cb (void *cls, struct GNUNET_CORE_Handle *ch, |
1460 | struct GNUNET_TRANSPORT_Handle *th) | ||
1434 | { | 1461 | { |
1435 | struct RemoteOverlayConnectCtx *rocc = cls; | 1462 | struct RemoteOverlayConnectCtx *rocc = cls; |
1436 | 1463 | ||
1437 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->timeout_rocc_task_id); | 1464 | if (NULL == th) |
1438 | rocc->tcc.op_id = rocc->op_id; | ||
1439 | rocc->tcc.th = | ||
1440 | GNUNET_TRANSPORT_connect (rocc->peer->details.local.cfg, NULL, rocc, NULL, | ||
1441 | &transport_connect_notify, NULL); | ||
1442 | if (NULL == rocc->tcc.th) | ||
1443 | { | 1465 | { |
1444 | rocc->timeout_rocc_task_id = | 1466 | rocc->timeout_rocc_task_id = |
1445 | GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc); | 1467 | GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc); |
1446 | return; | 1468 | return; |
1447 | } | 1469 | } |
1470 | rocc->tcc.th_ = th; | ||
1448 | rocc->tcc.pid = &rocc->a_id; | 1471 | rocc->tcc.pid = &rocc->a_id; |
1449 | rocc->attempt_connect_task_id = | 1472 | rocc->attempt_connect_task_id = |
1450 | GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc); | 1473 | GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc); |
1451 | rocc->timeout_rocc_task_id = | ||
1452 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc); | ||
1453 | } | 1474 | } |
1454 | 1475 | ||
1455 | 1476 | ||
1456 | /** | 1477 | /** |
1457 | * Callback which will be called when remote overlay connect operation is | ||
1458 | * released | ||
1459 | * | ||
1460 | * @param cls the remote overlay connect context | ||
1461 | */ | ||
1462 | static void | ||
1463 | oprelease_remote_overlay_connect (void *cls) | ||
1464 | { | ||
1465 | struct RemoteOverlayConnectCtx *rocc = cls; | ||
1466 | |||
1467 | GNUNET_assert (NULL != rocc->lop); | ||
1468 | rocc->lop = NULL; | ||
1469 | cleanup_rocc (rocc); | ||
1470 | } | ||
1471 | |||
1472 | /** | ||
1473 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages | 1478 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages |
1474 | * | 1479 | * |
1475 | * @param cls NULL | 1480 | * @param cls NULL |
@@ -1541,12 +1546,12 @@ GST_handle_remote_overlay_connect (void *cls, | |||
1541 | rocc->peer->reference_cnt++; | 1546 | rocc->peer->reference_cnt++; |
1542 | rocc->hello = GNUNET_malloc (hsize); | 1547 | rocc->hello = GNUNET_malloc (hsize); |
1543 | memcpy (rocc->hello, msg->hello, hsize); | 1548 | memcpy (rocc->hello, msg->hello, hsize); |
1544 | rocc->lop = | 1549 | rocc->tcc.cgh_th = GST_cache_get_handle_transport (peer_id, |
1545 | GNUNET_TESTBED_operation_create_ (rocc, &opstart_remote_overlay_connect, | 1550 | rocc->peer->details.local.cfg, |
1546 | &oprelease_remote_overlay_connect); | 1551 | &rocc_cache_get_handle_transport_cb, |
1547 | /* This operation needs only 1 connection to transport */ | 1552 | rocc); |
1548 | GNUNET_TESTBED_operation_queue_insert2_ (GST_opq_openfds, rocc->lop, 1); | 1553 | rocc->timeout_rocc_task_id = |
1549 | GNUNET_TESTBED_operation_begin_wait_ (rocc->lop); | 1554 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc); |
1550 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1555 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1551 | } | 1556 | } |
1552 | 1557 | ||