diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-31 11:26:51 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-31 11:26:51 +0000 |
commit | 28067448d3952faa16107f209e670c3a75d980d6 (patch) | |
tree | f2dd730474c9b1fcbe080130a99f210f3d868168 /src | |
parent | c3e341dbcf55f02e0b246ddc47c1e692cb9fe78f (diff) | |
download | gnunet-28067448d3952faa16107f209e670c3a75d980d6.tar.gz gnunet-28067448d3952faa16107f209e670c3a75d980d6.zip |
- get core handle in core startup callback
Diffstat (limited to 'src')
-rw-r--r-- | src/testbed/gnunet-service-testbed.h | 31 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_hc.c | 44 |
2 files changed, 54 insertions, 21 deletions
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h index bd18d69c8..d4adf2526 100644 --- a/src/testbed/gnunet-service-testbed.h +++ b/src/testbed/gnunet-service-testbed.h | |||
@@ -863,6 +863,37 @@ GST_cache_get_handle_transport (unsigned int peer_id, | |||
863 | 863 | ||
864 | 864 | ||
865 | /** | 865 | /** |
866 | * Get a CORE handle with the given configuration. If the handle is already | ||
867 | * cached before, it will be retured in the given callback; the peer_id is used | ||
868 | * to lookup in the cache. If the handle is not cached before, a new operation | ||
869 | * is started to open the CORE handle and will be given in the callback when it | ||
870 | * is available along with the peer identity | ||
871 | * | ||
872 | * @param peer_id the index of the peer | ||
873 | * @param cfg the configuration with which the transport handle has to be | ||
874 | * created if it was not present in the cache | ||
875 | * @param cb the callback to notify when the transport handle is available | ||
876 | * @param cb_cls the closure for the above callback | ||
877 | * @param target the peer identify of the peer whose connection to our CORE | ||
878 | * subsystem will be notified through the connect_notify_cb. Can be NULL | ||
879 | * @param connect_notify_cb the callback to call when the given target peer is | ||
880 | * connected. This callback will only be called once or never again (in | ||
881 | * case the target peer cannot be connected). Can be NULL | ||
882 | * @param connect_notify_cb_cls the closure for the above callback | ||
883 | * @return the handle which can be used cancel or mark that the handle is no | ||
884 | * longer being used | ||
885 | */ | ||
886 | struct GSTCacheGetHandle * | ||
887 | GST_cache_get_handle_core (unsigned int peer_id, | ||
888 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
889 | GST_cache_callback cb, | ||
890 | void *cb_cls, | ||
891 | const struct GNUNET_PeerIdentity *target, | ||
892 | GST_cache_peer_connect_notify connect_notify_cb, | ||
893 | void *connect_notify_cb_cls); | ||
894 | |||
895 | |||
896 | /** | ||
866 | * Mark the GetCacheHandle as being done if a handle has been provided already | 897 | * Mark the GetCacheHandle as being done if a handle has been provided already |
867 | * or as being cancelled if the callback for the handle hasn't been called. | 898 | * or as being cancelled if the callback for the handle hasn't been called. |
868 | * | 899 | * |
diff --git a/src/testbed/gnunet-service-testbed_hc.c b/src/testbed/gnunet-service-testbed_hc.c index 7516b9928..ea3cbad37 100644 --- a/src/testbed/gnunet-service-testbed_hc.c +++ b/src/testbed/gnunet-service-testbed_hc.c | |||
@@ -343,8 +343,6 @@ cache_remove (struct CacheEntry *entry) | |||
343 | GNUNET_TESTBED_operation_done (entry->core_op); | 343 | GNUNET_TESTBED_operation_done (entry->core_op); |
344 | entry->core_op = NULL; | 344 | entry->core_op = NULL; |
345 | } | 345 | } |
346 | GNUNET_free_non_null (entry->peer_identity); | ||
347 | entry->peer_identity = NULL; | ||
348 | if (NULL != entry->cfg) | 346 | if (NULL != entry->cfg) |
349 | { | 347 | { |
350 | GNUNET_CONFIGURATION_destroy (entry->cfg); | 348 | GNUNET_CONFIGURATION_destroy (entry->cfg); |
@@ -371,7 +369,7 @@ add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id) | |||
371 | 369 | ||
372 | 370 | ||
373 | static struct GSTCacheGetHandle * | 371 | static struct GSTCacheGetHandle * |
374 | search_suitable_gst (const struct CacheEntry *entry, | 372 | search_suitable_cgh (const struct CacheEntry *entry, |
375 | const struct GSTCacheGetHandle *head) | 373 | const struct GSTCacheGetHandle *head) |
376 | { | 374 | { |
377 | const struct GSTCacheGetHandle *cgh; | 375 | const struct GSTCacheGetHandle *cgh; |
@@ -406,11 +404,11 @@ call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
406 | 404 | ||
407 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->notify_task); | 405 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->notify_task); |
408 | entry->notify_task = GNUNET_SCHEDULER_NO_TASK; | 406 | entry->notify_task = GNUNET_SCHEDULER_NO_TASK; |
409 | cgh = search_suitable_gst (entry, entry->cgh_qhead); | 407 | cgh = search_suitable_cgh (entry, entry->cgh_qhead); |
410 | GNUNET_assert (NULL != cgh); | 408 | GNUNET_assert (NULL != cgh); |
411 | cgh2 = NULL; | 409 | cgh2 = NULL; |
412 | if (NULL != cgh->next) | 410 | if (NULL != cgh->next) |
413 | cgh2 = search_suitable_gst (entry, cgh->next); | 411 | cgh2 = search_suitable_cgh (entry, cgh->next); |
414 | GNUNET_CONTAINER_DLL_remove (entry->cgh_qhead, entry->cgh_qtail, cgh); | 412 | GNUNET_CONTAINER_DLL_remove (entry->cgh_qhead, entry->cgh_qtail, cgh); |
415 | cgh->notify_called = GNUNET_YES; | 413 | cgh->notify_called = GNUNET_YES; |
416 | GNUNET_CONTAINER_DLL_insert_tail (entry->cgh_qhead, entry->cgh_qtail, cgh); | 414 | GNUNET_CONTAINER_DLL_insert_tail (entry->cgh_qhead, entry->cgh_qtail, cgh); |
@@ -565,7 +563,7 @@ core_peer_connect_cb (void *cls, | |||
565 | const struct GNUNET_ATS_Information * atsi, | 563 | const struct GNUNET_ATS_Information * atsi, |
566 | unsigned int atsi_count) | 564 | unsigned int atsi_count) |
567 | { | 565 | { |
568 | peer_connect_notify_cb (cls, peer, CGT_TRANSPORT_HANDLE); | 566 | peer_connect_notify_cb (cls, peer, CGT_CORE_HANDLE); |
569 | } | 567 | } |
570 | 568 | ||
571 | 569 | ||
@@ -579,16 +577,17 @@ opstart_get_handle_core (void *cls) | |||
579 | 577 | ||
580 | GNUNET_assert (NULL != entry); | 578 | GNUNET_assert (NULL != entry); |
581 | LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->peer_id); | 579 | LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->peer_id); |
582 | entry->core_handle = GNUNET_CORE_connect (entry->cfg, | 580 | /* void?: We also get the handle when the connection to CORE is successful */ |
583 | entry, | 581 | (void) GNUNET_CORE_connect (entry->cfg, |
584 | &core_startup_cb, | 582 | entry, |
585 | &core_peer_connect_cb, | 583 | &core_startup_cb, |
586 | NULL, /* disconnect cb */ | 584 | &core_peer_connect_cb, |
587 | NULL, /* inbound notify */ | 585 | NULL, /* disconnect cb */ |
588 | GNUNET_NO, | 586 | NULL, /* inbound notify */ |
589 | NULL, /* outbound notify */ | 587 | GNUNET_NO, |
590 | GNUNET_NO, | 588 | NULL, /* outbound notify */ |
591 | no_handlers); | 589 | GNUNET_NO, |
590 | no_handlers); | ||
592 | if (NULL == entry->core_handle) | 591 | if (NULL == entry->core_handle) |
593 | { | 592 | { |
594 | GNUNET_break (0); | 593 | GNUNET_break (0); |
@@ -607,6 +606,8 @@ oprelease_get_handle_core (void *cls) | |||
607 | return; | 606 | return; |
608 | GNUNET_CORE_disconnect (entry->core_handle); | 607 | GNUNET_CORE_disconnect (entry->core_handle); |
609 | entry->core_handle = NULL; | 608 | entry->core_handle = NULL; |
609 | GNUNET_free_non_null (entry->peer_identity); | ||
610 | entry->peer_identity = NULL; | ||
610 | } | 611 | } |
611 | 612 | ||
612 | 613 | ||
@@ -847,17 +848,18 @@ GST_cache_get_handle_transport (unsigned int peer_id, | |||
847 | 848 | ||
848 | 849 | ||
849 | /** | 850 | /** |
850 | * Get a transport handle with the given configuration. If the handle is already | 851 | * Get a CORE handle with the given configuration. If the handle is already |
851 | * cached before, it will be retured in the given callback; the peer_id is used to lookup in the | 852 | * cached before, it will be retured in the given callback; the peer_id is used |
852 | * cache. If not a new operation is started to open the transport handle and | 853 | * to lookup in the cache. If the handle is not cached before, a new operation |
853 | * will be given in the callback when it is available. | 854 | * is started to open the CORE handle and will be given in the callback when it |
855 | * is available along with the peer identity | ||
854 | * | 856 | * |
855 | * @param peer_id the index of the peer | 857 | * @param peer_id the index of the peer |
856 | * @param cfg the configuration with which the transport handle has to be | 858 | * @param cfg the configuration with which the transport handle has to be |
857 | * created if it was not present in the cache | 859 | * created if it was not present in the cache |
858 | * @param cb the callback to notify when the transport handle is available | 860 | * @param cb the callback to notify when the transport handle is available |
859 | * @param cb_cls the closure for the above callback | 861 | * @param cb_cls the closure for the above callback |
860 | * @param target the peer identify of the peer whose connection to our TRANSPORT | 862 | * @param target the peer identify of the peer whose connection to our CORE |
861 | * subsystem will be notified through the connect_notify_cb. Can be NULL | 863 | * subsystem will be notified through the connect_notify_cb. Can be NULL |
862 | * @param connect_notify_cb the callback to call when the given target peer is | 864 | * @param connect_notify_cb the callback to call when the given target peer is |
863 | * connected. This callback will only be called once or never again (in | 865 | * connected. This callback will only be called once or never again (in |