* @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"
}
+/**
+ * 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
*
"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,
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);
}
}
-/**
- * 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
*/