aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-01-30 16:01:57 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-01-30 16:01:57 +0000
commitfab82ce632cff5d6db7006dedc8522214525080e (patch)
treebccf7fa3dd0193225e5a1b33383f56767569984f /src
parentfc7bafd3ef0dd1c89a17e758f2b451a053b8b51b (diff)
downloadgnunet-fab82ce632cff5d6db7006dedc8522214525080e.tar.gz
gnunet-fab82ce632cff5d6db7006dedc8522214525080e.zip
- unified notify callback for cached transport and core handles
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-service-testbed.h5
-rw-r--r--src/testbed/gnunet-service-testbed_hc.c67
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c8
3 files changed, 64 insertions, 16 deletions
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h
index b7924dc59..bd18d69c8 100644
--- a/src/testbed/gnunet-service-testbed.h
+++ b/src/testbed/gnunet-service-testbed.h
@@ -808,9 +808,12 @@ GST_cache_add_hello (const unsigned int peer_id,
808 * @param cls the closure passed to GST_cache_get_handle_transport() 808 * @param cls the closure passed to GST_cache_get_handle_transport()
809 * @param ch the handle to CORE. Can be NULL if it is not requested 809 * @param ch the handle to CORE. Can be NULL if it is not requested
810 * @param th the handle to TRANSPORT. Can be NULL if it is not requested 810 * @param th the handle to TRANSPORT. Can be NULL if it is not requested
811 * @param peer_id the identity of the peer. Will be NULL if ch is NULL. In other
812 * cases, its value being NULL means that CORE connection has failed.
811 */ 813 */
812typedef void (*GST_cache_callback) (void *cls, struct GNUNET_CORE_Handle *ch, 814typedef void (*GST_cache_callback) (void *cls, struct GNUNET_CORE_Handle *ch,
813 struct GNUNET_TRANSPORT_Handle *th); 815 struct GNUNET_TRANSPORT_Handle *th,
816 const struct GNUNET_PeerIdentity *peer_id);
814 817
815 818
816/** 819/**
diff --git a/src/testbed/gnunet-service-testbed_hc.c b/src/testbed/gnunet-service-testbed_hc.c
index 8bc95f78d..492c6b367 100644
--- a/src/testbed/gnunet-service-testbed_hc.c
+++ b/src/testbed/gnunet-service-testbed_hc.c
@@ -179,6 +179,13 @@ struct CacheEntry
179 struct GNUNET_TESTBED_Operation *core_op; 179 struct GNUNET_TESTBED_Operation *core_op;
180 180
181 /** 181 /**
182 * The peer identity of this peer. Will be set upon opening a connection to
183 * the peers CORE service. Will be NULL until then and after the CORE
184 * connection is closed
185 */
186 struct GNUNET_PeerIdentity *peer_identity;
187
188 /**
182 * The configuration of the peer. Should be not NULL as long as the core_handle 189 * The configuration of the peer. Should be not NULL as long as the core_handle
183 * or transport_handle are valid 190 * or transport_handle are valid
184 */ 191 */
@@ -334,6 +341,8 @@ cache_remove (struct CacheEntry *entry)
334 GNUNET_TESTBED_operation_done (entry->core_op); 341 GNUNET_TESTBED_operation_done (entry->core_op);
335 entry->core_op = NULL; 342 entry->core_op = NULL;
336 } 343 }
344 GNUNET_free_non_null (entry->peer_identity);
345 entry->peer_identity = NULL;
337 if (NULL != entry->cfg) 346 if (NULL != entry->cfg)
338 { 347 {
339 GNUNET_CONFIGURATION_destroy (entry->cfg); 348 GNUNET_CONFIGURATION_destroy (entry->cfg);
@@ -359,30 +368,54 @@ add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id)
359} 368}
360 369
361 370
371static struct GSTCacheGetHandle *
372search_suitable_gst (const struct CacheEntry *entry,
373 const struct GSTCacheGetHandle *head)
374{
375 const struct GSTCacheGetHandle *cgh;
376
377 for (cgh=head; NULL != cgh; cgh=cgh->next)
378 {
379 if (GNUNET_YES == cgh->notify_called)
380 return NULL;
381 switch (cgh->type)
382 {
383 case CGT_TRANSPORT_HANDLE:
384 if (NULL == entry->transport_handle_)
385 continue;
386 break;
387 case CGT_CORE_HANDLE:
388 if (NULL == entry->core_handle)
389 continue;
390 break;
391 }
392 break;
393 }
394 return (struct GSTCacheGetHandle *) cgh;
395}
396
397
362static void 398static void
363call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 399call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
364{ 400{
365 struct CacheEntry *entry = cls; 401 struct CacheEntry *entry = cls;
366 struct GSTCacheGetHandle *cgh; 402 struct GSTCacheGetHandle *cgh;
367 403 const struct GSTCacheGetHandle *cgh2;
404
368 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->notify_task); 405 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->notify_task);
369 entry->notify_task = GNUNET_SCHEDULER_NO_TASK; 406 entry->notify_task = GNUNET_SCHEDULER_NO_TASK;
370 cgh = entry->cgh_qhead; 407 cgh = search_suitable_gst (entry, entry->cgh_qhead);
371 GNUNET_assert (GNUNET_NO == cgh->notify_called); 408 GNUNET_assert (NULL != cgh);
409 cgh2 = NULL;
410 if (NULL != cgh->next)
411 cgh2 = search_suitable_gst (entry, cgh->next);
372 GNUNET_CONTAINER_DLL_remove (entry->cgh_qhead, entry->cgh_qtail, cgh); 412 GNUNET_CONTAINER_DLL_remove (entry->cgh_qhead, entry->cgh_qtail, cgh);
373 cgh->notify_called = GNUNET_YES; 413 cgh->notify_called = GNUNET_YES;
374 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);
375 if (GNUNET_NO == entry->cgh_qhead->notify_called) 415 if (NULL != cgh2)
376 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry); 416 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
377 switch (cgh->type) 417 cgh->cb (cgh->cb_cls, entry->core_handle,
378 { 418 entry->transport_handle_, entry->peer_identity);
379 case CGT_TRANSPORT_HANDLE:
380 cgh->cb (cgh->cb_cls, NULL, entry->transport_handle_);
381 break;
382 case CGT_CORE_HANDLE:
383 cgh->cb (cgh->cb_cls, entry->core_handle, NULL);
384 break;
385 }
386} 419}
387 420
388/** 421/**
@@ -498,6 +531,14 @@ core_peer_connect_cb (void *cls,
498{ 531{
499 struct CacheEntry *entry = cls; 532 struct CacheEntry *entry = cls;
500 533
534 if (NULL == peer)
535 {
536 GNUNET_break (0);
537 return;
538 }
539 GNUNET_assert (NULL == entry->peer_identity);
540 entry->peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
541 memcpy (entry->peer_identity, peer, sizeof (struct GNUNET_PeerIdentity));
501 if (0 == entry->demand) 542 if (0 == entry->demand)
502 return; 543 return;
503 if (GNUNET_NO == entry->cgh_qhead->notify_called) 544 if (GNUNET_NO == entry->cgh_qhead->notify_called)
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index 1148bb8ac..de6e53031 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -728,10 +728,12 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
728 * @param cls the closure passed to GST_cache_get_handle_transport() 728 * @param cls the closure passed to GST_cache_get_handle_transport()
729 * @param ch the handle to CORE. Can be NULL if it is not requested 729 * @param ch the handle to CORE. Can be NULL if it is not requested
730 * @param th the handle to TRANSPORT. Can be NULL if it is not requested 730 * @param th the handle to TRANSPORT. Can be NULL if it is not requested
731 * @param ignore_ peer identity which is ignored in this callback
731 */ 732 */
732static void 733static void
733p2_transport_connect_cache_callback (void *cls, struct GNUNET_CORE_Handle *ch, 734p2_transport_connect_cache_callback (void *cls, struct GNUNET_CORE_Handle *ch,
734 struct GNUNET_TRANSPORT_Handle *th) 735 struct GNUNET_TRANSPORT_Handle *th,
736 const struct GNUNET_PeerIdentity *ignore_)
735{ 737{
736 struct OverlayConnectContext *occ = cls; 738 struct OverlayConnectContext *occ = cls;
737 739
@@ -1461,10 +1463,12 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1461 * @param cls the closure passed to GST_cache_get_handle_transport() 1463 * @param cls the closure passed to GST_cache_get_handle_transport()
1462 * @param ch the handle to CORE. Can be NULL if it is not requested 1464 * @param ch the handle to CORE. Can be NULL if it is not requested
1463 * @param th the handle to TRANSPORT. Can be NULL if it is not requested 1465 * @param th the handle to TRANSPORT. Can be NULL if it is not requested
1466 * @param ignore_ peer identity which is ignored in this callback
1464 */ 1467 */
1465static void 1468static void
1466rocc_cache_get_handle_transport_cb (void *cls, struct GNUNET_CORE_Handle *ch, 1469rocc_cache_get_handle_transport_cb (void *cls, struct GNUNET_CORE_Handle *ch,
1467 struct GNUNET_TRANSPORT_Handle *th) 1470 struct GNUNET_TRANSPORT_Handle *th,
1471 const struct GNUNET_PeerIdentity *ignore_)
1468{ 1472{
1469 struct RemoteOverlayConnectCtx *rocc = cls; 1473 struct RemoteOverlayConnectCtx *rocc = cls;
1470 1474