aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-17 14:42:46 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-17 14:42:46 +0200
commit7eb7bd8666aeb2e855cd22b1ea7f44b87bb60400 (patch)
tree4847832d236a874f0a8b711a038c4c2950219848
parent64a7c356b391016be0aa01bc25c237f59fc03a34 (diff)
downloadgnunet-7eb7bd8666aeb2e855cd22b1ea7f44b87bb60400.tar.gz
gnunet-7eb7bd8666aeb2e855cd22b1ea7f44b87bb60400.zip
use namestore API for zone import instead of using plugin directly
-rw-r--r--src/include/gnunet_namestore_plugin.h29
-rw-r--r--src/include/gnunet_namestore_service.h5
-rw-r--r--src/namestore/Makefile.am1
-rw-r--r--src/namestore/gnunet-namestore.c3
-rw-r--r--src/namestore/gnunet-zoneimport.c279
-rw-r--r--src/namestore/plugin_namestore_flat.c43
-rw-r--r--src/namestore/plugin_namestore_postgres.c77
-rw-r--r--src/namestore/plugin_namestore_sqlite.c44
8 files changed, 137 insertions, 344 deletions
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h
index d1c68cd23..3ebf48987 100644
--- a/src/include/gnunet_namestore_plugin.h
+++ b/src/include/gnunet_namestore_plugin.h
@@ -145,35 +145,6 @@ struct GNUNET_NAMESTORE_PluginFunctions
145 void *iter_cls); 145 void *iter_cls);
146 146
147 147
148 /**
149 * Start a transaction.
150 *
151 * @param cls closure
152 * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
153 * #GNUNET_SYSERR on internal errors
154 */
155 int
156 (*begin_transaction) (void *cls);
157
158
159 /**
160 * Try to commit a transaction.
161 *
162 * @param cls closure
163 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
164 */
165 int
166 (*commit_transaction) (void *cls);
167
168
169 /**
170 * Rollback a transaction.
171 *
172 * @param cls closure
173 */
174 void
175 (*rollback_transaction) (void *cls);
176
177}; 148};
178 149
179 150
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 6d3c07f1d..f8c2eaf3b 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2012, 2013 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -128,7 +128,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
128 void *cont_cls); 128 void *cont_cls);
129 129
130 130
131
132/** 131/**
133 * Process a record that was stored in the namestore. 132 * Process a record that was stored in the namestore.
134 * 133 *
@@ -153,7 +152,7 @@ typedef void
153 * @param pkey private key of the zone 152 * @param pkey private key of the zone
154 * @param nick the nick name to set 153 * @param nick the nick name to set
155 * @param cont continuation to call when done 154 * @param cont continuation to call when done
156 * @param cont_cls closure for 'cont' 155 * @param cont_cls closure for @a cont
157 * @return handle to abort the request 156 * @return handle to abort the request
158 */ 157 */
159struct GNUNET_NAMESTORE_QueueEntry * 158struct GNUNET_NAMESTORE_QueueEntry *
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 50b60d020..fd8f8054f 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -138,6 +138,7 @@ endif
138gnunet_zoneimport_SOURCES = \ 138gnunet_zoneimport_SOURCES = \
139 gnunet-zoneimport.c 139 gnunet-zoneimport.c
140gnunet_zoneimport_LDADD = \ 140gnunet_zoneimport_LDADD = \
141 libgnunetnamestore.la \
141 $(top_builddir)/src/identity/libgnunetidentity.la \ 142 $(top_builddir)/src/identity/libgnunetidentity.la \
142 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 143 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
143 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 144 $(top_builddir)/src/dns/libgnunetdnsparser.la \
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 2eff995e0..9a1805af4 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -394,6 +394,7 @@ display_record (void *cls,
394 struct GNUNET_TIME_Relative rt; 394 struct GNUNET_TIME_Relative rt;
395 395
396 (void) cls; 396 (void) cls;
397 (void) zone_key;
397 if ( (NULL != name) && 398 if ( (NULL != name) &&
398 (0 != strcmp (name, rname)) ) 399 (0 != strcmp (name, rname)) )
399 { 400 {
@@ -509,6 +510,7 @@ get_existing_record (void *cls,
509 struct GNUNET_GNSRECORD_Data *rde; 510 struct GNUNET_GNSRECORD_Data *rde;
510 511
511 (void) cls; 512 (void) cls;
513 (void) zone_key;
512 add_qe = NULL; 514 add_qe = NULL;
513 if (0 != strcmp (rec_name, name)) 515 if (0 != strcmp (rec_name, name))
514 { 516 {
@@ -656,6 +658,7 @@ handle_reverse_lookup (void *cls,
656 const struct GNUNET_GNSRECORD_Data *rd) 658 const struct GNUNET_GNSRECORD_Data *rd)
657{ 659{
658 (void) cls; 660 (void) cls;
661 (void) zone;
659 reverse_qe = NULL; 662 reverse_qe = NULL;
660 if (NULL == label) 663 if (NULL == label)
661 FPRINTF (stdout, 664 FPRINTF (stdout,
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index 4d595e554..0148f42a7 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -30,7 +30,7 @@
30#include <gnunet_dnsstub_lib.h> 30#include <gnunet_dnsstub_lib.h>
31#include <gnunet_dnsparser_lib.h> 31#include <gnunet_dnsparser_lib.h>
32#include <gnunet_gnsrecord_lib.h> 32#include <gnunet_gnsrecord_lib.h>
33#include <gnunet_namestore_plugin.h> 33#include <gnunet_namestore_service.h>
34#include <gnunet_identity_service.h> 34#include <gnunet_identity_service.h>
35 35
36 36
@@ -164,6 +164,11 @@ struct Request
164 char *label; 164 char *label;
165 165
166 /** 166 /**
167 * Namestore operation pending for this record.
168 */
169 struct GNUNET_NAMESTORE_QueueEntry *qe;
170
171 /**
167 * Zone responsible for this request. 172 * Zone responsible for this request.
168 */ 173 */
169 const struct Zone *zone; 174 const struct Zone *zone;
@@ -210,9 +215,9 @@ struct Request
210static struct GNUNET_IDENTITY_Handle *id; 215static struct GNUNET_IDENTITY_Handle *id;
211 216
212/** 217/**
213 * Namestore plugin. 218 * Namestore handle.
214 */ 219 */
215static struct GNUNET_NAMESTORE_PluginFunctions *ns; 220static struct GNUNET_NAMESTORE_Handle *ns;
216 221
217/** 222/**
218 * Context for DNS resolution. 223 * Context for DNS resolution.
@@ -271,11 +276,6 @@ static struct GNUNET_SCHEDULER_Task *t;
271static char *dns_server; 276static char *dns_server;
272 277
273/** 278/**
274 * Name of the database plugin (for loading/unloading).
275 */
276static char *db_lib_name;
277
278/**
279 * Head of list of zones we are managing. 279 * Head of list of zones we are managing.
280 */ 280 */
281static struct Zone *zone_head; 281static struct Zone *zone_head;
@@ -285,16 +285,6 @@ static struct Zone *zone_head;
285 */ 285 */
286static struct Zone *zone_tail; 286static struct Zone *zone_tail;
287 287
288/**
289 * Set to #GNUNET_YES if we are currently in a DB transaction.
290 */
291static int in_transaction;
292
293/**
294 * Flag set if we should use transactions to batch DB operations.
295 */
296static int use_transactions;
297
298 288
299/** 289/**
300 * Callback for #for_all_records 290 * Callback for #for_all_records
@@ -790,6 +780,41 @@ process_record (void *cls,
790 780
791 781
792/** 782/**
783 * Continuation called to notify client about result of the
784 * operation.
785 *
786 * @param cls closure with our `struct Request`
787 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
788 * #GNUNET_NO if content was already there or not found
789 * #GNUNET_YES (or other positive value) on success
790 * @param emsg NULL on success, otherwise an error message
791 */
792static void
793store_completed_cb (void *cls,
794 int32_t success,
795 const char *emsg)
796{
797 struct Request *req = cls;
798
799 req->qe = NULL;
800 pending--;
801 if (GNUNET_SYSERR == success)
802 {
803 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
804 "Failed to store zone data for `%s': %s\n",
805 req->hostname,
806 emsg);
807 }
808 else
809 {
810 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
811 "Stored records under `%s'\n",
812 req->label);
813 }
814}
815
816
817/**
793 * Function called with the result of a DNS resolution. 818 * Function called with the result of a DNS resolution.
794 * 819 *
795 * @param cls closure with the `struct Request` 820 * @param cls closure with the `struct Request`
@@ -835,7 +860,6 @@ process_result (void *cls,
835 GNUNET_CONTAINER_DLL_remove (req_head, 860 GNUNET_CONTAINER_DLL_remove (req_head,
836 req_tail, 861 req_tail,
837 req); 862 req);
838 pending--;
839 GNUNET_DNSSTUB_resolve_cancel (req->rs); 863 GNUNET_DNSSTUB_resolve_cancel (req->rs);
840 req->rs = NULL; 864 req->rs = NULL;
841 p = GNUNET_DNSPARSER_parse ((const char *) dns, 865 p = GNUNET_DNSPARSER_parse ((const char *) dns,
@@ -849,9 +873,11 @@ process_result (void *cls,
849 { 873 {
850 failures++; 874 failures++;
851 insert_sorted (req); 875 insert_sorted (req);
876 pending--;
852 return; 877 return;
853 } 878 }
854 insert_sorted (req); 879 insert_sorted (req);
880 pending--;
855 return; 881 return;
856 } 882 }
857 /* Free old/legacy records */ 883 /* Free old/legacy records */
@@ -899,34 +925,13 @@ process_result (void *cls,
899 /* convert linked list into array */ 925 /* convert linked list into array */
900 for (rec = req->rec_head; NULL != rec; rec =rec->next) 926 for (rec = req->rec_head; NULL != rec; rec =rec->next)
901 rd[off++] = rec->grd; 927 rd[off++] = rec->grd;
902 if ( (! in_transaction) && 928 req->qe = GNUNET_NAMESTORE_records_store (ns,
903 (GNUNET_YES == use_transactions) ) 929 &req->zone->key,
904 { 930 req->label,
905 /* not all plugins support transactions, but if one does, 931 rd_count,
906 remember we need to eventually commit... */ 932 rd,
907 if (GNUNET_OK == 933 &store_completed_cb,
908 ns->begin_transaction (ns->cls)) 934 req);
909 in_transaction = GNUNET_YES;
910 }
911 if (GNUNET_OK !=
912 ns->store_records (ns->cls,
913 &req->zone->key,
914 req->label,
915 rd_count,
916 rd))
917 {
918 if (0 != rd_count)
919 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
920 "Failed to store zone data for `%s'\n",
921 req->hostname);
922 }
923 else
924 {
925 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
926 "Stored %u records under `%s'\n",
927 (unsigned int) rd_count,
928 req->label);
929 }
930 } 935 }
931 insert_sorted (req); 936 insert_sorted (req);
932} 937}
@@ -947,6 +952,8 @@ submit_req (struct Request *req)
947 static struct GNUNET_TIME_Absolute last_request; 952 static struct GNUNET_TIME_Absolute last_request;
948 struct GNUNET_TIME_Absolute now; 953 struct GNUNET_TIME_Absolute now;
949 954
955 if (NULL != req->qe)
956 return GNUNET_NO; /* namestore op still pending */
950 if (NULL != req->rs) 957 if (NULL != req->rs)
951 { 958 {
952 GNUNET_break (0); 959 GNUNET_break (0);
@@ -979,25 +986,6 @@ submit_req (struct Request *req)
979 986
980 987
981/** 988/**
982 * If we are currently in a transaction, commit it.
983 */
984static void
985finish_transaction ()
986{
987 if (! in_transaction)
988 return;
989 if (GNUNET_OK !=
990 ns->commit_transaction (ns->cls))
991 {
992 GNUNET_break (0);
993 GNUNET_SCHEDULER_shutdown ();
994 return;
995 }
996 in_transaction = GNUNET_NO;
997}
998
999
1000/**
1001 * Process as many requests as possible from the queue. 989 * Process as many requests as possible from the queue.
1002 * 990 *
1003 * @param cls NULL 991 * @param cls NULL
@@ -1006,7 +994,6 @@ static void
1006process_queue (void *cls) 994process_queue (void *cls)
1007{ 995{
1008 struct Request *req; 996 struct Request *req;
1009 static unsigned int cnt;
1010 997
1011 (void) cls; 998 (void) cls;
1012 t = NULL; 999 t = NULL;
@@ -1033,7 +1020,6 @@ process_queue (void *cls)
1033 "Waiting until %s for next record (`%s') to expire\n", 1020 "Waiting until %s for next record (`%s') to expire\n",
1034 GNUNET_STRINGS_absolute_time_to_string (req->expires), 1021 GNUNET_STRINGS_absolute_time_to_string (req->expires),
1035 req->hostname); 1022 req->hostname);
1036 finish_transaction ();
1037 if (NULL != t) 1023 if (NULL != t)
1038 GNUNET_SCHEDULER_cancel (t); 1024 GNUNET_SCHEDULER_cancel (t);
1039 t = GNUNET_SCHEDULER_add_at (req->expires, 1025 t = GNUNET_SCHEDULER_add_at (req->expires,
@@ -1042,8 +1028,6 @@ process_queue (void *cls)
1042 } 1028 }
1043 else 1029 else
1044 { 1030 {
1045 if (0 == cnt++ % TRANSACTION_SYNC_FREQ)
1046 finish_transaction ();
1047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1031 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1048 "Throttling for 1ms\n"); 1032 "Throttling for 1ms\n");
1049 if (NULL != t) 1033 if (NULL != t)
@@ -1077,14 +1061,10 @@ do_shutdown (void *cls)
1077 GNUNET_SCHEDULER_cancel (t); 1061 GNUNET_SCHEDULER_cancel (t);
1078 t = NULL; 1062 t = NULL;
1079 } 1063 }
1080 finish_transaction ();
1081 if (NULL != ns) 1064 if (NULL != ns)
1082 { 1065 {
1083 GNUNET_break (NULL == 1066 GNUNET_NAMESTORE_disconnect (ns);
1084 GNUNET_PLUGIN_unload (db_lib_name, 1067 ns = NULL;
1085 ns));
1086 GNUNET_free (db_lib_name);
1087 db_lib_name = NULL;
1088 } 1068 }
1089 if (NULL != ctx) 1069 if (NULL != ctx)
1090 { 1070 {
@@ -1120,26 +1100,46 @@ do_shutdown (void *cls)
1120 1100
1121 1101
1122/** 1102/**
1123 * Function called for each matching record. 1103 * Function called if #GNUNET_NAMESTORE_records_lookup() failed.
1104 * Continues resolution based on assumption namestore has no data.
1124 * 1105 *
1125 * @param cls `struct Request *` 1106 * @param cls a `struct Request`
1126 * @param zone_key private key of the zone
1127 * @param label name that is being mapped (at most 255 characters long)
1128 * @param rd_count number of entries in @a rd array
1129 * @param rd array of records with data to store
1130 */ 1107 */
1131static void 1108static void
1132import_records (void *cls, 1109ns_lookup_error_cb (void *cls)
1133 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
1134 const char *label,
1135 unsigned int rd_count,
1136 const struct GNUNET_GNSRECORD_Data *rd)
1137{ 1110{
1138 struct Request *req = cls; 1111 struct Request *req = cls;
1139 1112
1140 GNUNET_break (0 == memcmp (private_key, 1113 req->qe = NULL;
1114 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1115 "Failed to load data from namestore for `%s'\n",
1116 req->label);
1117 insert_sorted (req);
1118}
1119
1120
1121/**
1122 * Process a record that was stored in the namestore.
1123 *
1124 * @param cls a `struct Request *`
1125 * @param zone private key of the zone
1126 * @param label label of the records
1127 * @param rd_count number of entries in @a rd array, 0 if label was deleted
1128 * @param rd array of records with data to store
1129 */
1130static void
1131ns_lookup_result_cb (void *cls,
1132 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1133 const char *label,
1134 unsigned int rd_count,
1135 const struct GNUNET_GNSRECORD_Data *rd)
1136{
1137 struct Request *req = cls;
1138
1139 req->qe = NULL;
1140 GNUNET_break (0 == memcmp (zone,
1141 &req->zone->key, 1141 &req->zone->key,
1142 sizeof (*private_key))); 1142 sizeof (*zone)));
1143 GNUNET_break (0 == strcasecmp (label, 1143 GNUNET_break (0 == strcasecmp (label,
1144 req->label)); 1144 req->label));
1145 for (unsigned int i=0;i<rd_count;i++) 1145 for (unsigned int i=0;i<rd_count;i++)
@@ -1153,6 +1153,40 @@ import_records (void *cls,
1153 rd->data, 1153 rd->data,
1154 rd->data_size); 1154 rd->data_size);
1155 } 1155 }
1156 if (0 == rd_count)
1157 {
1158 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1159 "Empty record set in namestore for `%s'\n",
1160 req->label);
1161 }
1162 else
1163 {
1164 unsigned int pos = 0;
1165
1166 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS;
1167 for (struct Record *rec = req->rec_head;
1168 NULL != rec;
1169 rec = rec->next)
1170 {
1171 struct GNUNET_TIME_Absolute at;
1172
1173 at.abs_value_us = rec->grd.expiration_time;
1174 req->expires = GNUNET_TIME_absolute_min (req->expires,
1175 at);
1176 pos++;
1177 }
1178 if (0 == pos)
1179 req->expires = GNUNET_TIME_UNIT_ZERO_ABS;
1180 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1181 "Hot-start with %u existing records for `%s'\n",
1182 pos,
1183 req->label);
1184 }
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1186 "Adding `%s' to worklist to start at %s\n",
1187 req->hostname,
1188 GNUNET_STRINGS_absolute_time_to_string (req->expires));
1189 insert_sorted (req);
1156} 1190}
1157 1191
1158 1192
@@ -1236,45 +1270,13 @@ queue (const char *hostname)
1236 req->id = p.id; 1270 req->id = p.id;
1237 req->label = GNUNET_strndup (hostname, 1271 req->label = GNUNET_strndup (hostname,
1238 dot - hostname); 1272 dot - hostname);
1239 if (GNUNET_OK != 1273 req->qe = GNUNET_NAMESTORE_records_lookup (ns,
1240 ns->lookup_records (ns->cls, 1274 &req->zone->key,
1241 &req->zone->key, 1275 req->label,
1242 req->label, 1276 &ns_lookup_error_cb,
1243 &import_records, 1277 req,
1244 req)) 1278 &ns_lookup_result_cb,
1245 { 1279 req);
1246 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1247 "Failed to load data from namestore for `%s'\n",
1248 req->label);
1249 }
1250 else
1251 {
1252 unsigned int rd_count = 0;
1253
1254 req->expires = GNUNET_TIME_UNIT_FOREVER_ABS;
1255 for (struct Record *rec = req->rec_head;
1256 NULL != rec;
1257 rec = rec->next)
1258 {
1259 struct GNUNET_TIME_Absolute at;
1260
1261 at.abs_value_us = rec->grd.expiration_time;
1262 req->expires = GNUNET_TIME_absolute_min (req->expires,
1263 at);
1264 rd_count++;
1265 }
1266 if (0 == rd_count)
1267 req->expires = GNUNET_TIME_UNIT_ZERO_ABS;
1268 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1269 "Hot-start with %u existing records for `%s'\n",
1270 rd_count,
1271 req->label);
1272 }
1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1274 "Adding `%s' to worklist to start at %s\n",
1275 req->hostname,
1276 GNUNET_STRINGS_absolute_time_to_string (req->expires));
1277 insert_sorted (req);
1278} 1280}
1279 1281
1280 1282
@@ -1390,8 +1392,6 @@ run (void *cls,
1390 const char *cfgfile, 1392 const char *cfgfile,
1391 const struct GNUNET_CONFIGURATION_Handle *cfg) 1393 const struct GNUNET_CONFIGURATION_Handle *cfg)
1392{ 1394{
1393 char *database;
1394
1395 (void) cls; 1395 (void) cls;
1396 (void) args; 1396 (void) args;
1397 (void) cfgfile; 1397 (void) cfgfile;
@@ -1403,22 +1403,9 @@ run (void *cls,
1403 "Failed to initialize GNUnet DNS STUB\n"); 1403 "Failed to initialize GNUnet DNS STUB\n");
1404 return; 1404 return;
1405 } 1405 }
1406 if (GNUNET_OK !=
1407 GNUNET_CONFIGURATION_get_value_string (cfg,
1408 "namestore",
1409 "database",
1410 &database))
1411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1412 "No database backend configured\n");
1413
1414 GNUNET_asprintf (&db_lib_name,
1415 "libgnunet_plugin_namestore_%s",
1416 database);
1417 ns = GNUNET_PLUGIN_load (db_lib_name,
1418 (void *) cfg);
1419 GNUNET_free (database);
1420 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 1406 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
1421 NULL); 1407 NULL);
1408 ns = GNUNET_NAMESTORE_connect (cfg);
1422 if (NULL == ns) 1409 if (NULL == ns)
1423 { 1410 {
1424 GNUNET_SCHEDULER_shutdown (); 1411 GNUNET_SCHEDULER_shutdown ();
@@ -1448,10 +1435,6 @@ main (int argc,
1448 "IP", 1435 "IP",
1449 "which DNS server should be used", 1436 "which DNS server should be used",
1450 &dns_server)), 1437 &dns_server)),
1451 GNUNET_GETOPT_option_flag ('e',
1452 "enable-transactions",
1453 "enable use of transactions to reduce disk IO",
1454 &use_transactions),
1455 GNUNET_GETOPT_OPTION_END 1438 GNUNET_GETOPT_OPTION_END
1456 }; 1439 };
1457 1440
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index 170adb49e..305fe7ba1 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -667,46 +667,6 @@ namestore_flat_zone_to_name (void *cls,
667 667
668 668
669/** 669/**
670 * Start a transaction.
671 *
672 * @param cls closure
673 * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
674 * #GNUNET_SYSERR on internal errors
675 */
676static int
677namestore_flat_begin_transaction (void *cls)
678{
679 return GNUNET_NO;
680}
681
682
683/**
684 * Try to commit a transaction.
685 *
686 * @param cls closure
687 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
688 */
689static int
690namestore_flat_commit_transaction (void *cls)
691{
692 GNUNET_break (0);
693 return GNUNET_SYSERR;
694}
695
696
697/**
698 * Rollback a transaction.
699 *
700 * @param cls closure
701 */
702static void
703namestore_flat_rollback_transaction (void *cls)
704{
705 GNUNET_break (0);
706}
707
708
709/**
710 * Entry point for the plugin. 670 * Entry point for the plugin.
711 * 671 *
712 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*" 672 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
@@ -736,9 +696,6 @@ libgnunet_plugin_namestore_flat_init (void *cls)
736 api->iterate_records = &namestore_flat_iterate_records; 696 api->iterate_records = &namestore_flat_iterate_records;
737 api->zone_to_name = &namestore_flat_zone_to_name; 697 api->zone_to_name = &namestore_flat_zone_to_name;
738 api->lookup_records = &namestore_flat_lookup_records; 698 api->lookup_records = &namestore_flat_lookup_records;
739 api->begin_transaction = &namestore_flat_begin_transaction;
740 api->commit_transaction = &namestore_flat_commit_transaction;
741 api->rollback_transaction = &namestore_flat_rollback_transaction;
742 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 699 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
743 _("flat file database running\n")); 700 _("flat file database running\n"));
744 return api; 701 return api;
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c
index 378a88f51..a9c19d517 100644
--- a/src/namestore/plugin_namestore_postgres.c
+++ b/src/namestore/plugin_namestore_postgres.c
@@ -518,80 +518,6 @@ database_shutdown (struct Plugin *plugin)
518 518
519 519
520/** 520/**
521 * Start a transaction.
522 *
523 * @param cls closure
524 * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
525 * #GNUNET_SYSERR on internal errors
526 */
527static int
528namestore_postgres_begin_transaction (void *cls)
529{
530 struct Plugin *plugin = cls;
531 PGresult *result;
532 ExecStatusType ex;
533
534 result = PQexec (plugin->dbh,
535 "START TRANSACTION ISOLATION LEVEL SERIALIZABLE");
536 if (PGRES_COMMAND_OK !=
537 (ex = PQresultStatus (result)))
538 {
539 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
540 "Failed to start transaction (%s): %s\n",
541 PQresStatus (ex),
542 PQerrorMessage (plugin->dbh));
543 GNUNET_break (0);
544 PQclear (result);
545 return GNUNET_SYSERR;
546 }
547 PQclear (result);
548 return GNUNET_OK;
549}
550
551
552/**
553 * Try to commit a transaction.
554 *
555 * @param cls closure
556 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
557 */
558static int
559namestore_postgres_commit_transaction (void *cls)
560{
561 struct Plugin *plugin = cls;
562 PGresult *result;
563 ExecStatusType status;
564 int ret;
565
566 result = PQexec (plugin->dbh,
567 "COMMIT");
568 status = PQresultStatus (result);
569 ret = (PGRES_COMMAND_OK == status) ? GNUNET_OK : GNUNET_SYSERR;
570 PQclear (result);
571 return ret;
572}
573
574
575/**
576 * Rollback a transaction.
577 *
578 * @param cls closure
579 */
580static void
581namestore_postgres_rollback_transaction (void *cls)
582{
583 struct Plugin *plugin = cls;
584 PGresult *result;
585
586 result = PQexec (plugin->dbh,
587 "ROLLBACK");
588 GNUNET_break (PGRES_COMMAND_OK ==
589 PQresultStatus (result));
590 PQclear (result);
591}
592
593
594/**
595 * Entry point for the plugin. 521 * Entry point for the plugin.
596 * 522 *
597 * @param cls the `struct GNUNET_NAMESTORE_PluginEnvironment*` 523 * @param cls the `struct GNUNET_NAMESTORE_PluginEnvironment*`
@@ -619,9 +545,6 @@ libgnunet_plugin_namestore_postgres_init (void *cls)
619 api->iterate_records = &namestore_postgres_iterate_records; 545 api->iterate_records = &namestore_postgres_iterate_records;
620 api->zone_to_name = &namestore_postgres_zone_to_name; 546 api->zone_to_name = &namestore_postgres_zone_to_name;
621 api->lookup_records = &namestore_postgres_lookup_records; 547 api->lookup_records = &namestore_postgres_lookup_records;
622 api->begin_transaction = &namestore_postgres_begin_transaction;
623 api->commit_transaction = &namestore_postgres_commit_transaction;
624 api->rollback_transaction = &namestore_postgres_rollback_transaction;
625 LOG (GNUNET_ERROR_TYPE_INFO, 548 LOG (GNUNET_ERROR_TYPE_INFO,
626 "Postgres namestore plugin running\n"); 549 "Postgres namestore plugin running\n");
627 return api; 550 return api;
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 1ebb6bfc7..5ad84688c 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -773,47 +773,6 @@ namestore_sqlite_zone_to_name (void *cls,
773 773
774 774
775/** 775/**
776 * Start a transaction.
777 *
778 * @param cls closure
779 * @return #GNUNET_OK on success, #GNUNET_NO if transactions are not supported,
780 * #GNUNET_SYSERR on internal errors
781 */
782static int
783namestore_sqlite_begin_transaction (void *cls)
784{
785 return GNUNET_NO;
786}
787
788
789/**
790 * Try to commit a transaction.
791 *
792 * @param cls closure
793 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
794 */
795static int
796namestore_sqlite_commit_transaction (void *cls)
797{
798 GNUNET_break (0);
799 return GNUNET_SYSERR;
800}
801
802
803/**
804 * Rollback a transaction.
805 *
806 * @param cls closure
807 */
808static void
809namestore_sqlite_rollback_transaction (void *cls)
810{
811 GNUNET_break (0);
812}
813
814
815
816/**
817 * Entry point for the plugin. 776 * Entry point for the plugin.
818 * 777 *
819 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*" 778 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
@@ -841,9 +800,6 @@ libgnunet_plugin_namestore_sqlite_init (void *cls)
841 api->iterate_records = &namestore_sqlite_iterate_records; 800 api->iterate_records = &namestore_sqlite_iterate_records;
842 api->zone_to_name = &namestore_sqlite_zone_to_name; 801 api->zone_to_name = &namestore_sqlite_zone_to_name;
843 api->lookup_records = &namestore_sqlite_lookup_records; 802 api->lookup_records = &namestore_sqlite_lookup_records;
844 api->begin_transaction = &namestore_sqlite_begin_transaction;
845 api->commit_transaction = &namestore_sqlite_commit_transaction;
846 api->rollback_transaction = &namestore_sqlite_rollback_transaction;
847 LOG (GNUNET_ERROR_TYPE_INFO, 803 LOG (GNUNET_ERROR_TYPE_INFO,
848 _("Sqlite database running\n")); 804 _("Sqlite database running\n"));
849 return api; 805 return api;