aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c146
1 files changed, 77 insertions, 69 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 6d3cc45ec..a173e8927 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -132,6 +132,11 @@ struct NamestoreClient
132 struct GNUNET_SERVICE_Client *client; 132 struct GNUNET_SERVICE_Client *client;
133 133
134 /** 134 /**
135 * Database handle
136 */
137 struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
138
139 /**
135 * Message queue for transmission to @e client 140 * Message queue for transmission to @e client
136 */ 141 */
137 struct GNUNET_MQ_Handle *mq; 142 struct GNUNET_MQ_Handle *mq;
@@ -353,11 +358,6 @@ static struct GNUNET_STATISTICS_Handle *statistics;
353static struct GNUNET_NAMECACHE_Handle *namecache; 358static struct GNUNET_NAMECACHE_Handle *namecache;
354 359
355/** 360/**
356 * Database handle
357 */
358static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
359
360/**
361 * Name of the database plugin 361 * Name of the database plugin
362 */ 362 */
363static char *db_lib_name; 363static char *db_lib_name;
@@ -436,7 +436,6 @@ cleanup_task (void *cls)
436 GNUNET_NAMECACHE_disconnect (namecache); 436 GNUNET_NAMECACHE_disconnect (namecache);
437 namecache = NULL; 437 namecache = NULL;
438 } 438 }
439 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
440 GNUNET_free (db_lib_name); 439 GNUNET_free (db_lib_name);
441 db_lib_name = NULL; 440 db_lib_name = NULL;
442 if (NULL != monitor_nc) 441 if (NULL != monitor_nc)
@@ -560,11 +559,13 @@ cache_nick (const struct GNUNET_IDENTITY_PrivateKey *zone,
560/** 559/**
561 * Return the NICK record for the zone (if it exists). 560 * Return the NICK record for the zone (if it exists).
562 * 561 *
562 * @param nc the namestore client
563 * @param zone private key for the zone to look for nick 563 * @param zone private key for the zone to look for nick
564 * @return NULL if no NICK record was found 564 * @return NULL if no NICK record was found
565 */ 565 */
566static struct GNUNET_GNSRECORD_Data * 566static struct GNUNET_GNSRECORD_Data *
567get_nick_record (const struct GNUNET_IDENTITY_PrivateKey *zone) 567get_nick_record (const struct NamestoreClient *nc,
568 const struct GNUNET_IDENTITY_PrivateKey *zone)
568{ 569{
569 struct GNUNET_IDENTITY_PublicKey pub; 570 struct GNUNET_IDENTITY_PublicKey pub;
570 struct GNUNET_GNSRECORD_Data *nick; 571 struct GNUNET_GNSRECORD_Data *nick;
@@ -588,11 +589,11 @@ get_nick_record (const struct GNUNET_IDENTITY_PrivateKey *zone)
588 } 589 }
589 590
590 nick = NULL; 591 nick = NULL;
591 res = GSN_database->lookup_records (GSN_database->cls, 592 res = nc->GSN_database->lookup_records (nc->GSN_database->cls,
592 zone, 593 zone,
593 GNUNET_GNS_EMPTY_LABEL_AT, 594 GNUNET_GNS_EMPTY_LABEL_AT,
594 &lookup_nick_it, 595 &lookup_nick_it,
595 &nick); 596 &nick);
596 if ((GNUNET_OK != res) || (NULL == nick)) 597 if ((GNUNET_OK != res) || (NULL == nick))
597 { 598 {
598#if ! defined(GNUNET_CULL_LOGGING) 599#if ! defined(GNUNET_CULL_LOGGING)
@@ -735,7 +736,7 @@ send_lookup_response (struct NamestoreClient *nc,
735 char *name_tmp; 736 char *name_tmp;
736 char *rd_ser; 737 char *rd_ser;
737 738
738 nick = get_nick_record (zone_key); 739 nick = get_nick_record (nc, zone_key);
739 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (rd_count, rd)); 740 GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (rd_count, rd));
740 741
741 if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT))) 742 if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT)))
@@ -936,7 +937,7 @@ refresh_block (struct NamestoreClient *nc,
936 rd_clean[rd_count_clean++] = rd[i]; 937 rd_clean[rd_count_clean++] = rd[i];
937 } 938 }
938 939
939 nick = get_nick_record (zone_key); 940 nick = get_nick_record (nc, zone_key);
940 res_count = rd_count_clean; 941 res_count = rd_count_clean;
941 res = (struct GNUNET_GNSRECORD_Data *) rd_clean; /* fixme: a bit unclean... */ 942 res = (struct GNUNET_GNSRECORD_Data *) rd_clean; /* fixme: a bit unclean... */
942 if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT))) 943 if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT)))
@@ -1168,6 +1169,7 @@ client_disconnect_cb (void *cls,
1168 for (cop = cop_head; NULL != cop; cop = cop->next) 1169 for (cop = cop_head; NULL != cop; cop = cop->next)
1169 if (nc == cop->nc) 1170 if (nc == cop->nc)
1170 cop->nc = NULL; 1171 cop->nc = NULL;
1172 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, nc->GSN_database));
1171 GNUNET_free (nc); 1173 GNUNET_free (nc);
1172} 1174}
1173 1175
@@ -1186,12 +1188,35 @@ client_connect_cb (void *cls,
1186 struct GNUNET_MQ_Handle *mq) 1188 struct GNUNET_MQ_Handle *mq)
1187{ 1189{
1188 struct NamestoreClient *nc; 1190 struct NamestoreClient *nc;
1191 char *database;
1192 char *db_lib_name;
1189 1193
1190 (void) cls; 1194 (void) cls;
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); 1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1192 nc = GNUNET_new (struct NamestoreClient); 1196 nc = GNUNET_new (struct NamestoreClient);
1193 nc->client = client; 1197 nc->client = client;
1194 nc->mq = mq; 1198 nc->mq = mq;
1199 /* Loading database plugin */
1200 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (GSN_cfg,
1201 "namestore",
1202 "database",
1203 &database))
1204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
1205 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database);
1206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Loading %s\n", db_lib_name);
1207 nc->GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg);
1208 GNUNET_free (database);
1209 if (NULL == nc->GSN_database)
1210 {
1211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1212 "Could not load database backend `%s'\n",
1213 db_lib_name);
1214 GNUNET_free (db_lib_name);
1215 GNUNET_free (nc);
1216 return NULL;
1217 }
1218 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Loaded %s\n", db_lib_name);
1219 GNUNET_free (db_lib_name);
1195 return nc; 1220 return nc;
1196} 1221}
1197 1222
@@ -1402,12 +1427,12 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1402 rlc.res_rd_count = 0; 1427 rlc.res_rd_count = 0;
1403 rlc.res_rd = NULL; 1428 rlc.res_rd = NULL;
1404 rlc.rd_ser_len = 0; 1429 rlc.rd_ser_len = 0;
1405 rlc.nick = get_nick_record (&ll_msg->zone); 1430 rlc.nick = get_nick_record (nc, &ll_msg->zone);
1406 res = GSN_database->lookup_records (GSN_database->cls, 1431 res = nc->GSN_database->lookup_records (nc->GSN_database->cls,
1407 &ll_msg->zone, 1432 &ll_msg->zone,
1408 conv_name, 1433 conv_name,
1409 &lookup_it, 1434 &lookup_it,
1410 &rlc); 1435 &rlc);
1411 env = 1436 env =
1412 GNUNET_MQ_msg_extra (llr_msg, 1437 GNUNET_MQ_msg_extra (llr_msg,
1413 name_len + rlc.rd_ser_len, 1438 name_len + rlc.rd_ser_len,
@@ -1591,11 +1616,11 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1591 "Creating %u records for name `%s'\n", 1616 "Creating %u records for name `%s'\n",
1592 (unsigned int) rd_count, 1617 (unsigned int) rd_count,
1593 conv_name); 1618 conv_name);
1594 if ((GNUNET_NO == GSN_database->lookup_records (GSN_database->cls, 1619 if ((GNUNET_NO == nc->GSN_database->lookup_records (nc->GSN_database->cls,
1595 &rp_msg->private_key, 1620 &rp_msg->private_key,
1596 conv_name, 1621 conv_name,
1597 &get_block_exp_existing, 1622 &get_block_exp_existing,
1598 &existing_block_exp)) && 1623 &existing_block_exp)) &&
1599 (rd_count == 0)) 1624 (rd_count == 0))
1600 { 1625 {
1601 /* This name does not exist, so cannot be removed */ 1626 /* This name does not exist, so cannot be removed */
@@ -1676,11 +1701,11 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg)
1676 /* remove nick record from cache, in case we have one there */ 1701 /* remove nick record from cache, in case we have one there */
1677 cache_nick (&rp_msg->private_key, NULL); 1702 cache_nick (&rp_msg->private_key, NULL);
1678 } 1703 }
1679 res = GSN_database->store_records (GSN_database->cls, 1704 res = nc->GSN_database->store_records (nc->GSN_database->cls,
1680 &rp_msg->private_key, 1705 &rp_msg->private_key,
1681 conv_name, 1706 conv_name,
1682 rd_nf_count, 1707 rd_nf_count,
1683 rd_nf); 1708 rd_nf);
1684 } 1709 }
1685 1710
1686 if (GNUNET_OK != res) 1711 if (GNUNET_OK != res)
@@ -1817,11 +1842,11 @@ handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg)
1817 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 1842 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1818 ztn_ctx.nc = nc; 1843 ztn_ctx.nc = nc;
1819 ztn_ctx.success = GNUNET_NO; 1844 ztn_ctx.success = GNUNET_NO;
1820 if (GNUNET_SYSERR == GSN_database->zone_to_name (GSN_database->cls, 1845 if (GNUNET_SYSERR == nc->GSN_database->zone_to_name (nc->GSN_database->cls,
1821 &ztn_msg->zone, 1846 &ztn_msg->zone,
1822 &ztn_msg->value_zone, 1847 &ztn_msg->value_zone,
1823 &handle_zone_to_name_it, 1848 &handle_zone_to_name_it,
1824 &ztn_ctx)) 1849 &ztn_ctx))
1825 { 1850 {
1826 /* internal error, hang up instead of signalling something 1851 /* internal error, hang up instead of signalling something
1827 that might be wrong */ 1852 that might be wrong */
@@ -1935,6 +1960,7 @@ run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit)
1935 struct ZoneIterationProcResult proc; 1960 struct ZoneIterationProcResult proc;
1936 struct GNUNET_TIME_Absolute start; 1961 struct GNUNET_TIME_Absolute start;
1937 struct GNUNET_TIME_Relative duration; 1962 struct GNUNET_TIME_Relative duration;
1963 struct NamestoreClient *nc = zi->nc;
1938 1964
1939 memset (&proc, 0, sizeof(proc)); 1965 memset (&proc, 0, sizeof(proc));
1940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1966 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1945,15 +1971,16 @@ run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit)
1945 proc.limit = limit; 1971 proc.limit = limit;
1946 start = GNUNET_TIME_absolute_get (); 1972 start = GNUNET_TIME_absolute_get ();
1947 GNUNET_break (GNUNET_SYSERR != 1973 GNUNET_break (GNUNET_SYSERR !=
1948 GSN_database->iterate_records (GSN_database->cls, 1974 nc->GSN_database->iterate_records (nc->GSN_database->cls,
1949 (GNUNET_YES == GNUNET_is_zero ( 1975 (GNUNET_YES ==
1950 &zi->zone)) 1976 GNUNET_is_zero (
1977 &zi->zone))
1951 ? NULL 1978 ? NULL
1952 : &zi->zone, 1979 : &zi->zone,
1953 zi->seq, 1980 zi->seq,
1954 limit, 1981 limit,
1955 &zone_iterate_proc, 1982 &zone_iterate_proc,
1956 &proc)); 1983 &proc));
1957 duration = GNUNET_TIME_absolute_get_duration (start); 1984 duration = GNUNET_TIME_absolute_get_duration (start);
1958 duration = GNUNET_TIME_relative_divide (duration, limit - proc.limit); 1985 duration = GNUNET_TIME_relative_divide (duration, limit - proc.limit);
1959 GNUNET_STATISTICS_set (statistics, 1986 GNUNET_STATISTICS_set (statistics,
@@ -2212,6 +2239,7 @@ static void
2212monitor_iteration_next (void *cls) 2239monitor_iteration_next (void *cls)
2213{ 2240{
2214 struct ZoneMonitor *zm = cls; 2241 struct ZoneMonitor *zm = cls;
2242 struct NamestoreClient *nc = zm->nc;
2215 int ret; 2243 int ret;
2216 2244
2217 zm->task = NULL; 2245 zm->task = NULL;
@@ -2220,15 +2248,13 @@ monitor_iteration_next (void *cls)
2220 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */ 2248 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
2221 else 2249 else
2222 zm->iteration_cnt = zm->limit; /* use it all */ 2250 zm->iteration_cnt = zm->limit; /* use it all */
2223 ret = GSN_database->iterate_records (GSN_database->cls, 2251 ret = nc->GSN_database->iterate_records (nc->GSN_database->cls,
2224 (GNUNET_YES == GNUNET_is_zero ( 2252 (GNUNET_YES == GNUNET_is_zero (
2225 &zm->zone)) 2253 &zm->zone)) ? NULL : &zm->zone,
2226 ? NULL 2254 zm->seq,
2227 : &zm->zone, 2255 zm->iteration_cnt,
2228 zm->seq, 2256 &monitor_iterate_cb,
2229 zm->iteration_cnt, 2257 zm);
2230 &monitor_iterate_cb,
2231 zm);
2232 if (GNUNET_SYSERR == ret) 2258 if (GNUNET_SYSERR == ret)
2233 { 2259 {
2234 GNUNET_SERVICE_client_drop (zm->nc->client); 2260 GNUNET_SERVICE_client_drop (zm->nc->client);
@@ -2330,26 +2356,8 @@ run (void *cls,
2330 namecache = GNUNET_NAMECACHE_connect (cfg); 2356 namecache = GNUNET_NAMECACHE_connect (cfg);
2331 GNUNET_assert (NULL != namecache); 2357 GNUNET_assert (NULL != namecache);
2332 } 2358 }
2333 /* Loading database plugin */
2334 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
2335 "namestore",
2336 "database",
2337 &database))
2338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
2339
2340 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database);
2341 GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg);
2342 GNUNET_free (database);
2343 statistics = GNUNET_STATISTICS_create ("namestore", cfg); 2359 statistics = GNUNET_STATISTICS_create ("namestore", cfg);
2344 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 2360 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
2345 if (NULL == GSN_database)
2346 {
2347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2348 "Could not load database backend `%s'\n",
2349 db_lib_name);
2350 GNUNET_SCHEDULER_shutdown ();
2351 return;
2352 }
2353} 2361}
2354 2362
2355 2363