diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-31 10:11:48 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-31 10:11:48 +0000 |
commit | 19b889a241c7bebbaefefd6744a4f8029004a219 (patch) | |
tree | 471406c65a73a0950f674be2d0a1c57f95c11cb2 /src | |
parent | c4ad2cacffc201384df035846b3b093f17cb7bd0 (diff) | |
download | gnunet-19b889a241c7bebbaefefd6744a4f8029004a219.tar.gz gnunet-19b889a241c7bebbaefefd6744a4f8029004a219.zip |
- deduplicate
Diffstat (limited to 'src')
-rw-r--r-- | src/testbed/gnunet-service-testbed_hc.c | 88 |
1 files changed, 57 insertions, 31 deletions
diff --git a/src/testbed/gnunet-service-testbed_hc.c b/src/testbed/gnunet-service-testbed_hc.c index 492c6b367..7516b9928 100644 --- a/src/testbed/gnunet-service-testbed_hc.c +++ b/src/testbed/gnunet-service-testbed_hc.c | |||
@@ -94,6 +94,7 @@ struct ConnectNotifyContext | |||
94 | * The GSTCacheGetHandle reposible for creating this context | 94 | * The GSTCacheGetHandle reposible for creating this context |
95 | */ | 95 | */ |
96 | struct GSTCacheGetHandle *cgh; | 96 | struct GSTCacheGetHandle *cgh; |
97 | |||
97 | }; | 98 | }; |
98 | 99 | ||
99 | 100 | ||
@@ -239,6 +240,7 @@ struct CacheEntry | |||
239 | unsigned int peer_id; | 240 | unsigned int peer_id; |
240 | }; | 241 | }; |
241 | 242 | ||
243 | |||
242 | /** | 244 | /** |
243 | * Hashmap to maintain cache | 245 | * Hashmap to maintain cache |
244 | */ | 246 | */ |
@@ -424,14 +426,12 @@ call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
424 | * | 426 | * |
425 | * @param cls closure | 427 | * @param cls closure |
426 | * @param peer the peer that connected | 428 | * @param peer the peer that connected |
427 | * @param ats performance data | 429 | * @param type the type of the handle this notification is for |
428 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
429 | */ | 430 | */ |
430 | static void | 431 | static void |
431 | peer_connect_notify_cb (void *cls, | 432 | peer_connect_notify_cb (void *cls, |
432 | const struct GNUNET_PeerIdentity *peer, | 433 | const struct GNUNET_PeerIdentity *peer, |
433 | const struct GNUNET_ATS_Information *ats, | 434 | const enum CacheGetType type) |
434 | uint32_t ats_count) | ||
435 | { | 435 | { |
436 | struct CacheEntry *entry = cls; | 436 | struct CacheEntry *entry = cls; |
437 | struct ConnectNotifyContext *ctxt; | 437 | struct ConnectNotifyContext *ctxt; |
@@ -441,6 +441,9 @@ peer_connect_notify_cb (void *cls, | |||
441 | 441 | ||
442 | for (ctxt=entry->nctxt_qhead; NULL != ctxt; ctxt=ctxt->next) | 442 | for (ctxt=entry->nctxt_qhead; NULL != ctxt; ctxt=ctxt->next) |
443 | { | 443 | { |
444 | GNUNET_assert (NULL != ctxt->cgh); | ||
445 | if (type != ctxt->cgh->type) | ||
446 | continue; | ||
444 | if (0 == memcmp (ctxt->target, peer, sizeof (struct GNUNET_PeerIdentity))) | 447 | if (0 == memcmp (ctxt->target, peer, sizeof (struct GNUNET_PeerIdentity))) |
445 | break; | 448 | break; |
446 | } | 449 | } |
@@ -448,7 +451,6 @@ peer_connect_notify_cb (void *cls, | |||
448 | return; | 451 | return; |
449 | cb = ctxt->cb; | 452 | cb = ctxt->cb; |
450 | cb_cls = ctxt->cb_cls; | 453 | cb_cls = ctxt->cb_cls; |
451 | GNUNET_assert (NULL != ctxt->cgh); | ||
452 | ctxt->cgh->nctxt = NULL; | 454 | ctxt->cgh->nctxt = NULL; |
453 | GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt); | 455 | GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt); |
454 | GNUNET_free (ctxt); | 456 | GNUNET_free (ctxt); |
@@ -456,6 +458,25 @@ peer_connect_notify_cb (void *cls, | |||
456 | } | 458 | } |
457 | 459 | ||
458 | 460 | ||
461 | /** | ||
462 | * Function called to notify transport users that another | ||
463 | * peer connected to us. | ||
464 | * | ||
465 | * @param cls closure | ||
466 | * @param peer the peer that connected | ||
467 | * @param ats performance data | ||
468 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
469 | */ | ||
470 | static void | ||
471 | transport_peer_connect_notify_cb (void *cls, | ||
472 | const struct GNUNET_PeerIdentity *peer, | ||
473 | const struct GNUNET_ATS_Information *ats, | ||
474 | uint32_t ats_count) | ||
475 | { | ||
476 | peer_connect_notify_cb (cls, peer, CGT_TRANSPORT_HANDLE); | ||
477 | } | ||
478 | |||
479 | |||
459 | static void | 480 | static void |
460 | opstart_get_handle_transport (void *cls) | 481 | opstart_get_handle_transport (void *cls) |
461 | { | 482 | { |
@@ -463,11 +484,11 @@ opstart_get_handle_transport (void *cls) | |||
463 | 484 | ||
464 | GNUNET_assert (NULL != entry); | 485 | GNUNET_assert (NULL != entry); |
465 | LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id); | 486 | LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id); |
466 | entry->transport_handle_ = GNUNET_TRANSPORT_connect (entry->cfg, | 487 | entry->transport_handle_ = |
467 | NULL, entry, | 488 | GNUNET_TRANSPORT_connect (entry->cfg, |
468 | NULL, | 489 | NULL, entry, |
469 | &peer_connect_notify_cb, | 490 | NULL, |
470 | NULL); | 491 | &transport_peer_connect_notify_cb, NULL); |
471 | if (NULL == entry->transport_handle_) | 492 | if (NULL == entry->transport_handle_) |
472 | { | 493 | { |
473 | GNUNET_break (0); | 494 | GNUNET_break (0); |
@@ -506,12 +527,27 @@ oprelease_get_handle_transport (void *cls) | |||
506 | * @param server handle to the server, NULL if we failed | 527 | * @param server handle to the server, NULL if we failed |
507 | * @param my_identity ID of this peer, NULL if we failed | 528 | * @param my_identity ID of this peer, NULL if we failed |
508 | */ | 529 | */ |
509 | static void core_startup_cb (void *cls, | 530 | static void |
510 | struct GNUNET_CORE_Handle * server, | 531 | core_startup_cb (void *cls, |
511 | const struct GNUNET_PeerIdentity * | 532 | struct GNUNET_CORE_Handle * server, |
512 | my_identity) | 533 | const struct GNUNET_PeerIdentity *my_identity) |
513 | { | 534 | { |
514 | GNUNET_break (0); | 535 | struct CacheEntry *entry = cls; |
536 | |||
537 | if (NULL == my_identity) | ||
538 | { | ||
539 | GNUNET_break (0); | ||
540 | return; | ||
541 | } | ||
542 | GNUNET_assert (NULL == entry->peer_identity); | ||
543 | entry->core_handle = server; | ||
544 | entry->peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
545 | memcpy (entry->peer_identity, my_identity, | ||
546 | sizeof (struct GNUNET_PeerIdentity)); | ||
547 | if (0 == entry->demand) | ||
548 | return; | ||
549 | if (GNUNET_NO == entry->cgh_qhead->notify_called) | ||
550 | entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry); | ||
515 | } | 551 | } |
516 | 552 | ||
517 | 553 | ||
@@ -528,21 +564,8 @@ core_peer_connect_cb (void *cls, | |||
528 | const struct GNUNET_PeerIdentity * peer, | 564 | const struct GNUNET_PeerIdentity * peer, |
529 | const struct GNUNET_ATS_Information * atsi, | 565 | const struct GNUNET_ATS_Information * atsi, |
530 | unsigned int atsi_count) | 566 | unsigned int atsi_count) |
531 | { | 567 | { |
532 | struct CacheEntry *entry = cls; | 568 | peer_connect_notify_cb (cls, peer, CGT_TRANSPORT_HANDLE); |
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)); | ||
542 | if (0 == entry->demand) | ||
543 | return; | ||
544 | if (GNUNET_NO == entry->cgh_qhead->notify_called) | ||
545 | entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry); | ||
546 | } | 569 | } |
547 | 570 | ||
548 | 571 | ||
@@ -610,16 +633,19 @@ cache_get_handle (unsigned int peer_id, | |||
610 | case CGT_TRANSPORT_HANDLE: | 633 | case CGT_TRANSPORT_HANDLE: |
611 | entry = cache_lookup_handles (&key, (struct GNUNET_TRANSPORT_Handle **) | 634 | entry = cache_lookup_handles (&key, (struct GNUNET_TRANSPORT_Handle **) |
612 | &handle, NULL); | 635 | &handle, NULL); |
636 | if (NULL != handle) | ||
637 | LOG_DEBUG ("Found TRANSPORT handle in cache for peer %u\n", entry->peer_id); | ||
613 | break; | 638 | break; |
614 | case CGT_CORE_HANDLE: | 639 | case CGT_CORE_HANDLE: |
615 | entry = cache_lookup_handles (&key, NULL, | 640 | entry = cache_lookup_handles (&key, NULL, |
616 | (struct GNUNET_CORE_Handle **) &handle); | 641 | (struct GNUNET_CORE_Handle **) &handle); |
642 | if (NULL != handle) | ||
643 | LOG_DEBUG ("Found CORE handle in cache for peer %u\n", entry->peer_id); | ||
617 | break; | 644 | break; |
618 | } | 645 | } |
619 | if (NULL != handle) | 646 | if (NULL != handle) |
620 | { | 647 | { |
621 | GNUNET_assert (NULL != entry); | 648 | GNUNET_assert (NULL != entry); |
622 | LOG_DEBUG ("Found existing transport handle in cache\n"); | ||
623 | if (0 == entry->demand) | 649 | if (0 == entry->demand) |
624 | GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); | 650 | GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry); |
625 | } | 651 | } |