GNUnet 0.22.1
plugin_namestore_sqlite.c File Reference

sqlite-based namestore backend More...

#include "platform.h"
#include "gnunet_namestore_plugin.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_sq_lib.h"
#include <sqlite3.h>
Include dependency graph for plugin_namestore_sqlite.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 

Macros

#define BUSY_TIMEOUT_MS   1000
 After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more responsive to requests (especially PUTs). More...
 
#define LOG_SQLITE(db, level, cmd)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'filename' with the message given by strerror(errno). More...
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__)
 

Functions

static enum GNUNET_GenericReturnValue database_prepare (struct Plugin *plugin)
 Initialize the database connections and associated data structures (create tables and indices as needed as well). More...
 
static void database_shutdown (struct Plugin *plugin)
 Shutdown database connection and associate data structures. More...
 
static enum GNUNET_GenericReturnValue namestore_sqlite_store_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Store a record in the datastore. More...
 
static enum GNUNET_GenericReturnValue get_records_and_call_iterator (struct Plugin *plugin, sqlite3_stmt *stmt, const struct GNUNET_CRYPTO_PrivateKey *zone_key, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 The given 'sqlite' statement has been prepared to be run. More...
 
static enum GNUNET_GenericReturnValue lookup_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls, const char *editor_hint)
 Lookup records in the datastore for which we are the authority. More...
 
static enum GNUNET_GenericReturnValue namestore_sqlite_lookup_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 Lookup records in the datastore for which we are the authority. More...
 
static enum GNUNET_GenericReturnValue namestore_sqlite_editor_hint_clear (void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label)
 Clear editor hint. More...
 
static enum GNUNET_GenericReturnValue namestore_sqlite_edit_records (void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 Lookup records in the datastore for which we are the authority. More...
 
static enum GNUNET_GenericReturnValue namestore_sqlite_iterate_records (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 Iterate over the results for a particular key and zone in the datastore. More...
 
static enum GNUNET_GenericReturnValue namestore_sqlite_zone_to_name (void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 Look for an existing PKEY delegation record for a given public key. More...
 
static enum GNUNET_GenericReturnValue namestore_sqlite_create_tables (void *cls)
 
static enum GNUNET_GenericReturnValue namestore_sqlite_drop_tables (void *cls)
 
static enum GNUNET_GenericReturnValue namestore_sqlite_begin_tx (void *cls)
 
static enum GNUNET_GenericReturnValue namestore_sqlite_commit_tx (void *cls)
 
static enum GNUNET_GenericReturnValue namestore_sqlite_rollback_tx (void *cls)
 
static enum GNUNET_GenericReturnValue database_connect (struct Plugin *plugin)
 Initialize the database connections and associated data structures (create tables and indices as needed as well). More...
 
void * libgnunet_plugin_namestore_sqlite_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_namestore_sqlite_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

sqlite-based namestore backend

Author
Christian Grothoff

Definition in file plugin_namestore_sqlite.c.

Macro Definition Documentation

◆ BUSY_TIMEOUT_MS

#define BUSY_TIMEOUT_MS   1000

After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more responsive to requests (especially PUTs).

A high value guarantees a higher success rate (SELECTs in iterate can take several seconds despite LIMIT=1).

The default value of 1s should ensure that users do not experience huge latencies while at the same time allowing operations to succeed with reasonable probability.

Definition at line 43 of file plugin_namestore_sqlite.c.

◆ LOG_SQLITE

#define LOG_SQLITE (   db,
  level,
  cmd 
)
Value:
do { \
GNUNET_log_from (level, \
"namestore-sqlite", _ ( \
"`%s' failed at %s:%d with error: %s\n"), \
cmd, \
__FILE__, __LINE__, \
sqlite3_errmsg ( \
db->dbh)); \
} while (0)
static struct GNUNET_FS_DirectoryBuilder * db
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'filename' with the message given by strerror(errno).

Definition at line 51 of file plugin_namestore_sqlite.c.

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "namestore-sqlite", __VA_ARGS__)

Definition at line 61 of file plugin_namestore_sqlite.c.

Function Documentation

◆ database_prepare()

static enum GNUNET_GenericReturnValue database_prepare ( struct Plugin plugin)
static

Initialize the database connections and associated data structures (create tables and indices as needed as well).

Parameters
pluginthe plugin context (state for this module)
Returns
GNUNET_OK on success

Definition at line 132 of file plugin_namestore_sqlite.c.

133{
134 struct GNUNET_SQ_ExecuteStatement es[] = {
135 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
136 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
137 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
138 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
139 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
140 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=NORMAL"),
141 GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"),
142 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
144 };
145 struct GNUNET_SQ_PrepareStatement ps[] = {
146 GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
147 "(zone_private_key,pkey,rvalue,record_count,record_data,"
148 "label,editor_hint)"
149 " VALUES (?, ?, ?, ?, ?, ?, '')",
150 &plugin->store_records),
151 GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
152 "WHERE zone_private_key=? AND label=?",
153 &plugin->delete_records),
155 "SELECT uid,record_count,record_data,label,editor_hint"
156 " FROM ns098records"
157 " WHERE zone_private_key=? AND pkey=?",
158 &plugin->zone_to_name),
160 "SELECT uid,record_count,record_data,label,editor_hint"
161 " FROM ns098records"
162 " WHERE zone_private_key=? AND uid > ?"
163 " ORDER BY uid ASC"
164 " LIMIT ?",
165 &plugin->iterate_zone),
167 "SELECT uid,record_count,record_data,label,editor_hint,zone_private_key"
168 " FROM ns098records"
169 " WHERE uid > ?"
170 " ORDER BY uid ASC"
171 " LIMIT ?",
172 &plugin->iterate_all_zones),
173 GNUNET_SQ_make_prepare ("UPDATE ns098records"
174 " SET editor_hint=?"
175 " FROM ns098records AS old_ns098records"
176 " WHERE ns098records.zone_private_key=? AND ns098records.label=?"
177 " RETURNING ns098records.uid,ns098records.record_count,ns098records.record_data,ns098records.label,editor_hint ",
178 &plugin->lookup_label),
179 GNUNET_SQ_make_prepare ("UPDATE ns098records"
180 " SET editor_hint=?"
181 " FROM ns098records AS old_ns098records"
182 " WHERE ns098records.zone_private_key=? AND ns098records.label=? AND ns098records.editor_hint=?",
183 &plugin->editor_hint_clear),
185 };
186
187 if (plugin->ready)
188 return GNUNET_OK;
189 if (GNUNET_OK !=
191 es))
192 {
194 _ ("Failed to setup database with: `%s'\n"),
195 sqlite3_errmsg (plugin->dbh));
196 return GNUNET_SYSERR;
197 }
198 if (GNUNET_OK !=
200 ps))
201 {
202 GNUNET_break (0);
204 _ ("Failed to setup database with: `%s'\n"),
205 sqlite3_errmsg (plugin->dbh));
206 return GNUNET_SYSERR;
207 }
208 plugin->ready = GNUNET_YES;
209 return GNUNET_OK;
210}
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
struct GNUNET_SQ_PrepareStatement GNUNET_SQ_make_prepare(const char *sql, sqlite3_stmt **pstmt)
Create a struct GNUNET_SQ_PrepareStatement
Definition: sq_prepare.c:37
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_try_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors should be tolerated.
Definition: sq_exec.c:55
#define GNUNET_SQ_PREPARE_END
Terminator for executable statement list.
enum GNUNET_GenericReturnValue GNUNET_SQ_exec_statements(sqlite3 *dbh, const struct GNUNET_SQ_ExecuteStatement *es)
Request execution of an array of statements es from Postgres.
Definition: sq_exec.c:76
enum GNUNET_GenericReturnValue GNUNET_SQ_prepare(sqlite3 *dbh, const struct GNUNET_SQ_PrepareStatement *ps)
Prepare all statements given in the (NULL,NULL)-terminated array at ps.
Definition: sq_prepare.c:50
#define GNUNET_SQ_EXECUTE_STATEMENT_END
Terminator for executable statement list.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#define LOG(kind,...)
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().
Information needed to run a list of SQL statements using GNUNET_SQ_exec_statements().

References _, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_prepare(), GNUNET_SQ_make_try_execute(), GNUNET_SQ_prepare(), GNUNET_SQ_PREPARE_END, GNUNET_SYSERR, GNUNET_YES, LOG, plugin, and ps.

Referenced by lookup_records(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), and namestore_sqlite_zone_to_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ database_shutdown()

static void database_shutdown ( struct Plugin plugin)
static

Shutdown database connection and associate data structures.

Parameters
pluginthe plugin context (state for this module)

Definition at line 219 of file plugin_namestore_sqlite.c.

220{
221 int result;
222 sqlite3_stmt *stmt;
223
224 if (NULL != plugin->store_records)
225 sqlite3_finalize (plugin->store_records);
226 if (NULL != plugin->delete_records)
227 sqlite3_finalize (plugin->delete_records);
228 if (NULL != plugin->iterate_zone)
229 sqlite3_finalize (plugin->iterate_zone);
230 if (NULL != plugin->iterate_all_zones)
231 sqlite3_finalize (plugin->iterate_all_zones);
232 if (NULL != plugin->zone_to_name)
233 sqlite3_finalize (plugin->zone_to_name);
234 if (NULL != plugin->lookup_label)
235 sqlite3_finalize (plugin->lookup_label);
236 if (NULL != plugin->editor_hint_clear)
237 sqlite3_finalize (plugin->editor_hint_clear);
238 result = sqlite3_close (plugin->dbh);
239 if (result == SQLITE_BUSY)
240 {
242 _ (
243 "Tried to close sqlite without finalizing all prepared statements.\n"));
244 stmt = sqlite3_next_stmt (plugin->dbh,
245 NULL);
246 while (NULL != stmt)
247 {
249 "sqlite",
250 "Closing statement %p\n",
251 stmt);
252 result = sqlite3_finalize (stmt);
253 if (result != SQLITE_OK)
255 "sqlite",
256 "Failed to close statement %p: %d\n",
257 stmt,
258 result);
259 stmt = sqlite3_next_stmt (plugin->dbh,
260 NULL);
261 }
262 result = sqlite3_close (plugin->dbh);
263 }
264 if (SQLITE_OK != result)
267 "sqlite3_close");
268
269}
static int result
Global testing status.
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define LOG_SQLITE(db, level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'file...

References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, LOG, LOG_SQLITE, plugin, and result.

Referenced by libgnunet_plugin_namestore_sqlite_done().

Here is the caller graph for this function:

◆ namestore_sqlite_store_records()

static enum GNUNET_GenericReturnValue namestore_sqlite_store_records ( void *  cls,
const struct GNUNET_CRYPTO_PrivateKey zone_key,
const char *  label,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Store a record in the datastore.

Removes any existing record in the same zone with the same name.

Parameters
clsclosure (internal context for the plugin)
zone_keyprivate key of the zone
labelname that is being mapped (at most 255 characters long)
rd_countnumber of entries in rd array
rdarray of records with data to store
Returns
GNUNET_OK on success, else GNUNET_SYSERR

Definition at line 284 of file plugin_namestore_sqlite.c.

290{
291 struct Plugin *plugin = cls;
292 int n;
294 uint64_t rvalue;
295 ssize_t data_size;
296
298 memset (&pkey,
299 0,
300 sizeof(pkey));
301 for (unsigned int i = 0; i < rd_count; i++)
302 {
304 "Checking if `%d' is zonekey type\n",
305 rd[i].record_type);
306
307 if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
308 {
311 rd[i].data_size,
312 rd[i].record_type,
313 &pkey));
315 "Storing delegation zone record value `%s'\n",
317
318 break;
319 }
320 }
322 UINT64_MAX);
324 rd);
325 if (data_size < 0)
326 {
327 GNUNET_break (0);
328 return GNUNET_SYSERR;
329 }
330 if (data_size > 64 * 65536)
331 {
332 GNUNET_break (0);
333 return GNUNET_SYSERR;
334 }
335 {
336 /* First delete 'old' records */
337 char data[data_size];
338 struct GNUNET_SQ_QueryParam dparams[] = {
342 };
343 ssize_t ret;
344
346 rd,
347 data_size,
348 data);
349 if ((ret < 0) ||
350 (data_size != ret))
351 {
352 GNUNET_break (0);
353 return GNUNET_SYSERR;
354 }
355 if (GNUNET_OK !=
356 GNUNET_SQ_bind (plugin->delete_records,
357 dparams))
358 {
361 "sqlite3_bind_XXXX");
363 plugin->delete_records);
364 return GNUNET_SYSERR;
365 }
366 n = sqlite3_step (plugin->delete_records);
368 plugin->delete_records);
369
370 if (0 != rd_count)
371 {
372 uint32_t rd_count32 = (uint32_t) rd_count;
373 struct GNUNET_SQ_QueryParam sparams[] = {
377 GNUNET_SQ_query_param_uint32 (&rd_count32),
381 };
382
383 if (GNUNET_OK !=
384 GNUNET_SQ_bind (plugin->store_records,
385 sparams))
386 {
389 "sqlite3_bind_XXXX");
391 plugin->store_records);
392 return GNUNET_SYSERR;
393 }
394 n = sqlite3_step (plugin->store_records);
396 plugin->store_records);
397 }
398 }
399 switch (n)
400 {
401 case SQLITE_DONE:
402 if (0 != rd_count)
404 "sqlite",
405 "Record stored\n");
406 else
408 "sqlite",
409 "Record deleted\n");
410 return GNUNET_OK;
411
412 case SQLITE_BUSY:
415 "sqlite3_step");
416 return GNUNET_NO;
417
418 default:
421 "sqlite3_step");
422 return GNUNET_SYSERR;
423 }
424}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static char * data
The data to insert into the dht.
static char * pkey
Public key of the zone to look in, in ASCII.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static size_t data_size
Number of bytes in data.
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint16_t in host byte order.
#define GNUNET_SQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
enum GNUNET_GenericReturnValue GNUNET_SQ_bind(sqlite3_stmt *stmt, const struct GNUNET_SQ_QueryParam *params)
Execute binding operations for a prepared statement.
Definition: sq.c:30
void GNUNET_SQ_reset(sqlite3 *dbh, sqlite3_stmt *stmt)
Reset stmt and log error.
Definition: sq.c:119
#define GNUNET_SQ_query_param_end
End of query parameter specification.
Definition: gnunet_sq_lib.h:87
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_string(const char *ptr)
Generate query parameter for a string.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
const char * GNUNET_GNSRECORD_z2s(const struct GNUNET_CRYPTO_PublicKey *z)
Convert a zone to a string (for printing debug messages).
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data(const char *data, size_t data_size, uint32_t type, struct GNUNET_CRYPTO_PublicKey *key)
Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data.
ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type(uint32_t type)
Check if this type is one of the supported GNS zone types.
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_BULK
static enum GNUNET_GenericReturnValue database_prepare(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
An identity key as per LSD0001.
Description of a DB query parameter.
Definition: gnunet_sq_lib.h:56
Handle for a plugin.
Definition: block.c:38

References data, data_size, database_prepare(), GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNSRECORD_identity_from_data(), GNUNET_GNSRECORD_is_zonekey_type(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_GNSRECORD_z2s(), GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_fixed_size(), GNUNET_SQ_query_param_string(), GNUNET_SQ_query_param_uint32(), GNUNET_SQ_query_param_uint64(), GNUNET_SQ_reset(), GNUNET_SYSERR, GNUNET_YES, LOG, LOG_SQLITE, pkey, plugin, rd, rd_count, and ret.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_records_and_call_iterator()

static enum GNUNET_GenericReturnValue get_records_and_call_iterator ( struct Plugin plugin,
sqlite3_stmt *  stmt,
const struct GNUNET_CRYPTO_PrivateKey zone_key,
uint64_t  limit,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

The given 'sqlite' statement has been prepared to be run.

It will return a record which should be given to the iterator. Runs the statement and parses the returned record.

Parameters
pluginplugin context
stmtto run (and then clean up)
zone_keyprivate key of the zone
limitmaximum number of results to fetch
iteriterator to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error

Definition at line 441 of file plugin_namestore_sqlite.c.

448{
449 int ret;
450 int sret;
451
452 ret = GNUNET_OK;
453 for (uint64_t i = 0; i < limit; i++)
454 {
455 sret = sqlite3_step (stmt);
456
457 if (SQLITE_DONE == sret)
458 {
460 "Iteration done (no results)\n");
461 ret = GNUNET_NO;
462 break;
463 }
464 if (SQLITE_ROW != sret)
465 {
468 "sqlite_step");
470 break;
471 }
472
473 {
474 uint64_t seq;
475 uint32_t record_count;
476 size_t data_size;
477 void *data;
478 char *label;
479 char *editor_hint;
480 struct GNUNET_CRYPTO_PrivateKey zk;
481 struct GNUNET_SQ_ResultSpec rs[] = {
485 &data_size),
487 GNUNET_SQ_result_spec_string (&editor_hint),
489 };
490 struct GNUNET_SQ_ResultSpec rsx[] = {
494 &data_size),
496 GNUNET_SQ_result_spec_string (&editor_hint),
499 };
500
502 (NULL == zone_key)
503 ? rsx
504 : rs);
505 if ((GNUNET_OK != ret) ||
506 (record_count > 64 * 1024))
507 {
508 /* sanity check, don't stack allocate far too much just
509 because database might contain a large value here */
510 GNUNET_break (0);
512 break;
513 }
514 else
515 {
517
518 GNUNET_assert (0 != seq);
519 if (GNUNET_OK !=
521 data,
523 rd))
524 {
525 GNUNET_break (0);
527 break;
528 }
529 else
530 {
531 if (NULL != zone_key)
532 zk = *zone_key;
533 if (NULL != iter)
534 iter (iter_cls,
535 seq,
536 editor_hint,
537 &zk,
538 label,
540 rd);
541 }
542 }
544 }
545 }
547 stmt);
548 return ret;
549}
static uint64_t record_count
Record count.
enum GNUNET_GenericReturnValue GNUNET_SQ_extract_result(sqlite3_stmt *result, struct GNUNET_SQ_ResultSpec *rs)
Extract results from a query result according to the given specification.
Definition: sq.c:75
void GNUNET_SQ_cleanup_result(struct GNUNET_SQ_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_SQ_extract_result().
Definition: sq.c:104
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string(char **dst)
0-terminated string expected.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32(uint32_t *u32)
uint32_t expected.
#define GNUNET_SQ_result_spec_end
End of result parameter specification.
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size(void **dst, size_t *sptr)
Variable-size result expected.
#define GNUNET_SQ_result_spec_auto_from_type(dst)
We expect a fixed-size result, with size determined by the type of * dst
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64(uint64_t *u64)
uint64_t expected.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
#define GNUNET_log(kind,...)
A private key for an identity as per LSD0001.
Description of a DB result cell.

References data, data_size, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_GNSRECORD_records_deserialize(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_reset(), GNUNET_SQ_result_spec_auto_from_type, GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_string(), GNUNET_SQ_result_spec_uint32(), GNUNET_SQ_result_spec_uint64(), GNUNET_SQ_result_spec_variable_size(), GNUNET_SYSERR, LOG_SQLITE, plugin, rd, record_count, and ret.

Referenced by lookup_records(), namestore_sqlite_iterate_records(), and namestore_sqlite_zone_to_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_records()

static enum GNUNET_GenericReturnValue lookup_records ( void *  cls,
const struct GNUNET_CRYPTO_PrivateKey zone,
const char *  label,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls,
const char *  editor_hint 
)
static

Lookup records in the datastore for which we are the authority.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 563 of file plugin_namestore_sqlite.c.

570{
571 struct Plugin *plugin = cls;
572 struct GNUNET_SQ_QueryParam params[] = {
573 GNUNET_SQ_query_param_string (editor_hint),
577 };
578
580 if (NULL == zone)
581 {
582 GNUNET_break (0);
583 return GNUNET_SYSERR;
584 }
585 if (GNUNET_OK !=
586 GNUNET_SQ_bind (plugin->lookup_label,
587 params))
588 {
590 "sqlite3_bind_XXXX");
592 plugin->lookup_label);
593 return GNUNET_SYSERR;
594 }
596 plugin->lookup_label,
597 zone,
598 1,
599 iter,
600 iter_cls);
601}
static enum GNUNET_GenericReturnValue get_records_and_call_iterator(struct Plugin *plugin, sqlite3_stmt *stmt, const struct GNUNET_CRYPTO_PrivateKey *zone_key, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
The given 'sqlite' statement has been prepared to be run.

References database_prepare(), get_records_and_call_iterator(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_string(), GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, and plugin.

Referenced by namestore_sqlite_edit_records(), and namestore_sqlite_lookup_records().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_lookup_records()

static enum GNUNET_GenericReturnValue namestore_sqlite_lookup_records ( void *  cls,
const struct GNUNET_CRYPTO_PrivateKey zone,
const char *  label,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

Lookup records in the datastore for which we are the authority.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 615 of file plugin_namestore_sqlite.c.

621{
622 return lookup_records (cls, zone, label, iter, iter_cls, "");
623}
static enum GNUNET_GenericReturnValue lookup_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls, const char *editor_hint)
Lookup records in the datastore for which we are the authority.

References lookup_records().

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_editor_hint_clear()

static enum GNUNET_GenericReturnValue namestore_sqlite_editor_hint_clear ( void *  cls,
const char *  editor_hint,
const char *  editor_hint_replacement,
const struct GNUNET_CRYPTO_PrivateKey zone,
const char *  label 
)
static

Clear editor hint.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
editor_hinteditor hint to clear
editor_hint_repleditor hint to replace the old with (optional)
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 639 of file plugin_namestore_sqlite.c.

645{
646 struct Plugin *plugin = cls;
647 int n;
648 struct GNUNET_SQ_QueryParam params[] = {
649 GNUNET_SQ_query_param_string ((NULL == editor_hint_replacement) ? "":
650 editor_hint_replacement),
653 GNUNET_SQ_query_param_string (editor_hint),
655 };
656
658 if (NULL == zone)
659 {
660 GNUNET_break (0);
661 return GNUNET_SYSERR;
662 }
663 if (GNUNET_OK !=
664 GNUNET_SQ_bind (plugin->editor_hint_clear,
665 params))
666 {
668 "sqlite3_bind_XXXX");
670 plugin->editor_hint_clear);
671 return GNUNET_SYSERR;
672 }
673 n = sqlite3_step (plugin->editor_hint_clear);
675 plugin->store_records);
676 switch (n)
677 {
678 case SQLITE_DONE:
680 "sqlite",
681 "Editor hint cleared\n");
682 return GNUNET_OK;
683
684 case SQLITE_BUSY:
687 "sqlite3_step");
688 return GNUNET_NO;
689
690 default:
693 "sqlite3_step");
694 return GNUNET_SYSERR;
695 }
696}

References database_prepare(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_string(), GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_edit_records()

static enum GNUNET_GenericReturnValue namestore_sqlite_edit_records ( void *  cls,
const char *  editor_hint,
const struct GNUNET_CRYPTO_PrivateKey zone,
const char *  label,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

Lookup records in the datastore for which we are the authority.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 710 of file plugin_namestore_sqlite.c.

717{
718 return lookup_records (cls, zone, label, iter, iter_cls, editor_hint);
719}

References lookup_records().

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_iterate_records()

static enum GNUNET_GenericReturnValue namestore_sqlite_iterate_records ( void *  cls,
const struct GNUNET_CRYPTO_PrivateKey zone,
uint64_t  serial,
uint64_t  limit,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

Iterate over the results for a particular key and zone in the datastore.

Will return at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
zonehash of public key of the zone, NULL to iterate over all zones
serialserial number to exclude in the list of all matching records
limitmaximum number of results to return
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO if there were no more results, GNUNET_SYSERR on error

Definition at line 735 of file plugin_namestore_sqlite.c.

742{
743 struct Plugin *plugin = cls;
744 sqlite3_stmt *stmt;
745 int err;
746
748 if (NULL == zone)
749 {
750 struct GNUNET_SQ_QueryParam params[] = {
754 };
755
756 stmt = plugin->iterate_all_zones;
757 err = GNUNET_SQ_bind (stmt,
758 params);
759 }
760 else
761 {
762 struct GNUNET_SQ_QueryParam params[] = {
767 };
768
769 stmt = plugin->iterate_zone;
770 err = GNUNET_SQ_bind (stmt,
771 params);
772 }
773 if (GNUNET_OK != err)
774 {
777 "sqlite3_bind_XXXX");
779 stmt);
780 return GNUNET_SYSERR;
781 }
783 stmt,
784 zone,
785 limit,
786 iter,
787 iter_cls);
788}

References database_prepare(), get_records_and_call_iterator(), GNUNET_assert, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_uint64(), GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_zone_to_name()

static enum GNUNET_GenericReturnValue namestore_sqlite_zone_to_name ( void *  cls,
const struct GNUNET_CRYPTO_PrivateKey zone,
const struct GNUNET_CRYPTO_PublicKey value_zone,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

Look for an existing PKEY delegation record for a given public key.

Returns at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone to look up in, never NULL
value_zonepublic key of the target zone (value), never NULL
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error

Definition at line 803 of file plugin_namestore_sqlite.c.

809{
810 struct Plugin *plugin = cls;
811 struct GNUNET_SQ_QueryParam params[] = {
815 };
816
818 if (GNUNET_OK !=
819 GNUNET_SQ_bind (plugin->zone_to_name,
820 params))
821 {
824 "sqlite3_bind_XXXX");
826 plugin->zone_to_name);
827 return GNUNET_SYSERR;
828 }
830 "Performing reverse lookup for `%s'\n",
831 GNUNET_GNSRECORD_z2s (value_zone));
833 plugin->zone_to_name,
834 zone,
835 1,
836 iter,
837 iter_cls);
838}

References database_prepare(), get_records_and_call_iterator(), GNUNET_assert, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_GNSRECORD_z2s(), GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_SYSERR, LOG, LOG_SQLITE, and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_create_tables()

static enum GNUNET_GenericReturnValue namestore_sqlite_create_tables ( void *  cls)
static

Definition at line 842 of file plugin_namestore_sqlite.c.

843{
844 struct Plugin *plugin = cls;
845 struct GNUNET_SQ_ExecuteStatement es[] = {
846 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
847 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
848 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
849 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
850 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
851 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=NORMAL"),
852 GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"),
853 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
854 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
855 " uid INTEGER PRIMARY KEY,"
856 " zone_private_key BLOB NOT NULL,"
857 " pkey BLOB,"
858 " rvalue INT8 NOT NULL,"
859 " record_count INT NOT NULL,"
860 " record_data BLOB NOT NULL,"
861 " label TEXT NOT NULL,"
862 " editor_hint TEXT NOT NULL"
863 ")"),
864 GNUNET_SQ_make_try_execute ("CREATE INDEX ir_pkey_reverse "
865 "ON ns098records (zone_private_key,pkey)"),
866 GNUNET_SQ_make_try_execute ("CREATE INDEX ir_pkey_iter "
867 "ON ns098records (zone_private_key,uid)"),
869 };
870
871 if (GNUNET_OK !=
873 es))
874 {
876 "Failed to setup database with: `%s'\n",
877 sqlite3_errmsg (plugin->dbh));
878 return GNUNET_SYSERR;
879 }
880 return GNUNET_OK;
881}
struct GNUNET_SQ_ExecuteStatement GNUNET_SQ_make_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal.
Definition: sq_exec.c:36

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SQ_make_try_execute(), GNUNET_SYSERR, and plugin.

Referenced by database_connect(), and libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_drop_tables()

static enum GNUNET_GenericReturnValue namestore_sqlite_drop_tables ( void *  cls)
static

Definition at line 885 of file plugin_namestore_sqlite.c.

886{
887 struct Plugin *plugin = cls;
888 struct GNUNET_SQ_ExecuteStatement es_drop[] = {
889 GNUNET_SQ_make_execute ("DROP TABLE IF EXISTS ns098records"),
891 };
892
893 if (GNUNET_OK !=
895 es_drop))
896 {
898 "Failed to drop database with: `%s'\n",
899 sqlite3_errmsg (plugin->dbh));
900 return GNUNET_SYSERR;
901 }
902 return GNUNET_OK;
903}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_begin_tx()

static enum GNUNET_GenericReturnValue namestore_sqlite_begin_tx ( void *  cls)
static

Definition at line 907 of file plugin_namestore_sqlite.c.

908{
909 struct Plugin *plugin = cls;
910 struct GNUNET_SQ_ExecuteStatement es_drop[] = {
911 GNUNET_SQ_make_execute ("BEGIN"),
913 };
914
915 if (GNUNET_OK !=
917 es_drop))
918 {
920 "Failed to drop database with: `%s'\n",
921 sqlite3_errmsg (plugin->dbh));
922 return GNUNET_SYSERR;
923 }
924 return GNUNET_OK;
925}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_commit_tx()

static enum GNUNET_GenericReturnValue namestore_sqlite_commit_tx ( void *  cls)
static

Definition at line 929 of file plugin_namestore_sqlite.c.

930{
931 struct Plugin *plugin = cls;
932 struct GNUNET_SQ_ExecuteStatement es_drop[] = {
933 GNUNET_SQ_make_execute ("COMMIT"),
935 };
936
937 if (GNUNET_OK !=
939 es_drop))
940 {
942 "Failed to drop database with: `%s'\n",
943 sqlite3_errmsg (plugin->dbh));
944 return GNUNET_SYSERR;
945 }
946 return GNUNET_OK;
947}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ namestore_sqlite_rollback_tx()

static enum GNUNET_GenericReturnValue namestore_sqlite_rollback_tx ( void *  cls)
static

Definition at line 951 of file plugin_namestore_sqlite.c.

952{
953 struct Plugin *plugin = cls;
954 struct GNUNET_SQ_ExecuteStatement es_drop[] = {
955 GNUNET_SQ_make_execute ("ROLLBACK"),
957 };
958
959 if (GNUNET_OK !=
961 es_drop))
962 {
964 "Failed to drop database with: `%s'\n",
965 sqlite3_errmsg (plugin->dbh));
966 return GNUNET_SYSERR;
967 }
968 return GNUNET_OK;
969}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SYSERR, and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ database_connect()

static enum GNUNET_GenericReturnValue database_connect ( struct Plugin plugin)
static

Initialize the database connections and associated data structures (create tables and indices as needed as well).

Parameters
pluginthe plugin context (state for this module)
Returns
GNUNET_OK on success

Definition at line 981 of file plugin_namestore_sqlite.c.

982{
983 char *sqlite_filename;
984
985 if (GNUNET_OK !=
987 "namestore-sqlite",
988 "FILENAME",
989 &sqlite_filename))
990 {
992 "namestore-sqlite",
993 "FILENAME");
994 return GNUNET_SYSERR;
995 }
996 if (GNUNET_OK !=
997 GNUNET_DISK_file_test (sqlite_filename))
998 {
999 if (GNUNET_OK !=
1000 GNUNET_DISK_directory_create_for_file (sqlite_filename))
1001 {
1002 GNUNET_break (0);
1003 GNUNET_free (sqlite_filename);
1004 return GNUNET_SYSERR;
1005 }
1006 }
1007
1008 /* Open database and precompile statements */
1009 if ((NULL == plugin->dbh) &&
1010 (SQLITE_OK != sqlite3_open (sqlite_filename,
1011 &plugin->dbh)))
1012 {
1014 _ ("Unable to initialize SQLite: %s.\n"),
1015 sqlite3_errmsg (plugin->dbh));
1016 GNUNET_free (sqlite_filename);
1017 return GNUNET_SYSERR;
1018 }
1019 GNUNET_free (sqlite_filename);
1020 GNUNET_break (SQLITE_OK ==
1021 sqlite3_busy_timeout (plugin->dbh,
1023 if (GNUNET_YES ==
1025 "namestore-sqlite",
1026 "INIT_ON_CONNECT"))
1027 {
1028 if (GNUNET_OK !=
1030 return GNUNET_SYSERR;
1031 }
1032 return GNUNET_OK;
1033}
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:483
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:583
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_free(ptr)
Wrapper around free.
#define BUSY_TIMEOUT_MS
After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more...
static enum GNUNET_GenericReturnValue namestore_sqlite_create_tables(void *cls)

References _, BUSY_TIMEOUT_MS, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, LOG, namestore_sqlite_create_tables(), and plugin.

Referenced by libgnunet_plugin_namestore_sqlite_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_namestore_sqlite_init()

void * libgnunet_plugin_namestore_sqlite_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe "struct GNUNET_NAMESTORE_PluginEnvironment*"
Returns
NULL on error, otherwise the plugin context

Definition at line 1045 of file plugin_namestore_sqlite.c.

1046{
1047 struct Plugin *plugin;
1048 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1050
1051 plugin = GNUNET_new (struct Plugin);
1052 plugin->cfg = cfg;
1054 {
1056 "Database could not be connected to.\n");
1058 return NULL;
1059 }
1061 api->cls = plugin;
1074 _ ("SQlite database running\n"));
1075 return api;
1076}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static enum GNUNET_GenericReturnValue namestore_sqlite_lookup_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
static enum GNUNET_GenericReturnValue namestore_sqlite_begin_tx(void *cls)
static enum GNUNET_GenericReturnValue namestore_sqlite_iterate_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular key and zone in the datastore.
static enum GNUNET_GenericReturnValue namestore_sqlite_edit_records(void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
static enum GNUNET_GenericReturnValue namestore_sqlite_editor_hint_clear(void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label)
Clear editor hint.
static enum GNUNET_GenericReturnValue namestore_sqlite_drop_tables(void *cls)
static enum GNUNET_GenericReturnValue namestore_sqlite_commit_tx(void *cls)
static enum GNUNET_GenericReturnValue namestore_sqlite_store_records(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore.
static enum GNUNET_GenericReturnValue namestore_sqlite_rollback_tx(void *cls)
static enum GNUNET_GenericReturnValue database_connect(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
static enum GNUNET_GenericReturnValue namestore_sqlite_zone_to_name(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
struct returned by the initialization function of the plugin
enum GNUNET_GenericReturnValue(* clear_editor_hint)(void *cls, const char *editor_hint, const char *editor_hint_replacement, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label)
This clears the editor hint, unless it does not match the given editor hint, in which case this is a ...
enum GNUNET_GenericReturnValue(* zone_to_name)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
enum GNUNET_GenericReturnValue(* create_tables)(void *cls)
Setup the database.
enum GNUNET_GenericReturnValue(* edit_records)(void *cls, const char *editor_hint, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Transaction-based API draft.
enum GNUNET_GenericReturnValue(* rollback_tx)(void *cls)
Tell plugin to rollback what we started with begin_tx This may be a NOP (and thus NOT roll anything b...
enum GNUNET_GenericReturnValue(* iterate_records)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular zone in the datastore.
enum GNUNET_GenericReturnValue(* lookup_records)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
enum GNUNET_GenericReturnValue(* begin_tx)(void *cls)
Tell plugin that a set of procedures are coming that are ideally handled within a single TX (BEGIN/CO...
enum GNUNET_GenericReturnValue(* commit_tx)(void *cls)
Tell plugin the we finished what we started with begin_tx.
enum GNUNET_GenericReturnValue(* drop_tables)(void *cls)
Drop existing tables.
void * cls
Closure to pass to all plugin functions.
enum GNUNET_GenericReturnValue(* store_records)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore for which we are the authority.

References _, GNUNET_NAMESTORE_PluginFunctions::begin_tx, cfg, GNUNET_NAMESTORE_PluginFunctions::clear_editor_hint, GNUNET_NAMESTORE_PluginFunctions::cls, GNUNET_NAMESTORE_PluginFunctions::commit_tx, GNUNET_NAMESTORE_PluginFunctions::create_tables, database_connect(), GNUNET_NAMESTORE_PluginFunctions::drop_tables, GNUNET_NAMESTORE_PluginFunctions::edit_records, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_NAMESTORE_PluginFunctions::iterate_records, LOG, GNUNET_NAMESTORE_PluginFunctions::lookup_records, namestore_sqlite_begin_tx(), namestore_sqlite_commit_tx(), namestore_sqlite_create_tables(), namestore_sqlite_drop_tables(), namestore_sqlite_edit_records(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_lookup_records(), namestore_sqlite_rollback_tx(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), plugin, GNUNET_NAMESTORE_PluginFunctions::rollback_tx, GNUNET_NAMESTORE_PluginFunctions::store_records, and GNUNET_NAMESTORE_PluginFunctions::zone_to_name.

Here is the call graph for this function:

◆ libgnunet_plugin_namestore_sqlite_done()

void * libgnunet_plugin_namestore_sqlite_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe plugin context (as returned by "init")
Returns
always NULL

Definition at line 1088 of file plugin_namestore_sqlite.c.

1089{
1091 struct Plugin *plugin = api->cls;
1092
1094 plugin->cfg = NULL;
1096 GNUNET_free (api);
1098 "SQlite plugin is finished\n");
1099 return NULL;
1100}
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_NAMESTORE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, and plugin.

Here is the call graph for this function: