gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27828 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r27828 - gnunet/src/namestore
Date: Tue, 9 Jul 2013 15:26:11 +0200

Author: grothoff
Date: 2013-07-09 15:26:11 +0200 (Tue, 09 Jul 2013)
New Revision: 27828

Modified:
   gnunet/src/namestore/gnunet-service-namestore.c
Log:
finish implementation of monitoring, send change notifications to all clients

Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2013-07-09 13:19:11 UTC 
(rev 27827)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2013-07-09 13:26:11 UTC 
(rev 27828)
@@ -23,9 +23,6 @@
  * @brief namestore for the GNUnet naming system
  * @author Matthias Wachs
  * @author Christian Grothoff
- *
- * TODO:
- * - actually notify monitor clients on all changes!
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
@@ -974,6 +971,70 @@
 
 
 /**
+ * Generate a 'struct LookupNameResponseMessage' and send it to the
+ * given client using the given notification context.
+ *
+ * @param nc notification context to use
+ * @param client client to unicast to
+ * @param request_id request ID to use
+ * @param zone_key zone key of the zone
+ * @param expire expiration time
+ * @param name name
+ * @param rd_count number of records
+ * @param rd array of records
+ * @param signature signature
+ */
+static void
+send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,            
        
+                     struct GNUNET_SERVER_Client *client,
+                     uint32_t request_id,
+                     const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded 
*zone_key,
+                     struct GNUNET_TIME_Absolute expire,
+                     const char *name,
+                     unsigned int rd_count,
+                     const struct GNUNET_NAMESTORE_RecordData *rd,
+                     const struct GNUNET_CRYPTO_EccSignature *signature)
+{
+  struct LookupNameResponseMessage *zir_msg;
+  size_t name_len;
+  size_t rd_ser_len;
+  size_t msg_size;
+  char *name_tmp;
+  char *rd_ser;
+
+  name_len = strlen (name) + 1;
+  rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);  
+  msg_size = sizeof (struct LookupNameResponseMessage) + name_len + rd_ser_len;
+
+  zir_msg = GNUNET_malloc (msg_size);
+  zir_msg->gns_header.header.type = htons 
(GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
+  zir_msg->gns_header.header.size = htons (msg_size);
+  zir_msg->gns_header.r_id = htonl (request_id);
+  zir_msg->expire = GNUNET_TIME_absolute_hton (expire);
+  zir_msg->contains_sig = htons ((NULL == signature) ? GNUNET_NO : GNUNET_YES);
+  zir_msg->name_len = htons (name_len);
+  zir_msg->rd_count = htons (rd_count);
+  zir_msg->rd_len = htons (rd_ser_len);
+  if (NULL != signature)
+    zir_msg->signature = *signature;
+  zir_msg->public_key = *zone_key;
+  name_tmp = (char *) &zir_msg[1];
+  memcpy (name_tmp, name, name_len);
+  rd_ser = &name_tmp[name_len];
+  GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+             "Sending `%s' message with size %u\n", 
+             "ZONE_ITERATION_RESPONSE",
+             msg_size);
+  GNUNET_SERVER_notification_context_unicast (nc,
+                                             client, 
+                                             &zir_msg->gns_header.header,
+                                             GNUNET_NO);
+  GNUNET_free (zir_msg);
+}
+
+
+/**
  * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT' message
  *
  * @param cls unused
@@ -1071,12 +1132,28 @@
               "Putting %u records under name `%s' in zone `%s'\n",
               rd_count, conv_name,
               GNUNET_NAMESTORE_short_h2s (&zone_hash));
-  res = GSN_database->put_records(GSN_database->cls,
-                                  &rp_msg->public_key,
-                                  expire,
-                                  conv_name,
-                                  rd_count, rd,
-                                  signature);
+  res = GSN_database->put_records (GSN_database->cls,
+                                  &rp_msg->public_key,
+                                  expire,
+                                  conv_name,
+                                  rd_count, rd,
+                                  signature);
+  if (GNUNET_OK == res)
+  {
+    struct ZoneMonitor *zm;
+
+    for (zm = monitor_head; NULL != zm; zm = zm->next)    
+      if ( (GNUNET_NO == zm->has_zone) ||
+          (0 == memcmp (&zone_hash, &zm->zone, sizeof (struct 
GNUNET_CRYPTO_ShortHashCode))) )      
+       send_lookup_response (monitor_nc,
+                             zm->client,
+                             zm->request_id,
+                             &rp_msg->public_key,
+                             expire,
+                             conv_name,
+                             rd_count, rd,
+                             signature);      
+  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Putting record for name `%s': %s\n",
               conv_name,
@@ -1218,10 +1295,26 @@
     else
       res = GSN_database->put_records (GSN_database->cls,
                                       &pubkey,
-                                      
GNUNET_TIME_absolute_ntoh(rp_msg->expire),
+                                      GNUNET_TIME_absolute_ntoh 
(rp_msg->expire),
                                       conv_name,
                                       rd_count, rd,
                                       &dummy_signature);
+    if (GNUNET_OK == res)
+    {
+      struct ZoneMonitor *zm;
+      
+      for (zm = monitor_head; NULL != zm; zm = zm->next)    
+       if ( (GNUNET_NO == zm->has_zone) ||
+            (0 == memcmp (&pubkey_hash, &zm->zone, sizeof (struct 
GNUNET_CRYPTO_ShortHashCode))) )      
+         send_lookup_response (monitor_nc,
+                               zm->client,
+                               zm->request_id,
+                               &pubkey,
+                               GNUNET_TIME_absolute_ntoh (rp_msg->expire),
+                               conv_name,
+                               rd_count, rd,
+                               &dummy_signature);      
+    }    
     GNUNET_free (conv_name);
   }
   
@@ -1397,70 +1490,6 @@
 
 
 /**
- * Generate a 'struct LookupNameResponseMessage' and send it to the
- * given client using the given notification context.
- *
- * @param nc notification context to use
- * @param client client to unicast to
- * @param request_id request ID to use
- * @param zone_key zone key of the zone
- * @param expire expiration time
- * @param name name
- * @param rd_count number of records
- * @param rd array of records
- * @param signature signature
- */
-static void
-send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,            
        
-                     struct GNUNET_SERVER_Client *client,
-                     uint32_t request_id,
-                     const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded 
*zone_key,
-                     struct GNUNET_TIME_Absolute expire,
-                     const char *name,
-                     unsigned int rd_count,
-                     const struct GNUNET_NAMESTORE_RecordData *rd,
-                     const struct GNUNET_CRYPTO_EccSignature *signature)
-{
-  struct LookupNameResponseMessage *zir_msg;
-  size_t name_len;
-  size_t rd_ser_len;
-  size_t msg_size;
-  char *name_tmp;
-  char *rd_ser;
-
-  name_len = strlen (name) + 1;
-  rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);  
-  msg_size = sizeof (struct LookupNameResponseMessage) + name_len + rd_ser_len;
-
-  zir_msg = GNUNET_malloc (msg_size);
-  zir_msg->gns_header.header.type = htons 
(GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
-  zir_msg->gns_header.header.size = htons (msg_size);
-  zir_msg->gns_header.r_id = htonl (request_id);
-  zir_msg->expire = GNUNET_TIME_absolute_hton (expire);
-  zir_msg->contains_sig = htons ((NULL == signature) ? GNUNET_NO : GNUNET_YES);
-  zir_msg->name_len = htons (name_len);
-  zir_msg->rd_count = htons (rd_count);
-  zir_msg->rd_len = htons (rd_ser_len);
-  if (NULL != signature)
-    zir_msg->signature = *signature;
-  zir_msg->public_key = *zone_key;
-  name_tmp = (char *) &zir_msg[1];
-  memcpy (name_tmp, name, name_len);
-  rd_ser = &name_tmp[name_len];
-  GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
-             "Sending `%s' message with size %u\n", 
-             "ZONE_ITERATION_RESPONSE",
-             msg_size);
-  GNUNET_SERVER_notification_context_unicast (nc,
-                                             client, 
-                                             &zir_msg->gns_header.header,
-                                             GNUNET_NO);
-  GNUNET_free (zir_msg);
-}
-
-
-/**
  * Zone iteration processor result
  */
 enum ZoneIterationResult




reply via email to

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