GNUnet 0.28.1-dev.6-3-gbc381df64
 
Loading...
Searching...
No Matches
plugin_namecache_sqlite.c File Reference

sqlite-based namecache backend More...

#include "platform.h"
#include "gnunet_sq_lib.h"
#include "gnunet_namecache_plugin.h"
#include "gnunet_gnsrecord_lib.h"
#include <sqlite3.h>
Include dependency graph for plugin_namecache_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).
 
#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).
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "namecache-sqlite", __VA_ARGS__)
 

Functions

static int database_setup (struct Plugin *plugin)
 Initialize the database connections and associated data structures (create tables and indices as needed as well).
 
static void database_shutdown (struct Plugin *plugin)
 Shutdown database connection and associate data structures.
 
static void namecache_sqlite_expire_blocks (struct Plugin *plugin)
 Removes any expired block.
 
static int namecache_sqlite_cache_block (void *cls, const struct GNUNET_GNSRECORD_Block *block)
 Cache a block in the datastore.
 
static int namecache_sqlite_lookup_block (void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
 Get the block for a particular zone and label in the datastore.
 
static int namecache_sqlite_del_block (void *cls, const struct GNUNET_HashCode *query)
 Remove the block for a particular zone and label from the datastore.
 
void * libgnunet_plugin_namecache_sqlite_init (void *cls)
 Entry point for the plugin.
 
void * libgnunet_plugin_namecache_sqlite_done (void *cls)
 Exit point from the plugin.
 

Detailed Description

sqlite-based namecache backend

Author
Christian Grothoff

Definition in file plugin_namecache_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 42 of file plugin_namecache_sqlite.c.

◆ LOG_SQLITE

#define LOG_SQLITE (   db,
  level,
  cmd 
)
Value:
do { GNUNET_log_from (level, \
"namecache-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 GNUNET_log_from(kind, comp,...)
#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 50 of file plugin_namecache_sqlite.c.

50 { GNUNET_log_from (level, \
51 "namecache-sqlite", _ ( \
52 "`%s' failed at %s:%d with error: %s\n"), \
53 cmd, \
54 __FILE__, __LINE__, \
55 sqlite3_errmsg ( \
56 db->dbh)); \
57} while (0)

◆ LOG

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

Definition at line 59 of file plugin_namecache_sqlite.c.

Function Documentation

◆ database_setup()

static int database_setup ( 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 115 of file plugin_namecache_sqlite.c.

116{
117 struct GNUNET_SQ_ExecuteStatement es[] = {
118 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
119 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
120 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
121 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
122 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
123 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
124 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
125 GNUNET_SQ_make_try_execute ("PRAGMA journal_mode=WAL"),
126 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks ("
127 " query BLOB NOT NULL,"
128 " block BLOB NOT NULL,"
129 " expiration_time INT8 NOT NULL"
130 ")"),
131 GNUNET_SQ_make_execute ("CREATE INDEX IF NOT EXISTS ir_query_hash "
132 "ON ns096blocks (query,expiration_time)"),
133 GNUNET_SQ_make_execute ("CREATE INDEX IF NOT EXISTS ir_block_expiration "
134 "ON ns096blocks (expiration_time)"),
136 };
137 struct GNUNET_SQ_PrepareStatement ps[] = {
139 "INSERT INTO ns096blocks (query,block,expiration_time) VALUES (?, ?, ?)",
140 &plugin->cache_block),
141 GNUNET_SQ_make_prepare ("DELETE FROM ns096blocks WHERE expiration_time<?",
142 &plugin->expire_blocks),
144 "DELETE FROM ns096blocks WHERE query=? AND expiration_time<=?",
145 &plugin->delete_block),
147 "DELETE FROM ns096blocks WHERE query=?",
148 &plugin->purge_block),
149 GNUNET_SQ_make_prepare ("SELECT block FROM ns096blocks WHERE query=? "
150 "ORDER BY expiration_time DESC LIMIT 1",
151 &plugin->lookup_block),
153 };
154 char *afsdir;
155
156 if (GNUNET_OK !=
158 "namecache-sqlite",
159 "FILENAME",
160 &afsdir))
161 {
163 "namecache-sqlite",
164 "FILENAME");
165 return GNUNET_SYSERR;
166 }
167 if (GNUNET_OK !=
168 GNUNET_DISK_file_test (afsdir))
169 {
170 if (GNUNET_OK !=
172 {
173 GNUNET_break (0);
174 GNUNET_free (afsdir);
175 return GNUNET_SYSERR;
176 }
177 }
178 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
179 plugin->fn = afsdir;
180
181 /* Open database and precompile statements */
182 if (SQLITE_OK !=
183 sqlite3_open (plugin->fn, &plugin->dbh))
184 {
186 _ ("Unable to initialize SQLite: %s.\n"),
187 sqlite3_errmsg (plugin->dbh));
188 return GNUNET_SYSERR;
189 }
190 if (GNUNET_OK !=
192 es))
193 {
194 GNUNET_break (0);
196 _ ("Failed to setup database at `%s'\n"),
197 plugin->fn);
198 return GNUNET_SYSERR;
199 }
200 GNUNET_break (SQLITE_OK ==
201 sqlite3_busy_timeout (plugin->dbh,
203
204 if (GNUNET_OK !=
206 ps))
207 {
208 GNUNET_break (0);
210 _ ("Failed to setup database at `%s'\n"),
211 plugin->fn);
212 return GNUNET_SYSERR;
213 }
214
215 return GNUNET_OK;
216}
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_execute(const char *sql)
Create a struct GNUNET_SQ_ExecuteStatement where errors are fatal.
Definition sq_exec.c:36
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.
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_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:557
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_ERROR
#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...
#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 _, BUSY_TIMEOUT_MS, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SQ_exec_statements(), GNUNET_SQ_EXECUTE_STATEMENT_END, GNUNET_SQ_make_execute(), GNUNET_SQ_make_prepare(), GNUNET_SQ_make_try_execute(), GNUNET_SQ_prepare(), GNUNET_SQ_PREPARE_END, GNUNET_SYSERR, LOG, plugin, and ps.

Referenced by libgnunet_plugin_namecache_sqlite_init().

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 225 of file plugin_namecache_sqlite.c.

226{
227 int result;
228 sqlite3_stmt *stmt;
229
230 if (NULL != plugin->cache_block)
231 sqlite3_finalize (plugin->cache_block);
232 if (NULL != plugin->lookup_block)
233 sqlite3_finalize (plugin->lookup_block);
234 if (NULL != plugin->expire_blocks)
235 sqlite3_finalize (plugin->expire_blocks);
236 if (NULL != plugin->delete_block)
237 sqlite3_finalize (plugin->delete_block);
238 if (NULL != plugin->purge_block)
239 sqlite3_finalize (plugin->purge_block);
240 result = sqlite3_close (plugin->dbh);
241 if (result == SQLITE_BUSY)
242 {
244 _ (
245 "Tried to close sqlite without finalizing all prepared statements.\n"));
246 stmt = sqlite3_next_stmt (plugin->dbh,
247 NULL);
248 while (stmt != NULL)
249 {
251 "sqlite",
252 "Closing statement %p\n",
253 stmt);
254 result = sqlite3_finalize (stmt);
255 if (result != SQLITE_OK)
257 "sqlite",
258 "Failed to close statement %p: %d\n",
259 stmt,
260 result);
261 stmt = sqlite3_next_stmt (plugin->dbh,
262 NULL);
263 }
264 result = sqlite3_close (plugin->dbh);
265 }
266 if (SQLITE_OK != result)
269 "sqlite3_close");
270
271 GNUNET_free (plugin->fn);
272}
static int result
Global testing status.
@ 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_free, GNUNET_log_from, LOG, LOG_SQLITE, plugin, and result.

Referenced by libgnunet_plugin_namecache_sqlite_done(), and libgnunet_plugin_namecache_sqlite_init().

Here is the caller graph for this function:

◆ namecache_sqlite_expire_blocks()

static void namecache_sqlite_expire_blocks ( struct Plugin plugin)
static

Removes any expired block.

Parameters
pluginthe plugin

Definition at line 281 of file plugin_namecache_sqlite.c.

282{
284 struct GNUNET_SQ_QueryParam params[] = {
287 };
288 int n;
289
290 if (GNUNET_OK !=
291 GNUNET_SQ_bind (plugin->expire_blocks,
292 params))
293 {
296 "sqlite3_bind_XXXX");
298 plugin->expire_blocks);
299 return;
300 }
301 n = sqlite3_step (plugin->expire_blocks);
303 plugin->expire_blocks);
304 switch (n)
305 {
306 case SQLITE_DONE:
308 "sqlite",
309 "Records expired\n");
310 return;
311
312 case SQLITE_BUSY:
315 "sqlite3_step");
316 return;
317
318 default:
321 "sqlite3_step");
322 return;
323 }
324}
struct GNUNET_SQ_QueryParam GNUNET_SQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
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.
@ GNUNET_ERROR_TYPE_BULK
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
Description of a DB query parameter.
Time for absolute times used by GNUnet, in microseconds.

References GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_TIME_absolute_get(), LOG_SQLITE, and plugin.

Referenced by namecache_sqlite_cache_block().

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

◆ namecache_sqlite_cache_block()

static int namecache_sqlite_cache_block ( void *  cls,
const struct GNUNET_GNSRECORD_Block block 
)
static

Cache a block in the datastore.

Parameters
clsclosure (internal context for the plugin)
blockblock to cache
Returns
GNUNET_OK on success, else GNUNET_SYSERR

Definition at line 335 of file plugin_namecache_sqlite.c.

337{
338 static struct GNUNET_TIME_Absolute last_expire;
339 struct Plugin *plugin = cls;
340 struct GNUNET_HashCode query;
342 size_t block_size = GNUNET_GNSRECORD_block_get_size (block);
343 int n;
344
345 /* run expiration of old cache entries once per hour */
346 if (GNUNET_TIME_absolute_get_duration (last_expire).rel_value_us >
348 {
349 last_expire = GNUNET_TIME_absolute_get ();
351 }
353 GNUNET_GNSRECORD_query_from_block (block, &query));
356 "Caching new version of block %s (expires %s)\n",
357 GNUNET_h2s (&query),
359 if (block_size > 64 * 65536)
360 {
361 GNUNET_break (0);
362 return GNUNET_SYSERR;
363 }
364
365 {
366 struct GNUNET_SQ_QueryParam del_params[] = {
370 };
371 /* delete old version of the block */
372 if (GNUNET_OK !=
373 GNUNET_SQ_bind (plugin->delete_block,
374 del_params))
375 {
377 "sqlite3_bind_XXXX");
379 plugin->delete_block);
380 return GNUNET_SYSERR;
381 }
382 }
383 n = sqlite3_step (plugin->delete_block);
384 switch (n)
385 {
386 case SQLITE_DONE:
388 "sqlite",
389 "Old block deleted\n");
390 break;
391
392 case SQLITE_BUSY:
395 "sqlite3_step");
396 break;
397
398 default:
401 "sqlite3_step");
402 break;
403 }
405 plugin->delete_block);
406 {
407 struct GNUNET_SQ_QueryParam ins_params[] = {
410 block_size),
413 };
414
415 /* insert new version of the block */
416 if (GNUNET_OK !=
417 GNUNET_SQ_bind (plugin->cache_block,
418 ins_params))
419 {
422 "sqlite3_bind_XXXX");
424 plugin->cache_block);
425 return GNUNET_SYSERR;
426 }
427 }
429 "Caching block under derived key `%s'\n",
430 GNUNET_h2s_full (&query));
431 n = sqlite3_step (plugin->cache_block);
433 plugin->cache_block);
434 switch (n)
435 {
436 case SQLITE_DONE:
438 "Record stored\n");
439 return GNUNET_OK;
440
441 case SQLITE_BUSY:
444 "sqlite3_step");
445 return GNUNET_NO;
446
447 default:
450 "sqlite3_step");
451 return GNUNET_SYSERR;
452 }
453}
static struct GNUNET_TIME_Relative expiration
User supplied expiration value.
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.
#define GNUNET_SQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
size_t GNUNET_GNSRECORD_block_get_size(const struct GNUNET_GNSRECORD_Block *block)
Returns the length of this block in bytes.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_query_from_block(const struct GNUNET_GNSRECORD_Block *block, struct GNUNET_HashCode *query)
Builds the query hash from a block.
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_block_get_expiration(const struct GNUNET_GNSRECORD_Block *block)
Returns the expiration of a block.
#define GNUNET_log(kind,...)
@ GNUNET_NO
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_INFO
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition time.c:438
#define GNUNET_TIME_UNIT_HOURS
One hour.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:671
static void namecache_sqlite_expire_blocks(struct Plugin *plugin)
Removes any expired block.
A 512-bit hashcode.
uint64_t rel_value_us
The actual value.
Handle for a plugin.
Definition block.c:38

References expiration, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNSRECORD_block_get_expiration(), GNUNET_GNSRECORD_block_get_size(), GNUNET_GNSRECORD_query_from_block(), GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_absolute_time(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_query_param_fixed_size(), GNUNET_SQ_reset(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_HOURS, LOG, LOG_SQLITE, namecache_sqlite_expire_blocks(), plugin, and GNUNET_TIME_Relative::rel_value_us.

Referenced by libgnunet_plugin_namecache_sqlite_init().

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

◆ namecache_sqlite_lookup_block()

static int namecache_sqlite_lookup_block ( void *  cls,
const struct GNUNET_HashCode query,
GNUNET_NAMECACHE_BlockCallback  iter,
void *  iter_cls 
)
static

Get the block for a particular zone and label in the datastore.

Will return at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
queryhash of public key derived from the zone and the label
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 467 of file plugin_namecache_sqlite.c.

471{
472 struct Plugin *plugin = cls;
473 int ret;
474 int sret;
475 size_t block_size;
476 const struct GNUNET_GNSRECORD_Block *block;
477 struct GNUNET_SQ_QueryParam params[] = {
480 };
481 struct GNUNET_SQ_ResultSpec rs[] = {
482 GNUNET_SQ_result_spec_variable_size ((void **) &block,
483 &block_size),
485 };
486
487 if (GNUNET_OK !=
488 GNUNET_SQ_bind (plugin->lookup_block,
489 params))
490 {
493 "sqlite3_bind_XXXX");
495 plugin->lookup_block);
496 return GNUNET_SYSERR;
497 }
498 ret = GNUNET_NO;
499 if (SQLITE_ROW ==
500 (sret = sqlite3_step (plugin->lookup_block)))
501 {
502 if (GNUNET_OK !=
503 GNUNET_SQ_extract_result (plugin->lookup_block,
504 rs))
505 {
506 GNUNET_break (0);
508 }
509 else if ((block_size < sizeof(struct GNUNET_GNSRECORD_Block)))
510 {
511 GNUNET_break (0);
514 }
515 else
516 {
518 "Found block under derived key `%s'\n",
519 GNUNET_h2s_full (query));
520 iter (iter_cls,
521 block);
523 ret = GNUNET_YES;
524 }
525 }
526 else
527 {
528 if (SQLITE_DONE != sret)
529 {
532 "sqlite_step");
534 }
535 else
536 {
538 "No block found under derived key `%s'\n",
539 GNUNET_h2s_full (query));
540 }
541 }
543 plugin->lookup_block);
544 return ret;
545}
static int ret
Final status code.
Definition gnunet-arm.c:93
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
#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.
@ GNUNET_YES
Description of a DB result cell.

References GNUNET_break, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s_full(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_cleanup_result(), GNUNET_SQ_extract_result(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_SQ_result_spec_end, GNUNET_SQ_result_spec_variable_size(), GNUNET_SYSERR, GNUNET_YES, LOG_SQLITE, plugin, and ret.

Referenced by libgnunet_plugin_namecache_sqlite_init().

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

◆ namecache_sqlite_del_block()

static int namecache_sqlite_del_block ( void *  cls,
const struct GNUNET_HashCode query 
)
static

Remove the block for a particular zone and label from the datastore.

Parameters
clsclosure (internal context for the plugin)
queryhash of public key derived from the zone and the label
Returns
GNUNET_OK on success, GNUNET_NO if there was no such block, GNUNET_SYSERR on error

Definition at line 558 of file plugin_namecache_sqlite.c.

560{
561 struct Plugin *plugin = cls;
562 struct GNUNET_SQ_QueryParam params[] = {
565 };
566 int n;
567 int ret;
568
569 if (GNUNET_OK !=
570 GNUNET_SQ_bind (plugin->purge_block,
571 params))
572 {
575 "sqlite3_bind_XXXX");
577 plugin->purge_block);
578 return GNUNET_SYSERR;
579 }
580 n = sqlite3_step (plugin->purge_block);
581 switch (n)
582 {
583 case SQLITE_DONE:
584 ret = (0 == sqlite3_changes (plugin->dbh)) ? GNUNET_NO : GNUNET_OK;
586 "Removed %d block(s) under derived key `%s'\n",
587 sqlite3_changes (plugin->dbh),
588 GNUNET_h2s_full (query));
589 break;
590
591 default:
594 "sqlite3_step");
596 break;
597 }
599 plugin->purge_block);
600 return ret;
601}

References GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s_full(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SQ_bind(), GNUNET_SQ_query_param_auto_from_type, GNUNET_SQ_query_param_end, GNUNET_SQ_reset(), GNUNET_SYSERR, LOG_SQLITE, plugin, and ret.

Referenced by libgnunet_plugin_namecache_sqlite_init().

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

◆ libgnunet_plugin_namecache_sqlite_init()

void * libgnunet_plugin_namecache_sqlite_init ( void *  cls)

Entry point for the plugin.

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

Definition at line 614 of file plugin_namecache_sqlite.c.

615{
616 static struct Plugin plugin;
617 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
619
620 if (NULL != plugin.cfg)
621 return NULL; /* can only initialize once! */
622 memset (&plugin, 0, sizeof(struct Plugin));
623 plugin.cfg = cfg;
625 {
627 return NULL;
628 }
630 api->cls = &plugin;
635 _ ("Sqlite database running\n"));
636 return api;
637}
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 int namecache_sqlite_del_block(void *cls, const struct GNUNET_HashCode *query)
Remove the block for a particular zone and label from the datastore.
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
static int namecache_sqlite_cache_block(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Cache a block in the datastore.
static int database_setup(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
static int namecache_sqlite_lookup_block(void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
Get the block for a particular zone and label in the datastore.
struct returned by the initialization function of the plugin
int(* lookup_block)(void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
Get the block for a particular zone and label in the datastore.
int(* del_block)(void *cls, const struct GNUNET_HashCode *query)
Remove the block for a particular zone and label from the datastore.
int(* cache_block)(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Cache a block in the datastore.
void * cls
Closure to pass to all plugin functions.

References _, GNUNET_NAMECACHE_PluginFunctions::cache_block, cfg, GNUNET_NAMECACHE_PluginFunctions::cls, database_setup(), database_shutdown(), GNUNET_NAMECACHE_PluginFunctions::del_block, GNUNET_ERROR_TYPE_INFO, GNUNET_new, GNUNET_OK, LOG, GNUNET_NAMECACHE_PluginFunctions::lookup_block, namecache_sqlite_cache_block(), namecache_sqlite_del_block(), namecache_sqlite_lookup_block(), and plugin.

Here is the call graph for this function:

◆ libgnunet_plugin_namecache_sqlite_done()

void * libgnunet_plugin_namecache_sqlite_done ( void *  cls)

Exit point from the plugin.

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

Definition at line 650 of file plugin_namecache_sqlite.c.

651{
653 struct Plugin *plugin = api->cls;
654
656 plugin->cfg = NULL;
659 "sqlite plugin is finished\n");
660 return NULL;
661}
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_NAMECACHE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, LOG, and plugin.

Here is the call graph for this function: