aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-06-20 13:07:27 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-06-20 13:07:27 +0000
commitf920d447ef216a18b6db1427f164e8b805ba8aa5 (patch)
treef8f521b2f6ee337870f35562c0818a61380a4f88 /src/namestore
parentbd8ba044e2d6d9878b6a24eceb89b29965d08cf3 (diff)
downloadgnunet-f920d447ef216a18b6db1427f164e8b805ba8aa5.tar.gz
gnunet-f920d447ef216a18b6db1427f164e8b805ba8aa5.zip
- docu and cleanup
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-service-namestore.c150
1 files changed, 105 insertions, 45 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index e7ae25bff..ab07b250c 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -199,13 +199,12 @@ struct GNUNET_CONTAINER_MultiHashMap *zonekeys;
199 199
200 200
201/** 201/**
202 * Write zonefile to disk 202 * Writes the encrypted private key of a zone in a file
203 * @param filename where to write
204 * @param c the crypto container
205 * 203 *
204 * @param filename where to store the zone
205 * @param c the crypto container containing private key of the zone
206 * @return GNUNET_OK on success, GNUNET_SYSERR on fail 206 * @return GNUNET_OK on success, GNUNET_SYSERR on fail
207 */ 207 */
208
209static int 208static int
210write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer *c) 209write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer *c)
211{ 210{
@@ -282,6 +281,17 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer
282 return GNUNET_OK; 281 return GNUNET_OK;
283} 282}
284 283
284
285/**
286 * Write all zone keys to disk.
287 * Iterates over all entries of the hashmap 'zonekeys'
288 *
289 * @param cls unused
290 * @param key zone key
291 * @param value 'struct GNUNET_NAMESTORE_CryptoContainer' containing the private
292 * key
293 * @return GNUNET_OK to continue iteration
294 */
285static int 295static int
286zone_to_disk_it (void *cls, 296zone_to_disk_it (void *cls,
287 const struct GNUNET_HashCode *key, 297 const struct GNUNET_HashCode *key,
@@ -296,7 +306,6 @@ zone_to_disk_it (void *cls,
296 write_key_to_file(c->filename, c); 306 write_key_to_file(c->filename, c);
297 } 307 }
298 308
299
300 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value)); 309 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value));
301 GNUNET_CRYPTO_rsa_key_free (c->privkey); 310 GNUNET_CRYPTO_rsa_key_free (c->privkey);
302 GNUNET_free (c->pubkey); 311 GNUNET_free (c->pubkey);
@@ -307,6 +316,15 @@ zone_to_disk_it (void *cls,
307} 316}
308 317
309 318
319/**
320 * Returns the expiration time of the given block of records
321 * The block expiration time is the expiration time of the block with smallest
322 * expiration time
323 *
324 * @param rd_count number of records given in 'rd'
325 * @param rd array of records
326 * @return absolute expiration time
327 */
310struct GNUNET_TIME_Absolute 328struct GNUNET_TIME_Absolute
311get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) 329get_block_expiration_time (unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd)
312{ 330{
@@ -391,8 +409,8 @@ client_lookup (struct GNUNET_SERVER_Client *client)
391} 409}
392 410
393/** 411/**
394* Called whenever a client is disconnected. Frees our 412 * Called whenever a client is disconnected.
395 * resources associated with that client. 413 * Frees our resources associated with that client.
396 * 414 *
397 * @param cls closure 415 * @param cls closure
398 * @param client identification of the client 416 * @param client identification of the client
@@ -426,8 +444,13 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
426 nc = NULL; 444 nc = NULL;
427} 445}
428 446
429 447/**
430 448 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_START' message
449 *
450 * @param cls unused
451 * @param client GNUNET_SERVER_Client sending the message
452 * @param message unused
453 */
431static void 454static void
432handle_start (void *cls, 455handle_start (void *cls,
433 struct GNUNET_SERVER_Client *client, 456 struct GNUNET_SERVER_Client *client,
@@ -454,29 +477,6 @@ struct LookupNameContext
454 char *name; 477 char *name;
455}; 478};
456 479
457static void
458drop_iterator (void *cls,
459 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
460 struct GNUNET_TIME_Absolute expire,
461 const char *name,
462 unsigned int rd_len,
463 const struct GNUNET_NAMESTORE_RecordData *rd,
464 const struct GNUNET_CRYPTO_RsaSignature *signature)
465{
466 struct GNUNET_CRYPTO_ShortHashCode zone_hash;
467 int *stop = cls;
468 if (NULL != zone_key)
469 {
470 GNUNET_CRYPTO_short_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash);
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting zone `%s'\n", GNUNET_short_h2s (&zone_hash));
472 GSN_database->delete_zone (GSN_database->cls, &zone_hash);
473 }
474 else
475 {
476 (*stop) = GNUNET_YES;
477 }
478}
479
480 480
481static void 481static void
482handle_lookup_name_it (void *cls, 482handle_lookup_name_it (void *cls,
@@ -630,6 +630,13 @@ handle_lookup_name_it (void *cls,
630 GNUNET_free (lnr_msg); 630 GNUNET_free (lnr_msg);
631} 631}
632 632
633/**
634 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME' message
635 *
636 * @param cls unused
637 * @param client GNUNET_SERVER_Client sending the message
638 * @param message message of type 'struct LookupNameMessage'
639 */
633static void 640static void
634handle_lookup_name (void *cls, 641handle_lookup_name (void *cls,
635 struct GNUNET_SERVER_Client *client, 642 struct GNUNET_SERVER_Client *client,
@@ -694,6 +701,14 @@ handle_lookup_name (void *cls,
694 GNUNET_SERVER_receive_done (client, GNUNET_OK); 701 GNUNET_SERVER_receive_done (client, GNUNET_OK);
695} 702}
696 703
704
705/**
706 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT' message
707 *
708 * @param cls unused
709 * @param client GNUNET_SERVER_Client sending the message
710 * @param message message of type 'struct RecordPutMessage'
711 */
697static void 712static void
698handle_record_put (void *cls, 713handle_record_put (void *cls,
699 struct GNUNET_SERVER_Client *client, 714 struct GNUNET_SERVER_Client *client,
@@ -701,6 +716,7 @@ handle_record_put (void *cls,
701{ 716{
702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT"); 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_PUT");
703 struct GNUNET_NAMESTORE_Client *nc; 718 struct GNUNET_NAMESTORE_Client *nc;
719 struct RecordPutMessage *rp_msg;
704 struct GNUNET_TIME_Absolute expire; 720 struct GNUNET_TIME_Absolute expire;
705 struct GNUNET_CRYPTO_RsaSignature *signature; 721 struct GNUNET_CRYPTO_RsaSignature *signature;
706 struct RecordPutResponseMessage rpr_msg; 722 struct RecordPutResponseMessage rpr_msg;
@@ -729,8 +745,7 @@ handle_record_put (void *cls,
729 return; 745 return;
730 } 746 }
731 747
732 struct RecordPutMessage *rp_msg = (struct RecordPutMessage *) message; 748 rp_msg = (struct RecordPutMessage *) message;
733
734 rid = ntohl (rp_msg->gns_header.r_id); 749 rid = ntohl (rp_msg->gns_header.r_id);
735 msg_size = ntohs (rp_msg->gns_header.header.size); 750 msg_size = ntohs (rp_msg->gns_header.header.size);
736 name_len = ntohs (rp_msg->name_len); 751 name_len = ntohs (rp_msg->name_len);
@@ -967,11 +982,17 @@ end:
967 default: 982 default:
968 break; 983 break;
969 } 984 }
970
971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name `%s' %u\n", crc->name, res); 985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name `%s' %u\n", crc->name, res);
972
973} 986}
974 987
988
989/**
990 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE' message
991 *
992 * @param cls unused
993 * @param client GNUNET_SERVER_Client sending the message
994 * @param message message of type 'struct RecordCreateMessage'
995 */
975static void 996static void
976handle_record_create (void *cls, 997handle_record_create (void *cls,
977 struct GNUNET_SERVER_Client *client, 998 struct GNUNET_SERVER_Client *client,
@@ -979,6 +1000,7 @@ handle_record_create (void *cls,
979{ 1000{
980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); 1001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE");
981 struct GNUNET_NAMESTORE_Client *nc; 1002 struct GNUNET_NAMESTORE_Client *nc;
1003 struct RecordCreateMessage *rp_msg;
982 struct GNUNET_NAMESTORE_CryptoContainer *cc; 1004 struct GNUNET_NAMESTORE_CryptoContainer *cc;
983 struct CreateRecordContext crc; 1005 struct CreateRecordContext crc;
984 struct GNUNET_CRYPTO_RsaPrivateKey *pkey; 1006 struct GNUNET_CRYPTO_RsaPrivateKey *pkey;
@@ -1015,7 +1037,7 @@ handle_record_create (void *cls,
1015 return; 1037 return;
1016 } 1038 }
1017 1039
1018 struct RecordCreateMessage *rp_msg = (struct RecordCreateMessage *) message; 1040 rp_msg = (struct RecordCreateMessage *) message;
1019 rid = ntohl (rp_msg->gns_header.r_id); 1041 rid = ntohl (rp_msg->gns_header.r_id);
1020 name_len = ntohs (rp_msg->name_len); 1042 name_len = ntohs (rp_msg->name_len);
1021 msg_size = ntohs (message->size); 1043 msg_size = ntohs (message->size);
@@ -1228,7 +1250,13 @@ handle_record_remove_it (void *cls,
1228 rrc->op_res = 0; 1250 rrc->op_res = 0;
1229} 1251}
1230 1252
1231 1253/**
1254 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE' message
1255 *
1256 * @param cls unused
1257 * @param client GNUNET_SERVER_Client sending the message
1258 * @param message message of type 'struct RecordRemoveMessage'
1259 */
1232static void 1260static void
1233handle_record_remove (void *cls, 1261handle_record_remove (void *cls,
1234 struct GNUNET_SERVER_Client *client, 1262 struct GNUNET_SERVER_Client *client,
@@ -1496,7 +1524,13 @@ handle_zone_to_name_it (void *cls,
1496 GNUNET_free_non_null (rd_ser); 1524 GNUNET_free_non_null (rd_ser);
1497} 1525}
1498 1526
1499 1527/**
1528 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME' message
1529 *
1530 * @param cls unused
1531 * @param client GNUNET_SERVER_Client sending the message
1532 * @param message message of type 'struct ZoneToNameMessage'
1533 */
1500static void 1534static void
1501handle_zone_to_name (void *cls, 1535handle_zone_to_name (void *cls,
1502 struct GNUNET_SERVER_Client *client, 1536 struct GNUNET_SERVER_Client *client,
@@ -1504,6 +1538,7 @@ handle_zone_to_name (void *cls,
1504{ 1538{
1505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_TO_NAME"); 1539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_TO_NAME");
1506 struct GNUNET_NAMESTORE_Client *nc; 1540 struct GNUNET_NAMESTORE_Client *nc;
1541 struct ZoneToNameMessage *ztn_msg;
1507 struct ZoneToNameCtx ztn_ctx; 1542 struct ZoneToNameCtx ztn_ctx;
1508 size_t msg_size = 0; 1543 size_t msg_size = 0;
1509 uint32_t rid = 0; 1544 uint32_t rid = 0;
@@ -1523,7 +1558,7 @@ handle_zone_to_name (void *cls,
1523 return; 1558 return;
1524 } 1559 }
1525 1560
1526 struct ZoneToNameMessage *ztn_msg = (struct ZoneToNameMessage *) message; 1561 ztn_msg = (struct ZoneToNameMessage *) message;
1527 1562
1528 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE) 1563 if (msg_size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
1529 { 1564 {
@@ -1816,6 +1851,14 @@ clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc)
1816 proc->rd = NULL; 1851 proc->rd = NULL;
1817} 1852}
1818 1853
1854
1855/**
1856 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START' message
1857 *
1858 * @param cls unused
1859 * @param client GNUNET_SERVER_Client sending the message
1860 * @param message message of type 'struct ZoneIterationStartMessage'
1861 */
1819static void 1862static void
1820handle_iteration_start (void *cls, 1863handle_iteration_start (void *cls,
1821 struct GNUNET_SERVER_Client *client, 1864 struct GNUNET_SERVER_Client *client,
@@ -1826,6 +1869,8 @@ handle_iteration_start (void *cls,
1826 struct ZoneIterationStartMessage *zis_msg = (struct ZoneIterationStartMessage *) message; 1869 struct ZoneIterationStartMessage *zis_msg = (struct ZoneIterationStartMessage *) message;
1827 struct GNUNET_NAMESTORE_Client *nc; 1870 struct GNUNET_NAMESTORE_Client *nc;
1828 struct GNUNET_NAMESTORE_ZoneIteration *zi; 1871 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1872 struct GNUNET_CRYPTO_ShortHashCode dummy;
1873 struct ZoneIterationProcResult proc;
1829 1874
1830 nc = client_lookup(client); 1875 nc = client_lookup(client);
1831 if (nc == NULL) 1876 if (nc == NULL)
@@ -1842,7 +1887,6 @@ handle_iteration_start (void *cls,
1842 zi->must_have_flags = ntohs (zis_msg->must_have_flags); 1887 zi->must_have_flags = ntohs (zis_msg->must_have_flags);
1843 zi->must_not_have_flags = ntohs (zis_msg->must_not_have_flags); 1888 zi->must_not_have_flags = ntohs (zis_msg->must_not_have_flags);
1844 1889
1845 struct GNUNET_CRYPTO_ShortHashCode dummy;
1846 memset (&dummy, '\0', sizeof (dummy)); 1890 memset (&dummy, '\0', sizeof (dummy));
1847 if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy))) 1891 if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy)))
1848 { 1892 {
@@ -1859,9 +1903,7 @@ handle_iteration_start (void *cls,
1859 1903
1860 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 1904 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
1861 1905
1862 struct ZoneIterationProcResult proc;
1863 proc.zi = zi; 1906 proc.zi = zi;
1864
1865 find_next_zone_iteration_result (&proc); 1907 find_next_zone_iteration_result (&proc);
1866 if (GNUNET_YES == proc.res_iteration_finished) 1908 if (GNUNET_YES == proc.res_iteration_finished)
1867 { 1909 {
@@ -1877,6 +1919,14 @@ handle_iteration_start (void *cls,
1877 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1919 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1878} 1920}
1879 1921
1922
1923/**
1924 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP' message
1925 *
1926 * @param cls unused
1927 * @param client GNUNET_SERVER_Client sending the message
1928 * @param message message of type 'struct ZoneIterationStopMessage'
1929 */
1880static void 1930static void
1881handle_iteration_stop (void *cls, 1931handle_iteration_stop (void *cls,
1882 struct GNUNET_SERVER_Client *client, 1932 struct GNUNET_SERVER_Client *client,
@@ -1886,7 +1936,7 @@ handle_iteration_stop (void *cls,
1886 1936
1887 struct GNUNET_NAMESTORE_Client *nc; 1937 struct GNUNET_NAMESTORE_Client *nc;
1888 struct GNUNET_NAMESTORE_ZoneIteration *zi; 1938 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1889 struct ZoneIterationStopMessage *zis_msg = (struct ZoneIterationStopMessage *) message; 1939 struct ZoneIterationStopMessage *zis_msg;
1890 uint32_t rid; 1940 uint32_t rid;
1891 1941
1892 nc = client_lookup(client); 1942 nc = client_lookup(client);
@@ -1897,6 +1947,7 @@ handle_iteration_stop (void *cls,
1897 return; 1947 return;
1898 } 1948 }
1899 1949
1950 zis_msg = (struct ZoneIterationStopMessage *) message;
1900 rid = ntohl (zis_msg->gns_header.r_id); 1951 rid = ntohl (zis_msg->gns_header.r_id);
1901 for (zi = nc->op_head; zi != NULL; zi = zi->next) 1952 for (zi = nc->op_head; zi != NULL; zi = zi->next)
1902 { 1953 {
@@ -1920,6 +1971,14 @@ handle_iteration_stop (void *cls,
1920 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1971 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1921} 1972}
1922 1973
1974
1975/**
1976 * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP' message
1977 *
1978 * @param cls unused
1979 * @param client GNUNET_SERVER_Client sending the message
1980 * @param message message of type 'struct ZoneIterationNextMessage'
1981 */
1923static void 1982static void
1924handle_iteration_next (void *cls, 1983handle_iteration_next (void *cls,
1925 struct GNUNET_SERVER_Client *client, 1984 struct GNUNET_SERVER_Client *client,
@@ -1929,7 +1988,7 @@ handle_iteration_next (void *cls,
1929 1988
1930 struct GNUNET_NAMESTORE_Client *nc; 1989 struct GNUNET_NAMESTORE_Client *nc;
1931 struct GNUNET_NAMESTORE_ZoneIteration *zi; 1990 struct GNUNET_NAMESTORE_ZoneIteration *zi;
1932 struct ZoneIterationStopMessage *zis_msg = (struct ZoneIterationStopMessage *) message; 1991 struct ZoneIterationNextMessage *zis_msg;
1933 uint32_t rid; 1992 uint32_t rid;
1934 1993
1935 nc = client_lookup(client); 1994 nc = client_lookup(client);
@@ -1940,6 +1999,7 @@ handle_iteration_next (void *cls,
1940 return; 1999 return;
1941 } 2000 }
1942 2001
2002 zis_msg = (struct ZoneIterationNextMessage *) message;
1943 rid = ntohl (zis_msg->gns_header.r_id); 2003 rid = ntohl (zis_msg->gns_header.r_id);
1944 for (zi = nc->op_head; zi != NULL; zi = zi->next) 2004 for (zi = nc->op_head; zi != NULL; zi = zi->next)
1945 { 2005 {