diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-01-21 19:50:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-01-21 19:50:32 +0000 |
commit | 98554bb388165bd6ad3cb3220dc2b2f1aede61b3 (patch) | |
tree | 5c86585ab1ed5cae399baa5e3a696a2ec0c68ab2 /src | |
parent | a72baac5158e9ad5b69c7e9af1144604e92689cc (diff) | |
download | gnunet-98554bb388165bd6ad3cb3220dc2b2f1aede61b3.tar.gz gnunet-98554bb388165bd6ad3cb3220dc2b2f1aede61b3.zip |
implementing get_hello_cancel
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/transport_api.c | 131 |
1 files changed, 51 insertions, 80 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 998aded45..8c55c8c84 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -775,56 +775,6 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle, | |||
775 | 775 | ||
776 | 776 | ||
777 | /** | 777 | /** |
778 | * A "get_hello" request has timed out. Signal the client | ||
779 | * and clean up. | ||
780 | */ | ||
781 | #if 0 | ||
782 | static void | ||
783 | hello_wait_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
784 | { | ||
785 | struct HelloWaitList *hwl = cls; | ||
786 | struct HelloWaitList *pos; | ||
787 | struct HelloWaitList *prev; | ||
788 | |||
789 | hwl->task = GNUNET_SCHEDULER_NO_TASK; | ||
790 | if (GNUNET_TIME_absolute_get_remaining (hwl->timeout).value > 0) | ||
791 | { | ||
792 | #if DEBUG_TRANSPORT | ||
793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
794 | _ | ||
795 | ("First attempt to obtain `%s' from transport service failed, will try again for %llums.\n"), | ||
796 | "HELLO", | ||
797 | GNUNET_TIME_absolute_get_remaining (hwl->timeout).value); | ||
798 | #endif | ||
799 | hwl->task = GNUNET_SCHEDULER_add_delayed (hwl->handle->sched, | ||
800 | GNUNET_TIME_absolute_get_remaining | ||
801 | (hwl->timeout), | ||
802 | &hello_wait_timeout, hwl); | ||
803 | return; | ||
804 | } | ||
805 | /* signal timeout */ | ||
806 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
807 | _("Timeout trying to obtain `%s' from transport service.\n"), | ||
808 | "HELLO"); | ||
809 | prev = NULL; | ||
810 | pos = hwl->handle->hwl_head; | ||
811 | while (pos != hwl) | ||
812 | { | ||
813 | GNUNET_assert (pos != NULL); | ||
814 | prev = pos; | ||
815 | pos = pos->next; | ||
816 | } | ||
817 | if (prev == NULL) | ||
818 | hwl->handle->hwl_head = hwl->next; | ||
819 | else | ||
820 | prev->next = hwl->next; | ||
821 | if (hwl->rec != NULL) | ||
822 | hwl->rec (hwl->rec_cls, NULL); | ||
823 | GNUNET_free (hwl); | ||
824 | } | ||
825 | #endif | ||
826 | |||
827 | /** | ||
828 | * Obtain the HELLO message for this peer. | 778 | * Obtain the HELLO message for this peer. |
829 | * | 779 | * |
830 | * @param handle connection to transport service | 780 | * @param handle connection to transport service |
@@ -840,34 +790,54 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, | |||
840 | GNUNET_TRANSPORT_HelloUpdateCallback rec, | 790 | GNUNET_TRANSPORT_HelloUpdateCallback rec, |
841 | void *rec_cls) | 791 | void *rec_cls) |
842 | { | 792 | { |
843 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; | ||
844 | struct GNUNET_PeerIdentity me; | ||
845 | struct HelloWaitList *hwl; | 793 | struct HelloWaitList *hwl; |
846 | 794 | ||
795 | hwl = GNUNET_malloc (sizeof (struct HelloWaitList)); | ||
796 | hwl->next = handle->hwl_head; | ||
797 | handle->hwl_head = hwl; | ||
798 | hwl->handle = handle; | ||
799 | hwl->rec = rec; | ||
800 | hwl->rec_cls = rec_cls; | ||
847 | if (handle->my_hello == NULL) | 801 | if (handle->my_hello == NULL) |
802 | return; | ||
803 | rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello); | ||
804 | } | ||
805 | |||
806 | |||
807 | |||
808 | /** | ||
809 | * Stop receiving updates about changes to our HELLO message. | ||
810 | * | ||
811 | * @param handle connection to transport service | ||
812 | * @param rec function previously registered to be called with the HELLOs | ||
813 | * @param rec_cls closure for rec | ||
814 | */ | ||
815 | void | ||
816 | GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle, | ||
817 | GNUNET_TRANSPORT_HelloUpdateCallback rec, | ||
818 | void *rec_cls) | ||
819 | { | ||
820 | struct HelloWaitList *pos; | ||
821 | struct HelloWaitList *prev; | ||
822 | |||
823 | prev = NULL; | ||
824 | pos = handle->hwl_head; | ||
825 | while (pos != NULL) | ||
848 | { | 826 | { |
849 | hwl = GNUNET_malloc (sizeof (struct HelloWaitList)); | 827 | if ( (pos->rec == rec) && |
850 | hwl->next = handle->hwl_head; | 828 | (pos->rec_cls == rec_cls) ) |
851 | handle->hwl_head = hwl; | 829 | break; |
852 | hwl->handle = handle; | 830 | prev = pos; |
853 | hwl->rec = rec; | 831 | pos = pos->next; |
854 | hwl->rec_cls = rec_cls; | ||
855 | /* hwl->timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
856 | * Timeout not needed, because we should notify on change. | ||
857 | * FIXME: set up scheduler to notify on modification? | ||
858 | |||
859 | hwl->task = GNUNET_SCHEDULER_add_delayed (handle->sched, | ||
860 | timeout, | ||
861 | &hello_wait_timeout, hwl); | ||
862 | */ | ||
863 | return; | ||
864 | } | 832 | } |
865 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_key (handle->my_hello, &pk)); | 833 | GNUNET_break (pos != NULL); |
866 | GNUNET_CRYPTO_hash (&pk, | 834 | if (pos == NULL) |
867 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 835 | return; |
868 | &me.hashPubKey); | 836 | if (prev == NULL) |
869 | 837 | handle->hwl_head = pos->next; | |
870 | rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello); | 838 | else |
839 | prev->next = pos->next; | ||
840 | GNUNET_free (pos); | ||
871 | } | 841 | } |
872 | 842 | ||
873 | 843 | ||
@@ -1512,7 +1482,7 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) | |||
1512 | GNUNET_SCHEDULER_cancel (handle->sched, hwl->task); | 1482 | GNUNET_SCHEDULER_cancel (handle->sched, hwl->task); |
1513 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1483 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1514 | _ | 1484 | _ |
1515 | ("Disconnect while trying to obtain `%s' from transport service.\n"), | 1485 | ("Disconnect while notification for `%s' still registered.\n"), |
1516 | "HELLO"); | 1486 | "HELLO"); |
1517 | if (hwl->rec != NULL) | 1487 | if (hwl->rec != NULL) |
1518 | hwl->rec (hwl->rec_cls, NULL); | 1488 | hwl->rec (hwl->rec_cls, NULL); |
@@ -1562,6 +1532,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1562 | const struct GNUNET_MessageHeader *imm; | 1532 | const struct GNUNET_MessageHeader *imm; |
1563 | const struct SendOkMessage *okm; | 1533 | const struct SendOkMessage *okm; |
1564 | struct HelloWaitList *hwl; | 1534 | struct HelloWaitList *hwl; |
1535 | struct HelloWaitList *next_hwl; | ||
1565 | struct NeighbourList *n; | 1536 | struct NeighbourList *n; |
1566 | struct GNUNET_PeerIdentity me; | 1537 | struct GNUNET_PeerIdentity me; |
1567 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 1538 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
@@ -1629,13 +1600,13 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1629 | } | 1600 | } |
1630 | h->my_hello = GNUNET_malloc (size); | 1601 | h->my_hello = GNUNET_malloc (size); |
1631 | memcpy (h->my_hello, msg, size); | 1602 | memcpy (h->my_hello, msg, size); |
1632 | while (NULL != (hwl = h->hwl_head)) | 1603 | hwl = h->hwl_head; |
1604 | while (NULL != hwl) | ||
1633 | { | 1605 | { |
1634 | h->hwl_head = hwl->next; | 1606 | next_hwl = hwl->next; |
1635 | GNUNET_SCHEDULER_cancel (h->sched, hwl->task); | 1607 | hwl->rec (hwl->rec_cls, |
1636 | GNUNET_TRANSPORT_get_hello (h, | 1608 | (const struct GNUNET_MessageHeader *) h->my_hello); |
1637 | hwl->rec, hwl->rec_cls); | 1609 | hwl = next_hwl; |
1638 | GNUNET_free (hwl); | ||
1639 | } | 1610 | } |
1640 | break; | 1611 | break; |
1641 | case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT: | 1612 | case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT: |