[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27804 - gnunet/src/namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27804 - gnunet/src/namestore |
Date: |
Mon, 8 Jul 2013 23:44:05 +0200 |
Author: grothoff
Date: 2013-07-08 23:44:05 +0200 (Mon, 08 Jul 2013)
New Revision: 27804
Modified:
gnunet/src/namestore/namestore.h
gnunet/src/namestore/namestore_api_monitor.c
Log:
-skeleton for monitor API
Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h 2013-07-08 18:10:14 UTC (rev 27803)
+++ gnunet/src/namestore/namestore.h 2013-07-08 21:44:05 UTC (rev 27804)
@@ -368,7 +368,30 @@
};
+/**
+ * Start monitoring a zone.
+ */
+struct ZoneMonitorStartMessage
+{
+ /**
+ * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
+ */
+ struct GNUNET_NAMESTORE_Header gns_header;
+ /**
+ * Zone hash
+ */
+ struct GNUNET_CRYPTO_ShortHashCode zone;
+
+ /**
+ * All zones. GNUNET_YES to monitor all zones,
+ * GNUNET_NO to only monitor 'zone'. In NBO.
+ */
+ uint32_t all_zones GNUNET_PACKED;
+
+};
+
+
/**
* Start a zone iteration for the given zone
*/
@@ -419,6 +442,7 @@
struct GNUNET_NAMESTORE_Header gns_header;
};
+
/**
* Next result of zone iteration for the given operation
* // FIXME: use 'struct LookupResponseMessage' instead? (identical except
@@ -435,7 +459,9 @@
uint16_t name_len;
- /* Record data length */
+ /**
+ * Record data length
+ */
uint16_t rd_len;
/**
@@ -458,9 +484,11 @@
*/
struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
-
-
};
+
+
+
+
GNUNET_NETWORK_STRUCT_END
Modified: gnunet/src/namestore/namestore_api_monitor.c
===================================================================
--- gnunet/src/namestore/namestore_api_monitor.c 2013-07-08 18:10:14 UTC
(rev 27803)
+++ gnunet/src/namestore/namestore_api_monitor.c 2013-07-08 21:44:05 UTC
(rev 27804)
@@ -35,16 +35,149 @@
#include "namestore.h"
-
/**
* Handle for a monitoring activity.
*/
struct GNUNET_NAMESTORE_ZoneMonitor
{
+ /**
+ * Configuration (to reconnect).
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Handle to namestore service.
+ */
+ struct GNUNET_CLIENT_Connection *h;
+
+ /**
+ * Function to call on events.
+ */
+ GNUNET_NAMESTORE_RecordMonitor monitor;
+
+ /**
+ * Closure for 'monitor'.
+ */
+ void *monitor_cls;
+
+ /**
+ * Transmission handle to client.
+ */
+ struct GNUNET_CLIENT_TransmitHandle *th;
+
+ /**
+ * Monitored zone.
+ */
+ struct GNUNET_CRYPTO_ShortHashCode zone;
+
+ /**
+ * GNUNET_YES if we monitor all zones, GNUNET_NO if we only monitor 'zone'.
+ */
+ int all_zones;
};
/**
+ * Send our request to start monitoring to the service.
+ *
+ * @param cls the monitor handle
+ * @param size number of bytes available in buf
+ * @param buf where to copy the message to the service
+ * @return number of bytes copied to buf
+ */
+static size_t
+transmit_monitor_message (void *cls,
+ size_t size,
+ void *buf);
+
+
+/**
+ * Reconnect to the namestore service.
+ *
+ * @param zm monitor to reconnect
+ */
+static void
+reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
+{
+ if (NULL != zm->h)
+ GNUNET_CLIENT_disconnect (zm->h);
+ zm->monitor (zm->monitor_cls,
+ NULL,
+ GNUNET_TIME_UNIT_ZERO_ABS,
+ NULL, 0, NULL, NULL);
+ GNUNET_assert (NULL != (zm->h = GNUNET_CLIENT_connect ("namestore",
zm->cfg)));
+ zm->th = GNUNET_CLIENT_notify_transmit_ready (zm->h,
+ sizeof (struct
ZoneMonitorStartMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &transmit_monitor_message,
+ zm);
+}
+
+
+/**
+ * We've received a notification about a change to our zone.
+ * Forward to monitor callback.
+ *
+ * @param cls the zone monitor handle
+ * @param msg the message from the service.
+ */
+static void
+handle_updates (void *cls,
+ const struct GNUNET_MessageHeader *msg)
+{
+ struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
+
+ if (NULL == msg)
+ {
+ reconnect (zm);
+ return;
+ }
+ // FIXME: parse, validate
+
+ GNUNET_CLIENT_receive (zm->h,
+ &handle_updates,
+ zm,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ // FIXME: call 'monitor'.
+ // zm->monitor (zm->monitor_cls, ...);
+}
+
+
+/**
+ * Send our request to start monitoring to the service.
+ *
+ * @param cls the monitor handle
+ * @param size number of bytes available in buf
+ * @param buf where to copy the message to the service
+ * @return number of bytes copied to buf
+ */
+static size_t
+transmit_monitor_message (void *cls,
+ size_t size,
+ void *buf)
+{
+ struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
+ struct ZoneMonitorStartMessage sm;
+
+ if (size < sizeof (struct ZoneMonitorStartMessage))
+ {
+ reconnect (zm);
+ return 0;
+ }
+
+ sm.zone = zm->zone;
+ sm.all_zones = htonl (zm->all_zones);
+ memcpy (buf, &sm, sizeof (sm));
+ GNUNET_CLIENT_receive (zm->h,
+ &handle_updates,
+ zm,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ return sizeof (sm);
+}
+
+
+/**
* 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.
@@ -61,8 +194,27 @@
GNUNET_NAMESTORE_RecordMonitor monitor,
void *monitor_cls)
{
- GNUNET_break (0);
- return NULL;
+ struct GNUNET_NAMESTORE_ZoneMonitor *zm;
+ struct GNUNET_CLIENT_Connection *client;
+
+ if (NULL == (client = GNUNET_CLIENT_connect ("namestore", cfg)))
+ return NULL;
+ zm = GNUNET_new (struct GNUNET_NAMESTORE_ZoneMonitor);
+ zm->cfg = cfg;
+ zm->h = client;
+ if (NULL == zone)
+ zm->all_zones = GNUNET_YES;
+ else
+ zm->zone = *zone;
+ zm->monitor = monitor;
+ zm->monitor_cls = monitor_cls;
+ zm->th = GNUNET_CLIENT_notify_transmit_ready (zm->h,
+ sizeof (struct
ZoneMonitorStartMessage),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &transmit_monitor_message,
+ zm);
+ return zm;
}
@@ -74,6 +226,13 @@
void
GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
{
+ if (NULL != zm->th)
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (zm->th);
+ zm->th = NULL;
+ }
+ GNUNET_CLIENT_disconnect (zm->h);
+ GNUNET_free (zm);
}
/* end of namestore_api_monitor.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27804 - gnunet/src/namestore,
gnunet <=