aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/gnunet-service-peerinfo.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-30 19:24:12 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-30 19:24:12 +0000
commit427dd6f998fb1fde515a3b5c800f9f6d308197b2 (patch)
tree8cbe9bf7b43fafae07ed1a25753ccccdbe430148 /src/peerinfo/gnunet-service-peerinfo.c
parentb18fa7b1e7fcb4d48e2ef314a7d822ccddd8bd60 (diff)
downloadgnunet-427dd6f998fb1fde515a3b5c800f9f6d308197b2.tar.gz
gnunet-427dd6f998fb1fde515a3b5c800f9f6d308197b2.zip
-towards addressing #3047, note this causes the code to FTBFS
Diffstat (limited to 'src/peerinfo/gnunet-service-peerinfo.c')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index f0e298cf5..cf28484eb 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -136,7 +136,7 @@ struct NotificationContext
136 * The in-memory list of known hosts, mapping of 136 * The in-memory list of known hosts, mapping of
137 * host IDs to 'struct HostEntry*' values. 137 * host IDs to 'struct HostEntry*' values.
138 */ 138 */
139static struct GNUNET_CONTAINER_MultiHashMap *hostmap; 139static struct GNUNET_CONTAINER_MultiPeerMap *hostmap;
140 140
141/** 141/**
142 * Clients to immediately notify about all changes. 142 * Clients to immediately notify about all changes.
@@ -249,13 +249,12 @@ count_addresses (void *cls, const struct GNUNET_HELLO_Address *address,
249static char * 249static char *
250get_host_filename (const struct GNUNET_PeerIdentity *id) 250get_host_filename (const struct GNUNET_PeerIdentity *id)
251{ 251{
252 struct GNUNET_CRYPTO_HashAsciiEncoded fil;
253 char *fn; 252 char *fn;
254 253
255 if (NULL == networkIdDirectory) 254 if (NULL == networkIdDirectory)
256 return NULL; 255 return NULL;
257 GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); 256 GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR,
258 GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); 257 GNUNET_i2s_full (id));
259 return fn; 258 return fn;
260} 259}
261 260
@@ -441,7 +440,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
441 struct ReadHostFileContext r; 440 struct ReadHostFileContext r;
442 char *fn; 441 char *fn;
443 442
444 entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); 443 entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity);
445 if (NULL == entry) 444 if (NULL == entry)
446 { 445 {
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer `%s'\n", GNUNET_i2s (identity)); 446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer `%s'\n", GNUNET_i2s (identity));
@@ -449,7 +448,7 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
449 GNUNET_NO); 448 GNUNET_NO);
450 entry = GNUNET_malloc (sizeof (struct HostEntry)); 449 entry = GNUNET_malloc (sizeof (struct HostEntry));
451 entry->identity = *identity; 450 entry->identity = *identity;
452 GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry, 451 GNUNET_CONTAINER_multipeermap_put (hostmap, &entry->identity, entry,
453 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 452 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
454 notify_all (entry); 453 notify_all (entry);
455 fn = get_host_filename (identity); 454 fn = get_host_filename (identity);
@@ -576,7 +575,9 @@ hosts_directory_scan_callback (void *cls, const char *fullname)
576 remove_garbage (fullname); 575 remove_garbage (fullname);
577 return GNUNET_OK; 576 return GNUNET_OK;
578 } 577 }
579 if (GNUNET_OK == GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) 578 if (GNUNET_OK == GNUNET_CRYPTO_ecc_public_sign_key_from_string (filename,
579 strlen (filename),
580 &identity.public_key))
580 { 581 {
581 if (0 != memcmp (&id, &identity, sizeof (id_friend))) 582 if (0 != memcmp (&id, &identity, sizeof (id_friend)))
582 { 583 {
@@ -699,7 +700,7 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
699 int pos; 700 int pos;
700 char *buffer; 701 char *buffer;
701 702
702 host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); 703 host = GNUNET_CONTAINER_multipeermap_get (hostmap, peer);
703 GNUNET_assert (NULL != host); 704 GNUNET_assert (NULL != host);
704 705
705 friend_hello_type = GNUNET_HELLO_is_friend_only (hello); 706 friend_hello_type = GNUNET_HELLO_is_friend_only (hello);
@@ -830,7 +831,7 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
830 * @return GNUNET_YES (continue to iterate) 831 * @return GNUNET_YES (continue to iterate)
831 */ 832 */
832static int 833static int
833add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value) 834add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
834{ 835{
835 struct TransmitContext *tc = cls; 836 struct TransmitContext *tc = cls;
836 struct HostEntry *pos = value; 837 struct HostEntry *pos = value;
@@ -848,8 +849,9 @@ add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
848 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE - 849 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE -
849 sizeof (struct InfoMessage)); 850 sizeof (struct InfoMessage));
850 memcpy (&im[1], pos->hello, hs); 851 memcpy (&im[1], pos->hello, hs);
851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending public HELLO with size %u for peer `%4s'\n", 852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
852 hs, GNUNET_h2s (key)); 853 "Sending public HELLO with size %u for peer `%4s'\n",
854 hs, GNUNET_i2s (key));
853 } 855 }
854 else if ((pos->friend_only_hello != NULL) && (GNUNET_YES == tc->friend_only)) 856 else if ((pos->friend_only_hello != NULL) && (GNUNET_YES == tc->friend_only))
855 { 857 {
@@ -858,13 +860,15 @@ add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
858 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE - 860 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE -
859 sizeof (struct InfoMessage)); 861 sizeof (struct InfoMessage));
860 memcpy (&im[1], pos->friend_only_hello, hs); 862 memcpy (&im[1], pos->friend_only_hello, hs);
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending friend-only HELLO with size %u for peer `%4s'\n", 863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
862 hs, GNUNET_h2s (key)); 864 "Sending friend-only HELLO with size %u for peer `%4s'\n",
865 hs, GNUNET_i2s (key));
863 } 866 }
864 else 867 else
865 { 868 {
866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding no HELLO for peer `%s'\n", 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
867 GNUNET_h2s (key)); 870 "Adding no HELLO for peer `%s'\n",
871 GNUNET_i2s (key));
868 } 872 }
869 873
870 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); 874 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
@@ -1027,7 +1031,7 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
1027 "GET", GNUNET_i2s (&lpm->peer)); 1031 "GET", GNUNET_i2s (&lpm->peer));
1028 tcx.friend_only = ntohl (lpm->include_friend_only); 1032 tcx.friend_only = ntohl (lpm->include_friend_only);
1029 tcx.tc = GNUNET_SERVER_transmit_context_create (client); 1033 tcx.tc = GNUNET_SERVER_transmit_context_create (client);
1030 GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, &lpm->peer.hashPubKey, 1034 GNUNET_CONTAINER_multipeermap_get_multiple (hostmap, &lpm->peer,
1031 &add_to_tc, &tcx); 1035 &add_to_tc, &tcx);
1032 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0, 1036 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0,
1033 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 1037 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
@@ -1053,7 +1057,7 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
1053 tcx.friend_only = ntohl (lapm->include_friend_only); 1057 tcx.friend_only = ntohl (lapm->include_friend_only);
1054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); 1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL");
1055 tcx.tc = GNUNET_SERVER_transmit_context_create (client); 1059 tcx.tc = GNUNET_SERVER_transmit_context_create (client);
1056 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, &tcx); 1060 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx);
1057 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0, 1061 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0,
1058 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 1062 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1059 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL); 1063 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -1071,7 +1075,7 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
1071 * @return GNUNET_YES (always, continue to iterate) 1075 * @return GNUNET_YES (always, continue to iterate)
1072 */ 1076 */
1073static int 1077static int
1074do_notify_entry (void *cls, const struct GNUNET_HashCode * key, void *value) 1078do_notify_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1075{ 1079{
1076 struct NotificationContext *nc = cls; 1080 struct NotificationContext *nc = cls;
1077 struct HostEntry *he = value; 1081 struct HostEntry *he = value;
@@ -1124,7 +1128,7 @@ handle_notify (void *cls, struct GNUNET_SERVER_Client *client,
1124 GNUNET_CONTAINER_DLL_insert (nc_head, nc_tail, nc); 1128 GNUNET_CONTAINER_DLL_insert (nc_head, nc_tail, nc);
1125 GNUNET_SERVER_client_mark_monitor (client); 1129 GNUNET_SERVER_client_mark_monitor (client);
1126 GNUNET_SERVER_notification_context_add (notify_list, client); 1130 GNUNET_SERVER_notification_context_add (notify_list, client);
1127 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, nc); 1131 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &do_notify_entry, nc);
1128 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1132 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1129} 1133}
1130 1134
@@ -1159,7 +1163,7 @@ disconnect_cb (void *cls,struct GNUNET_SERVER_Client *client)
1159 * @return GNUNET_YES (continue to iterate) 1163 * @return GNUNET_YES (continue to iterate)
1160 */ 1164 */
1161static int 1165static int
1162free_host_entry (void *cls, const struct GNUNET_HashCode * key, void *value) 1166free_host_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1163{ 1167{
1164 struct HostEntry *he = value; 1168 struct HostEntry *he = value;
1165 1169
@@ -1191,8 +1195,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1191 GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur); 1195 GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur);
1192 GNUNET_free (cur); 1196 GNUNET_free (cur);
1193 } 1197 }
1194 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL); 1198 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &free_host_entry, NULL);
1195 GNUNET_CONTAINER_multihashmap_destroy (hostmap); 1199 GNUNET_CONTAINER_multipeermap_destroy (hostmap);
1196 if (NULL != stats) 1200 if (NULL != stats)
1197 { 1201 {
1198 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 1202 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
@@ -1228,7 +1232,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1228 int noio; 1232 int noio;
1229 int use_included; 1233 int use_included;
1230 1234
1231 hostmap = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES); 1235 hostmap = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES);
1232 stats = GNUNET_STATISTICS_create ("peerinfo", cfg); 1236 stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
1233 notify_list = GNUNET_SERVER_notification_context_create (server, 0); 1237 notify_list = GNUNET_SERVER_notification_context_create (server, 0);
1234 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO"); 1238 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO");