aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-28 20:39:31 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-28 20:39:31 +0000
commit9ceaa074240bdc82daf5be233a3035714f002990 (patch)
tree3f9b20e4bae9e6963cff00f78685c45b950d07d9 /src/namestore
parent8113ba1371bfd97a4a09c47b070e8f4425ba10a9 (diff)
downloadgnunet-9ceaa074240bdc82daf5be233a3035714f002990.tar.gz
gnunet-9ceaa074240bdc82daf5be233a3035714f002990.zip
-more namestore service cleanup -- wip
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-service-namestore.c217
-rw-r--r--src/namestore/namestore.h7
-rw-r--r--src/namestore/namestore_api.c4
3 files changed, 96 insertions, 132 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 3e29ba389..2faaaa3ab 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -847,9 +847,6 @@ handle_record_put (void *cls,
847} 847}
848 848
849 849
850/////////////////////////////////////////////////////////////
851
852
853/** 850/**
854 * Context for record create operations passed from 'handle_record_create' to 851 * Context for record create operations passed from 'handle_record_create' to
855 * 'handle_create_record_it' as closure 852 * 'handle_create_record_it' as closure
@@ -862,11 +859,6 @@ struct CreateRecordContext
862 const struct GNUNET_NAMESTORE_RecordData *rd; 859 const struct GNUNET_NAMESTORE_RecordData *rd;
863 860
864 /** 861 /**
865 * Zone's private key
866 */
867 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
868
869 /**
870 * Zone's public key 862 * Zone's public key
871 */ 863 */
872 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; 864 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey;
@@ -912,43 +904,46 @@ handle_create_record_it (void *cls,
912 const struct GNUNET_NAMESTORE_RecordData *rd, 904 const struct GNUNET_NAMESTORE_RecordData *rd,
913 const struct GNUNET_CRYPTO_RsaSignature *signature) 905 const struct GNUNET_CRYPTO_RsaSignature *signature)
914{ 906{
907 static struct GNUNET_CRYPTO_RsaSignature dummy_signature;
915 struct CreateRecordContext *crc = cls; 908 struct CreateRecordContext *crc = cls;
916 struct GNUNET_NAMESTORE_RecordData *rd_new = NULL; 909 struct GNUNET_NAMESTORE_RecordData *rd_new;
917 struct GNUNET_CRYPTO_RsaSignature dummy_signature;
918 struct GNUNET_TIME_Absolute block_expiration; 910 struct GNUNET_TIME_Absolute block_expiration;
919 int res; 911 int exist;
920 int exist = GNUNET_SYSERR; 912 int update;
921 int update = GNUNET_NO; 913 unsigned int c;
922 int c; 914 unsigned int rd_count_new;
923 int rd_count_new = 0;
924 915
925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926 "Found %u existing records for `%s'\n", 917 "Found %u existing records for `%s'\n",
927 rd_count, crc->name); 918 rd_count, crc->name);
919 exist = -1;
920 update = GNUNET_NO;
928 for (c = 0; c < rd_count; c++) 921 for (c = 0; c < rd_count; c++)
929 { 922 {
930 if ( (crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PKEY) && 923 if (crc->rd->record_type != rd[c].record_type)
931 (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PKEY)) 924 continue; /* no match */
925 if ( (GNUNET_NAMESTORE_TYPE_PKEY == crc->rd->record_type) ||
926 (GNUNET_NAMESTORE_TYPE_PSEU == crc->rd->record_type) )
932 { 927 {
933 /* Update unique PKEY */ 928 /* Update unique PKEY or PSEU */
929 /* FIXME: should we do this test here? Is this not something
930 that should be handled closer to the UI? If not, what
931 about othrer 'unique' record types like CNAME? */
934 exist = c; 932 exist = c;
935 update = GNUNET_YES; 933 if ( (crc->rd->data_size != rd[c].data_size) ||
936 break; 934 (0 != memcmp (crc->rd->data, rd[c].data, rd[c].data_size)) ||
937 } 935 (crc->rd->expiration_time != rd[c].expiration_time) ||
938 if ( (crc->rd->record_type == GNUNET_NAMESTORE_TYPE_PSEU) && 936 ((crc->rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)
939 (rd[c].record_type == GNUNET_NAMESTORE_TYPE_PSEU)) 937 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) )
940 { 938 update = GNUNET_YES;
941 /* Update unique PSEU */
942 exist = c;
943 update = GNUNET_YES;
944 break; 939 break;
945 } 940 }
946 if ((crc->rd->record_type == rd[c].record_type) && 941 if ( (crc->rd->data_size == rd[c].data_size) &&
947 (crc->rd->data_size == rd[c].data_size) && 942 (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
948 (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size)))
949 { 943 {
944 /* FIXME: again, do we need to handle this special case here? */
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
951 "Found existing records for `%s' to update expiration date!\n", 946 "Found matching existing record for `%s'; only updating expiration date!\n",
952 crc->name); 947 crc->name);
953 exist = c; 948 exist = c;
954 if ( (crc->rd->expiration_time != rd[c].expiration_time) && 949 if ( (crc->rd->expiration_time != rd[c].expiration_time) &&
@@ -959,93 +954,50 @@ handle_create_record_it (void *cls,
959 } 954 }
960 } 955 }
961 956
962 if (exist == GNUNET_SYSERR) 957 if ( (-1 != exist) &&
958 (GNUNET_NO == update) )
963 { 959 {
960 /* Exact same record already exists */
964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
965 "No existing record for name `%s'!\n", 962 "Matching record for %s' exists, no change required!\n",
966 crc->name); 963 crc->name);
967 rd_new = GNUNET_malloc ((rd_count+1) * sizeof (struct GNUNET_NAMESTORE_RecordData)); 964 crc->res = GNUNET_NO; /* identical record existed */
968 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); 965 return;
969 rd_count_new = rd_count + 1;
970 rd_new[rd_count] = *(crc->rd);
971 } 966 }
972 else if (update == GNUNET_NO) 967 if (-1 == exist)
973 { 968 {
974 /* Exact same record already exists */
975 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
976 "Matching record for %s' exists, no change required!\n", 970 "No existing record for name `%s'!\n",
977 crc->name); 971 crc->name);
978 crc->res = GNUNET_NO; 972 rd_count_new = rd_count + 1;
979 return; 973 rd_new = GNUNET_malloc (rd_count_new * sizeof (struct GNUNET_NAMESTORE_RecordData));
974 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
975 rd_new[rd_count] = *(crc->rd);
980 } 976 }
981 else 977 else
982 { 978 {
983 /* Update record */
984 GNUNET_assert (GNUNET_YES == update);
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
986 "Updating existing records for `%s'!\n", 980 "Updating existing records for `%s'!\n",
987 crc->name); 981 crc->name);
988 rd_new = GNUNET_malloc ((rd_count) * sizeof (struct GNUNET_NAMESTORE_RecordData));
989 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
990 rd_count_new = rd_count; 982 rd_count_new = rd_count;
991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 983 rd_new = GNUNET_malloc (rd_count_new * sizeof (struct GNUNET_NAMESTORE_RecordData));
992 (0 == (crc->rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) 984 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
993 ? "Updating absolute expiration from %llu to %llu!\n"
994 : "Updating relative expiration from %llu to %llu!\n",
995 rd_new[exist].expiration_time, crc->rd->expiration_time);
996 rd_new[exist] = *(crc->rd); 985 rd_new[exist] = *(crc->rd);
997 } 986 }
998 987 block_expiration = GNUNET_TIME_absolute_max (crc->expire, expire);
999 block_expiration = GNUNET_TIME_absolute_max(crc->expire, expire); 988 if (GNUNET_OK !=
1000 if (block_expiration.abs_value != expire.abs_value) 989 GSN_database->put_records (GSN_database->cls,
1001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 990 crc->pubkey,
1002 "Updated block expiration time\n"); 991 block_expiration,
1003 992 crc->name,
1004 memset (&dummy_signature, '\0', sizeof (dummy_signature)); 993 rd_count_new, rd_new,
1005 994 &dummy_signature))
1006 /* Database operation */ 995 crc->res = GNUNET_SYSERR; /* error */
1007 GNUNET_assert ((rd_new != NULL) && (rd_count_new > 0)); 996 else if (GNUNET_YES == update)
1008 res = GSN_database->put_records(GSN_database->cls, 997 crc->res = GNUNET_NO; /* update */
1009 (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) crc->pubkey,
1010 block_expiration,
1011 crc->name,
1012 rd_count_new, rd_new,
1013 &dummy_signature);
1014 GNUNET_break (GNUNET_OK == res);
1015 if (res == GNUNET_OK)
1016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully put record for `%s' in database \n", crc->name);
1017 else 998 else
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to put record for `%s' in database \n", crc->name); 999 crc->res = GNUNET_YES; /* created new record */
1019 res = GNUNET_YES; 1000 GNUNET_free (rd_new);
1020
1021 GNUNET_free_non_null (rd_new);
1022
1023 switch (res) {
1024 case GNUNET_SYSERR:
1025 /* failed to create the record */
1026 crc->res = GNUNET_SYSERR;
1027 break;
1028 case GNUNET_YES:
1029 /* database operations OK */
1030 if (GNUNET_YES == update)
1031 {
1032 /* we updated an existing record */
1033 crc->res = GNUNET_NO;
1034 }
1035 else
1036 {
1037 /* we created a new record */
1038 crc->res = GNUNET_YES;
1039 }
1040 break;
1041 case GNUNET_NO:
1042 /* identical entry existed, so we did nothing */
1043 crc->res = GNUNET_NO;
1044 break;
1045 default:
1046 break;
1047 }
1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name `%s' %u\n", crc->name, res);
1049} 1001}
1050 1002
1051 1003
@@ -1140,6 +1092,7 @@ handle_record_create (void *cls,
1140 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1092 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1141 return; 1093 return;
1142 } 1094 }
1095
1143 /* Extracting and converting private key */ 1096 /* Extracting and converting private key */
1144 GNUNET_CRYPTO_rsa_key_get_public (pkey, &pub); 1097 GNUNET_CRYPTO_rsa_key_get_public (pkey, &pub);
1145 GNUNET_CRYPTO_short_hash (&pub, 1098 GNUNET_CRYPTO_short_hash (&pub,
@@ -1153,7 +1106,8 @@ handle_record_create (void *cls,
1153 "Received new private key for zone `%s'\n", 1106 "Received new private key for zone `%s'\n",
1154 GNUNET_short_h2s(&pubkey_hash)); 1107 GNUNET_short_h2s(&pubkey_hash));
1155 cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); 1108 cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
1156 cc->privkey = GNUNET_CRYPTO_rsa_decode_key (pkey_tmp, key_len); 1109 cc->privkey = pkey;
1110 pkey = NULL;
1157 cc->zone = pubkey_hash; 1111 cc->zone = pubkey_hash;
1158 GNUNET_assert (GNUNET_YES == 1112 GNUNET_assert (GNUNET_YES ==
1159 GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, 1113 GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc,
@@ -1165,7 +1119,6 @@ handle_record_create (void *cls,
1165 name_tmp, GNUNET_short_h2s(&pubkey_hash)); 1119 name_tmp, GNUNET_short_h2s(&pubkey_hash));
1166 crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); 1120 crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
1167 crc.res = GNUNET_SYSERR; 1121 crc.res = GNUNET_SYSERR;
1168 crc.pkey = pkey;
1169 crc.pubkey = &pub; 1122 crc.pubkey = &pub;
1170 crc.rd = &rd; 1123 crc.rd = &rd;
1171 crc.name = name_tmp; 1124 crc.name = name_tmp;
@@ -1175,7 +1128,8 @@ handle_record_create (void *cls,
1175 &handle_create_record_it, &crc); 1128 &handle_create_record_it, &crc);
1176 if (res != GNUNET_SYSERR) 1129 if (res != GNUNET_SYSERR)
1177 res = GNUNET_OK; 1130 res = GNUNET_OK;
1178 GNUNET_CRYPTO_rsa_key_free (pkey); 1131 if (NULL != pkey)
1132 GNUNET_CRYPTO_rsa_key_free (pkey);
1179 1133
1180 /* Send response */ 1134 /* Send response */
1181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1196,9 +1150,10 @@ handle_record_create (void *cls,
1196} 1150}
1197 1151
1198 1152
1153/////////////////////////////////////////////////////////////
1154
1155
1199/** 1156/**
1200 * RemoveRecordContext
1201 *
1202 * Context for record remove operations passed from 'handle_record_remove' to 1157 * Context for record remove operations passed from 'handle_record_remove' to
1203 * 'handle_record_remove_it' as closure 1158 * 'handle_record_remove_it' as closure
1204 */ 1159 */
@@ -1207,40 +1162,39 @@ struct RemoveRecordContext
1207 /** 1162 /**
1208 * Record to remove 1163 * Record to remove
1209 */ 1164 */
1210 struct GNUNET_NAMESTORE_RecordData *rd; 1165 const struct GNUNET_NAMESTORE_RecordData *rd;
1211
1212 /**
1213 * Zone's private keys
1214 */
1215 struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
1216
1217 /**
1218 * Name to remove
1219 */
1220 int remove_name;
1221 1166
1222 /** 1167 /**
1223 * 0 : Success 1168 * See RECORD_REMOVE_RESULT_*-codes. Set by 'handle_record_remove_it'
1224 * 1 : Could not find record to remove, empty result set 1169 * to the result of the operation.
1225 * 2 : Could not find record to remove, record did not exist in result set
1226 * 3 : Could not remove records from database
1227 * 4 : Could not put records into database
1228 */ 1170 */
1229 uint16_t op_res; 1171 int32_t op_res;
1230}; 1172};
1231 1173
1232 1174
1233/** 1175/**
1234 * FIXME... 1176 * We are to remove a record (or all records for a given name). This function
1177 * will be called with the existing records (if there are any) and is to then
1178 * compute what to keep and trigger the necessary changes.
1179 *
1180 * @param cls the 'struct RecordRemoveContext' with information about what to remove
1181 * @param zone_key public key of the zone
1182 * @param expire when does the corresponding block in the DHT expire (until
1183 * when should we never do a DHT lookup for the same name again)?
1184 * @param name name that is being mapped (at most 255 characters long)
1185 * @param rd_count number of entries in 'rd' array
1186 * @param rd array of records with data to store
1187 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
1188 * because the user queried for a particular record type only)
1235 */ 1189 */
1236static void 1190static void
1237handle_record_remove_it (void *cls, 1191handle_record_remove_it (void *cls,
1238 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, 1192 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
1239 struct GNUNET_TIME_Absolute expire, 1193 struct GNUNET_TIME_Absolute expire,
1240 const char *name, 1194 const char *name,
1241 unsigned int rd_count, 1195 unsigned int rd_count,
1242 const struct GNUNET_NAMESTORE_RecordData *rd, 1196 const struct GNUNET_NAMESTORE_RecordData *rd,
1243 const struct GNUNET_CRYPTO_RsaSignature *signature) 1197 const struct GNUNET_CRYPTO_RsaSignature *signature)
1244{ 1198{
1245 static struct GNUNET_CRYPTO_RsaSignature dummy_signature; 1199 static struct GNUNET_CRYPTO_RsaSignature dummy_signature;
1246 struct RemoveRecordContext *rrc = cls; 1200 struct RemoveRecordContext *rrc = cls;
@@ -1301,7 +1255,7 @@ handle_record_remove_it (void *cls,
1301 name)) 1255 name))
1302 { 1256 {
1303 /* Could not remove records from database */ 1257 /* Could not remove records from database */
1304 rrc->op_res = RECORD_REMOVE_RESULT_FAILED_TO_SIGN; /* ??? */ 1258 rrc->op_res = RECORD_REMOVE_RESULT_FAILED_TO_REMOVE;
1305 return; 1259 return;
1306 } 1260 }
1307 rrc->op_res = RECORD_REMOVE_RESULT_SUCCESS; 1261 rrc->op_res = RECORD_REMOVE_RESULT_SUCCESS;
@@ -1469,7 +1423,6 @@ handle_record_remove (void *cls,
1469 "Removing record for name `%s' in zone `%s'\n", name_tmp, 1423 "Removing record for name `%s' in zone `%s'\n", name_tmp,
1470 GNUNET_short_h2s (&pubkey_hash)); 1424 GNUNET_short_h2s (&pubkey_hash));
1471 rrc.rd = &rd; 1425 rrc.rd = &rd;
1472 rrc.pkey = pkey;
1473 res = GSN_database->iterate_records (GSN_database->cls, 1426 res = GSN_database->iterate_records (GSN_database->cls,
1474 &pubkey_hash, 1427 &pubkey_hash,
1475 name_tmp, 1428 name_tmp,
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index c86a2513b..990deab1e 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -423,6 +423,7 @@ struct RecordRemoveMessage
423 423
424/** 424/**
425 * Internal error, failed to sign the remaining records. 425 * Internal error, failed to sign the remaining records.
426 * (Note: not used?)
426 */ 427 */
427#define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3 428#define RECORD_REMOVE_RESULT_FAILED_TO_SIGN 3
428 429
@@ -432,6 +433,12 @@ struct RecordRemoveMessage
432#define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4 433#define RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE 4
433 434
434/** 435/**
436 * Internal error, failed to remove records from database
437 */
438#define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5
439
440
441/**
435 * Remove a record from the namestore response 442 * Remove a record from the namestore response
436 */ 443 */
437struct RecordRemoveResponseMessage 444struct RecordRemoveResponseMessage
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 34c83f0b4..f48ea25e5 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -418,6 +418,10 @@ handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
418 ret = GNUNET_SYSERR; 418 ret = GNUNET_SYSERR;
419 emsg = _("Failed to put new set of records in database"); 419 emsg = _("Failed to put new set of records in database");
420 break; 420 break;
421 case RECORD_REMOVE_RESULT_FAILED_TO_REMOVE:
422 ret = GNUNET_SYSERR;
423 emsg = _("Failed to remove records from database");
424 break;
421 default: 425 default:
422 GNUNET_break (0); 426 GNUNET_break (0);
423 ret = GNUNET_SYSERR; 427 ret = GNUNET_SYSERR;