From: Christian Grothoff Date: Tue, 9 Jul 2013 13:26:11 +0000 (+0000) Subject: finish implementation of monitoring, send change notifications to all clients X-Git-Tag: initial-import-from-subversion-38251~8461 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3102825b3ba6e097f1a6f370a6ab4a6291cc9fcf;p=oweals%2Fgnunet.git finish implementation of monitoring, send change notifications to all clients --- diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 73392f9f0..eb1dc17b8 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -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" @@ -973,6 +970,70 @@ handle_lookup_name (void *cls, } +/** + * 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 * @@ -1071,12 +1132,28 @@ handle_record_put (void *cls, "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 @@ handle_record_create (void *cls, 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); } @@ -1396,70 +1489,6 @@ handle_zone_to_name (void *cls, } -/** - * 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 */