gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r27810 - in gnunet: doc/man src/include src/namestore


From: gnunet
Subject: [GNUnet-SVN] r27810 - in gnunet: doc/man src/include src/namestore
Date: Tue, 9 Jul 2013 09:18:53 +0200

Author: grothoff
Date: 2013-07-09 09:18:53 +0200 (Tue, 09 Jul 2013)
New Revision: 27810

Modified:
   gnunet/doc/man/gnunet-namestore.1
   gnunet/src/include/gnunet_namestore_service.h
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/namestore/gnunet-namestore.c
   gnunet/src/namestore/namestore_api_monitor.c
Log:
add '-m' option to gnunet-namestore, extend namestore monitor API with 
notification about being in sync

Modified: gnunet/doc/man/gnunet-namestore.1
===================================================================
--- gnunet/doc/man/gnunet-namestore.1   2013-07-08 23:24:34 UTC (rev 27809)
+++ gnunet/doc/man/gnunet-namestore.1   2013-07-09 07:18:53 UTC (rev 27810)
@@ -34,6 +34,9 @@
 .IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL"
 Use LOGLEVEL for logging.  Valid values are DEBUG, INFO, WARNING and ERROR.
 .B
+.IP "\-m, \-\-monitor"
+Monitor changes to the zone on an ongoing basis (in contrast to \-D, which 
merely displays the current records)
+.B
 .IP "\-n NAME, \-\-name=NAME"
 Name of the record to add/delete/display
 .B

Modified: gnunet/src/include/gnunet_namestore_service.h
===================================================================
--- gnunet/src/include/gnunet_namestore_service.h       2013-07-08 23:24:34 UTC 
(rev 27809)
+++ gnunet/src/include/gnunet_namestore_service.h       2013-07-09 07:18:53 UTC 
(rev 27810)
@@ -484,21 +484,37 @@
 
 
 /**
+ * Function called once the monitor has caught up with the current 
+ * state of the database.  Will be called AGAIN after each disconnect
+ * (record monitor called with 'NULL' for zone_key) once we're again
+ * in sync.
+ *
+ * @param cls closure
+ */
+typedef void (*GNUNET_NAMESTORE_RecordsSynchronizedCallback)(void *cls);
+
+
+/**
  * 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.
+ * on all existing records in the selected zone(s), then calls 'sync_cb',
+ * and then calls the 'monitor' whenever a record changes.  If the namestore
+ * disconnects, the '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).
  *
  * @param cfg configuration to use to connect to namestore
  * @param zone zone to monitor, NULL for all zones
  * @param monitor function to call on zone changes
- * @param monitor_cls closure for 'monitor'
+ * @param sync_cb function called when we're in sync with the namestore
+ * @param cls closure for 'monitor' and '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_ShortHashCode 
*zone,
                                     GNUNET_NAMESTORE_RecordMonitor monitor,
-                                    void *monitor_cls);
+                                    
GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
+                                    void *cls);
 
 
 /**

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2013-07-08 23:24:34 UTC (rev 
27809)
+++ gnunet/src/include/gnunet_protocols.h       2013-07-09 07:18:53 UTC (rev 
27810)
@@ -1408,6 +1408,11 @@
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START 441
 
 /**
+ * Service to client: you're now in sync.
+ */
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC 442
+
+/**
  * Client to service: please start iteration; receives
  * "GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE" messages in return.
  */

Modified: gnunet/src/namestore/gnunet-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-namestore.c     2013-07-08 23:24:34 UTC (rev 
27809)
+++ gnunet/src/namestore/gnunet-namestore.c     2013-07-09 07:18:53 UTC (rev 
27810)
@@ -163,8 +163,17 @@
  */
 static int etime_is_rel = GNUNET_SYSERR;
 
+/**
+ * Monitor handle.
+ */
+static struct GNUNET_NAMESTORE_ZoneMonitor *zm;
 
 /**
+ * Enables monitor mode.
+ */
+static int monitor;
+
+/**
  * Task run on shutdown.  Cleans up everything.
  *
  * @param cls unused
@@ -215,6 +224,11 @@
     GNUNET_free (uri);
     uri = NULL;
   }
+  if (NULL != zm)
+  {
+    GNUNET_NAMESTORE_zone_monitor_stop (zm);
+    zm = NULL;
+  }
 }
 
 
@@ -358,6 +372,18 @@
 
 
 /**
+ * Function called once we are in sync in monitor mode.
+ *
+ * @param cls NULL
+ */
+static void
+sync_cb (void *cls)
+{
+  FPRINTF (stdout, "%s", "Monitor is now in sync.\n");
+}
+
+
+/**
  * We're storing a record; this function is given the existing record
  * so that we can merge the information.
  *
@@ -643,6 +669,14 @@
                                                           &add_qe_uri);
   }
   GNUNET_free_non_null (data);
+  if (monitor)
+  {
+    zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
+                                             &zone,
+                                             &display_record,
+                                             &sync_cb,
+                                             NULL);
+  }
 }
 
 
@@ -740,6 +774,9 @@
     {'e', "expiration", "TIME",
      gettext_noop ("expiration time for record to use (for adding only), 
\"never\" is possible"), 1,
      &GNUNET_GETOPT_set_string, &expirationstring},   
+    {'m', "monitor", NULL,
+     gettext_noop ("monitor changes in the namestore"), 0,
+     &GNUNET_GETOPT_set_one, &monitor},   
     {'n', "name", "NAME",
      gettext_noop ("name of the record to add/delete/display"), 1,
      &GNUNET_GETOPT_set_string, &name},   

Modified: gnunet/src/namestore/namestore_api_monitor.c
===================================================================
--- gnunet/src/namestore/namestore_api_monitor.c        2013-07-08 23:24:34 UTC 
(rev 27809)
+++ gnunet/src/namestore/namestore_api_monitor.c        2013-07-09 07:18:53 UTC 
(rev 27810)
@@ -56,11 +56,16 @@
   GNUNET_NAMESTORE_RecordMonitor monitor;
 
   /**
-   * Closure for 'monitor'.
+   * Function called when we've synchronized.
    */
-  void *monitor_cls;
+  GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb;
 
   /**
+   * Closure for 'monitor' and 'sync_cb'.
+   */
+  void *cls;
+
+  /**
    * Transmission handle to client.
    */
   struct GNUNET_CLIENT_TransmitHandle *th;
@@ -101,7 +106,7 @@
 {
   if (NULL != zm->h)
     GNUNET_CLIENT_disconnect (zm->h);
-  zm->monitor (zm->monitor_cls,
+  zm->monitor (zm->cls,
               NULL,
               GNUNET_TIME_UNIT_ZERO_ABS,
               NULL, 0, NULL, NULL);
@@ -142,6 +147,17 @@
     reconnect (zm);
     return;
   }
+  if ( (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)) &&
+       (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC == ntohs (msg->type) ) )
+  {
+    GNUNET_CLIENT_receive (zm->h,
+                          &handle_updates,
+                          zm,
+                          GNUNET_TIME_UNIT_FOREVER_REL);
+    if (NULL != zm->sync_cb)
+      zm->sync_cb (zm->cls);
+    return;
+  }
   if ( (ntohs (msg->size) < sizeof (struct LookupNameResponseMessage)) ||
        (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE != ntohs 
(msg->type) ) )
   {
@@ -189,7 +205,7 @@
                           &handle_updates,
                           zm,
                           GNUNET_TIME_UNIT_FOREVER_REL);
-    zm->monitor(zm->monitor_cls, 
+    zm->monitor(zm->cls, 
                &lrm->public_key, expire, 
                name_tmp, 
                rd_count, rd, &lrm->signature);
@@ -238,14 +254,16 @@
  * @param cfg configuration to use to connect to namestore
  * @param zone zone to monitor, NULL for all zones
  * @param monitor function to call on zone changes
- * @param monitor_cls closure for 'monitor'
+ * @param sync_cb function called when we're in sync with the namestore
+ * @param cls closure for 'monitor' and '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_ShortHashCode 
*zone,
                                     GNUNET_NAMESTORE_RecordMonitor monitor,
-                                    void *monitor_cls)
+                                    
GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb,
+                                    void *cls)
 {
   struct GNUNET_NAMESTORE_ZoneMonitor *zm;
   struct GNUNET_CLIENT_Connection *client;
@@ -260,7 +278,8 @@
   else
     zm->zone = *zone;
   zm->monitor = monitor;
-  zm->monitor_cls = monitor_cls;
+  zm->sync_cb = sync_cb;
+  zm->cls = cls;
   zm->th = GNUNET_CLIENT_notify_transmit_ready (zm->h,
                                                sizeof (struct 
ZoneMonitorStartMessage),
                                                GNUNET_TIME_UNIT_FOREVER_REL,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]