aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api_monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/namestore_api_monitor.c')
-rw-r--r--src/namestore/namestore_api_monitor.c76
1 files changed, 52 insertions, 24 deletions
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 6670e54ce..968d7ed58 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -65,6 +65,16 @@ struct GNUNET_NAMESTORE_ZoneMonitor
65 GNUNET_NAMESTORE_RecordMonitor monitor; 65 GNUNET_NAMESTORE_RecordMonitor monitor;
66 66
67 /** 67 /**
68 * Function to call on events.
69 */
70 GNUNET_NAMESTORE_RecordSetMonitor monitor2;
71
72 /**
73 * Record set filter for this monitor
74 */
75 enum GNUNET_GNSRECORD_Filter filter;
76
77 /**
68 * Closure for @e monitor. 78 * Closure for @e monitor.
69 */ 79 */
70 void *monitor_cls; 80 void *monitor_cls;
@@ -213,7 +223,11 @@ handle_result (void *cls, const struct RecordResultMessage *lrm)
213 GNUNET_assert ( 223 GNUNET_assert (
214 GNUNET_OK == 224 GNUNET_OK ==
215 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)); 225 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd));
216 zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); 226 if (NULL != zm->monitor2)
227 zm->monitor2 (zm->monitor_cls, &lrm->private_key, name_tmp,
228 rd_count, rd, GNUNET_TIME_absolute_ntoh (lrm->expire));
229 else
230 zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd);
217 } 231 }
218} 232}
219 233
@@ -272,33 +286,11 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
272 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); 286 env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
273 sm->iterate_first = htonl (zm->iterate_first); 287 sm->iterate_first = htonl (zm->iterate_first);
274 sm->zone = zm->zone; 288 sm->zone = zm->zone;
289 sm->filter = htons ((uint16_t) zm->filter);
275 GNUNET_MQ_send (zm->mq, env); 290 GNUNET_MQ_send (zm->mq, env);
276} 291}
277 292
278 293
279/**
280 * Begin monitoring a zone for changes. If @a iterate_first is set,
281 * we Will first call the @a monitor function on all existing records
282 * in the selected zone(s). In any case, we will call @a sync and
283 * afterwards call @a monitor whenever a record changes.
284 *
285 * @param cfg configuration to use to connect to namestore
286 * @param zone zone to monitor
287 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
288 * #GNUNET_NO to only return changes that happen from now
289 * on
290 * @param error_cb function to call on error (i.e. disconnect); note that
291 * unlike the other error callbacks in this API, a call to this
292 * function does NOT destroy the monitor handle, it merely signals
293 * that monitoring is down. You need to still explicitly call
294 * #GNUNET_NAMESTORE_zone_monitor_stop().
295 * @param error_cb_cls closure for @a error_cb
296 * @param monitor function to call on zone changes
297 * @param monitor_cls closure for @a monitor
298 * @param sync_cb function called when we're in sync with the namestore
299 * @param cls closure for @a sync_cb
300 * @return handle to stop monitoring
301 */
302struct GNUNET_NAMESTORE_ZoneMonitor * 294struct GNUNET_NAMESTORE_ZoneMonitor *
303GNUNET_NAMESTORE_zone_monitor_start ( 295GNUNET_NAMESTORE_zone_monitor_start (
304 const struct GNUNET_CONFIGURATION_Handle *cfg, 296 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -333,6 +325,42 @@ GNUNET_NAMESTORE_zone_monitor_start (
333 return zm; 325 return zm;
334} 326}
335 327
328struct GNUNET_NAMESTORE_ZoneMonitor *
329GNUNET_NAMESTORE_zone_monitor_start2 (
330 const struct GNUNET_CONFIGURATION_Handle *cfg,
331 const struct GNUNET_IDENTITY_PrivateKey *zone,
332 int iterate_first,
333 GNUNET_SCHEDULER_TaskCallback error_cb,
334 void *error_cb_cls,
335 GNUNET_NAMESTORE_RecordSetMonitor monitor,
336 void *monitor_cls,
337 GNUNET_SCHEDULER_TaskCallback sync_cb,
338 void *sync_cb_cls,
339 enum GNUNET_GNSRECORD_Filter filter)
340{
341 struct GNUNET_NAMESTORE_ZoneMonitor *zm;
342
343 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
344 if (NULL != zone)
345 zm->zone = *zone;
346 zm->iterate_first = iterate_first;
347 zm->error_cb = error_cb;
348 zm->error_cb_cls = error_cb_cls;
349 zm->monitor2 = monitor;
350 zm->monitor_cls = monitor_cls;
351 zm->sync_cb = sync_cb;
352 zm->sync_cb_cls = sync_cb_cls;
353 zm->cfg = cfg;
354 zm->filter = filter;
355 reconnect (zm);
356 if (NULL == zm->mq)
357 {
358 GNUNET_free (zm);
359 return NULL;
360 }
361 return zm;
362}
363
336 364
337/** 365/**
338 * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start 366 * Calls the monitor processor specified in #GNUNET_NAMESTORE_zone_monitor_start