aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-04-04 13:41:16 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-04-04 13:41:16 +0000
commit40ae7b109ac101984cebc3f506c2fe390a803b54 (patch)
treed986f72c82bc062531f5966882ad632095ed89c4 /src
parentcdd86bad46753710ec2570c926dbe57f1801af43 (diff)
downloadgnunet-40ae7b109ac101984cebc3f506c2fe390a803b54.tar.gz
gnunet-40ae7b109ac101984cebc3f506c2fe390a803b54.zip
peerinfo get implementation
Diffstat (limited to 'src')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 348db8256..7475ee34f 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -511,6 +511,15 @@ bind_address (const struct GNUNET_PeerIdentity *peer,
511} 511}
512 512
513 513
514struct TransmitContext
515{
516 struct GNUNET_SERVER_TransmitContext *tc;
517
518 int friend_only;
519};
520
521
522
514/** 523/**
515 * Do transmit info about peer to given host. 524 * Do transmit info about peer to given host.
516 * 525 *
@@ -522,7 +531,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer,
522static int 531static int
523add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value) 532add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
524{ 533{
525 struct GNUNET_SERVER_TransmitContext *tc = cls; 534 struct TransmitContext *tc = cls;
526 struct HostEntry *pos = value; 535 struct HostEntry *pos = value;
527 struct InfoMessage *im; 536 struct InfoMessage *im;
528 uint16_t hs; 537 uint16_t hs;
@@ -530,7 +539,9 @@ add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
530 539
531 hs = 0; 540 hs = 0;
532 im = (struct InfoMessage *) buf; 541 im = (struct InfoMessage *) buf;
533 if (pos->hello != NULL) 542 if ((pos->hello != NULL) &&
543 ((GNUNET_NO == GNUNET_HELLO_is_friend_only (pos->hello)) ||
544 ((GNUNET_YES == GNUNET_HELLO_is_friend_only (pos->hello)) && (GNUNET_YES == tc->friend_only))))
534 { 545 {
535 hs = GNUNET_HELLO_size (pos->hello); 546 hs = GNUNET_HELLO_size (pos->hello);
536 GNUNET_assert (hs < 547 GNUNET_assert (hs <
@@ -542,7 +553,7 @@ add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
542 im->header.size = htons (sizeof (struct InfoMessage) + hs); 553 im->header.size = htons (sizeof (struct InfoMessage) + hs);
543 im->reserved = htonl (0); 554 im->reserved = htonl (0);
544 im->peer = pos->identity; 555 im->peer = pos->identity;
545 GNUNET_SERVER_transmit_context_append_message (tc, &im->header); 556 GNUNET_SERVER_transmit_context_append_message (tc->tc, &im->header);
546 return GNUNET_YES; 557 return GNUNET_YES;
547} 558}
548 559
@@ -658,19 +669,18 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
658 const struct GNUNET_MessageHeader *message) 669 const struct GNUNET_MessageHeader *message)
659{ 670{
660 const struct ListPeerMessage *lpm; 671 const struct ListPeerMessage *lpm;
661 struct GNUNET_SERVER_TransmitContext *tc; 672 struct TransmitContext tcx;
662 int friend_only;
663 673
664 lpm = (const struct ListPeerMessage *) message; 674 lpm = (const struct ListPeerMessage *) message;
665 friend_only = ntohl (lpm->include_friend_only);
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", 675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n",
667 "GET", GNUNET_i2s (&lpm->peer)); 676 "GET", GNUNET_i2s (&lpm->peer));
668 tc = GNUNET_SERVER_transmit_context_create (client); 677 tcx.friend_only = ntohl (lpm->include_friend_only);
678 tcx.tc = GNUNET_SERVER_transmit_context_create (client);
669 GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, &lpm->peer.hashPubKey, 679 GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, &lpm->peer.hashPubKey,
670 &add_to_tc, tc); 680 &add_to_tc, &tcx);
671 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 681 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0,
672 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 682 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
673 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 683 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL);
674} 684}
675 685
676 686
@@ -686,17 +696,16 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
686 const struct GNUNET_MessageHeader *message) 696 const struct GNUNET_MessageHeader *message)
687{ 697{
688 const struct ListAllPeersMessage *lapm; 698 const struct ListAllPeersMessage *lapm;
689 struct GNUNET_SERVER_TransmitContext *tc; 699 struct TransmitContext tcx;
690 int friend_only;
691 700
692 lapm = (const struct ListAllPeersMessage *) message; 701 lapm = (const struct ListAllPeersMessage *) message;
693 friend_only = ntohl (lapm->include_friend_only); 702 tcx.friend_only = ntohl (lapm->include_friend_only);
694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); 703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL");
695 tc = GNUNET_SERVER_transmit_context_create (client); 704 tcx.tc = GNUNET_SERVER_transmit_context_create (client);
696 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc); 705 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, &tcx);
697 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 706 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0,
698 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 707 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
699 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 708 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL);
700} 709}
701 710
702struct NotificationContext 711struct NotificationContext