aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api_monitor.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-20 17:58:46 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-20 17:58:46 +0000
commitc1ff578c693e4e45125ead915dc515bb141883ec (patch)
treee4573d2a5cc18aca5bcf3942a3fc267ef13fbc28 /src/namestore/namestore_api_monitor.c
parent379bca7ce074b828fc09f592fcae2e94945da6cd (diff)
downloadgnunet-c1ff578c693e4e45125ead915dc515bb141883ec.tar.gz
gnunet-c1ff578c693e4e45125ead915dc515bb141883ec.zip
-allow namestore to monitor ALL zones, and to optionally only monitor changes
Diffstat (limited to 'src/namestore/namestore_api_monitor.c')
-rw-r--r--src/namestore/namestore_api_monitor.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 076add1eb..4319f574f 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -75,6 +75,11 @@ struct GNUNET_NAMESTORE_ZoneMonitor
75 */ 75 */
76 struct GNUNET_CRYPTO_EcdsaPrivateKey zone; 76 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
77 77
78 /**
79 * Do we first iterate over all existing records?
80 */
81 int iterate_first;
82
78}; 83};
79 84
80 85
@@ -228,9 +233,9 @@ transmit_monitor_message (void *cls,
228 reconnect (zm); 233 reconnect (zm);
229 return 0; 234 return 0;
230 } 235 }
231 sm.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); 236 sm.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
232 sm.gns_header.header.size = htons (sizeof (struct ZoneMonitorStartMessage)); 237 sm.header.size = htons (sizeof (struct ZoneMonitorStartMessage));
233 sm.gns_header.r_id = htonl (0); 238 sm.iterate_first = htonl (zm->iterate_first);
234 sm.zone = zm->zone; 239 sm.zone = zm->zone;
235 memcpy (buf, &sm, sizeof (sm)); 240 memcpy (buf, &sm, sizeof (sm));
236 GNUNET_CLIENT_receive (zm->h, 241 GNUNET_CLIENT_receive (zm->h,
@@ -242,20 +247,24 @@ transmit_monitor_message (void *cls,
242 247
243 248
244/** 249/**
245 * Begin monitoring a zone for changes. Will first call the 'monitor' function 250 * Begin monitoring a zone for changes. If @a iterate_first is set,
246 * on all existing records in the selected zone(s) and then call it whenever 251 * we Will first call the @a monitor function on all existing records
247 * a record changes. 252 * in the selected zone(s). In any case, we will call @a sync and
253 * afterwards call @a monitor whenever a record changes.
248 * 254 *
249 * @param cfg configuration to use to connect to namestore 255 * @param cfg configuration to use to connect to namestore
250 * @param zone zone to monitor 256 * @param zone zone to monitor
257 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
258 * #GNUNET_NO to only return changes that happen from now on
251 * @param monitor function to call on zone changes 259 * @param monitor function to call on zone changes
252 * @param sync_cb function called when we're in sync with the namestore 260 * @param sync_cb function called when we're in sync with the namestore
253 * @param cls closure for 'monitor' and 'sync_cb' 261 * @param cls closure for @a monitor and @a sync_cb
254 * @return handle to stop monitoring 262 * @return handle to stop monitoring
255 */ 263 */
256struct GNUNET_NAMESTORE_ZoneMonitor * 264struct GNUNET_NAMESTORE_ZoneMonitor *
257GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 265GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
258 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 266 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
267 int iterate_first,
259 GNUNET_NAMESTORE_RecordMonitor monitor, 268 GNUNET_NAMESTORE_RecordMonitor monitor,
260 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, 269 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
261 void *cls) 270 void *cls)
@@ -263,16 +272,14 @@ GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *c
263 struct GNUNET_NAMESTORE_ZoneMonitor *zm; 272 struct GNUNET_NAMESTORE_ZoneMonitor *zm;
264 struct GNUNET_CLIENT_Connection *client; 273 struct GNUNET_CLIENT_Connection *client;
265 274
266 if (NULL == zone)
267 return NULL;
268 if (NULL == (client = GNUNET_CLIENT_connect ("namestore", cfg))) 275 if (NULL == (client = GNUNET_CLIENT_connect ("namestore", cfg)))
269 return NULL; 276 return NULL;
270
271
272 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor); 277 zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
273 zm->cfg = cfg; 278 zm->cfg = cfg;
274 zm->h = client; 279 zm->h = client;
275 zm->zone = *zone; 280 if (NULL != zone)
281 zm->zone = *zone;
282 zm->iterate_first = iterate_first;
276 zm->monitor = monitor; 283 zm->monitor = monitor;
277 zm->sync_cb = sync_cb; 284 zm->sync_cb = sync_cb;
278 zm->cls = cls; 285 zm->cls = cls;