GNUnet 0.22.2
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:179

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 as x"
174 " SET editor_hint_old=x.editor_hint, editor_hint=?"
175 " WHERE zone_private_key=? AND label=?"
176 " RETURNING uid,record_count,record_data,label,editor_hint_old",
177 &plugin->lookup_label),
178 GNUNET_SQ_make_prepare ("UPDATE ns098records"
179 " SET editor_hint=?"
180 " FROM ns098records AS old_ns098records"
181 " WHERE ns098records.zone_private_key=? AND ns098records.label=? AND ns098records.editor_hint=?",
182 &plugin->editor_hint_clear),
184 };
185
186 if (plugin->ready)
187 return GNUNET_OK;
188 if (GNUNET_OK !=
190 es))
191 {
193 _ ("Failed to setup database with: `%s'\n"),
194 sqlite3_errmsg (plugin->dbh));
195 return GNUNET_SYSERR;
196 }
197 if (GNUNET_OK !=
199 ps))
200 {
201 GNUNET_break (0);
203 _ ("Failed to setup database with: `%s'\n"),
204 sqlite3_errmsg (plugin->dbh));
205 return GNUNET_SYSERR;
206 }
207 plugin->ready = GNUNET_YES;
208 return GNUNET_OK;
209}
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 218 of file plugin_namestore_sqlite.c.

219{
220 int result;
221 sqlite3_stmt *stmt;
222
223 if (NULL != plugin->store_records)
224 sqlite3_finalize (plugin->store_records);
225 if (NULL != plugin->delete_records)
226 sqlite3_finalize (plugin->delete_records);
227 if (NULL != plugin->iterate_zone)
228 sqlite3_finalize (plugin->iterate_zone);
229 if (NULL != plugin->iterate_all_zones)
230 sqlite3_finalize (plugin->iterate_all_zones);
231 if (NULL != plugin->zone_to_name)
232 sqlite3_finalize (plugin->zone_to_name);
233 if (NULL != plugin->lookup_label)
234 sqlite3_finalize (plugin->lookup_label);
235 if (NULL != plugin->editor_hint_clear)
236 sqlite3_finalize (plugin->editor_hint_clear);
237 result = sqlite3_close (plugin->dbh);
238 if (result == SQLITE_BUSY)
239 {
241 _ (
242 "Tried to close sqlite without finalizing all prepared statements.\n"));
243 stmt = sqlite3_next_stmt (plugin->dbh,
244 NULL);
245 while (NULL != stmt)
246 {
248 "sqlite",
249 "Closing statement %p\n",
250 stmt);
251 result = sqlite3_finalize (stmt);
252 if (result != SQLITE_OK)
254 "sqlite",
255 "Failed to close statement %p: %d\n",
256 stmt,
257 result);
258 stmt = sqlite3_next_stmt (plugin->dbh,
259 NULL);
260 }
261 result = sqlite3_close (plugin->dbh);
262 }
263 if (SQLITE_OK != result)
266 "sqlite3_close");
267
268}
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 283 of file plugin_namestore_sqlite.c.

289{
290 struct Plugin *plugin = cls;
291 int n;
293 uint64_t rvalue;
294 ssize_t data_size;
295
297 memset (&pkey,
298 0,
299 sizeof(pkey));
300 for (unsigned int i = 0; i < rd_count; i++)
301 {
303 "Checking if `%d' is zonekey type\n",
304 rd[i].record_type);
305
306 if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
307 {
310 rd[i].data_size,
311 rd[i].record_type,
312 &pkey));
314 "Storing delegation zone record value `%s'\n",
316
317 break;
318 }
319 }
321 UINT64_MAX);
323 rd);
324 if (data_size < 0)
325 {
326 GNUNET_break (0);
327 return GNUNET_SYSERR;
328 }
329 if (data_size > 64 * 65536)
330 {
331 GNUNET_break (0);
332 return GNUNET_SYSERR;
333 }
334 {
335 /* First delete 'old' records */
336 char data[data_size];
337 struct GNUNET_SQ_QueryParam dparams[] = {
341 };
342 ssize_t ret;
343
345 rd,
346 data_size,
347 data);
348 if ((ret < 0) ||
349 (data_size != ret))
350 {
351 GNUNET_break (0);
352 return GNUNET_SYSERR;
353 }
354 if (GNUNET_OK !=
355 GNUNET_SQ_bind (plugin->delete_records,
356 dparams))
357 {
360 "sqlite3_bind_XXXX");
362 plugin->delete_records);
363 return GNUNET_SYSERR;
364 }
365 n = sqlite3_step (plugin->delete_records);
367 plugin->delete_records);
368
369 if (0 != rd_count)
370 {
371 uint32_t rd_count32 = (uint32_t) rd_count;
372 struct GNUNET_SQ_QueryParam sparams[] = {
376 GNUNET_SQ_query_param_uint32 (&rd_count32),
380 };
381
382 if (GNUNET_OK !=
383 GNUNET_SQ_bind (plugin->store_records,
384 sparams))
385 {
388 "sqlite3_bind_XXXX");
390 plugin->store_records);
391 return GNUNET_SYSERR;
392 }
393 n = sqlite3_step (plugin->store_records);
395 plugin->store_records);
396 }
397 }
398 switch (n)
399 {
400 case SQLITE_DONE:
401 if (0 != rd_count)
403 "sqlite",
404 "Record stored\n");
405 else
407 "sqlite",
408 "Record deleted\n");
409 return GNUNET_OK;
410
411 case SQLITE_BUSY:
414 "sqlite3_step");
415 return GNUNET_NO;
416
417 default:
420 "sqlite3_step");
421 return GNUNET_SYSERR;
422 }
423}
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 440 of file plugin_namestore_sqlite.c.

447{
448 int ret;
449 int sret;
450
451 ret = GNUNET_OK;
452 for (uint64_t i = 0; i < limit; i++)
453 {
454 sret = sqlite3_step (stmt);
455
456 if (SQLITE_DONE == sret)
457 {
459 "Iteration done (no results)\n");
460 ret = GNUNET_NO;
461 break;
462 }
463 if (SQLITE_ROW != sret)
464 {
467 "sqlite_step");
469 break;
470 }
471
472 {
473 uint64_t seq;
474 uint32_t record_count;
475 size_t data_size;
476 void *data;
477 char *label;
478 char *editor_hint;
479 struct GNUNET_CRYPTO_PrivateKey zk;
480 struct GNUNET_SQ_ResultSpec rs[] = {
484 &data_size),
486 GNUNET_SQ_result_spec_string (&editor_hint),
488 };
489 struct GNUNET_SQ_ResultSpec rsx[] = {
493 &data_size),
495 GNUNET_SQ_result_spec_string (&editor_hint),
498 };
499
501 (NULL == zone_key)
502 ? rsx
503 : rs);
504 if ((GNUNET_OK != ret) ||
505 (record_count > 64 * 1024))
506 {
507 /* sanity check, don't stack allocate far too much just
508 because database might contain a large value here */
509 GNUNET_break (0);
511 break;
512 }
513 else
514 {
516
517 GNUNET_assert (0 != seq);
518 if (GNUNET_OK !=
520 data,
522 rd))
523 {
524 GNUNET_break (0);
526 break;
527 }
528 else
529 {
530 if (NULL != zone_key)
531 zk = *zone_key;
532 if (NULL != iter)
533 iter (iter_cls,
534 seq,
535 editor_hint,
536 &zk,
537 label,
539 rd);
540 }
541 }
543 }
544 }
546 stmt);
547 return ret;
548}
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 562 of file plugin_namestore_sqlite.c.

569{
570 struct Plugin *plugin = cls;
571 struct GNUNET_SQ_QueryParam params[] = {
572 GNUNET_SQ_query_param_string (editor_hint),
576 };
577
579 if (NULL == zone)
580 {
581 GNUNET_break (0);
582 return GNUNET_SYSERR;
583 }
584 if (GNUNET_OK !=
585 GNUNET_SQ_bind (plugin->lookup_label,
586 params))
587 {
589 "sqlite3_bind_XXXX");
591 plugin->lookup_label);
592 return GNUNET_SYSERR;
593 }
595 plugin->lookup_label,
596 zone,
597 1,
598 iter,
599 iter_cls);
600}
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 614 of file plugin_namestore_sqlite.c.

620{
621 return lookup_records (cls, zone, label, iter, iter_cls, "");
622}
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 638 of file plugin_namestore_sqlite.c.

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

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 709 of file plugin_namestore_sqlite.c.

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

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 734 of file plugin_namestore_sqlite.c.

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

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 802 of file plugin_namestore_sqlite.c.

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

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 841 of file plugin_namestore_sqlite.c.

842{
843 struct Plugin *plugin = cls;
844 struct GNUNET_SQ_ExecuteStatement es[] = {
845 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
846 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
847 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
848 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
849 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
850 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=NORMAL"),
851 GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"),
852 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
853 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
854 " uid INTEGER PRIMARY KEY,"
855 " zone_private_key BLOB NOT NULL,"
856 " pkey BLOB,"
857 " rvalue INT8 NOT NULL,"
858 " record_count INT NOT NULL,"
859 " record_data BLOB NOT NULL,"
860 " label TEXT NOT NULL,"
861 " editor_hint TEXT NOT NULL,"
862 " editor_hint_old TEXT"
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:520
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:620
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: