diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-02 17:27:36 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-02 17:27:42 +0200 |
commit | 7fc3ecc8e8859e8cd47c37457f7991460d81b1ed (patch) | |
tree | baab47fe05f324b10263bcd92828d74ffc1a5b63 /src/namestore | |
parent | 32cc463b677a8bc46b61111fe1bbc38554cb2ca0 (diff) | |
download | gnunet-7fc3ecc8e8859e8cd47c37457f7991460d81b1ed.tar.gz gnunet-7fc3ecc8e8859e8cd47c37457f7991460d81b1ed.zip |
start preparations for flow control by namestore monitors
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 59 | ||||
-rw-r--r-- | src/namestore/namestore.h | 28 | ||||
-rw-r--r-- | src/namestore/namestore_api_monitor.c | 39 |
3 files changed, 121 insertions, 5 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index fa189dbc3..f47c8776b 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -169,6 +169,12 @@ struct ZoneMonitor | |||
169 | */ | 169 | */ |
170 | uint64_t seq; | 170 | uint64_t seq; |
171 | 171 | ||
172 | /** | ||
173 | * Current limit of how many more messages we are allowed | ||
174 | * to queue to this monitor. | ||
175 | */ | ||
176 | uint64_t limit; | ||
177 | |||
172 | }; | 178 | }; |
173 | 179 | ||
174 | 180 | ||
@@ -1667,7 +1673,7 @@ monitor_iterate_cb (void *cls, | |||
1667 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message | 1673 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message |
1668 | * | 1674 | * |
1669 | * @param cls the client sending the message | 1675 | * @param cls the client sending the message |
1670 | * @param message message from the client | 1676 | * @param zis_msg message from the client |
1671 | */ | 1677 | */ |
1672 | static void | 1678 | static void |
1673 | handle_monitor_start (void *cls, | 1679 | handle_monitor_start (void *cls, |
@@ -1685,7 +1691,7 @@ handle_monitor_start (void *cls, | |||
1685 | monitor_tail, | 1691 | monitor_tail, |
1686 | zm); | 1692 | zm); |
1687 | GNUNET_SERVICE_client_mark_monitor (nc->client); | 1693 | GNUNET_SERVICE_client_mark_monitor (nc->client); |
1688 | GNUNET_SERVICE_client_disable_continue_warning (nc->client); | 1694 | GNUNET_SERVICE_client_continue (nc->client); |
1689 | GNUNET_notification_context_add (monitor_nc, | 1695 | GNUNET_notification_context_add (monitor_nc, |
1690 | nc->mq); | 1696 | nc->mq); |
1691 | if (GNUNET_YES == ntohl (zis_msg->iterate_first)) | 1697 | if (GNUNET_YES == ntohl (zis_msg->iterate_first)) |
@@ -1733,6 +1739,51 @@ monitor_next (void *cls) | |||
1733 | 1739 | ||
1734 | 1740 | ||
1735 | /** | 1741 | /** |
1742 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT message | ||
1743 | * | ||
1744 | * @param cls the client sending the message | ||
1745 | * @param nm message from the client | ||
1746 | */ | ||
1747 | static void | ||
1748 | handle_monitor_next (void *cls, | ||
1749 | const struct ZoneMonitorNextMessage *nm) | ||
1750 | { | ||
1751 | struct NamestoreClient *nc = cls; | ||
1752 | struct ZoneMonitor *zm; | ||
1753 | uint64_t inc; | ||
1754 | |||
1755 | inc = GNUNET_ntohll (nm->limit); | ||
1756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1757 | "Received ZONE_MONITOR_NEXT message with limit %llu\n", | ||
1758 | (unsigned long long) inc); | ||
1759 | for (zm = monitor_head; NULL != zm; zm = zm->next) | ||
1760 | if (zm->nc == nc) | ||
1761 | break; | ||
1762 | if (NULL == zm) | ||
1763 | { | ||
1764 | GNUNET_break (0); | ||
1765 | GNUNET_SERVICE_client_drop (nc->client); | ||
1766 | return; | ||
1767 | } | ||
1768 | GNUNET_SERVICE_client_continue (nc->client); | ||
1769 | if (zm->limit + inc < zm->limit) | ||
1770 | { | ||
1771 | GNUNET_break (0); | ||
1772 | GNUNET_SERVICE_client_drop (nc->client); | ||
1773 | return; | ||
1774 | } | ||
1775 | zm->limit += inc; | ||
1776 | #if 0 | ||
1777 | if (GNUNET_YES == ntohl (zis_msg->iterate_first)) | ||
1778 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, | ||
1779 | zm); | ||
1780 | else | ||
1781 | monitor_sync (zm); | ||
1782 | #endif | ||
1783 | } | ||
1784 | |||
1785 | |||
1786 | /** | ||
1736 | * Process namestore requests. | 1787 | * Process namestore requests. |
1737 | * | 1788 | * |
1738 | * @param cls closure | 1789 | * @param cls closure |
@@ -1831,6 +1882,10 @@ GNUNET_SERVICE_MAIN | |||
1831 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, | 1882 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, |
1832 | struct ZoneMonitorStartMessage, | 1883 | struct ZoneMonitorStartMessage, |
1833 | NULL), | 1884 | NULL), |
1885 | GNUNET_MQ_hd_fixed_size (monitor_next, | ||
1886 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT, | ||
1887 | struct ZoneMonitorNextMessage, | ||
1888 | NULL), | ||
1834 | GNUNET_MQ_handler_end ()); | 1889 | GNUNET_MQ_handler_end ()); |
1835 | 1890 | ||
1836 | 1891 | ||
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index 207b35662..679ca3d3d 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -161,7 +161,7 @@ struct LabelLookupResponseMessage | |||
161 | * Length of serialized record data | 161 | * Length of serialized record data |
162 | */ | 162 | */ |
163 | uint16_t rd_len GNUNET_PACKED; | 163 | uint16_t rd_len GNUNET_PACKED; |
164 | 164 | ||
165 | /** | 165 | /** |
166 | * Number of records contained | 166 | * Number of records contained |
167 | */ | 167 | */ |
@@ -319,6 +319,32 @@ struct ZoneMonitorStartMessage | |||
319 | 319 | ||
320 | 320 | ||
321 | /** | 321 | /** |
322 | * Ask for next result of zone iteration for the given operation | ||
323 | */ | ||
324 | struct ZoneMonitorNextMessage | ||
325 | { | ||
326 | /** | ||
327 | * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT | ||
328 | */ | ||
329 | struct GNUNET_MessageHeader header; | ||
330 | |||
331 | /** | ||
332 | * Always zero. | ||
333 | */ | ||
334 | uint32_t reserved; | ||
335 | |||
336 | /** | ||
337 | * Number of records to return to the iterator in one shot | ||
338 | * (before #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_MONITOR_NEXT | ||
339 | * should be send again). In NBO. | ||
340 | */ | ||
341 | uint64_t limit; | ||
342 | |||
343 | }; | ||
344 | |||
345 | |||
346 | |||
347 | /** | ||
322 | * Start a zone iteration for the given zone | 348 | * Start a zone iteration for the given zone |
323 | */ | 349 | */ |
324 | struct ZoneIterationStartMessage | 350 | struct ZoneIterationStartMessage |
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index 8e6d39ad7..9ba90833b 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2013, 2016, 2018 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 |
@@ -17,7 +17,6 @@ | |||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * @file namestore/namestore_api_monitor.c | 21 | * @file namestore/namestore_api_monitor.c |
23 | * @brief API to monitor changes in the NAMESTORE | 22 | * @brief API to monitor changes in the NAMESTORE |
@@ -340,6 +339,42 @@ GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *c | |||
340 | 339 | ||
341 | 340 | ||
342 | /** | 341 | /** |
342 | * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start | ||
343 | * for the next record(s). This function is used to allow clients that merely | ||
344 | * monitor the NAMESTORE to still throttle namestore operations, so we can be | ||
345 | * sure that the monitors can keep up. | ||
346 | * | ||
347 | * Note that #GNUNET_NAMESTORE_records_store() only waits for this | ||
348 | * call if the previous limit set by the client was already reached. | ||
349 | * Thus, by using a @a limit greater than 1, monitors basically enable | ||
350 | * a queue of notifications to be processed asynchronously with some | ||
351 | * delay. Note that even with a limit of 1 the | ||
352 | * #GNUNET_NAMESTORE_records_store() function will run asynchronously | ||
353 | * and the continuation may be invoked before the monitors completed | ||
354 | * (or even started) processing the notification. Thus, monitors will | ||
355 | * only closely track the current state of the namestore, but not | ||
356 | * be involved in the transactions. | ||
357 | * | ||
358 | * @param zm the monitor | ||
359 | * @param limit number of records to return to the iterator in one shot | ||
360 | * (before #GNUNET_NAMESTORE_zone_monitor_next is to be called again) | ||
361 | */ | ||
362 | void | ||
363 | GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm, | ||
364 | uint64_t limit) | ||
365 | { | ||
366 | struct GNUNET_MQ_Envelope *env; | ||
367 | struct ZoneMonitorNextMessage *nm; | ||
368 | |||
369 | env = GNUNET_MQ_msg (nm, | ||
370 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); | ||
371 | nm->limit = GNUNET_htonll (limit); | ||
372 | GNUNET_MQ_send (zm->mq, | ||
373 | env); | ||
374 | } | ||
375 | |||
376 | |||
377 | /** | ||
343 | * Stop monitoring a zone for changes. | 378 | * Stop monitoring a zone for changes. |
344 | * | 379 | * |
345 | * @param zm handle to the monitor activity to stop | 380 | * @param zm handle to the monitor activity to stop |