aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-09 13:26:11 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-09 13:26:11 +0000
commit3102825b3ba6e097f1a6f370a6ab4a6291cc9fcf (patch)
treedd179e3c8db0e38e3d0ceaff57a8b4969c6db62d /src/namestore/gnunet-service-namestore.c
parent22fa041be71030a5367ccb2f63158e22983aa49b (diff)
downloadgnunet-3102825b3ba6e097f1a6f370a6ab4a6291cc9fcf.tar.gz
gnunet-3102825b3ba6e097f1a6f370a6ab4a6291cc9fcf.zip
finish implementation of monitoring, send change notifications to all clients
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c177
1 files changed, 103 insertions, 74 deletions
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 @@
23 * @brief namestore for the GNUnet naming system 23 * @brief namestore for the GNUnet naming system
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * TODO:
28 * - actually notify monitor clients on all changes!
29 */ 26 */
30#include "platform.h" 27#include "platform.h"
31#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
@@ -974,6 +971,70 @@ handle_lookup_name (void *cls,
974 971
975 972
976/** 973/**
974 * Generate a 'struct LookupNameResponseMessage' and send it to the
975 * given client using the given notification context.
976 *
977 * @param nc notification context to use
978 * @param client client to unicast to
979 * @param request_id request ID to use
980 * @param zone_key zone key of the zone
981 * @param expire expiration time
982 * @param name name
983 * @param rd_count number of records
984 * @param rd array of records
985 * @param signature signature
986 */
987static void
988send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
989 struct GNUNET_SERVER_Client *client,
990 uint32_t request_id,
991 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
992 struct GNUNET_TIME_Absolute expire,
993 const char *name,
994 unsigned int rd_count,
995 const struct GNUNET_NAMESTORE_RecordData *rd,
996 const struct GNUNET_CRYPTO_EccSignature *signature)
997{
998 struct LookupNameResponseMessage *zir_msg;
999 size_t name_len;
1000 size_t rd_ser_len;
1001 size_t msg_size;
1002 char *name_tmp;
1003 char *rd_ser;
1004
1005 name_len = strlen (name) + 1;
1006 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1007 msg_size = sizeof (struct LookupNameResponseMessage) + name_len + rd_ser_len;
1008
1009 zir_msg = GNUNET_malloc (msg_size);
1010 zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
1011 zir_msg->gns_header.header.size = htons (msg_size);
1012 zir_msg->gns_header.r_id = htonl (request_id);
1013 zir_msg->expire = GNUNET_TIME_absolute_hton (expire);
1014 zir_msg->contains_sig = htons ((NULL == signature) ? GNUNET_NO : GNUNET_YES);
1015 zir_msg->name_len = htons (name_len);
1016 zir_msg->rd_count = htons (rd_count);
1017 zir_msg->rd_len = htons (rd_ser_len);
1018 if (NULL != signature)
1019 zir_msg->signature = *signature;
1020 zir_msg->public_key = *zone_key;
1021 name_tmp = (char *) &zir_msg[1];
1022 memcpy (name_tmp, name, name_len);
1023 rd_ser = &name_tmp[name_len];
1024 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
1025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1026 "Sending `%s' message with size %u\n",
1027 "ZONE_ITERATION_RESPONSE",
1028 msg_size);
1029 GNUNET_SERVER_notification_context_unicast (nc,
1030 client,
1031 &zir_msg->gns_header.header,
1032 GNUNET_NO);
1033 GNUNET_free (zir_msg);
1034}
1035
1036
1037/**
977 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT' message 1038 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT' message
978 * 1039 *
979 * @param cls unused 1040 * @param cls unused
@@ -1071,12 +1132,28 @@ handle_record_put (void *cls,
1071 "Putting %u records under name `%s' in zone `%s'\n", 1132 "Putting %u records under name `%s' in zone `%s'\n",
1072 rd_count, conv_name, 1133 rd_count, conv_name,
1073 GNUNET_NAMESTORE_short_h2s (&zone_hash)); 1134 GNUNET_NAMESTORE_short_h2s (&zone_hash));
1074 res = GSN_database->put_records(GSN_database->cls, 1135 res = GSN_database->put_records (GSN_database->cls,
1075 &rp_msg->public_key, 1136 &rp_msg->public_key,
1076 expire, 1137 expire,
1077 conv_name, 1138 conv_name,
1078 rd_count, rd, 1139 rd_count, rd,
1079 signature); 1140 signature);
1141 if (GNUNET_OK == res)
1142 {
1143 struct ZoneMonitor *zm;
1144
1145 for (zm = monitor_head; NULL != zm; zm = zm->next)
1146 if ( (GNUNET_NO == zm->has_zone) ||
1147 (0 == memcmp (&zone_hash, &zm->zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode))) )
1148 send_lookup_response (monitor_nc,
1149 zm->client,
1150 zm->request_id,
1151 &rp_msg->public_key,
1152 expire,
1153 conv_name,
1154 rd_count, rd,
1155 signature);
1156 }
1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1081 "Putting record for name `%s': %s\n", 1158 "Putting record for name `%s': %s\n",
1082 conv_name, 1159 conv_name,
@@ -1218,10 +1295,26 @@ handle_record_create (void *cls,
1218 else 1295 else
1219 res = GSN_database->put_records (GSN_database->cls, 1296 res = GSN_database->put_records (GSN_database->cls,
1220 &pubkey, 1297 &pubkey,
1221 GNUNET_TIME_absolute_ntoh(rp_msg->expire), 1298 GNUNET_TIME_absolute_ntoh (rp_msg->expire),
1222 conv_name, 1299 conv_name,
1223 rd_count, rd, 1300 rd_count, rd,
1224 &dummy_signature); 1301 &dummy_signature);
1302 if (GNUNET_OK == res)
1303 {
1304 struct ZoneMonitor *zm;
1305
1306 for (zm = monitor_head; NULL != zm; zm = zm->next)
1307 if ( (GNUNET_NO == zm->has_zone) ||
1308 (0 == memcmp (&pubkey_hash, &zm->zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode))) )
1309 send_lookup_response (monitor_nc,
1310 zm->client,
1311 zm->request_id,
1312 &pubkey,
1313 GNUNET_TIME_absolute_ntoh (rp_msg->expire),
1314 conv_name,
1315 rd_count, rd,
1316 &dummy_signature);
1317 }
1225 GNUNET_free (conv_name); 1318 GNUNET_free (conv_name);
1226 } 1319 }
1227 1320
@@ -1397,70 +1490,6 @@ handle_zone_to_name (void *cls,
1397 1490
1398 1491
1399/** 1492/**
1400 * Generate a 'struct LookupNameResponseMessage' and send it to the
1401 * given client using the given notification context.
1402 *
1403 * @param nc notification context to use
1404 * @param client client to unicast to
1405 * @param request_id request ID to use
1406 * @param zone_key zone key of the zone
1407 * @param expire expiration time
1408 * @param name name
1409 * @param rd_count number of records
1410 * @param rd array of records
1411 * @param signature signature
1412 */
1413static void
1414send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
1415 struct GNUNET_SERVER_Client *client,
1416 uint32_t request_id,
1417 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
1418 struct GNUNET_TIME_Absolute expire,
1419 const char *name,
1420 unsigned int rd_count,
1421 const struct GNUNET_NAMESTORE_RecordData *rd,
1422 const struct GNUNET_CRYPTO_EccSignature *signature)
1423{
1424 struct LookupNameResponseMessage *zir_msg;
1425 size_t name_len;
1426 size_t rd_ser_len;
1427 size_t msg_size;
1428 char *name_tmp;
1429 char *rd_ser;
1430
1431 name_len = strlen (name) + 1;
1432 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1433 msg_size = sizeof (struct LookupNameResponseMessage) + name_len + rd_ser_len;
1434
1435 zir_msg = GNUNET_malloc (msg_size);
1436 zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
1437 zir_msg->gns_header.header.size = htons (msg_size);
1438 zir_msg->gns_header.r_id = htonl (request_id);
1439 zir_msg->expire = GNUNET_TIME_absolute_hton (expire);
1440 zir_msg->contains_sig = htons ((NULL == signature) ? GNUNET_NO : GNUNET_YES);
1441 zir_msg->name_len = htons (name_len);
1442 zir_msg->rd_count = htons (rd_count);
1443 zir_msg->rd_len = htons (rd_ser_len);
1444 if (NULL != signature)
1445 zir_msg->signature = *signature;
1446 zir_msg->public_key = *zone_key;
1447 name_tmp = (char *) &zir_msg[1];
1448 memcpy (name_tmp, name, name_len);
1449 rd_ser = &name_tmp[name_len];
1450 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
1451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1452 "Sending `%s' message with size %u\n",
1453 "ZONE_ITERATION_RESPONSE",
1454 msg_size);
1455 GNUNET_SERVER_notification_context_unicast (nc,
1456 client,
1457 &zir_msg->gns_header.header,
1458 GNUNET_NO);
1459 GNUNET_free (zir_msg);
1460}
1461
1462
1463/**
1464 * Zone iteration processor result 1493 * Zone iteration processor result
1465 */ 1494 */
1466enum ZoneIterationResult 1495enum ZoneIterationResult