diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-04-21 20:19:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-04-21 20:19:43 +0000 |
commit | 84e15afe4933ee2ca62e3e111ca261c3a986c157 (patch) | |
tree | 8a9cd9a06b723b940f6d11b0272f5eb395db39c4 /src/peerinfo/peerinfo_api.c | |
parent | a06d7742d5a48229767c152f9466432d17e162de (diff) | |
download | gnunet-84e15afe4933ee2ca62e3e111ca261c3a986c157.tar.gz gnunet-84e15afe4933ee2ca62e3e111ca261c3a986c157.zip |
activating new peerinfo API
Diffstat (limited to 'src/peerinfo/peerinfo_api.c')
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 344 |
1 files changed, 22 insertions, 322 deletions
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index 5392d1696..44af04c92 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -127,14 +127,14 @@ struct GNUNET_PEERINFO_Handle | |||
127 | /** | 127 | /** |
128 | * Connect to the peerinfo service. | 128 | * Connect to the peerinfo service. |
129 | * | 129 | * |
130 | * @param cfg configuration to use | ||
131 | * @param sched scheduler to use | 130 | * @param sched scheduler to use |
131 | * @param cfg configuration to use | ||
132 | * @return NULL on error (configuration related, actual connection | 132 | * @return NULL on error (configuration related, actual connection |
133 | * etablishment may happen asynchronously). | 133 | * etablishment may happen asynchronously). |
134 | */ | 134 | */ |
135 | struct GNUNET_PEERINFO_Handle * | 135 | struct GNUNET_PEERINFO_Handle * |
136 | GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 136 | GNUNET_PEERINFO_connect (struct GNUNET_SCHEDULER_Handle *sched, |
137 | struct GNUNET_SCHEDULER_Handle *sched) | 137 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
138 | { | 138 | { |
139 | struct GNUNET_CLIENT_Connection *client; | 139 | struct GNUNET_CLIENT_Connection *client; |
140 | struct GNUNET_PEERINFO_Handle *ret; | 140 | struct GNUNET_PEERINFO_Handle *ret; |
@@ -197,7 +197,7 @@ static void | |||
197 | reconnect (struct GNUNET_PEERINFO_Handle *h) | 197 | reconnect (struct GNUNET_PEERINFO_Handle *h) |
198 | { | 198 | { |
199 | GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR); | 199 | GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR); |
200 | h->client = GNUNET_CLIENT_connect (h->sched, "client", h->cfg); | 200 | h->client = GNUNET_CLIENT_connect (h->sched, "peerinfo", h->cfg); |
201 | GNUNET_assert (h->client != NULL); | 201 | GNUNET_assert (h->client != NULL); |
202 | } | 202 | } |
203 | 203 | ||
@@ -291,8 +291,8 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h) | |||
291 | * @param hello the verified (!) HELLO message | 291 | * @param hello the verified (!) HELLO message |
292 | */ | 292 | */ |
293 | void | 293 | void |
294 | GNUNET_PEERINFO_add_peer_new (struct GNUNET_PEERINFO_Handle *h, | 294 | GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, |
295 | const struct GNUNET_HELLO_Message *hello) | 295 | const struct GNUNET_HELLO_Message *hello) |
296 | { | 296 | { |
297 | uint16_t hs = GNUNET_HELLO_size (hello); | 297 | uint16_t hs = GNUNET_HELLO_size (hello); |
298 | struct TransmissionQueueEntry *tqe; | 298 | struct TransmissionQueueEntry *tqe; |
@@ -321,7 +321,7 @@ GNUNET_PEERINFO_add_peer_new (struct GNUNET_PEERINFO_Handle *h, | |||
321 | /** | 321 | /** |
322 | * Context for an iteration request. | 322 | * Context for an iteration request. |
323 | */ | 323 | */ |
324 | struct GNUNET_PEERINFO_NewIteratorContext | 324 | struct GNUNET_PEERINFO_IteratorContext |
325 | { | 325 | { |
326 | /** | 326 | /** |
327 | * Handle to the PEERINFO service. | 327 | * Handle to the PEERINFO service. |
@@ -370,7 +370,7 @@ struct GNUNET_PEERINFO_NewIteratorContext | |||
370 | static void | 370 | static void |
371 | peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | 371 | peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
372 | { | 372 | { |
373 | struct GNUNET_PEERINFO_NewIteratorContext *ic = cls; | 373 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; |
374 | const struct InfoMessage *im; | 374 | const struct InfoMessage *im; |
375 | const struct GNUNET_HELLO_Message *hello; | 375 | const struct GNUNET_HELLO_Message *hello; |
376 | uint16_t ms; | 376 | uint16_t ms; |
@@ -461,14 +461,14 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
461 | * We've transmitted the iteration request. Now get ready to process | 461 | * We've transmitted the iteration request. Now get ready to process |
462 | * the results (or handle transmission error). | 462 | * the results (or handle transmission error). |
463 | * | 463 | * |
464 | * @param cls the 'struct GNUNET_PEERINFO_NewIteratorContext' | 464 | * @param cls the 'struct GNUNET_PEERINFO_IteratorContext' |
465 | * @param transmit_success GNUNET_OK if transmission worked | 465 | * @param transmit_success GNUNET_OK if transmission worked |
466 | */ | 466 | */ |
467 | static void | 467 | static void |
468 | iterator_start_receive (void *cls, | 468 | iterator_start_receive (void *cls, |
469 | int transmit_success) | 469 | int transmit_success) |
470 | { | 470 | { |
471 | struct GNUNET_PEERINFO_NewIteratorContext *ic = cls; | 471 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; |
472 | 472 | ||
473 | if (GNUNET_OK != transmit_success) | 473 | if (GNUNET_OK != transmit_success) |
474 | { | 474 | { |
@@ -491,14 +491,14 @@ iterator_start_receive (void *cls, | |||
491 | /** | 491 | /** |
492 | * Peerinfo iteration request has timed out. | 492 | * Peerinfo iteration request has timed out. |
493 | * | 493 | * |
494 | * @param cls the 'struct GNUNET_PEERINFO_NewIteratorContext*' | 494 | * @param cls the 'struct GNUNET_PEERINFO_IteratorContext*' |
495 | * @param tc scheduler context | 495 | * @param tc scheduler context |
496 | */ | 496 | */ |
497 | static void | 497 | static void |
498 | signal_timeout (void *cls, | 498 | signal_timeout (void *cls, |
499 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 499 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
500 | { | 500 | { |
501 | struct GNUNET_PEERINFO_NewIteratorContext *ic = cls; | 501 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; |
502 | 502 | ||
503 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 503 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
504 | ic->callback (ic->callback_cls, NULL, NULL, 1); | 504 | ic->callback (ic->callback_cls, NULL, NULL, 1); |
@@ -535,17 +535,17 @@ signal_timeout (void *cls, | |||
535 | * @return NULL on error (in this case, 'callback' is never called!), | 535 | * @return NULL on error (in this case, 'callback' is never called!), |
536 | * otherwise an iterator context | 536 | * otherwise an iterator context |
537 | */ | 537 | */ |
538 | struct GNUNET_PEERINFO_NewIteratorContext * | 538 | struct GNUNET_PEERINFO_IteratorContext * |
539 | GNUNET_PEERINFO_iterate_new (struct GNUNET_PEERINFO_Handle *h, | 539 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, |
540 | const struct GNUNET_PeerIdentity *peer, | 540 | const struct GNUNET_PeerIdentity *peer, |
541 | int trust_delta, | 541 | int trust_delta, |
542 | struct GNUNET_TIME_Relative timeout, | 542 | struct GNUNET_TIME_Relative timeout, |
543 | GNUNET_PEERINFO_Processor callback, | 543 | GNUNET_PEERINFO_Processor callback, |
544 | void *callback_cls) | 544 | void *callback_cls) |
545 | { | 545 | { |
546 | struct ListAllPeersMessage *lapm; | 546 | struct ListAllPeersMessage *lapm; |
547 | struct ListPeerMessage *lpm; | 547 | struct ListPeerMessage *lpm; |
548 | struct GNUNET_PEERINFO_NewIteratorContext *ic; | 548 | struct GNUNET_PEERINFO_IteratorContext *ic; |
549 | struct TransmissionQueueEntry *tqe; | 549 | struct TransmissionQueueEntry *tqe; |
550 | 550 | ||
551 | #if DEBUG_PEERINFO | 551 | #if DEBUG_PEERINFO |
@@ -573,7 +573,7 @@ GNUNET_PEERINFO_iterate_new (struct GNUNET_PEERINFO_Handle *h, | |||
573 | lpm->trust_change = htonl (trust_delta); | 573 | lpm->trust_change = htonl (trust_delta); |
574 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 574 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
575 | } | 575 | } |
576 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NewIteratorContext)); | 576 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); |
577 | ic->h = h; | 577 | ic->h = h; |
578 | ic->tqe = tqe; | 578 | ic->tqe = tqe; |
579 | ic->callback = callback; | 579 | ic->callback = callback; |
@@ -603,7 +603,7 @@ GNUNET_PEERINFO_iterate_new (struct GNUNET_PEERINFO_Handle *h, | |||
603 | * @param ic context of the iterator to cancel | 603 | * @param ic context of the iterator to cancel |
604 | */ | 604 | */ |
605 | void | 605 | void |
606 | GNUNET_PEERINFO_iterate_cancel_new (struct GNUNET_PEERINFO_NewIteratorContext *ic) | 606 | GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) |
607 | { | 607 | { |
608 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 608 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
609 | { | 609 | { |
@@ -622,304 +622,4 @@ GNUNET_PEERINFO_iterate_cancel_new (struct GNUNET_PEERINFO_NewIteratorContext *i | |||
622 | } | 622 | } |
623 | 623 | ||
624 | 624 | ||
625 | |||
626 | /* ***************************** OLD API ****************************** */ | ||
627 | |||
628 | |||
629 | |||
630 | |||
631 | #define ADD_PEER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
632 | |||
633 | |||
634 | struct CAFContext | ||
635 | { | ||
636 | struct GNUNET_CLIENT_Connection *client; | ||
637 | struct GNUNET_MessageHeader *msg; | ||
638 | }; | ||
639 | |||
640 | |||
641 | static size_t | ||
642 | copy_and_free (void *cls, size_t size, void *buf) | ||
643 | { | ||
644 | struct CAFContext *cc = cls; | ||
645 | struct GNUNET_MessageHeader *msg = cc->msg; | ||
646 | uint16_t msize; | ||
647 | |||
648 | if (buf == NULL) | ||
649 | { | ||
650 | #if DEBUG_PEERINFO | ||
651 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
652 | _ | ||
653 | ("Failed to transmit message of type %u to `%s' service.\n"), | ||
654 | ntohs (msg->type), "peerinfo"); | ||
655 | #endif | ||
656 | GNUNET_free (msg); | ||
657 | GNUNET_CLIENT_disconnect (cc->client, GNUNET_NO); | ||
658 | GNUNET_free (cc); | ||
659 | return 0; | ||
660 | } | ||
661 | msize = ntohs (msg->size); | ||
662 | GNUNET_assert (size >= msize); | ||
663 | memcpy (buf, msg, msize); | ||
664 | GNUNET_free (msg); | ||
665 | GNUNET_CLIENT_disconnect (cc->client, GNUNET_YES); | ||
666 | GNUNET_free (cc); | ||
667 | return msize; | ||
668 | } | ||
669 | |||
670 | |||
671 | |||
672 | /** | ||
673 | * Add a host to the persistent list. | ||
674 | * | ||
675 | * @param cfg configuration to use | ||
676 | * @param sched scheduler to use | ||
677 | * @param peer identity of the peer | ||
678 | * @param hello the verified (!) HELLO message | ||
679 | */ | ||
680 | void | ||
681 | GNUNET_PEERINFO_add_peer (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
682 | struct GNUNET_SCHEDULER_Handle *sched, | ||
683 | const struct GNUNET_PeerIdentity *peer, | ||
684 | const struct GNUNET_HELLO_Message *hello) | ||
685 | { | ||
686 | struct GNUNET_CLIENT_Connection *client; | ||
687 | struct PeerAddMessage *pam; | ||
688 | uint16_t hs; | ||
689 | struct CAFContext *cc; | ||
690 | |||
691 | #if DEBUG_PEERINFO | ||
692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
693 | "Adding peer `%s' to peerinfo database\n", | ||
694 | GNUNET_i2s(peer)); | ||
695 | #endif | ||
696 | client = GNUNET_CLIENT_connect (sched, "peerinfo", cfg); | ||
697 | if (client == NULL) | ||
698 | { | ||
699 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
700 | _("Could not connect to `%s' service.\n"), "peerinfo"); | ||
701 | return; | ||
702 | } | ||
703 | hs = GNUNET_HELLO_size (hello); | ||
704 | #if DEBUG_PEERINFO | ||
705 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
706 | "Size of `%s' is %u bytes\n", | ||
707 | "HELLO", | ||
708 | (unsigned int) GNUNET_HELLO_size (hello)); | ||
709 | #endif | ||
710 | pam = GNUNET_malloc (sizeof (struct PeerAddMessage) + hs); | ||
711 | pam->header.size = htons (hs + sizeof (struct PeerAddMessage)); | ||
712 | pam->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_ADD); | ||
713 | memcpy (&pam->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | ||
714 | memcpy (&pam[1], hello, hs); | ||
715 | cc = GNUNET_malloc (sizeof (struct CAFContext)); | ||
716 | cc->client = client; | ||
717 | cc->msg = &pam->header; | ||
718 | GNUNET_CLIENT_notify_transmit_ready (client, | ||
719 | ntohs (pam->header.size), | ||
720 | ADD_PEER_TIMEOUT, | ||
721 | GNUNET_NO, | ||
722 | ©_and_free, cc); | ||
723 | } | ||
724 | |||
725 | |||
726 | /** | ||
727 | * Context for the info handler. | ||
728 | */ | ||
729 | struct GNUNET_PEERINFO_IteratorContext | ||
730 | { | ||
731 | |||
732 | /** | ||
733 | * Our connection to the PEERINFO service. | ||
734 | */ | ||
735 | struct GNUNET_CLIENT_Connection *client; | ||
736 | |||
737 | /** | ||
738 | * Function to call with information. | ||
739 | */ | ||
740 | GNUNET_PEERINFO_Processor callback; | ||
741 | |||
742 | /** | ||
743 | * Closure for callback. | ||
744 | */ | ||
745 | void *callback_cls; | ||
746 | |||
747 | /** | ||
748 | * When should we time out? | ||
749 | */ | ||
750 | struct GNUNET_TIME_Absolute timeout; | ||
751 | |||
752 | }; | ||
753 | |||
754 | |||
755 | /** | ||
756 | * Type of a function to call when we receive a message | ||
757 | * from the service. | ||
758 | * | ||
759 | * @param cls closure | ||
760 | * @param msg message received, NULL on timeout or fatal error | ||
761 | */ | ||
762 | static void | ||
763 | info_handler (void *cls, const struct GNUNET_MessageHeader *msg) | ||
764 | { | ||
765 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; | ||
766 | const struct InfoMessage *im; | ||
767 | const struct GNUNET_HELLO_Message *hello; | ||
768 | uint16_t ms; | ||
769 | |||
770 | if (msg == NULL) | ||
771 | { | ||
772 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
773 | _("Failed to receive response from `%s' service.\n"), | ||
774 | "peerinfo"); | ||
775 | ic->callback (ic->callback_cls, NULL, NULL, 1); | ||
776 | GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO); | ||
777 | GNUNET_free (ic); | ||
778 | return; | ||
779 | } | ||
780 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END) | ||
781 | { | ||
782 | #if DEBUG_PEERINFO | ||
783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
784 | "Received end of list of peers from peerinfo database\n"); | ||
785 | #endif | ||
786 | ic->callback (ic->callback_cls, NULL, NULL, 0); | ||
787 | GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO); | ||
788 | GNUNET_free (ic); | ||
789 | return; | ||
790 | } | ||
791 | ms = ntohs (msg->size); | ||
792 | if ((ms < sizeof (struct InfoMessage)) || | ||
793 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) | ||
794 | { | ||
795 | GNUNET_break (0); | ||
796 | ic->callback (ic->callback_cls, NULL, NULL, 2); | ||
797 | GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO); | ||
798 | GNUNET_free (ic); | ||
799 | return; | ||
800 | } | ||
801 | im = (const struct InfoMessage *) msg; | ||
802 | hello = NULL; | ||
803 | if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
804 | { | ||
805 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
806 | if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) | ||
807 | { | ||
808 | GNUNET_break (0); | ||
809 | ic->callback (ic->callback_cls, NULL, NULL, 2); | ||
810 | GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO); | ||
811 | GNUNET_free (ic); | ||
812 | return; | ||
813 | } | ||
814 | } | ||
815 | #if DEBUG_PEERINFO | ||
816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
817 | "Received %u bytes of `%s' information about peer `%s' from PEERINFO database\n", | ||
818 | (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello), | ||
819 | "HELLO", | ||
820 | GNUNET_i2s (&im->peer)); | ||
821 | #endif | ||
822 | ic->callback (ic->callback_cls, &im->peer, hello, ntohl (im->trust)); | ||
823 | GNUNET_CLIENT_receive (ic->client, | ||
824 | &info_handler, | ||
825 | ic, | ||
826 | GNUNET_TIME_absolute_get_remaining (ic->timeout)); | ||
827 | } | ||
828 | |||
829 | |||
830 | /** | ||
831 | * Call a method for each known matching host and change | ||
832 | * its trust value. The method will be invoked once for | ||
833 | * each host and then finally once with a NULL pointer. | ||
834 | * Note that the last call can be triggered by timeout or | ||
835 | * by simply being done; however, the trust argument will | ||
836 | * be set to zero if we are done and to 1 if we timed out. | ||
837 | * | ||
838 | * @param cfg configuration to use | ||
839 | * @param sched scheduler to use | ||
840 | * @param peer restrict iteration to this peer only (can be NULL) | ||
841 | * @param trust_delta how much to change the trust in all matching peers | ||
842 | * @param timeout how long to wait until timing out | ||
843 | * @param callback the method to call for each peer | ||
844 | * @param callback_cls closure for callback | ||
845 | * @return NULL on error, otherwise an iterator context | ||
846 | */ | ||
847 | struct GNUNET_PEERINFO_IteratorContext * | ||
848 | GNUNET_PEERINFO_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
849 | struct GNUNET_SCHEDULER_Handle *sched, | ||
850 | const struct GNUNET_PeerIdentity *peer, | ||
851 | int trust_delta, | ||
852 | struct GNUNET_TIME_Relative timeout, | ||
853 | GNUNET_PEERINFO_Processor callback, | ||
854 | void *callback_cls) | ||
855 | { | ||
856 | struct GNUNET_CLIENT_Connection *client; | ||
857 | struct ListAllPeersMessage *lapm; | ||
858 | struct ListPeerMessage *lpm; | ||
859 | struct GNUNET_PEERINFO_IteratorContext *ihc; | ||
860 | |||
861 | client = GNUNET_CLIENT_connect (sched, "peerinfo", cfg); | ||
862 | if (client == NULL) | ||
863 | { | ||
864 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
865 | _("Could not connect to `%s' service.\n"), "peerinfo"); | ||
866 | return NULL; | ||
867 | } | ||
868 | #if DEBUG_PEERINFO | ||
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
870 | "Requesting list of peers from peerinfo database\n"); | ||
871 | #endif | ||
872 | if (peer == NULL) | ||
873 | { | ||
874 | ihc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext) + | ||
875 | sizeof (struct ListAllPeersMessage)); | ||
876 | lapm = (struct ListAllPeersMessage *) &ihc[1]; | ||
877 | lapm->header.size = htons (sizeof (struct ListAllPeersMessage)); | ||
878 | lapm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); | ||
879 | lapm->trust_change = htonl (trust_delta); | ||
880 | } | ||
881 | else | ||
882 | { | ||
883 | ihc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext) + | ||
884 | sizeof (struct ListPeerMessage)); | ||
885 | lpm = (struct ListPeerMessage *) &ihc[1]; | ||
886 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); | ||
887 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); | ||
888 | lpm->trust_change = htonl (trust_delta); | ||
889 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | ||
890 | } | ||
891 | ihc->client = client; | ||
892 | ihc->callback = callback; | ||
893 | ihc->callback_cls = callback_cls; | ||
894 | ihc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
895 | if (GNUNET_OK != | ||
896 | GNUNET_CLIENT_transmit_and_get_response (client, | ||
897 | (const struct GNUNET_MessageHeader*) &ihc[1], | ||
898 | timeout, | ||
899 | GNUNET_YES, | ||
900 | &info_handler, | ||
901 | ihc)) | ||
902 | { | ||
903 | GNUNET_break (0); | ||
904 | GNUNET_CLIENT_disconnect (ihc->client, GNUNET_NO); | ||
905 | GNUNET_free (ihc); | ||
906 | return NULL; | ||
907 | } | ||
908 | return ihc; | ||
909 | } | ||
910 | |||
911 | |||
912 | /** | ||
913 | * Cancel an iteration over peer information. | ||
914 | * | ||
915 | * @param ic context of the iterator to cancel | ||
916 | */ | ||
917 | void | ||
918 | GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) | ||
919 | { | ||
920 | GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO); | ||
921 | GNUNET_free (ic); | ||
922 | } | ||
923 | |||
924 | |||
925 | /* end of peerinfo_api.c */ | 625 | /* end of peerinfo_api.c */ |