diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-09 07:18:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-09 07:18:53 +0000 |
commit | a13d301ba2910e6df6c93eb4a15106a0323e46cc (patch) | |
tree | acf9f3c3189d65fff3a4a08f2bb33fe3be0b2153 | |
parent | cdb6307117f72f42da7889debc4b4e903e4ca953 (diff) | |
download | gnunet-a13d301ba2910e6df6c93eb4a15106a0323e46cc.tar.gz gnunet-a13d301ba2910e6df6c93eb4a15106a0323e46cc.zip |
add '-m' option to gnunet-namestore, extend namestore monitor API with notification about being in sync
-rw-r--r-- | doc/man/gnunet-namestore.1 | 3 | ||||
-rw-r--r-- | src/include/gnunet_namestore_service.h | 24 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 5 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 37 | ||||
-rw-r--r-- | src/namestore/namestore_api_monitor.c | 33 |
5 files changed, 91 insertions, 11 deletions
diff --git a/doc/man/gnunet-namestore.1 b/doc/man/gnunet-namestore.1 index 19c1ba285..f7a4695d7 100644 --- a/doc/man/gnunet-namestore.1 +++ b/doc/man/gnunet-namestore.1 | |||
@@ -34,6 +34,9 @@ Print short help on options. | |||
34 | .IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL" | 34 | .IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL" |
35 | Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR. | 35 | Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR. |
36 | .B | 36 | .B |
37 | .IP "\-m, \-\-monitor" | ||
38 | Monitor changes to the zone on an ongoing basis (in contrast to \-D, which merely displays the current records) | ||
39 | .B | ||
37 | .IP "\-n NAME, \-\-name=NAME" | 40 | .IP "\-n NAME, \-\-name=NAME" |
38 | Name of the record to add/delete/display | 41 | Name of the record to add/delete/display |
39 | .B | 42 | .B |
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 3966c3db2..70dbb5bb2 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -484,21 +484,37 @@ typedef void (*GNUNET_NAMESTORE_RecordMonitor)(void *cls, | |||
484 | 484 | ||
485 | 485 | ||
486 | /** | 486 | /** |
487 | * Function called once the monitor has caught up with the current | ||
488 | * state of the database. Will be called AGAIN after each disconnect | ||
489 | * (record monitor called with 'NULL' for zone_key) once we're again | ||
490 | * in sync. | ||
491 | * | ||
492 | * @param cls closure | ||
493 | */ | ||
494 | typedef void (*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls); | ||
495 | |||
496 | |||
497 | /** | ||
487 | * Begin monitoring a zone for changes. Will first call the 'monitor' function | 498 | * Begin monitoring a zone for changes. Will first call the 'monitor' function |
488 | * on all existing records in the selected zone(s) and then call it whenever | 499 | * on all existing records in the selected zone(s), then calls 'sync_cb', |
489 | * a record changes. | 500 | * and then calls the 'monitor' whenever a record changes. If the namestore |
501 | * disconnects, the 'monitor' function is called with a disconnect event; if | ||
502 | * the connection is re-established, the process begins from the start (all | ||
503 | * existing records, sync, then updates). | ||
490 | * | 504 | * |
491 | * @param cfg configuration to use to connect to namestore | 505 | * @param cfg configuration to use to connect to namestore |
492 | * @param zone zone to monitor, NULL for all zones | 506 | * @param zone zone to monitor, NULL for all zones |
493 | * @param monitor function to call on zone changes | 507 | * @param monitor function to call on zone changes |
494 | * @param monitor_cls closure for 'monitor' | 508 | * @param sync_cb function called when we're in sync with the namestore |
509 | * @param cls closure for 'monitor' and 'sync_cb' | ||
495 | * @return handle to stop monitoring | 510 | * @return handle to stop monitoring |
496 | */ | 511 | */ |
497 | struct GNUNET_NAMESTORE_ZoneMonitor * | 512 | struct GNUNET_NAMESTORE_ZoneMonitor * |
498 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 513 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
499 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 514 | const struct GNUNET_CRYPTO_ShortHashCode *zone, |
500 | GNUNET_NAMESTORE_RecordMonitor monitor, | 515 | GNUNET_NAMESTORE_RecordMonitor monitor, |
501 | void *monitor_cls); | 516 | GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, |
517 | void *cls); | ||
502 | 518 | ||
503 | 519 | ||
504 | /** | 520 | /** |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 9238924ee..c8e6a4d00 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1408,6 +1408,11 @@ extern "C" | |||
1408 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START 441 | 1408 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START 441 |
1409 | 1409 | ||
1410 | /** | 1410 | /** |
1411 | * Service to client: you're now in sync. | ||
1412 | */ | ||
1413 | #define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC 442 | ||
1414 | |||
1415 | /** | ||
1411 | * Client to service: please start iteration; receives | 1416 | * Client to service: please start iteration; receives |
1412 | * "GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE" messages in return. | 1417 | * "GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE" messages in return. |
1413 | */ | 1418 | */ |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index c43b18593..95f0b520f 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -163,6 +163,15 @@ static struct GNUNET_TIME_Absolute etime_abs; | |||
163 | */ | 163 | */ |
164 | static int etime_is_rel = GNUNET_SYSERR; | 164 | static int etime_is_rel = GNUNET_SYSERR; |
165 | 165 | ||
166 | /** | ||
167 | * Monitor handle. | ||
168 | */ | ||
169 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; | ||
170 | |||
171 | /** | ||
172 | * Enables monitor mode. | ||
173 | */ | ||
174 | static int monitor; | ||
166 | 175 | ||
167 | /** | 176 | /** |
168 | * Task run on shutdown. Cleans up everything. | 177 | * Task run on shutdown. Cleans up everything. |
@@ -215,6 +224,11 @@ do_shutdown (void *cls, | |||
215 | GNUNET_free (uri); | 224 | GNUNET_free (uri); |
216 | uri = NULL; | 225 | uri = NULL; |
217 | } | 226 | } |
227 | if (NULL != zm) | ||
228 | { | ||
229 | GNUNET_NAMESTORE_zone_monitor_stop (zm); | ||
230 | zm = NULL; | ||
231 | } | ||
218 | } | 232 | } |
219 | 233 | ||
220 | 234 | ||
@@ -358,6 +372,18 @@ display_record (void *cls, | |||
358 | 372 | ||
359 | 373 | ||
360 | /** | 374 | /** |
375 | * Function called once we are in sync in monitor mode. | ||
376 | * | ||
377 | * @param cls NULL | ||
378 | */ | ||
379 | static void | ||
380 | sync_cb (void *cls) | ||
381 | { | ||
382 | FPRINTF (stdout, "%s", "Monitor is now in sync.\n"); | ||
383 | } | ||
384 | |||
385 | |||
386 | /** | ||
361 | * We're storing a record; this function is given the existing record | 387 | * We're storing a record; this function is given the existing record |
362 | * so that we can merge the information. | 388 | * so that we can merge the information. |
363 | * | 389 | * |
@@ -643,6 +669,14 @@ key_generation_cb (void *cls, | |||
643 | &add_qe_uri); | 669 | &add_qe_uri); |
644 | } | 670 | } |
645 | GNUNET_free_non_null (data); | 671 | GNUNET_free_non_null (data); |
672 | if (monitor) | ||
673 | { | ||
674 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, | ||
675 | &zone, | ||
676 | &display_record, | ||
677 | &sync_cb, | ||
678 | NULL); | ||
679 | } | ||
646 | } | 680 | } |
647 | 681 | ||
648 | 682 | ||
@@ -740,6 +774,9 @@ main (int argc, char *const *argv) | |||
740 | {'e', "expiration", "TIME", | 774 | {'e', "expiration", "TIME", |
741 | gettext_noop ("expiration time for record to use (for adding only), \"never\" is possible"), 1, | 775 | gettext_noop ("expiration time for record to use (for adding only), \"never\" is possible"), 1, |
742 | &GNUNET_GETOPT_set_string, &expirationstring}, | 776 | &GNUNET_GETOPT_set_string, &expirationstring}, |
777 | {'m', "monitor", NULL, | ||
778 | gettext_noop ("monitor changes in the namestore"), 0, | ||
779 | &GNUNET_GETOPT_set_one, &monitor}, | ||
743 | {'n', "name", "NAME", | 780 | {'n', "name", "NAME", |
744 | gettext_noop ("name of the record to add/delete/display"), 1, | 781 | gettext_noop ("name of the record to add/delete/display"), 1, |
745 | &GNUNET_GETOPT_set_string, &name}, | 782 | &GNUNET_GETOPT_set_string, &name}, |
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index 5eb3e6803..8f6aacf19 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -56,9 +56,14 @@ struct GNUNET_NAMESTORE_ZoneMonitor | |||
56 | GNUNET_NAMESTORE_RecordMonitor monitor; | 56 | GNUNET_NAMESTORE_RecordMonitor monitor; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Closure for 'monitor'. | 59 | * Function called when we've synchronized. |
60 | */ | 60 | */ |
61 | void *monitor_cls; | 61 | GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb; |
62 | |||
63 | /** | ||
64 | * Closure for 'monitor' and 'sync_cb'. | ||
65 | */ | ||
66 | void *cls; | ||
62 | 67 | ||
63 | /** | 68 | /** |
64 | * Transmission handle to client. | 69 | * Transmission handle to client. |
@@ -101,7 +106,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
101 | { | 106 | { |
102 | if (NULL != zm->h) | 107 | if (NULL != zm->h) |
103 | GNUNET_CLIENT_disconnect (zm->h); | 108 | GNUNET_CLIENT_disconnect (zm->h); |
104 | zm->monitor (zm->monitor_cls, | 109 | zm->monitor (zm->cls, |
105 | NULL, | 110 | NULL, |
106 | GNUNET_TIME_UNIT_ZERO_ABS, | 111 | GNUNET_TIME_UNIT_ZERO_ABS, |
107 | NULL, 0, NULL, NULL); | 112 | NULL, 0, NULL, NULL); |
@@ -142,6 +147,17 @@ handle_updates (void *cls, | |||
142 | reconnect (zm); | 147 | reconnect (zm); |
143 | return; | 148 | return; |
144 | } | 149 | } |
150 | if ( (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)) && | ||
151 | (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC == ntohs (msg->type) ) ) | ||
152 | { | ||
153 | GNUNET_CLIENT_receive (zm->h, | ||
154 | &handle_updates, | ||
155 | zm, | ||
156 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
157 | if (NULL != zm->sync_cb) | ||
158 | zm->sync_cb (zm->cls); | ||
159 | return; | ||
160 | } | ||
145 | if ( (ntohs (msg->size) < sizeof (struct LookupNameResponseMessage)) || | 161 | if ( (ntohs (msg->size) < sizeof (struct LookupNameResponseMessage)) || |
146 | (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE != ntohs (msg->type) ) ) | 162 | (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE != ntohs (msg->type) ) ) |
147 | { | 163 | { |
@@ -189,7 +205,7 @@ handle_updates (void *cls, | |||
189 | &handle_updates, | 205 | &handle_updates, |
190 | zm, | 206 | zm, |
191 | GNUNET_TIME_UNIT_FOREVER_REL); | 207 | GNUNET_TIME_UNIT_FOREVER_REL); |
192 | zm->monitor(zm->monitor_cls, | 208 | zm->monitor(zm->cls, |
193 | &lrm->public_key, expire, | 209 | &lrm->public_key, expire, |
194 | name_tmp, | 210 | name_tmp, |
195 | rd_count, rd, &lrm->signature); | 211 | rd_count, rd, &lrm->signature); |
@@ -238,14 +254,16 @@ transmit_monitor_message (void *cls, | |||
238 | * @param cfg configuration to use to connect to namestore | 254 | * @param cfg configuration to use to connect to namestore |
239 | * @param zone zone to monitor, NULL for all zones | 255 | * @param zone zone to monitor, NULL for all zones |
240 | * @param monitor function to call on zone changes | 256 | * @param monitor function to call on zone changes |
241 | * @param monitor_cls closure for 'monitor' | 257 | * @param sync_cb function called when we're in sync with the namestore |
258 | * @param cls closure for 'monitor' and 'sync_cb' | ||
242 | * @return handle to stop monitoring | 259 | * @return handle to stop monitoring |
243 | */ | 260 | */ |
244 | struct GNUNET_NAMESTORE_ZoneMonitor * | 261 | struct GNUNET_NAMESTORE_ZoneMonitor * |
245 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 262 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
246 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 263 | const struct GNUNET_CRYPTO_ShortHashCode *zone, |
247 | GNUNET_NAMESTORE_RecordMonitor monitor, | 264 | GNUNET_NAMESTORE_RecordMonitor monitor, |
248 | void *monitor_cls) | 265 | GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, |
266 | void *cls) | ||
249 | { | 267 | { |
250 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 268 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
251 | struct GNUNET_CLIENT_Connection *client; | 269 | struct GNUNET_CLIENT_Connection *client; |
@@ -260,7 +278,8 @@ GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *c | |||
260 | else | 278 | else |
261 | zm->zone = *zone; | 279 | zm->zone = *zone; |
262 | zm->monitor = monitor; | 280 | zm->monitor = monitor; |
263 | zm->monitor_cls = monitor_cls; | 281 | zm->sync_cb = sync_cb; |
282 | zm->cls = cls; | ||
264 | zm->th = GNUNET_CLIENT_notify_transmit_ready (zm->h, | 283 | zm->th = GNUNET_CLIENT_notify_transmit_ready (zm->h, |
265 | sizeof (struct ZoneMonitorStartMessage), | 284 | sizeof (struct ZoneMonitorStartMessage), |
266 | GNUNET_TIME_UNIT_FOREVER_REL, | 285 | GNUNET_TIME_UNIT_FOREVER_REL, |