aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-04-04 13:08:51 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-04-04 13:08:51 +0000
commit84d17ce6a280971018ca01dbd71c1cd0ae0ea53b (patch)
tree2795b8c790dea49017a540ef64fd8413d0a2d904 /src/peerinfo
parent2acba37f79c69837a2045bda86bdbcb89bf125cc (diff)
downloadgnunet-84d17ce6a280971018ca01dbd71c1cd0ae0ea53b.tar.gz
gnunet-84d17ce6a280971018ca01dbd71c1cd0ae0ea53b.zip
implement peerinfo notification api
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 55d4177cf..348db8256 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -68,6 +68,8 @@ struct HostEntry
68}; 68};
69 69
70 70
71
72
71/** 73/**
72 * The in-memory list of known hosts, mapping of 74 * The in-memory list of known hosts, mapping of
73 * host IDs to 'struct HostEntry*' values. 75 * host IDs to 'struct HostEntry*' values.
@@ -80,6 +82,11 @@ static struct GNUNET_CONTAINER_MultiHashMap *hostmap;
80static struct GNUNET_SERVER_NotificationContext *notify_list; 82static struct GNUNET_SERVER_NotificationContext *notify_list;
81 83
82/** 84/**
85 * Clients to immediately notify about all changes.
86 */
87static struct GNUNET_SERVER_NotificationContext *notify_friend_only_list;
88
89/**
83 * Directory where the hellos are stored in (data/hosts) 90 * Directory where the hellos are stored in (data/hosts)
84 */ 91 */
85static char *networkIdDirectory; 92static char *networkIdDirectory;
@@ -192,8 +199,21 @@ notify_all (struct HostEntry *entry)
192 struct InfoMessage *msg; 199 struct InfoMessage *msg;
193 200
194 msg = make_info_message (entry); 201 msg = make_info_message (entry);
195 GNUNET_SERVER_notification_context_broadcast (notify_list, &msg->header, 202 if ((NULL != entry->hello) &&
203 (GNUNET_YES == GNUNET_HELLO_is_friend_only(entry->hello)))
204 {
205 GNUNET_SERVER_notification_context_broadcast (notify_friend_only_list,
206 &msg->header,
207 GNUNET_NO);
208 }
209 else
210 {
211 GNUNET_SERVER_notification_context_broadcast (notify_friend_only_list,
212 &msg->header,
196 GNUNET_NO); 213 GNUNET_NO);
214 GNUNET_SERVER_notification_context_broadcast (notify_list, &msg->header,
215 GNUNET_NO);
216 }
197 GNUNET_free (msg); 217 GNUNET_free (msg);
198} 218}
199 219
@@ -679,6 +699,13 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
679 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 699 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
680} 700}
681 701
702struct NotificationContext
703{
704 struct GNUNET_SERVER_Client *client;
705
706 int friend_only;
707};
708
682 709
683/** 710/**
684 * Pass the given client the information we have in the respective 711 * Pass the given client the information we have in the respective
@@ -692,18 +719,22 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
692static int 719static int
693do_notify_entry (void *cls, const struct GNUNET_HashCode * key, void *value) 720do_notify_entry (void *cls, const struct GNUNET_HashCode * key, void *value)
694{ 721{
695 struct GNUNET_SERVER_Client *client = cls; 722 struct NotificationContext *nc = cls;
696 struct HostEntry *he = value; 723 struct HostEntry *he = value;
697 struct InfoMessage *msg; 724 struct InfoMessage *msg;
698 725
726 if ((NULL != he->hello) &&
727 (GNUNET_YES == GNUNET_HELLO_is_friend_only(he->hello)) &&
728 (GNUNET_NO == nc->friend_only))
729 return GNUNET_YES;
730
699 msg = make_info_message (he); 731 msg = make_info_message (he);
700 GNUNET_SERVER_notification_context_unicast (notify_list, client, &msg->header, 732 GNUNET_SERVER_notification_context_unicast (notify_list, nc->client, &msg->header,
701 GNUNET_NO); 733 GNUNET_NO);
702 GNUNET_free (msg); 734 GNUNET_free (msg);
703 return GNUNET_YES; 735 return GNUNET_YES;
704} 736}
705 737
706
707/** 738/**
708 * Handle NOTIFY-message. 739 * Handle NOTIFY-message.
709 * 740 *
@@ -716,13 +747,20 @@ handle_notify (void *cls, struct GNUNET_SERVER_Client *client,
716 const struct GNUNET_MessageHeader *message) 747 const struct GNUNET_MessageHeader *message)
717{ 748{
718 struct NotifyMessage *nm = (struct NotifyMessage *) message; 749 struct NotifyMessage *nm = (struct NotifyMessage *) message;
750 struct NotificationContext nc;
719 int friend_only; 751 int friend_only;
720 752
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY"); 753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY");
722 friend_only = ntohl (nm->include_friend_only); 754
755 nc.client = client;
756 nc.friend_only = ntohl (nm->include_friend_only);
757
723 GNUNET_SERVER_client_mark_monitor (client); 758 GNUNET_SERVER_client_mark_monitor (client);
724 GNUNET_SERVER_notification_context_add (notify_list, client); 759 if (GNUNET_YES == ntohl (nm->include_friend_only))
725 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client); 760 GNUNET_SERVER_notification_context_add (notify_friend_only_list, client);
761 else
762 GNUNET_SERVER_notification_context_add (notify_list, client);
763 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, &nc);
726 GNUNET_SERVER_receive_done (client, GNUNET_OK); 764 GNUNET_SERVER_receive_done (client, GNUNET_OK);
727} 765}
728 766
@@ -757,6 +795,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
757{ 795{
758 GNUNET_SERVER_notification_context_destroy (notify_list); 796 GNUNET_SERVER_notification_context_destroy (notify_list);
759 notify_list = NULL; 797 notify_list = NULL;
798 GNUNET_SERVER_notification_context_destroy (notify_friend_only_list);
799 notify_friend_only_list = NULL;
760 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL); 800 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL);
761 GNUNET_CONTAINER_multihashmap_destroy (hostmap); 801 GNUNET_CONTAINER_multihashmap_destroy (hostmap);
762 if (NULL != stats) 802 if (NULL != stats)
@@ -796,6 +836,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
796 hostmap = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES); 836 hostmap = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
797 stats = GNUNET_STATISTICS_create ("peerinfo", cfg); 837 stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
798 notify_list = GNUNET_SERVER_notification_context_create (server, 0); 838 notify_list = GNUNET_SERVER_notification_context_create (server, 0);
839 notify_friend_only_list = GNUNET_SERVER_notification_context_create (server, 0);
799 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO"); 840 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO");
800 if (GNUNET_YES != noio) 841 if (GNUNET_YES != noio)
801 { 842 {