aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-21 20:19:43 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-21 20:19:43 +0000
commit84e15afe4933ee2ca62e3e111ca261c3a986c157 (patch)
tree8a9cd9a06b723b940f6d11b0272f5eb395db39c4 /src/peerinfo
parenta06d7742d5a48229767c152f9466432d17e162de (diff)
downloadgnunet-84e15afe4933ee2ca62e3e111ca261c3a986c157.tar.gz
gnunet-84e15afe4933ee2ca62e3e111ca261c3a986c157.zip
activating new peerinfo API
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c40
-rw-r--r--src/peerinfo/peerinfo.h25
-rw-r--r--src/peerinfo/peerinfo_api.c344
-rw-r--r--src/peerinfo/test_peerinfo_api.c30
4 files changed, 37 insertions, 402 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 1802da959..e200eae2f 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -29,8 +29,6 @@
29 * 29 *
30 * TODO: 30 * TODO:
31 * - HostEntries are never 'free'd (add expiration, upper bound?) 31 * - HostEntries are never 'free'd (add expiration, upper bound?)
32 * - AddPeer message is obsolete with NEW peerinfo API (remove handler,
33 * message struct and protocol)
34 */ 32 */
35 33
36#include "platform.h" 34#include "platform.h"
@@ -649,43 +647,6 @@ cron_clean_data_hosts (void *cls,
649 647
650 648
651/** 649/**
652 * Handle ADD-message.
653 *
654 * @param cls closure
655 * @param client identification of the client
656 * @param message the actual message
657 */
658static void
659handle_add (void *cls,
660 struct GNUNET_SERVER_Client *client,
661 const struct GNUNET_MessageHeader *message)
662{
663 const struct PeerAddMessage *pam;
664 const struct GNUNET_MessageHeader *hello;
665 uint16_t size;
666
667 size = ntohs (message->size);
668 if (size <
669 sizeof (struct PeerAddMessage) + sizeof (struct GNUNET_MessageHeader))
670 {
671 GNUNET_break (0);
672 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
673 return;
674 }
675 pam = (const struct PeerAddMessage *) message;
676 hello = (const struct GNUNET_MessageHeader *) &pam[1];
677 if (size != sizeof (struct PeerAddMessage) + ntohs (hello->size))
678 {
679 GNUNET_break (0);
680 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
681 return;
682 }
683 bind_address (&pam->peer, (const struct GNUNET_HELLO_Message *) hello);
684 GNUNET_SERVER_receive_done (client, GNUNET_OK);
685}
686
687
688/**
689 * Handle HELLO-message. 650 * Handle HELLO-message.
690 * 651 *
691 * @param cls closure 652 * @param cls closure
@@ -787,7 +748,6 @@ handle_notify (void *cls,
787 */ 748 */
788static struct GNUNET_SERVER_MessageHandler handlers[] = { 749static struct GNUNET_SERVER_MessageHandler handlers[] = {
789 {&handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0}, 750 {&handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0},
790 {&handle_add, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_ADD, 0},
791 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET, 751 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET,
792 sizeof (struct ListPeerMessage)}, 752 sizeof (struct ListPeerMessage)},
793 {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, 753 {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
diff --git a/src/peerinfo/peerinfo.h b/src/peerinfo/peerinfo.h
index 607aad4db..3e959a6c7 100644
--- a/src/peerinfo/peerinfo.h
+++ b/src/peerinfo/peerinfo.h
@@ -30,31 +30,6 @@
30#define DEBUG_PEERINFO GNUNET_NO 30#define DEBUG_PEERINFO GNUNET_NO
31 31
32/** 32/**
33 * Add the given peer to the list. This message
34 * is always followed by a verified HELLO message.
35 */
36struct PeerAddMessage
37{
38
39 /**
40 * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_ADD
41 */
42 struct GNUNET_MessageHeader header;
43
44 /**
45 * Always zero.
46 */
47 uint32_t reserved GNUNET_PACKED;
48
49 /**
50 * For which peer do we provide a HELLO message here?
51 */
52 struct GNUNET_PeerIdentity peer;
53
54};
55
56
57/**
58 * Message requesting a listing of all known peers, 33 * Message requesting a listing of all known peers,
59 * possibly modified by the specified trust value 34 * possibly modified by the specified trust value
60 * and restricted to the specified peer identity. 35 * and restricted to the specified peer identity.
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 */
135struct GNUNET_PEERINFO_Handle * 135struct GNUNET_PEERINFO_Handle *
136GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 136GNUNET_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
197reconnect (struct GNUNET_PEERINFO_Handle *h) 197reconnect (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 */
293void 293void
294GNUNET_PEERINFO_add_peer_new (struct GNUNET_PEERINFO_Handle *h, 294GNUNET_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 */
324struct GNUNET_PEERINFO_NewIteratorContext 324struct 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
370static void 370static void
371peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) 371peerinfo_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 */
467static void 467static void
468iterator_start_receive (void *cls, 468iterator_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 */
497static void 497static void
498signal_timeout (void *cls, 498signal_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 */
538struct GNUNET_PEERINFO_NewIteratorContext * 538struct GNUNET_PEERINFO_IteratorContext *
539GNUNET_PEERINFO_iterate_new (struct GNUNET_PEERINFO_Handle *h, 539GNUNET_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 */
605void 605void
606GNUNET_PEERINFO_iterate_cancel_new (struct GNUNET_PEERINFO_NewIteratorContext *ic) 606GNUNET_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
634struct CAFContext
635{
636 struct GNUNET_CLIENT_Connection *client;
637 struct GNUNET_MessageHeader *msg;
638};
639
640
641static size_t
642copy_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 */
680void
681GNUNET_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 &copy_and_free, cc);
723}
724
725
726/**
727 * Context for the info handler.
728 */
729struct 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 */
762static void
763info_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 */
847struct GNUNET_PEERINFO_IteratorContext *
848GNUNET_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 */
917void
918GNUNET_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 */
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index 10ea1fa81..3fa622f50 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -40,7 +40,7 @@ static struct GNUNET_SCHEDULER_Handle *sched;
40 40
41static const struct GNUNET_CONFIGURATION_Handle *cfg; 41static const struct GNUNET_CONFIGURATION_Handle *cfg;
42 42
43static struct GNUNET_PEERINFO_NewIteratorContext *ic; 43static struct GNUNET_PEERINFO_IteratorContext *ic;
44 44
45static struct GNUNET_PEERINFO_Handle *h; 45static struct GNUNET_PEERINFO_Handle *h;
46 46
@@ -93,7 +93,7 @@ add_peer ()
93 memset (&pkey, 32, sizeof (pkey)); 93 memset (&pkey, 32, sizeof (pkey));
94 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); 94 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
95 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc); 95 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc);
96 GNUNET_PEERINFO_add_peer_new (h, h2); 96 GNUNET_PEERINFO_add_peer (h, h2);
97 GNUNET_free (h2); 97 GNUNET_free (h2);
98 98
99} 99}
@@ -116,12 +116,12 @@ process (void *cls,
116 /* try again */ 116 /* try again */
117 retries++; 117 retries++;
118 add_peer (); 118 add_peer ();
119 ic = GNUNET_PEERINFO_iterate_new (h, 119 ic = GNUNET_PEERINFO_iterate (h,
120 NULL, 120 NULL,
121 0, 121 0,
122 GNUNET_TIME_relative_multiply 122 GNUNET_TIME_relative_multiply
123 (GNUNET_TIME_UNIT_SECONDS, 15), 123 (GNUNET_TIME_UNIT_SECONDS, 15),
124 &process, cls); 124 &process, cls);
125 return; 125 return;
126 } 126 }
127 GNUNET_assert (peer == NULL); 127 GNUNET_assert (peer == NULL);
@@ -152,14 +152,14 @@ run (void *cls,
152{ 152{
153 sched = s; 153 sched = s;
154 cfg = c; 154 cfg = c;
155 h = GNUNET_PEERINFO_connect (cfg, sched); 155 h = GNUNET_PEERINFO_connect (sched, cfg);
156 add_peer (); 156 add_peer ();
157 ic = GNUNET_PEERINFO_iterate_new (h, 157 ic = GNUNET_PEERINFO_iterate (h,
158 NULL, 158 NULL,
159 0, 159 0,
160 GNUNET_TIME_relative_multiply 160 GNUNET_TIME_relative_multiply
161 (GNUNET_TIME_UNIT_SECONDS, 15), 161 (GNUNET_TIME_UNIT_SECONDS, 15),
162 &process, cls); 162 &process, cls);
163} 163}
164 164
165 165