From ee35363d3dc4888592d29a205c7036451965250d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 10 Apr 2018 20:48:46 +0200 Subject: [PATCH] minor bugfixes --- src/datacache/datacache.conf | 2 +- .../test_datacache_data_postgres.conf | 1 + src/datastore/datastore.conf.in | 2 +- src/namecache/namecache.conf.in | 2 +- src/namestore/gnunet-zoneimport.c | 49 ++++++++++++++----- src/namestore/namestore.conf.in | 2 +- src/namestore/plugin_namestore_postgres.c | 4 +- 7 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/datacache/datacache.conf b/src/datacache/datacache.conf index 033b56db1..f9c718eb0 100644 --- a/src/datacache/datacache.conf +++ b/src/datacache/datacache.conf @@ -1,2 +1,2 @@ [datacache-postgres] -CONFIG = connect_timeout=10; dbname=gnunet +CONFIG = postgres:///gnunet diff --git a/src/datacache/test_datacache_data_postgres.conf b/src/datacache/test_datacache_data_postgres.conf index 09e8e7253..47c954b55 100644 --- a/src/datacache/test_datacache_data_postgres.conf +++ b/src/datacache/test_datacache_data_postgres.conf @@ -6,3 +6,4 @@ DATABASE = postgres [datacache-postgres] CONFIG = connect_timeout=10; dbname=gnunetcheck + diff --git a/src/datastore/datastore.conf.in b/src/datastore/datastore.conf.in index b6b7c13bc..721c865c8 100644 --- a/src/datastore/datastore.conf.in +++ b/src/datastore/datastore.conf.in @@ -17,7 +17,7 @@ DATABASE = sqlite FILENAME = $GNUNET_DATA_HOME/datastore/sqlite.db [datastore-postgres] -CONFIG = connect_timeout=10; dbname=gnunet +CONFIG = postgres:///gnunet [datastore-mysql] DATABASE = gnunet diff --git a/src/namecache/namecache.conf.in b/src/namecache/namecache.conf.in index f70fa487e..236cafecd 100644 --- a/src/namecache/namecache.conf.in +++ b/src/namecache/namecache.conf.in @@ -18,7 +18,7 @@ FILENAME = $GNUNET_DATA_HOME/namecache/sqlite.db FILENAME = $GNUNET_DATA_HOME/namecache/flat.db [namecache-postgres] -CONFIG = connect_timeout=10; dbname=gnunet +CONFIG = postgres:///gnunet TEMPORARY_TABLE = NO diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index 75bf6d639..763a94c3a 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c @@ -162,6 +162,11 @@ static unsigned int pending; */ static unsigned int lookups; +/** + * How many hostnames did we reject (malformed). + */ +static unsigned int rejects; + /** * Number of lookups that failed. */ @@ -805,14 +810,12 @@ process_result (void *cls, = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS); /* convert records to namestore import format */ { - struct GNUNET_GNSRECORD_Data rd[rd_count]; - unsigned int off; + struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; + unsigned int off = 0; /* convert linked list into array */ - for (rec = req->rec_head, off = 0; - NULL != rec; - rec =rec->next, off++) - rd[off] = rec->grd; + for (rec = req->rec_head; NULL != rec; rec =rec->next) + rd[off++] = rec->grd; if (GNUNET_OK != ns->store_records (ns->cls, &zone, @@ -820,9 +823,17 @@ process_result (void *cls, rd_count, rd)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to store zone data for `%s'\n", - req->hostname); + if (0 != rd_count) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to store zone data for `%s'\n", + req->hostname); + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Stored %u records under `%s'\n", + (unsigned int) rd_count, + req->label); } } insert_sorted (req); @@ -893,8 +904,9 @@ process_queue(void *cls) if (GNUNET_TIME_absolute_get_remaining (req_head->expires).rel_value_us > 0) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Waiting until %s for next record to expire\n", - GNUNET_STRINGS_absolute_time_to_string (req_head->expires)); + "Waiting until %s for next record (`%s') to expire\n", + GNUNET_STRINGS_absolute_time_to_string (req_head->expires), + req_head->hostname); t = GNUNET_SCHEDULER_add_at (req_head->expires, &process_queue, NULL); @@ -1007,6 +1019,7 @@ queue (const char *hostname) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Refusing invalid hostname `%s'\n", hostname); + rejects++; return; } /* TODO: may later support importing zones that @@ -1020,6 +1033,7 @@ queue (const char *hostname) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Refusing invalid hostname `%s' (lacks '.')\n", hostname); + rejects++; return; } q.name = (char *) hostname; @@ -1043,6 +1057,7 @@ queue (const char *hostname) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to pack query for hostname `%s'\n", hostname); + rejects++; return; } @@ -1059,6 +1074,7 @@ queue (const char *hostname) GNUNET_free (req->hostname); GNUNET_free (req->label); GNUNET_free (req); + rejects++; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Label contained a `.', invalid hostname `%s'\n", hostname); @@ -1071,10 +1087,16 @@ queue (const char *hostname) &import_records, req)) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to load data from namestore for `%s'\n", req->label); } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Succeeded hot-start with existing data for `%s'\n", + req->label); + } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding `%s' to worklist to start at %s\n", req->hostname, @@ -1265,7 +1287,8 @@ main (int argc, NULL); GNUNET_free ((void*) argv); fprintf (stderr, - "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n", + "Rejected %u names, did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n", + rejects, lookups, records, failures, diff --git a/src/namestore/namestore.conf.in b/src/namestore/namestore.conf.in index 89fa945bc..0ebd2586b 100644 --- a/src/namestore/namestore.conf.in +++ b/src/namestore/namestore.conf.in @@ -19,7 +19,7 @@ FILENAME = $GNUNET_DATA_HOME/namestore/flat.db [namestore-postgres] -CONFIG = connect_timeout=10; dbname=gnunet +CONFIG = postgres:///gnunet TEMPORARY_TABLE = NO [uri] diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index de8d76853..9c6d05a21 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c @@ -1,6 +1,6 @@ /* * This file is part of GNUnet - * Copyright (C) 2009-2013, 2016, 2017 GNUnet e.V. + * Copyright (C) 2009-2013, 2016-2018 GNUnet e.V. * * GNUnet is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published @@ -319,7 +319,7 @@ parse_result_call_iterator (void *cls, } { - struct GNUNET_GNSRECORD_Data rd[record_count]; + struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(record_count)]; if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (data_size, -- 2.25.1