aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
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
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')
-rw-r--r--src/namestore/gnunet-namestore.c1
-rw-r--r--src/namestore/gnunet-service-namestore.c34
-rw-r--r--src/namestore/namestore.h8
-rw-r--r--src/namestore/namestore_api_monitor.c31
-rw-r--r--src/namestore/test_namestore_api_monitoring.c3
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c9
6 files changed, 59 insertions, 27 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 36aae6056..f23988df6 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -718,6 +718,7 @@ testservice_task (void *cls,
718 { 718 {
719 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 719 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
720 &zone_pkey, 720 &zone_pkey,
721 GNUNET_YES,
721 &display_record, 722 &display_record,
722 &sync_cb, 723 &sync_cb,
723 NULL); 724 NULL);
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 53a685c63..b0704d7bd 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -144,11 +144,6 @@ struct ZoneMonitor
144 struct GNUNET_CRYPTO_EcdsaPrivateKey zone; 144 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
145 145
146 /** 146 /**
147 * The operation id fot the zone iteration in the response for the client
148 */
149 uint32_t request_id;
150
151 /**
152 * Task active during initial iteration. 147 * Task active during initial iteration.
153 */ 148 */
154 GNUNET_SCHEDULER_TaskIdentifier task; 149 GNUNET_SCHEDULER_TaskIdentifier task;
@@ -679,17 +674,36 @@ handle_record_store (void *cls,
679 if (GNUNET_OK == res) 674 if (GNUNET_OK == res)
680 { 675 {
681 for (zm = monitor_head; NULL != zm; zm = zm->next) 676 for (zm = monitor_head; NULL != zm; zm = zm->next)
677 {
682 if ( (0 == memcmp (&rp_msg->private_key, &zm->zone, 678 if ( (0 == memcmp (&rp_msg->private_key, &zm->zone,
683 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) || 679 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ||
684 (0 == memcmp (&zm->zone, 680 (0 == memcmp (&zm->zone,
685 &zero, 681 &zero,
686 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) 682 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
683 {
684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
685 "Notifying monitor about changes under label `%s'\n",
686 conv_name);
687 send_lookup_response (monitor_nc, 687 send_lookup_response (monitor_nc,
688 zm->nc->client, 688 zm->nc->client,
689 zm->request_id, 689 0,
690 &rp_msg->private_key, 690 &rp_msg->private_key,
691 conv_name, 691 conv_name,
692 rd_count, rd); 692 rd_count, rd);
693 }
694 else
695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
696 "Monitor is for another zone\n");
697 }
698 if (NULL == monitor_head)
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "No monitors active\n");
701 }
702 else
703 {
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
705 "Error storing record: %d\n",
706 res);
693 } 707 }
694 } 708 }
695 if (GNUNET_OK == res) 709 if (GNUNET_OK == res)
@@ -1186,7 +1200,7 @@ monitor_iterate_cb (void *cls,
1186 } 1200 }
1187 send_lookup_response (monitor_nc, 1201 send_lookup_response (monitor_nc,
1188 zm->nc->client, 1202 zm->nc->client,
1189 zm->request_id, 1203 0,
1190 zone_key, 1204 zone_key,
1191 name, 1205 name,
1192 rd_count, 1206 rd_count,
@@ -1215,7 +1229,6 @@ handle_monitor_start (void *cls,
1215 "ZONE_MONITOR_START"); 1229 "ZONE_MONITOR_START");
1216 zis_msg = (const struct ZoneMonitorStartMessage *) message; 1230 zis_msg = (const struct ZoneMonitorStartMessage *) message;
1217 zm = GNUNET_new (struct ZoneMonitor); 1231 zm = GNUNET_new (struct ZoneMonitor);
1218 zm->request_id = ntohl (zis_msg->gns_header.r_id);
1219 zm->offset = 0; 1232 zm->offset = 0;
1220 zm->nc = client_lookup (client); 1233 zm->nc = client_lookup (client);
1221 zm->zone = zis_msg->zone; 1234 zm->zone = zis_msg->zone;
@@ -1224,7 +1237,10 @@ handle_monitor_start (void *cls,
1224 GNUNET_SERVER_disable_receive_done_warning (client); 1237 GNUNET_SERVER_disable_receive_done_warning (client);
1225 GNUNET_SERVER_notification_context_add (monitor_nc, 1238 GNUNET_SERVER_notification_context_add (monitor_nc,
1226 client); 1239 client);
1227 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm); 1240 if (GNUNET_YES == ntohs (zis_msg->iterate_first))
1241 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm);
1242 else
1243 monitor_sync (zm);
1228} 1244}
1229 1245
1230 1246
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index b95358fa4..bd0cf82cc 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -353,7 +353,13 @@ struct ZoneMonitorStartMessage
353 /** 353 /**
354 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START 354 * Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
355 */ 355 */
356 struct GNUNET_NAMESTORE_Header gns_header; 356 struct GNUNET_MessageHeader header;
357
358 /**
359 * #GNUNET_YES to first iterate over all records,
360 * #GNUNET_NO to only monitor changes.o
361 */
362 uint32_t iterate_first GNUNET_PACKED;
357 363
358 /** 364 /**
359 * Zone key. 365 * Zone key.
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;
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index 0bd1e1350..c9b182fc8 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -274,7 +274,8 @@ run (void *cls,
274 274
275 /* Start monitoring */ 275 /* Start monitoring */
276 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 276 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
277 privkey, 277 privkey,
278 GNUNET_YES,
278 &zone_proc, 279 &zone_proc,
279 NULL, 280 NULL,
280 NULL); 281 NULL);
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index bab857def..16e4e4157 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -237,10 +237,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
237 { 237 {
238 /* Start monitoring */ 238 /* Start monitoring */
239 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 239 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
240 privkey, 240 privkey,
241 &zone_proc, 241 GNUNET_YES,
242 NULL, 242 &zone_proc,
243 NULL); 243 NULL,
244 NULL);
244 if (NULL == zm) 245 if (NULL == zm)
245 { 246 {
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone monitor\n"); 247 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone monitor\n");