aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api_monitor.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
commit03374cc39814fa4bfb8d96e1165c688c44d8342f (patch)
treeed772250c49b39d82b9708ec8df0ee3e07e366d1 /src/namestore/namestore_api_monitor.c
parent0c13a1e6fb0baffd83d413f313742a5f2b420297 (diff)
downloadgnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.tar.gz
gnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.zip
make namestore API less brittle/sublte to use
Diffstat (limited to 'src/namestore/namestore_api_monitor.c')
-rw-r--r--src/namestore/namestore_api_monitor.c52
1 files changed, 38 insertions, 14 deletions
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c
index 85131f9cc..7e75b07e5 100644
--- a/src/namestore/namestore_api_monitor.c
+++ b/src/namestore/namestore_api_monitor.c
@@ -51,19 +51,34 @@ struct GNUNET_NAMESTORE_ZoneMonitor
51 struct GNUNET_MQ_Handle *mq; 51 struct GNUNET_MQ_Handle *mq;
52 52
53 /** 53 /**
54 * Function to call on errors.
55 */
56 GNUNET_SCHEDULER_TaskCallback error_cb;
57
58 /**
59 * Closure for @e error_cb.
60 */
61 void *error_cb_cls;
62
63 /**
54 * Function to call on events. 64 * Function to call on events.
55 */ 65 */
56 GNUNET_NAMESTORE_RecordMonitor monitor; 66 GNUNET_NAMESTORE_RecordMonitor monitor;
57 67
58 /** 68 /**
69 * Closure for @e monitor.
70 */
71 void *monitor_cls;
72
73 /**
59 * Function called when we've synchronized. 74 * Function called when we've synchronized.
60 */ 75 */
61 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb; 76 GNUNET_SCHEDULER_TaskCallback sync_cb;
62 77
63 /** 78 /**
64 * Closure for @e monitor and @e sync_cb. 79 * Closure for @e sync_cb.
65 */ 80 */
66 void *cls; 81 void *sync_cb_cls;
67 82
68 /** 83 /**
69 * Monitored zone. 84 * Monitored zone.
@@ -100,7 +115,7 @@ handle_sync (void *cls,
100 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; 115 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
101 116
102 if (NULL != zm->sync_cb) 117 if (NULL != zm->sync_cb)
103 zm->sync_cb (zm->cls); 118 zm->sync_cb (zm->sync_cb_cls);
104} 119}
105 120
106 121
@@ -193,7 +208,7 @@ handle_result (void *cls,
193 rd_ser_tmp, 208 rd_ser_tmp,
194 rd_count, 209 rd_count,
195 rd)); 210 rd));
196 zm->monitor (zm->cls, 211 zm->monitor (zm->monitor_cls,
197 &lrm->private_key, 212 &lrm->private_key,
198 name_tmp, 213 name_tmp,
199 rd_count, 214 rd_count,
@@ -245,11 +260,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
245 if (NULL != zm->mq) 260 if (NULL != zm->mq)
246 { 261 {
247 GNUNET_MQ_destroy (zm->mq); 262 GNUNET_MQ_destroy (zm->mq);
248 zm->monitor (zm->cls, 263 zm->error_cb (zm->error_cb_cls);
249 NULL,
250 NULL,
251 0,
252 NULL);
253 } 264 }
254 zm->mq = GNUNET_CLIENT_connecT (zm->cfg, 265 zm->mq = GNUNET_CLIENT_connecT (zm->cfg,
255 "namestore", 266 "namestore",
@@ -278,18 +289,28 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
278 * @param zone zone to monitor 289 * @param zone zone to monitor
279 * @param iterate_first #GNUNET_YES to first iterate over all existing records, 290 * @param iterate_first #GNUNET_YES to first iterate over all existing records,
280 * #GNUNET_NO to only return changes that happen from now on 291 * #GNUNET_NO to only return changes that happen from now on
292 * @param error_cb function to call on error (i.e. disconnect); note that
293 * unlike the other error callbacks in this API, a call to this
294 * function does NOT destroy the monitor handle, it merely signals
295 * that monitoring is down. You need to still explicitly call
296 * #GNUNET_NAMESTORE_zone_monitor_stop().
297 * @param error_cb_cls closure for @a error_cb
281 * @param monitor function to call on zone changes 298 * @param monitor function to call on zone changes
299 * @param monitor_cls closure for @a monitor
282 * @param sync_cb function called when we're in sync with the namestore 300 * @param sync_cb function called when we're in sync with the namestore
283 * @param cls closure for @a monitor and @a sync_cb 301 * @param cls closure for @a sync_cb
284 * @return handle to stop monitoring 302 * @return handle to stop monitoring
285 */ 303 */
286struct GNUNET_NAMESTORE_ZoneMonitor * 304struct GNUNET_NAMESTORE_ZoneMonitor *
287GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 305GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
288 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 306 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
289 int iterate_first, 307 int iterate_first,
308 GNUNET_SCHEDULER_TaskCallback error_cb,
309 void *error_cb_cls,
290 GNUNET_NAMESTORE_RecordMonitor monitor, 310 GNUNET_NAMESTORE_RecordMonitor monitor,
291 GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, 311 void *monitor_cls,
292 void *cls) 312 GNUNET_SCHEDULER_TaskCallback sync_cb,
313 void *sync_cb_cls)
293{ 314{
294 struct GNUNET_NAMESTORE_ZoneMonitor *zm; 315 struct GNUNET_NAMESTORE_ZoneMonitor *zm;
295 316
@@ -297,9 +318,12 @@ GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *c
297 if (NULL != zone) 318 if (NULL != zone)
298 zm->zone = *zone; 319 zm->zone = *zone;
299 zm->iterate_first = iterate_first; 320 zm->iterate_first = iterate_first;
321 zm->error_cb = error_cb;
322 zm->error_cb_cls = error_cb_cls;
300 zm->monitor = monitor; 323 zm->monitor = monitor;
324 zm->monitor_cls = monitor_cls;
301 zm->sync_cb = sync_cb; 325 zm->sync_cb = sync_cb;
302 zm->cls = cls; 326 zm->sync_cb_cls = sync_cb_cls;
303 zm->cfg = cfg; 327 zm->cfg = cfg;
304 reconnect (zm); 328 reconnect (zm);
305 if (NULL == zm->mq) 329 if (NULL == zm->mq)