diff options
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 0a3dfea25..36f6d337c 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -137,11 +137,16 @@ struct NamestoreClient | |||
137 | struct GNUNET_SERVICE_Client *client; | 137 | struct GNUNET_SERVICE_Client *client; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * Database handle | 140 | * Database handle for client |
141 | */ | 141 | */ |
142 | struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; | 142 | struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * Name of loaded plugin (neeed for cleanup) | ||
146 | */ | ||
147 | char *db_lib_name; | ||
148 | |||
149 | /** | ||
145 | * Message queue for transmission to @e client | 150 | * Message queue for transmission to @e client |
146 | */ | 151 | */ |
147 | struct GNUNET_MQ_Handle *mq; | 152 | struct GNUNET_MQ_Handle *mq; |
@@ -373,6 +378,12 @@ static struct GNUNET_NAMECACHE_Handle *namecache; | |||
373 | static char *db_lib_name; | 378 | static char *db_lib_name; |
374 | 379 | ||
375 | /** | 380 | /** |
381 | * Database handle for service | ||
382 | */ | ||
383 | struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; | ||
384 | |||
385 | |||
386 | /** | ||
376 | * Head of cop DLL. | 387 | * Head of cop DLL. |
377 | */ | 388 | */ |
378 | static struct CacheOperation *cop_head; | 389 | static struct CacheOperation *cop_head; |
@@ -446,8 +457,6 @@ cleanup_task (void *cls) | |||
446 | GNUNET_NAMECACHE_disconnect (namecache); | 457 | GNUNET_NAMECACHE_disconnect (namecache); |
447 | namecache = NULL; | 458 | namecache = NULL; |
448 | } | 459 | } |
449 | GNUNET_free (db_lib_name); | ||
450 | db_lib_name = NULL; | ||
451 | if (NULL != monitor_nc) | 460 | if (NULL != monitor_nc) |
452 | { | 461 | { |
453 | GNUNET_notification_context_destroy (monitor_nc); | 462 | GNUNET_notification_context_destroy (monitor_nc); |
@@ -458,6 +467,9 @@ cleanup_task (void *cls) | |||
458 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); | 467 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); |
459 | statistics = NULL; | 468 | statistics = NULL; |
460 | } | 469 | } |
470 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); | ||
471 | GNUNET_free (db_lib_name); | ||
472 | db_lib_name = NULL; | ||
461 | } | 473 | } |
462 | 474 | ||
463 | 475 | ||
@@ -574,8 +586,7 @@ cache_nick (const struct GNUNET_IDENTITY_PrivateKey *zone, | |||
574 | * @return NULL if no NICK record was found | 586 | * @return NULL if no NICK record was found |
575 | */ | 587 | */ |
576 | static struct GNUNET_GNSRECORD_Data * | 588 | static struct GNUNET_GNSRECORD_Data * |
577 | get_nick_record (const struct NamestoreClient *nc, | 589 | get_nick_record (const struct GNUNET_IDENTITY_PrivateKey *zone) |
578 | const struct GNUNET_IDENTITY_PrivateKey *zone) | ||
579 | { | 590 | { |
580 | struct GNUNET_IDENTITY_PublicKey pub; | 591 | struct GNUNET_IDENTITY_PublicKey pub; |
581 | struct GNUNET_GNSRECORD_Data *nick; | 592 | struct GNUNET_GNSRECORD_Data *nick; |
@@ -599,11 +610,11 @@ get_nick_record (const struct NamestoreClient *nc, | |||
599 | } | 610 | } |
600 | 611 | ||
601 | nick = NULL; | 612 | nick = NULL; |
602 | res = nc->GSN_database->lookup_records (nc->GSN_database->cls, | 613 | res = GSN_database->lookup_records (GSN_database->cls, |
603 | zone, | 614 | zone, |
604 | GNUNET_GNS_EMPTY_LABEL_AT, | 615 | GNUNET_GNS_EMPTY_LABEL_AT, |
605 | &lookup_nick_it, | 616 | &lookup_nick_it, |
606 | &nick); | 617 | &nick); |
607 | if ((GNUNET_OK != res) || (NULL == nick)) | 618 | if ((GNUNET_OK != res) || (NULL == nick)) |
608 | { | 619 | { |
609 | #if ! defined(GNUNET_CULL_LOGGING) | 620 | #if ! defined(GNUNET_CULL_LOGGING) |
@@ -753,7 +764,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, | |||
753 | char *rd_ser; | 764 | char *rd_ser; |
754 | char *emsg; | 765 | char *emsg; |
755 | 766 | ||
756 | nick = get_nick_record (nc, zone_key); | 767 | nick = get_nick_record (zone_key); |
757 | GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (rd_count, rd)); | 768 | GNUNET_assert (-1 != GNUNET_GNSRECORD_records_get_size (rd_count, rd)); |
758 | 769 | ||
759 | if (GNUNET_OK != GNUNET_GNSRECORD_normalize_record_set (name, | 770 | if (GNUNET_OK != GNUNET_GNSRECORD_normalize_record_set (name, |
@@ -996,7 +1007,7 @@ refresh_block (struct NamestoreClient *nc, | |||
996 | rd_clean[rd_count_clean++] = rd[i]; | 1007 | rd_clean[rd_count_clean++] = rd[i]; |
997 | } | 1008 | } |
998 | 1009 | ||
999 | nick = get_nick_record (nc, zone_key); | 1010 | nick = get_nick_record (zone_key); |
1000 | res_count = rd_count_clean; | 1011 | res_count = rd_count_clean; |
1001 | res = (struct GNUNET_GNSRECORD_Data *) rd_clean; /* fixme: a bit unclean... */ | 1012 | res = (struct GNUNET_GNSRECORD_Data *) rd_clean; /* fixme: a bit unclean... */ |
1002 | if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT))) | 1013 | if ((NULL != nick) && (0 != strcmp (name, GNUNET_GNS_EMPTY_LABEL_AT))) |
@@ -1229,7 +1240,8 @@ client_disconnect_cb (void *cls, | |||
1229 | for (cop = cop_head; NULL != cop; cop = cop->next) | 1240 | for (cop = cop_head; NULL != cop; cop = cop->next) |
1230 | if (nc == cop->nc) | 1241 | if (nc == cop->nc) |
1231 | cop->nc = NULL; | 1242 | cop->nc = NULL; |
1232 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, nc->GSN_database)); | 1243 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (nc->db_lib_name, nc->GSN_database)); |
1244 | GNUNET_free (nc->db_lib_name); | ||
1233 | GNUNET_free (nc); | 1245 | GNUNET_free (nc); |
1234 | } | 1246 | } |
1235 | 1247 | ||
@@ -1249,7 +1261,6 @@ client_connect_cb (void *cls, | |||
1249 | { | 1261 | { |
1250 | struct NamestoreClient *nc; | 1262 | struct NamestoreClient *nc; |
1251 | char *database; | 1263 | char *database; |
1252 | char *db_lib_name; | ||
1253 | 1264 | ||
1254 | (void) cls; | 1265 | (void) cls; |
1255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); | 1266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); |
@@ -1261,9 +1272,12 @@ client_connect_cb (void *cls, | |||
1261 | "namestore", | 1272 | "namestore", |
1262 | "database", | 1273 | "database", |
1263 | &database)) | 1274 | &database)) |
1275 | { | ||
1264 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); | 1276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); |
1265 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); | 1277 | GNUNET_free (nc); |
1266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Loading %s\n", db_lib_name); | 1278 | return NULL; |
1279 | } | ||
1280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading %s\n", db_lib_name); | ||
1267 | nc->GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg); | 1281 | nc->GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg); |
1268 | GNUNET_free (database); | 1282 | GNUNET_free (database); |
1269 | if (NULL == nc->GSN_database) | 1283 | if (NULL == nc->GSN_database) |
@@ -1271,12 +1285,11 @@ client_connect_cb (void *cls, | |||
1271 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1285 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1272 | "Could not load database backend `%s'\n", | 1286 | "Could not load database backend `%s'\n", |
1273 | db_lib_name); | 1287 | db_lib_name); |
1274 | GNUNET_free (db_lib_name); | ||
1275 | GNUNET_free (nc); | 1288 | GNUNET_free (nc); |
1276 | return NULL; | 1289 | return NULL; |
1277 | } | 1290 | } |
1278 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Loaded %s\n", db_lib_name); | 1291 | nc->db_lib_name = GNUNET_strdup (db_lib_name); |
1279 | GNUNET_free (db_lib_name); | 1292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded %s\n", db_lib_name); |
1280 | return nc; | 1293 | return nc; |
1281 | } | 1294 | } |
1282 | 1295 | ||
@@ -1487,7 +1500,7 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) | |||
1487 | rlc.res_rd_count = 0; | 1500 | rlc.res_rd_count = 0; |
1488 | rlc.res_rd = NULL; | 1501 | rlc.res_rd = NULL; |
1489 | rlc.rd_ser_len = 0; | 1502 | rlc.rd_ser_len = 0; |
1490 | rlc.nick = get_nick_record (nc, &ll_msg->zone); | 1503 | rlc.nick = get_nick_record (&ll_msg->zone); |
1491 | if (GNUNET_YES != ntohl (ll_msg->is_edit_request)) | 1504 | if (GNUNET_YES != ntohl (ll_msg->is_edit_request)) |
1492 | res = nc->GSN_database->lookup_records (nc->GSN_database->cls, | 1505 | res = nc->GSN_database->lookup_records (nc->GSN_database->cls, |
1493 | &ll_msg->zone, | 1506 | &ll_msg->zone, |
@@ -2469,6 +2482,7 @@ run (void *cls, | |||
2469 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 2482 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
2470 | struct GNUNET_SERVICE_Handle *service) | 2483 | struct GNUNET_SERVICE_Handle *service) |
2471 | { | 2484 | { |
2485 | char *database; | ||
2472 | (void) cls; | 2486 | (void) cls; |
2473 | (void) service; | 2487 | (void) service; |
2474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); | 2488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); |
@@ -2484,6 +2498,29 @@ run (void *cls, | |||
2484 | GNUNET_assert (NULL != namecache); | 2498 | GNUNET_assert (NULL != namecache); |
2485 | } | 2499 | } |
2486 | statistics = GNUNET_STATISTICS_create ("namestore", cfg); | 2500 | statistics = GNUNET_STATISTICS_create ("namestore", cfg); |
2501 | /* Loading database plugin */ | ||
2502 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | ||
2503 | "namestore", | ||
2504 | "database", | ||
2505 | &database)) | ||
2506 | { | ||
2507 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); | ||
2508 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | ||
2509 | return; | ||
2510 | } | ||
2511 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); | ||
2512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading %s\n", db_lib_name); | ||
2513 | GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); | ||
2514 | GNUNET_free (database); | ||
2515 | if (NULL == GSN_database) | ||
2516 | { | ||
2517 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2518 | "Could not load database backend `%s'\n", | ||
2519 | db_lib_name); | ||
2520 | GNUNET_free (db_lib_name); | ||
2521 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | ||
2522 | return; | ||
2523 | } | ||
2487 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); | 2524 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); |
2488 | } | 2525 | } |
2489 | 2526 | ||