aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-28 20:58:15 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-28 20:58:15 +0000
commitb20a41aaa09caa197e789584e5ad2b0f29b143f1 (patch)
treefe9c9f9d24702b3a708d1e81d6a9db19064b0455 /src/namestore
parent9ceaa074240bdc82daf5be233a3035714f002990 (diff)
downloadgnunet-b20a41aaa09caa197e789584e5ad2b0f29b143f1.tar.gz
gnunet-b20a41aaa09caa197e789584e5ad2b0f29b143f1.zip
-more namestore service cleanup -- wip
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-service-namestore.c142
-rw-r--r--src/namestore/namestore.h10
-rw-r--r--src/namestore/namestore_api.c8
-rw-r--r--src/namestore/plugin_namestore_postgres.c3
-rw-r--r--src/namestore/plugin_namestore_sqlite.c1
5 files changed, 99 insertions, 65 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 2faaaa3ab..83cad685b 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1150,9 +1150,6 @@ handle_record_create (void *cls,
1150} 1150}
1151 1151
1152 1152
1153/////////////////////////////////////////////////////////////
1154
1155
1156/** 1153/**
1157 * Context for record remove operations passed from 'handle_record_remove' to 1154 * Context for record remove operations passed from 'handle_record_remove' to
1158 * 'handle_record_remove_it' as closure 1155 * 'handle_record_remove_it' as closure
@@ -1200,7 +1197,7 @@ handle_record_remove_it (void *cls,
1200 struct RemoveRecordContext *rrc = cls; 1197 struct RemoveRecordContext *rrc = cls;
1201 unsigned int c; 1198 unsigned int c;
1202 int found; 1199 int found;
1203 unsigned int rd_count_new; 1200 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
1204 1201
1205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1206 "Name `%s 'currently has %u records\n", 1203 "Name `%s 'currently has %u records\n",
@@ -1213,9 +1210,11 @@ handle_record_remove_it (void *cls,
1213 } 1210 }
1214 1211
1215 /* Find record to remove */ 1212 /* Find record to remove */
1216 found = GNUNET_SYSERR; 1213 found = -1;
1217 for (c = 0; c < rd_count; c++) 1214 for (c = 0; c < rd_count; c++)
1218 { 1215 {
1216 /* FIXME: shouldn't we test for all fields to match? Otherwise
1217 we might remove the wrong record, just because the type matches! */
1219 /* 1218 /*
1220 if (rd[c].flags != rrc->rd->flags) 1219 if (rd[c].flags != rrc->rd->flags)
1221 continue;*/ 1220 continue;*/
@@ -1232,17 +1231,14 @@ handle_record_remove_it (void *cls,
1232 found = c; 1231 found = c;
1233 break; 1232 break;
1234 } 1233 }
1235 if (GNUNET_SYSERR == found) 1234 if (-1 == found)
1236 { 1235 {
1237 /* Could not find record to remove */ 1236 /* Could not find record to remove */
1238 rrc->op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND; 1237 rrc->op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND;
1239 return; 1238 return;
1240 } 1239 }
1241
1242 if (1 == rd_count) 1240 if (1 == rd_count)
1243 { 1241 {
1244 struct GNUNET_CRYPTO_ShortHashCode pubkey_hash;
1245
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1247 "No records left for name `%s', removing name\n", 1243 "No records left for name `%s', removing name\n",
1248 name); 1244 name);
@@ -1262,31 +1258,28 @@ handle_record_remove_it (void *cls,
1262 return; 1258 return;
1263 } 1259 }
1264 1260
1265 rd_count_new = rd_count - 1;
1266 struct GNUNET_NAMESTORE_RecordData rd_new[rd_count_new];
1267 unsigned int c2 = 0;
1268 for (c = 0; c < rd_count; c++)
1269 { 1261 {
1270 if (c != found) 1262 struct GNUNET_NAMESTORE_RecordData rd_new[rd_count - 1];
1263 unsigned int c2 = 0;
1264
1265 for (c = 0; c < rd_count; c++)
1271 { 1266 {
1272 GNUNET_assert (c2 < rd_count_new); 1267 if (c == found)
1273 rd_new[c2] = rd[c]; 1268 continue;
1274 c2++; 1269 rd_new[c2++] = rd[c];
1270 }
1271 if (GNUNET_OK !=
1272 GSN_database->put_records(GSN_database->cls,
1273 zone_key,
1274 expire,
1275 name,
1276 rd_count - 1, rd_new,
1277 &dummy_signature))
1278 {
1279 /* Could not put records into database */
1280 rrc->op_res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE;
1281 return;
1275 } 1282 }
1276 }
1277
1278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name `%s' now has %u records\n", name, rd_count_new);
1279 if (GNUNET_OK !=
1280 GSN_database->put_records(GSN_database->cls,
1281 zone_key,
1282 expire,
1283 name,
1284 rd_count_new, rd_new,
1285 &dummy_signature))
1286 {
1287 /* Could not put records into database */
1288 rrc->op_res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE;
1289 return;
1290 } 1283 }
1291 rrc->op_res = RECORD_REMOVE_RESULT_SUCCESS; 1284 rrc->op_res = RECORD_REMOVE_RESULT_SUCCESS;
1292} 1285}
@@ -1326,7 +1319,9 @@ handle_record_remove (void *cls,
1326 struct RemoveRecordContext rrc; 1319 struct RemoveRecordContext rrc;
1327 int res; 1320 int res;
1328 1321
1329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE"); 1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1323 "Received `%s' message\n",
1324 "NAMESTORE_RECORD_REMOVE");
1330 if (ntohs (message->size) < sizeof (struct RecordRemoveMessage)) 1325 if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
1331 { 1326 {
1332 GNUNET_break (0); 1327 GNUNET_break (0);
@@ -1385,18 +1380,21 @@ handle_record_remove (void *cls,
1385 "Received new private key for zone `%s'\n", 1380 "Received new private key for zone `%s'\n",
1386 GNUNET_short_h2s (&pubkey_hash)); 1381 GNUNET_short_h2s (&pubkey_hash));
1387 cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); 1382 cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer));
1388 cc->privkey = GNUNET_CRYPTO_rsa_decode_key (pkey_tmp, key_len); 1383 cc->privkey = pkey;
1384 pkey = NULL;
1389 cc->zone = pubkey_hash; 1385 cc->zone = pubkey_hash;
1390 GNUNET_assert (GNUNET_YES == 1386 GNUNET_assert (GNUNET_YES ==
1391 GNUNET_CONTAINER_multihashmap_put (zonekeys, 1387 GNUNET_CONTAINER_multihashmap_put (zonekeys,
1392 &long_hash, cc, 1388 &long_hash, cc,
1393 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1389 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1394 } 1390 }
1391 if (NULL != pkey)
1392 GNUNET_CRYPTO_rsa_key_free (pkey);
1393
1395 if (GNUNET_OK != 1394 if (GNUNET_OK !=
1396 GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, &rd)) 1395 GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, &rd))
1397 { 1396 {
1398 GNUNET_break (0); 1397 GNUNET_break (0);
1399 GNUNET_CRYPTO_rsa_key_free (pkey);
1400 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1398 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1401 return; 1399 return;
1402 } 1400 }
@@ -1428,12 +1426,22 @@ handle_record_remove (void *cls,
1428 name_tmp, 1426 name_tmp,
1429 0, 1427 0,
1430 handle_record_remove_it, &rrc); 1428 handle_record_remove_it, &rrc);
1431 1429 switch (res)
1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1430 {
1433 "Removing record for name `%s': %s\n", 1431 case GNUNET_OK:
1434 name_tmp, 1432 res = rrc.op_res;
1435 (0 == rrc.op_res) ? "OK" : "FAIL"); 1433 break;
1436 res = rrc.op_res; 1434 case GNUNET_NO:
1435 res = RECORD_REMOVE_RESULT_NO_RECORDS;
1436 break;
1437 case GNUNET_SYSERR:
1438 res = RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE;
1439 break;
1440 default:
1441 GNUNET_break (0);
1442 res = RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR;
1443 break;
1444 }
1437 } 1445 }
1438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1439 "Sending `%s' message\n", 1447 "Sending `%s' message\n",
@@ -1445,7 +1453,6 @@ handle_record_remove (void *cls,
1445 GNUNET_SERVER_notification_context_unicast (snc, nc->client, 1453 GNUNET_SERVER_notification_context_unicast (snc, nc->client,
1446 &rrr_msg.gns_header.header, 1454 &rrr_msg.gns_header.header,
1447 GNUNET_NO); 1455 GNUNET_NO);
1448 GNUNET_CRYPTO_rsa_key_free (pkey);
1449 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1456 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1450} 1457}
1451 1458
@@ -1462,12 +1469,14 @@ struct ZoneToNameCtx
1462 struct GNUNET_NAMESTORE_Client *nc; 1469 struct GNUNET_NAMESTORE_Client *nc;
1463 1470
1464 /** 1471 /**
1465 * Request id 1472 * Request id (to be used in the response to the client).
1466 */ 1473 */
1467 uint32_t rid; 1474 uint32_t rid;
1468 1475
1469 /** 1476 /**
1470 * Set to GNUNET_OK on success, GNUNET_SYSERR on error 1477 * Set to GNUNET_OK on success, GNUNET_SYSERR on error. Note that
1478 * not finding a name for the zone still counts as a 'success' here,
1479 * as this field is about the success of executing the IPC protocol.
1471 */ 1480 */
1472 int success; 1481 int success;
1473}; 1482};
@@ -1503,29 +1512,27 @@ handle_zone_to_name_it (void *cls,
1503 char *rd_tmp; 1512 char *rd_tmp;
1504 char *sig_tmp; 1513 char *sig_tmp;
1505 1514
1506 if ((zone_key != NULL) && (name != NULL)) 1515 if ((NULL != zone_key) && (NULL != name))
1507 { 1516 {
1508 /* found result */ 1517 /* found result */
1509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name is `%s', has %u records\n", name, rd_count); 1518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1519 "Found result: name `%s' has %u records\n",
1520 name, rd_count);
1510 res = GNUNET_YES; 1521 res = GNUNET_YES;
1511 name_len = strlen (name) + 1; 1522 name_len = strlen (name) + 1;
1512 } 1523 }
1513 else 1524 else
1514 { 1525 {
1515 /* no result found */ 1526 /* no result found */
1516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found no results\n"); 1527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1528 "Found no results\n");
1517 res = GNUNET_NO; 1529 res = GNUNET_NO;
1518 name_len = 0; 1530 name_len = 0;
1519 } 1531 }
1520
1521 if (rd_count > 0)
1522 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1523 else
1524 rd_ser_len = 0;
1525
1526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1527 "Sending `%s' message\n", 1533 "Sending `%s' message\n",
1528 "ZONE_TO_NAME_RESPONSE"); 1534 "ZONE_TO_NAME_RESPONSE");
1535 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1529 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len; 1536 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len;
1530 if (NULL != signature) 1537 if (NULL != signature)
1531 msg_size += sizeof (struct GNUNET_CRYPTO_RsaSignature); 1538 msg_size += sizeof (struct GNUNET_CRYPTO_RsaSignature);
@@ -1581,30 +1588,35 @@ handle_zone_to_name (void *cls,
1581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1582 "Received `%s' message\n", 1589 "Received `%s' message\n",
1583 "ZONE_TO_NAME"); 1590 "ZONE_TO_NAME");
1584 if (ntohs (message->size) != sizeof (struct ZoneToNameMessage)) 1591 ztn_msg = (const struct ZoneToNameMessage *) message;
1585 {
1586 GNUNET_break (0);
1587 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1588 return;
1589 }
1590 if (NULL == (nc = client_lookup(client))) 1592 if (NULL == (nc = client_lookup(client)))
1591 { 1593 {
1592 GNUNET_break (0); 1594 GNUNET_break (0);
1593 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1595 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1594 return; 1596 return;
1595 } 1597 }
1596 ztn_msg = (const struct ZoneToNameMessage *) message;
1597 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 1598 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1598 ztn_ctx.nc = nc; 1599 ztn_ctx.nc = nc;
1599 ztn_ctx.success = GNUNET_SYSERR; 1600 ztn_ctx.success = GNUNET_SYSERR;
1600 GSN_database->zone_to_name (GSN_database->cls, 1601 if (GNUNET_SYSERR ==
1601 &ztn_msg->zone, 1602 GSN_database->zone_to_name (GSN_database->cls,
1602 &ztn_msg->value_zone, 1603 &ztn_msg->zone,
1603 &handle_zone_to_name_it, &ztn_ctx); 1604 &ztn_msg->value_zone,
1605 &handle_zone_to_name_it, &ztn_ctx))
1606 {
1607 /* internal error, hang up instead of signalling something
1608 that might be wrong */
1609 GNUNET_break (0);
1610 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1611 return;
1612 }
1604 GNUNET_SERVER_receive_done (client, ztn_ctx.success); 1613 GNUNET_SERVER_receive_done (client, ztn_ctx.success);
1605} 1614}
1606 1615
1607 1616
1617/////////////////////////////////////////////////////////////
1618
1619
1608/** 1620/**
1609 * Copy record, data has to be free'd separetely 1621 * Copy record, data has to be free'd separetely
1610 * 1622 *
@@ -1814,6 +1826,8 @@ zone_iteraterate_proc (void *cls,
1814 return; 1826 return;
1815 } 1827 }
1816} 1828}
1829
1830
1817///////////////////////////////////////////////////////////// 1831/////////////////////////////////////////////////////////////
1818 1832
1819 1833
@@ -2182,7 +2196,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
2182 {&handle_record_remove, NULL, 2196 {&handle_record_remove, NULL,
2183 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0}, 2197 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
2184 {&handle_zone_to_name, NULL, 2198 {&handle_zone_to_name, NULL,
2185 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, 0}, 2199 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, sizeof (struct ZoneToNameMessage) },
2186 {&handle_iteration_start, NULL, 2200 {&handle_iteration_start, NULL,
2187 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage) }, 2201 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage) },
2188 {&handle_iteration_next, NULL, 2202 {&handle_iteration_next, NULL,
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index 990deab1e..ca4dae8d8 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -437,6 +437,16 @@ struct RecordRemoveMessage
437 */ 437 */
438#define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5 438#define RECORD_REMOVE_RESULT_FAILED_TO_REMOVE 5
439 439
440/**
441 * Internal error, failed to access database
442 */
443#define RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE 6
444
445/**
446 * Internal error, failed to access database
447 */
448#define RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR 7
449
440 450
441/** 451/**
442 * Remove a record from the namestore response 452 * Remove a record from the namestore response
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index f48ea25e5..3b9675e25 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -422,6 +422,14 @@ handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
422 ret = GNUNET_SYSERR; 422 ret = GNUNET_SYSERR;
423 emsg = _("Failed to remove records from database"); 423 emsg = _("Failed to remove records from database");
424 break; 424 break;
425 case RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE:
426 ret = GNUNET_SYSERR;
427 emsg = _("Failed to access database");
428 break;
429 case RECORD_REMOVE_RESULT_FAILED_INTERNAL_ERROR:
430 ret = GNUNET_SYSERR;
431 emsg = _("unknown internal error in namestore");
432 break;
425 default: 433 default:
426 GNUNET_break (0); 434 GNUNET_break (0);
427 ret = GNUNET_SYSERR; 435 ret = GNUNET_SYSERR;
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index 0df6aa413..214727f7c 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -370,6 +370,7 @@ namestore_postgres_put_records (void *cls,
370 * @param iter iterator to call with the result 370 * @param iter iterator to call with the result
371 * @param iter_cls closure for 'iter' 371 * @param iter_cls closure for 'iter'
372 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error 372 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
373 * 'iter' will have been called unless the return value is 'GNUNET_SYSERR'
373 */ 374 */
374static int 375static int
375get_record_and_call_iterator (struct Plugin *plugin, 376get_record_and_call_iterator (struct Plugin *plugin,
@@ -466,6 +467,7 @@ get_record_and_call_iterator (struct Plugin *plugin,
466 * @param iter function to call with the result 467 * @param iter function to call with the result
467 * @param iter_cls closure for iter 468 * @param iter_cls closure for iter
468 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error 469 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
470 * 'iter' will have been called unless the return value is 'GNUNET_SYSERR'
469 */ 471 */
470static int 472static int
471namestore_postgres_iterate_records (void *cls, 473namestore_postgres_iterate_records (void *cls,
@@ -544,6 +546,7 @@ namestore_postgres_iterate_records (void *cls,
544 * @param iter function to call with the result 546 * @param iter function to call with the result
545 * @param iter_cls closure for iter 547 * @param iter_cls closure for iter
546 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error 548 * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error
549 * 'iter' will have been called unless the return value is 'GNUNET_SYSERR'
547 */ 550 */
548static int 551static int
549namestore_postgres_zone_to_name (void *cls, 552namestore_postgres_zone_to_name (void *cls,
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index b3f57033a..8b35fb84c 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -752,7 +752,6 @@ namestore_sqlite_zone_to_name (void *cls,
752 "sqlite3_reset"); 752 "sqlite3_reset");
753 return GNUNET_SYSERR; 753 return GNUNET_SYSERR;
754 } 754 }
755
756 return get_record_and_call_iterator (plugin, stmt, iter, iter_cls); 755 return get_record_and_call_iterator (plugin, stmt, iter, iter_cls);
757} 756}
758 757