aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/gnunet-daemon-hostlist_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist_client.c')
-rw-r--r--src/hostlist/gnunet-daemon-hostlist_client.c123
1 files changed, 63 insertions, 60 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c
index 9f6413898..c1a2c2721 100644
--- a/src/hostlist/gnunet-daemon-hostlist_client.c
+++ b/src/hostlist/gnunet-daemon-hostlist_client.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2010, 2014 GNUnet e.V. 3 Copyright (C) 2001-2010, 2014, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -1187,14 +1187,20 @@ task_hostlist_saving (void *cls)
1187 * 1187 *
1188 * @param cls closure 1188 * @param cls closure
1189 * @param peer peer identity this notification is about 1189 * @param peer peer identity this notification is about
1190 * @param mq message queue for transmissions to @a peer
1190 */ 1191 */
1191static void 1192static void *
1192handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 1193handler_connect (void *cls,
1194 const struct GNUNET_PeerIdentity *peer,
1195 struct GNUNET_MQ_Handle *mq)
1193{ 1196{
1194 GNUNET_assert (stat_connection_count < UINT_MAX); 1197 GNUNET_assert (stat_connection_count < UINT_MAX);
1195 stat_connection_count++; 1198 stat_connection_count++;
1196 GNUNET_STATISTICS_update (stats, gettext_noop ("# active connections"), 1, 1199 GNUNET_STATISTICS_update (stats,
1200 gettext_noop ("# active connections"),
1201 1,
1197 GNUNET_NO); 1202 GNUNET_NO);
1203 return NULL;
1198} 1204}
1199 1205
1200 1206
@@ -1205,11 +1211,15 @@ handler_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
1205 * @param peer peer identity this notification is about 1211 * @param peer peer identity this notification is about
1206 */ 1212 */
1207static void 1213static void
1208handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 1214handler_disconnect (void *cls,
1215 const struct GNUNET_PeerIdentity *peer,
1216 void *internal_cls)
1209{ 1217{
1210 GNUNET_assert (stat_connection_count > 0); 1218 GNUNET_assert (stat_connection_count > 0);
1211 stat_connection_count--; 1219 stat_connection_count--;
1212 GNUNET_STATISTICS_update (stats, gettext_noop ("# active connections"), -1, 1220 GNUNET_STATISTICS_update (stats,
1221 gettext_noop ("# active connections"),
1222 -1,
1213 GNUNET_NO); 1223 GNUNET_NO);
1214} 1224}
1215 1225
@@ -1217,63 +1227,44 @@ handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1217/** 1227/**
1218 * Method called whenever an advertisement message arrives. 1228 * Method called whenever an advertisement message arrives.
1219 * 1229 *
1220 * @param cls closure (always NULL) 1230 * @param uri the advertised URI
1221 * @param peer the peer sending the message
1222 * @param message the actual message
1223 * @return #GNUNET_OK to keep the connection open,
1224 * #GNUNET_SYSERR to close it (signal serious error)
1225 */ 1231 */
1226static int 1232static void
1227handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer, 1233handler_advertisement (const char *uri)
1228 const struct GNUNET_MessageHeader *message)
1229{ 1234{
1230 size_t size;
1231 size_t uri_size; 1235 size_t uri_size;
1232 const struct GNUNET_MessageHeader *incoming;
1233 const char *uri;
1234 struct Hostlist *hostlist; 1236 struct Hostlist *hostlist;
1235 1237
1236 GNUNET_assert (ntohs (message->type) == 1238 uri_size = strlen (uri) + 1;
1237 GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
1238 size = ntohs (message->size);
1239 if (size <= sizeof (struct GNUNET_MessageHeader))
1240 {
1241 GNUNET_break_op (0);
1242 return GNUNET_SYSERR;
1243 }
1244 incoming = (const struct GNUNET_MessageHeader *) message;
1245 uri = (const char *) &incoming[1];
1246 uri_size = size - sizeof (struct GNUNET_MessageHeader);
1247 if (uri[uri_size - 1] != '\0')
1248 {
1249 GNUNET_break_op (0);
1250 return GNUNET_SYSERR;
1251 }
1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1253 "Hostlist client recieved advertisement from `%s' containing URI `%s'\n", 1240 "Hostlist client recieved advertisement containing URI `%s'\n",
1254 GNUNET_i2s (peer), uri); 1241 uri);
1255 if (GNUNET_NO != linked_list_contains (uri)) 1242 if (GNUNET_NO != linked_list_contains (uri))
1256 { 1243 {
1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); 1244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1258 return GNUNET_OK; 1245 "URI `%s' is already known\n",
1246 uri);
1247 return;
1259 } 1248 }
1260 1249
1261 if (GNUNET_NO == stat_testing_allowed) 1250 if (GNUNET_NO == stat_testing_allowed)
1262 { 1251 {
1263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1264 "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); 1253 "Currently not accepting new advertisements: interval between to advertisements is not reached\n");
1265 return GNUNET_SYSERR; 1254 return;
1266 } 1255 }
1267 if (GNUNET_YES == stat_testing_hostlist) 1256 if (GNUNET_YES == stat_testing_hostlist)
1268 { 1257 {
1269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1270 "Currently not accepting new advertisements: we are already testing a hostlist\n"); 1259 "Currently not accepting new advertisements: we are already testing a hostlist\n");
1271 return GNUNET_SYSERR; 1260 return;
1272 } 1261 }
1273 1262
1274 hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); 1263 hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size);
1275 hostlist->hostlist_uri = (const char *) &hostlist[1]; 1264 hostlist->hostlist_uri = (const char *) &hostlist[1];
1276 GNUNET_memcpy (&hostlist[1], uri, uri_size); 1265 GNUNET_memcpy (&hostlist[1],
1266 uri,
1267 uri_size);
1277 hostlist->time_creation = GNUNET_TIME_absolute_get (); 1268 hostlist->time_creation = GNUNET_TIME_absolute_get ();
1278 hostlist->quality = HOSTLIST_INITIAL; 1269 hostlist->quality = HOSTLIST_INITIAL;
1279 hostlist_to_test = hostlist; 1270 hostlist_to_test = hostlist;
@@ -1282,7 +1273,8 @@ handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer,
1282 stat_testing_allowed = GNUNET_NO; 1273 stat_testing_allowed = GNUNET_NO;
1283 ti_testing_intervall_task = 1274 ti_testing_intervall_task =
1284 GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, 1275 GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL,
1285 &task_testing_intervall_reset, NULL); 1276 &task_testing_intervall_reset,
1277 NULL);
1286 1278
1287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1288 "Testing new hostlist advertisements is locked for the next %s\n", 1280 "Testing new hostlist advertisements is locked for the next %s\n",
@@ -1290,9 +1282,8 @@ handler_advertisement (void *cls, const struct GNUNET_PeerIdentity *peer,
1290 GNUNET_YES)); 1282 GNUNET_YES));
1291 1283
1292 ti_download_dispatcher_task = 1284 ti_download_dispatcher_task =
1293 GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); 1285 GNUNET_SCHEDULER_add_now (&task_download_dispatcher,
1294 1286 NULL);
1295 return GNUNET_OK;
1296} 1287}
1297 1288
1298 1289
@@ -1557,9 +1548,9 @@ save_hostlist_file (int shutdown)
1557int 1548int
1558GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, 1549GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1559 struct GNUNET_STATISTICS_Handle *st, 1550 struct GNUNET_STATISTICS_Handle *st,
1560 GNUNET_CORE_ConnectEventHandler *ch, 1551 GNUNET_CORE_ConnecTEventHandler *ch,
1561 GNUNET_CORE_DisconnectEventHandler *dh, 1552 GNUNET_CORE_DisconnecTEventHandler *dh,
1562 GNUNET_CORE_MessageCallback *msgh, 1553 GNUNET_HOSTLIST_UriHandler *msgh,
1563 int learn) 1554 int learn)
1564{ 1555{
1565 char *filename; 1556 char *filename;
@@ -1578,23 +1569,31 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1578 /* Read proxy configuration */ 1569 /* Read proxy configuration */
1579 if (GNUNET_OK == 1570 if (GNUNET_OK ==
1580 GNUNET_CONFIGURATION_get_value_string (cfg, 1571 GNUNET_CONFIGURATION_get_value_string (cfg,
1581 "HOSTLIST", "PROXY", &proxy)) 1572 "HOSTLIST",
1573 "PROXY",
1574 &proxy))
1582 { 1575 {
1583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1584 "Found proxy host: `%s'\n", 1577 "Found proxy host: `%s'\n",
1585 proxy); 1578 proxy);
1586 /* proxy username */ 1579 /* proxy username */
1587 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, 1580 if (GNUNET_OK ==
1588 "HOSTLIST", "PROXY_USERNAME", &proxy_username)) 1581 GNUNET_CONFIGURATION_get_value_string (cfg,
1582 "HOSTLIST",
1583 "PROXY_USERNAME",
1584 &proxy_username))
1589 { 1585 {
1590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1591 "Found proxy username name: `%s'\n", 1587 "Found proxy username name: `%s'\n",
1592 proxy_username); 1588 proxy_username);
1593 } 1589 }
1594 1590
1595 /* proxy password */ 1591 /* proxy password */
1596 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, 1592 if (GNUNET_OK ==
1597 "HOSTLIST", "PROXY_PASSWORD", &proxy_password)) 1593 GNUNET_CONFIGURATION_get_value_string (cfg,
1594 "HOSTLIST",
1595 "PROXY_PASSWORD",
1596 &proxy_password))
1598 { 1597 {
1599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1600 "Found proxy password name: `%s'\n", 1599 "Found proxy password name: `%s'\n",
@@ -1659,7 +1658,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1659 load_hostlist_file (); 1658 load_hostlist_file ();
1660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1661 "Hostlists will be saved to file again in %s\n", 1660 "Hostlists will be saved to file again in %s\n",
1662 GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, GNUNET_YES)); 1661 GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL,
1662 GNUNET_YES));
1663 ti_saving_task = 1663 ti_saving_task =
1664 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, 1664 GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
1665 &task_hostlist_saving, 1665 &task_hostlist_saving,
@@ -1671,8 +1671,10 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1671 _("Learning is not enabled on this peer\n")); 1671 _("Learning is not enabled on this peer\n"));
1672 *msgh = NULL; 1672 *msgh = NULL;
1673 if (GNUNET_OK == 1673 if (GNUNET_OK ==
1674 GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", 1674 GNUNET_CONFIGURATION_get_value_filename (cfg,
1675 "HOSTLISTFILE", &filename)) 1675 "HOSTLIST",
1676 "HOSTLISTFILE",
1677 &filename))
1676 { 1678 {
1677 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 1679 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
1678 { 1680 {
@@ -1706,9 +1708,10 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
1706 } 1708 }
1707 else 1709 else
1708 { 1710 {
1709 ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 1711 ti_check_download
1710 &stat_timeout_task, 1712 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
1711 NULL); 1713 &stat_timeout_task,
1714 NULL);
1712 } 1715 }
1713 return GNUNET_OK; 1716 return GNUNET_OK;
1714} 1717}