[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r30368 - in gnunet/src: include namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r30368 - in gnunet/src: include namestore |
Date: |
Sun, 20 Oct 2013 19:58:46 +0200 |
Author: grothoff
Date: 2013-10-20 19:58:46 +0200 (Sun, 20 Oct 2013)
New Revision: 30368
Modified:
gnunet/src/include/gnunet_namestore_service.h
gnunet/src/namestore/gnunet-namestore.c
gnunet/src/namestore/gnunet-service-namestore.c
gnunet/src/namestore/namestore.h
gnunet/src/namestore/namestore_api_monitor.c
gnunet/src/namestore/test_namestore_api_monitoring.c
gnunet/src/namestore/test_namestore_api_monitoring_existing.c
Log:
-allow namestore to monitor ALL zones, and to optionally only monitor changes
Modified: gnunet/src/include/gnunet_namestore_service.h
===================================================================
--- gnunet/src/include/gnunet_namestore_service.h 2013-10-20 16:31:05 UTC
(rev 30367)
+++ gnunet/src/include/gnunet_namestore_service.h 2013-10-20 17:58:46 UTC
(rev 30368)
@@ -247,15 +247,20 @@
/**
- * Begin monitoring a zone for changes. Will first call the @a monitor
function
- * on all existing records in the selected zone(s), then calls @a sync_cb,
- * and then calls the @a monitor whenever a record changes. If the namestore
- * disconnects, the @a monitor function is called with a disconnect event; if
- * the connection is re-established, the process begins from the start (all
- * existing records, sync, then updates).
+ * Begin monitoring a zone for changes. Will first call the @a
+ * monitor function on all existing records in the selected zone(s) if
+ * @a iterate_first is #GNUNET_YES. In any case, we will then call @a
+ * sync_cb, and then afterwards call the @a monitor whenever a record
+ * changes. If the namestore disconnects, the @a monitor function is
+ * called with a disconnect event; if the connection is
+ * re-established, the process begins from the start (depending on @a
+ * iterate_first, we first do all existing records, then @a sync, then
+ * updates).
*
* @param cfg configuration to use to connect to namestore
- * @param zone zone to monitor
+ * @param zone zone to monitor, NULL for all zones
+ * @param iterate_first #GNUNET_YES to first iterate over all existing records,
+ * #GNUNET_NO to only return changes that happen from now
on
* @param monitor function to call on zone changes
* @param sync_cb function called when we're in sync with the namestore
* @param cls closure for @a monitor and @a sync_cb
@@ -264,6 +269,7 @@
struct GNUNET_NAMESTORE_ZoneMonitor *
GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle
*cfg,
const struct GNUNET_CRYPTO_EcdsaPrivateKey
*zone,
+ int iterate_first,
GNUNET_NAMESTORE_RecordMonitor monitor,
GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
void *cls);
Modified: gnunet/src/namestore/gnunet-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-namestore.c 2013-10-20 16:31:05 UTC (rev
30367)
+++ gnunet/src/namestore/gnunet-namestore.c 2013-10-20 17:58:46 UTC (rev
30368)
@@ -718,6 +718,7 @@
{
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
&zone_pkey,
+ GNUNET_YES,
&display_record,
&sync_cb,
NULL);
Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c 2013-10-20 16:31:05 UTC
(rev 30367)
+++ gnunet/src/namestore/gnunet-service-namestore.c 2013-10-20 17:58:46 UTC
(rev 30368)
@@ -144,11 +144,6 @@
struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
/**
- * The operation id fot the zone iteration in the response for the client
- */
- uint32_t request_id;
-
- /**
* Task active during initial iteration.
*/
GNUNET_SCHEDULER_TaskIdentifier task;
@@ -679,18 +674,37 @@
if (GNUNET_OK == res)
{
for (zm = monitor_head; NULL != zm; zm = zm->next)
+ {
if ( (0 == memcmp (&rp_msg->private_key, &zm->zone,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ||
(0 == memcmp (&zm->zone,
&zero,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Notifying monitor about changes under label `%s'\n",
+ conv_name);
send_lookup_response (monitor_nc,
zm->nc->client,
- zm->request_id,
+ 0,
&rp_msg->private_key,
conv_name,
rd_count, rd);
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Monitor is for another zone\n");
+ }
+ if (NULL == monitor_head)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No monitors active\n");
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Error storing record: %d\n",
+ res);
+ }
}
if (GNUNET_OK == res)
{
@@ -1186,7 +1200,7 @@
}
send_lookup_response (monitor_nc,
zm->nc->client,
- zm->request_id,
+ 0,
zone_key,
name,
rd_count,
@@ -1215,7 +1229,6 @@
"ZONE_MONITOR_START");
zis_msg = (const struct ZoneMonitorStartMessage *) message;
zm = GNUNET_new (struct ZoneMonitor);
- zm->request_id = ntohl (zis_msg->gns_header.r_id);
zm->offset = 0;
zm->nc = client_lookup (client);
zm->zone = zis_msg->zone;
@@ -1224,7 +1237,10 @@
GNUNET_SERVER_disable_receive_done_warning (client);
GNUNET_SERVER_notification_context_add (monitor_nc,
client);
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm);
+ if (GNUNET_YES == ntohs (zis_msg->iterate_first))
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm);
+ else
+ monitor_sync (zm);
}
Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h 2013-10-20 16:31:05 UTC (rev 30367)
+++ gnunet/src/namestore/namestore.h 2013-10-20 17:58:46 UTC (rev 30368)
@@ -353,9 +353,15 @@
/**
* Type will be #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
*/
- struct GNUNET_NAMESTORE_Header gns_header;
+ struct GNUNET_MessageHeader header;
/**
+ * #GNUNET_YES to first iterate over all records,
+ * #GNUNET_NO to only monitor changes.o
+ */
+ uint32_t iterate_first GNUNET_PACKED;
+
+ /**
* Zone key.
*/
struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
Modified: gnunet/src/namestore/namestore_api_monitor.c
===================================================================
--- gnunet/src/namestore/namestore_api_monitor.c 2013-10-20 16:31:05 UTC
(rev 30367)
+++ gnunet/src/namestore/namestore_api_monitor.c 2013-10-20 17:58:46 UTC
(rev 30368)
@@ -75,6 +75,11 @@
*/
struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
+ /**
+ * Do we first iterate over all existing records?
+ */
+ int iterate_first;
+
};
@@ -228,9 +233,9 @@
reconnect (zm);
return 0;
}
- sm.gns_header.header.type = htons
(GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
- sm.gns_header.header.size = htons (sizeof (struct ZoneMonitorStartMessage));
- sm.gns_header.r_id = htonl (0);
+ sm.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START);
+ sm.header.size = htons (sizeof (struct ZoneMonitorStartMessage));
+ sm.iterate_first = htonl (zm->iterate_first);
sm.zone = zm->zone;
memcpy (buf, &sm, sizeof (sm));
GNUNET_CLIENT_receive (zm->h,
@@ -242,20 +247,24 @@
/**
- * Begin monitoring a zone for changes. Will first call the 'monitor' function
- * on all existing records in the selected zone(s) and then call it whenever
- * a record changes.
+ * Begin monitoring a zone for changes. If @a iterate_first is set,
+ * we Will first call the @a monitor function on all existing records
+ * in the selected zone(s). In any case, we will call @a sync and
+ * afterwards call @a monitor whenever a record changes.
*
* @param cfg configuration to use to connect to namestore
* @param zone zone to monitor
+ * @param iterate_first #GNUNET_YES to first iterate over all existing records,
+ * #GNUNET_NO to only return changes that happen from now
on
* @param monitor function to call on zone changes
* @param sync_cb function called when we're in sync with the namestore
- * @param cls closure for 'monitor' and 'sync_cb'
+ * @param cls closure for @a monitor and @a sync_cb
* @return handle to stop monitoring
*/
struct GNUNET_NAMESTORE_ZoneMonitor *
GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle
*cfg,
const struct GNUNET_CRYPTO_EcdsaPrivateKey
*zone,
+ int iterate_first,
GNUNET_NAMESTORE_RecordMonitor monitor,
GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
void *cls)
@@ -263,16 +272,14 @@
struct GNUNET_NAMESTORE_ZoneMonitor *zm;
struct GNUNET_CLIENT_Connection *client;
- if (NULL == zone)
- return NULL;
if (NULL == (client = GNUNET_CLIENT_connect ("namestore", cfg)))
return NULL;
-
-
zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
zm->cfg = cfg;
zm->h = client;
- zm->zone = *zone;
+ if (NULL != zone)
+ zm->zone = *zone;
+ zm->iterate_first = iterate_first;
zm->monitor = monitor;
zm->sync_cb = sync_cb;
zm->cls = cls;
Modified: gnunet/src/namestore/test_namestore_api_monitoring.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_monitoring.c 2013-10-20
16:31:05 UTC (rev 30367)
+++ gnunet/src/namestore/test_namestore_api_monitoring.c 2013-10-20
17:58:46 UTC (rev 30368)
@@ -274,7 +274,8 @@
/* Start monitoring */
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
- privkey,
+ privkey,
+ GNUNET_YES,
&zone_proc,
NULL,
NULL);
Modified: gnunet/src/namestore/test_namestore_api_monitoring_existing.c
===================================================================
--- gnunet/src/namestore/test_namestore_api_monitoring_existing.c
2013-10-20 16:31:05 UTC (rev 30367)
+++ gnunet/src/namestore/test_namestore_api_monitoring_existing.c
2013-10-20 17:58:46 UTC (rev 30368)
@@ -237,10 +237,11 @@
{
/* Start monitoring */
zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
- privkey,
- &zone_proc,
- NULL,
- NULL);
+ privkey,
+ GNUNET_YES,
+ &zone_proc,
+ NULL,
+ NULL);
if (NULL == zm)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone monitor\n");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r30368 - in gnunet/src: include namestore,
gnunet <=