GNUnet  0.11.x
Data Structures | Macros | Functions
plugin_datastore_mysql.c File Reference

mysql-based datastore backend More...

#include "platform.h"
#include "gnunet_datastore_plugin.h"
#include "gnunet_util_lib.h"
#include "gnunet_mysql_lib.h"
#include "gnunet_my_lib.h"
Include dependency graph for plugin_datastore_mysql.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  ReplCtx
 Context for repl_proc() function. More...
 
struct  ExpiCtx
 Context for expi_proc() function. More...
 

Macros

#define MAX_DATUM_SIZE   65536
 
#define INSERT_ENTRY   "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
 Prepared statements. More...
 
#define DELETE_ENTRY_BY_UID   "DELETE FROM gn090 WHERE uid=?"
 
#define DELETE_ENTRY_BY_HASH_VALUE
 
#define RESULT_COLUMNS   "repl, type, prio, anonLevel, expire, hash, value, uid"
 
#define SELECT_ENTRY
 
#define SELECT_ENTRY_BY_HASH
 
#define SELECT_ENTRY_BY_HASH_AND_TYPE
 
#define UPDATE_ENTRY
 
#define DEC_REPL   "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"
 
#define SELECT_SIZE   "SELECT SUM(LENGTH(value)+256) FROM gn090"
 
#define SELECT_IT_NON_ANONYMOUS
 
#define SELECT_IT_EXPIRATION
 
#define SELECT_IT_PRIORITY
 
#define SELECT_IT_REPLICATION
 
#define SELECT_MAX_REPL   "SELECT MAX(repl) FROM gn090"
 
#define GET_ALL_KEYS   "SELECT hash from gn090"
 
#define MAX_PARAM   16
 
#define MRUNS(a)   (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a))
 
#define PINIT(a, b)
 

Functions

static int do_delete_entry (struct Plugin *plugin, unsigned long long uid)
 Delete an entry from the gn090 table. More...
 
static void mysql_plugin_estimate_size (void *cls, unsigned long long *estimate)
 Get an estimate of how much space the database is currently using. More...
 
static void mysql_plugin_put (void *cls, const struct GNUNET_HashCode *key, bool absent, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, void *cont_cls)
 Store an item in the datastore. More...
 
static void execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select)
 Run the given select statement and call 'proc' on the resulting values (which must be in particular positions). More...
 
static void mysql_plugin_get_key (void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
 Get one of the results for a particular key in the datastore. More...
 
static void mysql_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
 Get a zero-anonymity datum from the datastore. More...
 
static int repl_proc (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
 Wrapper for the processor for mysql_plugin_get_replication(). More...
 
static void mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc, void *proc_cls)
 Get a random item for replication. More...
 
static void mysql_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls)
 Get all of the keys in the datastore. More...
 
static int expi_proc (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
 Wrapper for the processor for mysql_plugin_get_expiration(). More...
 
static void mysql_plugin_get_expiration (void *cls, PluginDatumProcessor proc, void *proc_cls)
 Get a random item for expiration. More...
 
static void mysql_plugin_drop (void *cls)
 Drop database. More...
 
static void mysql_plugin_remove_key (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls)
 Remove a particular key in the datastore. More...
 
void * libgnunet_plugin_datastore_mysql_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_datastore_mysql_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

mysql-based datastore backend

Author
Igor Wronsky
Christian Grothoff
Christophe Genevey

NOTE: This db module does NOT work with mysql prior to 4.1 since it uses prepared statements. MySQL 5.0.46 promises to fix a bug in MyISAM that is causing us grief. At the time of this writing, that version is yet to be released. In anticipation, the code will use MyISAM with 5.0.46 (and higher). If you run such a version, please run "make check" to verify that the MySQL bug was actually fixed in your version (and if not, change the code below to use MyISAM for gn071).

HIGHLIGHTS

Pros

MANUAL SETUP INSTRUCTIONS

1) in gnunet.conf, set

    [datastore]
    DATABASE = "mysql"

2) Then access mysql as root,

  $ mysql -u root -p

and do the following. [You should replace $USER with the username that will be running the gnunetd process].

   CREATE DATABASE gnunet;
   GRANT select,insert,update,delete,create,alter,drop,create temporary tables
      ON gnunet.* TO $USER@localhost;
   SET PASSWORD FOR $USER@localhost=PASSWORD('$the_password_you_like');
   FLUSH PRIVILEGES;

3) In the $HOME directory of $USER, create a ".my.cnf" file with the following lines

   [client]
   user=$USER
   password=$the_password_you_like

Thats it. Note that .my.cnf file is a security risk unless its on a safe partition etc. The $HOME/.my.cnf can of course be a symbolic link. Even greater security risk can be achieved by setting no password for $USER. Luckily $USER has only privileges to mess up GNUnet's tables, nothing else (unless you give them more, of course).

4) Still, perhaps you should briefly try if the DB connection works. First, login as $USER. Then use,

  $ mysql -u $USER -p $the_password_you_like
  mysql> use gnunet;

If you get the message "Database changed" it probably works.

[If you get "ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" it may be resolvable by "ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock" so there may be some additional trouble depending on your mysql setup.]

REPAIRING TABLES

PROBLEMS?

If you have problems related to the mysql module, your best friend is probably the mysql manual. The first thing to check is that mysql is basically operational, that you can connect to it, create tables, issue queries etc.

Definition in file plugin_datastore_mysql.c.

Macro Definition Documentation

◆ MAX_DATUM_SIZE

#define MAX_DATUM_SIZE   65536

Definition at line 126 of file plugin_datastore_mysql.c.

Referenced by execute_select(), and mysql_plugin_put().

◆ INSERT_ENTRY

#define INSERT_ENTRY   "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"

Prepared statements.

Definition at line 147 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ DELETE_ENTRY_BY_UID

#define DELETE_ENTRY_BY_UID   "DELETE FROM gn090 WHERE uid=?"

Definition at line 151 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ DELETE_ENTRY_BY_HASH_VALUE

#define DELETE_ENTRY_BY_HASH_VALUE
Value:
"DELETE FROM gn090 " \
"WHERE hash = ? AND " \
"value = ? " \
"LIMIT 1"

Definition at line 154 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ RESULT_COLUMNS

#define RESULT_COLUMNS   "repl, type, prio, anonLevel, expire, hash, value, uid"

Definition at line 160 of file plugin_datastore_mysql.c.

◆ SELECT_ENTRY

#define SELECT_ENTRY
Value:
"SELECT " RESULT_COLUMNS " FROM gn090 " \
"WHERE uid >= ? AND " \
"(rvalue >= ? OR 0 = ?) " \
"ORDER BY uid LIMIT 1"
#define RESULT_COLUMNS

Definition at line 162 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_ENTRY_BY_HASH

#define SELECT_ENTRY_BY_HASH
Value:
"SELECT " RESULT_COLUMNS " FROM gn090 " \
"FORCE INDEX (idx_hash_type_uid) " \
"WHERE hash=? AND " \
"uid >= ? AND " \
"(rvalue >= ? OR 0 = ?) " \
"ORDER BY uid LIMIT 1"
#define RESULT_COLUMNS

Definition at line 168 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_ENTRY_BY_HASH_AND_TYPE

#define SELECT_ENTRY_BY_HASH_AND_TYPE
Value:
"SELECT " RESULT_COLUMNS " FROM gn090 " \
"FORCE INDEX (idx_hash_type_uid) " \
"WHERE hash = ? AND " \
"type = ? AND " \
"uid >= ? AND " \
"(rvalue >= ? OR 0 = ?) " \
"ORDER BY uid LIMIT 1"
#define RESULT_COLUMNS

Definition at line 176 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ UPDATE_ENTRY

#define UPDATE_ENTRY
Value:
"UPDATE gn090 SET " \
"prio = prio + ?, " \
"repl = repl + ?, " \
"expire = GREATEST(expire, ?) " \
"WHERE hash = ? AND vhash = ?"

Definition at line 185 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ DEC_REPL

#define DEC_REPL   "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"

Definition at line 192 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_SIZE

#define SELECT_SIZE   "SELECT SUM(LENGTH(value)+256) FROM gn090"

Definition at line 195 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_IT_NON_ANONYMOUS

#define SELECT_IT_NON_ANONYMOUS
Value:
"SELECT " RESULT_COLUMNS " FROM gn090 " \
"FORCE INDEX (idx_anonLevel_type_rvalue) " \
"WHERE anonLevel=0 AND " \
"type=? AND " \
"uid >= ? " \
"ORDER BY uid LIMIT 1"
#define RESULT_COLUMNS

Definition at line 198 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_IT_EXPIRATION

#define SELECT_IT_EXPIRATION
Value:
"SELECT " RESULT_COLUMNS " FROM gn090 " \
"FORCE INDEX (idx_expire) " \
"WHERE expire < ? " \
"ORDER BY expire ASC LIMIT 1"
#define RESULT_COLUMNS

Definition at line 206 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_IT_PRIORITY

#define SELECT_IT_PRIORITY
Value:
"SELECT " RESULT_COLUMNS " FROM gn090 " \
"FORCE INDEX (idx_prio) " \
"ORDER BY prio ASC LIMIT 1"
#define RESULT_COLUMNS

Definition at line 212 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_IT_REPLICATION

#define SELECT_IT_REPLICATION
Value:
"SELECT " RESULT_COLUMNS " FROM gn090 " \
"FORCE INDEX (idx_repl_rvalue) " \
"WHERE repl=? AND " \
" (rvalue>=? OR" \
" NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) " \
"ORDER BY rvalue ASC " \
"LIMIT 1"
#define RESULT_COLUMNS

Definition at line 217 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ SELECT_MAX_REPL

#define SELECT_MAX_REPL   "SELECT MAX(repl) FROM gn090"

Definition at line 226 of file plugin_datastore_mysql.c.

Referenced by libgnunet_plugin_datastore_mysql_init().

◆ GET_ALL_KEYS

#define GET_ALL_KEYS   "SELECT hash from gn090"

◆ MAX_PARAM

#define MAX_PARAM   16

Definition at line 233 of file plugin_datastore_mysql.c.

◆ MRUNS

#define MRUNS (   a)    (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a))

◆ PINIT

#define PINIT (   a,
 
)
Value:
b)))
static char * plugin
Solver plugin name as string.
struct GNUNET_MYSQL_StatementHandle * GNUNET_MYSQL_statement_prepare(struct GNUNET_MYSQL_Context *mc, const char *query)
Prepare a statement.
Definition: mysql.c:393

Referenced by libgnunet_plugin_datastore_mysql_init().

Function Documentation

◆ do_delete_entry()

static int do_delete_entry ( struct Plugin plugin,
unsigned long long  uid 
)
static

Delete an entry from the gn090 table.

Parameters
pluginplugin context
uidunique ID of the entry to delete
Returns
GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error

Definition at line 243 of file plugin_datastore_mysql.c.

References Plugin::delete_entry_by_uid, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint64(), GNUNET_OK, Plugin::mc, and ret.

Referenced by execute_select().

245 {
246  int ret;
247  uint64_t uid64 = (uint64_t) uid;
248  struct GNUNET_MY_QueryParam params_delete[] = {
251  };
252 
254  "Deleting value %llu from gn090 table\n",
255  uid);
256  ret = GNUNET_MY_exec_prepared (plugin->mc,
257  plugin->delete_entry_by_uid,
258  params_delete);
259  if (ret >= 0)
260  {
261  return GNUNET_OK;
262  }
264  "Deleting value %llu from gn090 table failed\n",
265  (unsigned long long) uid);
266  return ret;
267 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_uid
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
#define GNUNET_MY_query_param_end
End of query parameter specification.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_estimate_size()

static void mysql_plugin_estimate_size ( void *  cls,
unsigned long long *  estimate 
)
static

Get an estimate of how much space the database is currently using.

Parameters
clsour struct Plugin *
Returns
number of bytes used on disk

Definition at line 278 of file plugin_datastore_mysql.c.

References Plugin::get_size, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_end, GNUNET_MY_result_spec_end, GNUNET_MY_result_spec_uint64(), GNUNET_NO, GNUNET_OK, Plugin::mc, plugin, and ret.

Referenced by libgnunet_plugin_datastore_mysql_init().

280 {
281  struct Plugin *plugin = cls;
282  uint64_t total;
283  int ret;
284  struct GNUNET_MY_QueryParam params_get[] = {
286  };
287  struct GNUNET_MY_ResultSpec results_get[] = {
290  };
291 
292  ret = GNUNET_MY_exec_prepared (plugin->mc,
293  plugin->get_size,
294  params_get);
295  *estimate = 0;
296  total = UINT64_MAX;
297  if ((GNUNET_OK == ret) &&
298  (GNUNET_OK ==
300  results_get)))
301  {
302  *estimate = (unsigned long long) total;
304  "Size estimate for MySQL payload is %lld\n",
305  (long long) total);
306  GNUNET_assert (UINT64_MAX != total);
309  NULL));
310  }
311 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
#define GNUNET_MY_result_spec_end
End of result speceter specification.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static char * plugin
Solver plugin name as string.
int GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs)
Extract results from a query result according to the given specification.
Definition: my.c:136
#define GNUNET_MY_query_param_end
End of query parameter specification.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
struct GNUNET_MYSQL_StatementHandle * get_size
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_put()

static void mysql_plugin_put ( void *  cls,
const struct GNUNET_HashCode key,
bool  absent,
uint32_t  size,
const void *  data,
enum GNUNET_BLOCK_Type  type,
uint32_t  priority,
uint32_t  anonymity,
uint32_t  replication,
struct GNUNET_TIME_Absolute  expiration,
PluginPutCont  cont,
void *  cont_cls 
)
static

Store an item in the datastore.

Parameters
clsclosure
keykey for the item
absenttrue if the key was not found in the bloom filter
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
contcontinuation called with success or failure status
cont_clsclosure for cont

Definition at line 331 of file plugin_datastore_mysql.c.

References _, GNUNET_TIME_Absolute::abs_value_us, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_break, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_auto_from_type, GNUNET_MY_query_param_end, GNUNET_MY_query_param_fixed_size(), GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), GNUNET_MYSQL_statement_get_stmt(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, Plugin::insert_entry, MAX_DATUM_SIZE, Plugin::mc, plugin, and Plugin::update_entry.

Referenced by libgnunet_plugin_datastore_mysql_init().

343 {
344  struct Plugin *plugin = cls;
345  uint64_t lexpiration = expiration.abs_value_us;
346  struct GNUNET_HashCode vhash;
347 
349  size,
350  &vhash);
351  if (! absent)
352  {
353  struct GNUNET_MY_QueryParam params_update[] = {
354  GNUNET_MY_query_param_uint32 (&priority),
356  GNUNET_MY_query_param_uint64 (&lexpiration),
360  };
361 
362  if (GNUNET_OK !=
363  GNUNET_MY_exec_prepared (plugin->mc,
364  plugin->update_entry,
365  params_update))
366  {
367  cont (cont_cls,
368  key,
369  size,
371  _ ("MySQL statement run failure"));
372  return;
373  }
374 
375  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->update_entry);
376  my_ulonglong rows = mysql_stmt_affected_rows (stmt);
377 
380  NULL));
381  if (0 != rows)
382  {
383  cont (cont_cls,
384  key,
385  size,
386  GNUNET_NO,
387  NULL);
388  return;
389  }
390  }
391 
393  UINT64_MAX);
394  struct GNUNET_MY_QueryParam params_insert[] = {
397  GNUNET_MY_query_param_uint32 (&priority),
399  GNUNET_MY_query_param_uint64 (&lexpiration),
400  GNUNET_MY_query_param_uint64 (&lrvalue),
405  };
406 
407  if (size > MAX_DATUM_SIZE)
408  {
409  GNUNET_break (0);
410  cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
411  return;
412  }
413 
414  if (GNUNET_OK !=
415  GNUNET_MY_exec_prepared (plugin->mc,
416  plugin->insert_entry,
417  params_insert))
418  {
419  cont (cont_cls,
420  key,
421  size,
423  _ ("MySQL statement run failure"));
424  return;
425  }
427  "Inserted value `%s' with size %u into gn090 table\n",
428  GNUNET_h2s (key),
429  (unsigned int) size);
430  if (size > 0)
431  plugin->env->duc (plugin->env->cls,
432  size);
435  NULL));
436  cont (cont_cls,
437  key,
438  size,
439  GNUNET_OK,
440  NULL);
441 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
#define GNUNET_MY_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
struct GNUNET_MYSQL_StatementHandle * insert_entry
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.FG.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
static unsigned int replication
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
Definition: mysql.c:478
A 512-bit hashcode.
static char * plugin
Solver plugin name as string.
int GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs)
Extract results from a query result according to the given specification.
Definition: my.c:136
#define GNUNET_MY_query_param_end
End of query parameter specification.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define MAX_DATUM_SIZE
void * cls
Closure to use for callbacks.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static unsigned int anonymity
struct GNUNET_MYSQL_StatementHandle * update_entry
uint32_t data
The data value.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute_select()

static void execute_select ( struct Plugin plugin,
struct GNUNET_MYSQL_StatementHandle stmt,
PluginDatumProcessor  proc,
void *  proc_cls,
struct GNUNET_MY_QueryParam params_select 
)
static

Run the given select statement and call 'proc' on the resulting values (which must be in particular positions).

Parameters
pluginthe plugin handle
stmtselect statement to run
procfunction to call on result
proc_clsclosure for proc
params_selectarguments to initialize stmt

Definition at line 455 of file plugin_datastore_mysql.c.

References anonymity, GNUNET_DATACACHE_PluginEnvironment::cls, do_delete_entry(), Plugin::env, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MY_cleanup_result(), GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_result_spec_absolute_time(), GNUNET_MY_result_spec_auto_from_type, GNUNET_MY_result_spec_end, GNUNET_MY_result_spec_uint32(), GNUNET_MY_result_spec_uint64(), GNUNET_MY_result_spec_variable_size(), GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_UNIT_ZERO_ABS, MAX_DATUM_SIZE, Plugin::mc, replication, ret, type, and value.

Referenced by expi_proc(), mysql_plugin_get_expiration(), mysql_plugin_get_key(), mysql_plugin_get_replication(), and mysql_plugin_get_zero_anonymity().

460 {
461  int ret;
462  uint32_t replication;
463  uint32_t type;
464  uint32_t priority;
465  uint32_t anonymity;
466  uint64_t uid;
467  size_t value_size;
468  void *value;
469  struct GNUNET_HashCode key;
471  struct GNUNET_MY_ResultSpec results_select[] = {
472  GNUNET_MY_result_spec_uint32 (&replication),
474  GNUNET_MY_result_spec_uint32 (&priority),
475  GNUNET_MY_result_spec_uint32 (&anonymity),
478  GNUNET_MY_result_spec_variable_size (&value, &value_size),
481  };
482 
483  ret = GNUNET_MY_exec_prepared (plugin->mc,
484  stmt,
485  params_select);
486  if (GNUNET_OK != ret)
487  {
488  proc (proc_cls,
489  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
490  return;
491  }
492 
493  ret = GNUNET_MY_extract_result (stmt,
494  results_select);
495  if (GNUNET_OK != ret)
496  {
497  proc (proc_cls,
498  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
499  return;
500  }
501 
503  "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
504  (unsigned int) value_size,
505  GNUNET_h2s (&key),
506  (unsigned int) priority,
507  (unsigned int) anonymity,
509  GNUNET_assert (value_size < MAX_DATUM_SIZE);
512  NULL));
513  ret = proc (proc_cls,
514  &key,
515  value_size,
516  value,
517  type,
518  priority,
519  anonymity,
520  replication,
521  expiration,
522  uid);
523  GNUNET_MY_cleanup_result (results_select);
524  if (GNUNET_NO == ret)
525  {
526  do_delete_entry (plugin, uid);
527  if (0 != value_size)
528  plugin->env->duc (plugin->env->cls,
529  -value_size);
530  }
531 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define GNUNET_MY_result_spec_end
End of result speceter specification.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int replication
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
Absolute time expected.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static char * value
Value of the record to add/remove.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
void GNUNET_MY_cleanup_result(struct GNUNET_MY_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_MY_extract_result().
Definition: my.c:257
A 512-bit hashcode.
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
int GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs)
Extract results from a query result according to the given specification.
Definition: my.c:136
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_MY_result_spec_auto_from_type(dst)
We expect a fixed-size result, with size determined by the type of * dst
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint32(uint32_t *u32)
uint32_t expected
#define GNUNET_log(kind,...)
#define MAX_DATUM_SIZE
void * cls
Closure to use for callbacks.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
static unsigned int anonymity
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size(void **dst, size_t *ptr_size)
Variable-size result expected.
static int do_delete_entry(struct Plugin *plugin, unsigned long long uid)
Delete an entry from the gn090 table.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_get_key()

static void mysql_plugin_get_key ( void *  cls,
uint64_t  next_uid,
bool  random,
const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get one of the results for a particular key in the datastore.

Parameters
clsclosure
next_uidreturn the result with lowest uid >= next_uid
randomif true, return a random result instead of using next_uid
keykey to match, never NULL
typeentries of which type are relevant? Use 0 for any type.
procfunction to call on the matching value, with NULL for if no value matches
proc_clsclosure for proc

Definition at line 548 of file plugin_datastore_mysql.c.

References execute_select(), GNUNET_BLOCK_TYPE_ANY, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_MY_query_param_auto_from_type, GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), plugin, Plugin::select_entry, Plugin::select_entry_by_hash, and Plugin::select_entry_by_hash_and_type.

Referenced by libgnunet_plugin_datastore_mysql_init().

555 {
556  struct Plugin *plugin = cls;
557  uint64_t rvalue;
558 
559  if (random)
560  {
562  UINT64_MAX);
563  next_uid = 0;
564  }
565  else
566  rvalue = 0;
567 
568  if (NULL == key)
569  {
570  struct GNUNET_MY_QueryParam params_select[] = {
571  GNUNET_MY_query_param_uint64 (&next_uid),
575  };
576 
577  execute_select (plugin,
578  plugin->select_entry,
579  proc,
580  proc_cls,
581  params_select);
582  }
583  else if (type != GNUNET_BLOCK_TYPE_ANY)
584  {
585  struct GNUNET_MY_QueryParam params_select[] = {
588  GNUNET_MY_query_param_uint64 (&next_uid),
592  };
593 
594  execute_select (plugin,
596  proc,
597  proc_cls,
598  params_select);
599  }
600  else
601  {
602  struct GNUNET_MY_QueryParam params_select[] = {
604  GNUNET_MY_query_param_uint64 (&next_uid),
608  };
609 
610  execute_select (plugin,
611  plugin->select_entry_by_hash,
612  proc,
613  proc_cls,
614  params_select);
615  }
616 }
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash_and_type
#define GNUNET_MY_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
Any type of block, used as a wildcard when searching.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static char * plugin
Solver plugin name as string.
#define GNUNET_MY_query_param_end
End of query parameter specification.
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
struct GNUNET_MYSQL_StatementHandle * select_entry
Handle for a plugin.
Definition: block.c:37
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
static void execute_select(struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select)
Run the given select statement and call &#39;proc&#39; on the resulting values (which must be in particular p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_get_zero_anonymity()

static void mysql_plugin_get_zero_anonymity ( void *  cls,
uint64_t  next_uid,
enum GNUNET_BLOCK_Type  type,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get a zero-anonymity datum from the datastore.

Parameters
clsour struct Plugin *
next_uidreturn the result with lowest uid >= next_uid
typeentries of which type should be considered? Must not be zero (ANY).
procfunction to call on a matching value; will be called with NULL if no value matches
proc_clsclosure for proc

Definition at line 631 of file plugin_datastore_mysql.c.

References execute_select(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), plugin, and Plugin::zero_iter.

Referenced by libgnunet_plugin_datastore_mysql_init().

636 {
637  struct Plugin *plugin = cls;
638  uint32_t typei = (uint32_t) type;
639 
640  struct GNUNET_MY_QueryParam params_zero_iter[] = {
642  GNUNET_MY_query_param_uint64 (&next_uid),
644  };
645 
646  execute_select (plugin,
647  plugin->zero_iter,
648  proc,
649  proc_cls,
650  params_zero_iter);
651 }
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
struct GNUNET_MYSQL_StatementHandle * zero_iter
static char * plugin
Solver plugin name as string.
#define GNUNET_MY_query_param_end
End of query parameter specification.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
Handle for a plugin.
Definition: block.c:37
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static void execute_select(struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select)
Run the given select statement and call &#39;proc&#39; on the resulting values (which must be in particular p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ repl_proc()

static int repl_proc ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  size,
const void *  data,
enum GNUNET_BLOCK_Type  type,
uint32_t  priority,
uint32_t  anonymity,
uint32_t  replication,
struct GNUNET_TIME_Absolute  expiration,
uint64_t  uid 
)
static

Wrapper for the processor for mysql_plugin_get_replication().

Decrements the replication counter and calls the original iterator.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available
Returns
GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue (continue on call to "next", of course), GNUNET_NO to delete the item and continue (if supported)

Definition at line 697 of file plugin_datastore_mysql.c.

References Plugin::dec_repl, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint64(), GNUNET_SYSERR, Plugin::mc, plugin, ReplCtx::plugin, ReplCtx::proc, ReplCtx::proc_cls, and ret.

Referenced by mysql_plugin_get_replication().

707 {
708  struct ReplCtx *rc = cls;
709  struct Plugin *plugin = rc->plugin;
710  int ret;
711  int iret;
712 
713  ret = rc->proc (rc->proc_cls,
714  key,
715  size,
716  data,
717  type,
718  priority,
719  anonymity,
720  replication,
721  expiration,
722  uid);
723  if (NULL != key)
724  {
725  struct GNUNET_MY_QueryParam params_proc[] = {
728  };
729 
730  iret = GNUNET_MY_exec_prepared (plugin->mc,
731  plugin->dec_repl,
732  params_proc);
733  if (GNUNET_SYSERR == iret)
734  {
736  "Failed to reduce replication counter\n");
737  return GNUNET_SYSERR;
738  }
739  }
740  return ret;
741 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
void * proc_cls
Closure for proc.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
struct Plugin * plugin
Plugin handle.
static unsigned int replication
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
struct GNUNET_MYSQL_StatementHandle * dec_repl
static char * plugin
Solver plugin name as string.
#define GNUNET_MY_query_param_end
End of query parameter specification.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
Context for repl_proc() function.
Handle for a plugin.
Definition: block.c:37
PluginDatumProcessor proc
Function to call for the result (or the NULL).
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static unsigned int anonymity
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_get_replication()

static void mysql_plugin_get_replication ( void *  cls,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get a random item for replication.

Returns a single, not expired, random item from those with the highest replication counters. The item's replication counter is decremented by one IF it was positive before. Call proc with all values ZERO or NULL if the datastore is empty.

Parameters
clsclosure
procfunction to call the value (once only).
proc_clsclosure for proc

Definition at line 756 of file plugin_datastore_mysql.c.

References execute_select(), GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_end, GNUNET_MY_query_param_uint32(), GNUNET_MY_query_param_uint64(), GNUNET_MY_result_spec_end, GNUNET_MY_result_spec_uint32(), GNUNET_NO, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, Plugin::max_repl, Plugin::mc, plugin, ReplCtx::plugin, ReplCtx::proc, ReplCtx::proc_cls, repl_proc(), and Plugin::select_replication.

Referenced by libgnunet_plugin_datastore_mysql_init().

759 {
760  struct Plugin *plugin = cls;
761  uint64_t rvalue;
762  uint32_t repl;
763  struct ReplCtx rc;
764  struct GNUNET_MY_QueryParam params_get[] = {
766  };
767  struct GNUNET_MY_ResultSpec results_get[] = {
770  };
771  struct GNUNET_MY_QueryParam params_select[] = {
777  };
778 
779  rc.plugin = plugin;
780  rc.proc = proc;
781  rc.proc_cls = proc_cls;
782 
783  if (1 !=
784  GNUNET_MY_exec_prepared (plugin->mc,
785  plugin->max_repl,
786  params_get))
787  {
788  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
789  return;
790  }
791 
792  if (GNUNET_OK !=
794  results_get))
795  {
796  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
797  return;
798  }
801  NULL));
803  UINT64_MAX);
804 
805  execute_select (plugin,
806  plugin->select_replication,
807  &repl_proc,
808  &rc,
809  params_select);
810 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define GNUNET_MY_result_spec_end
End of result speceter specification.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int repl_proc(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Wrapper for the processor for mysql_plugin_get_replication().
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
struct GNUNET_MYSQL_StatementHandle * max_repl
static char * plugin
Solver plugin name as string.
int GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs)
Extract results from a query result according to the given specification.
Definition: my.c:136
#define GNUNET_MY_query_param_end
End of query parameter specification.
Context for repl_proc() function.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint32(uint32_t *u32)
uint32_t expected
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_MYSQL_StatementHandle * select_replication
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
static void execute_select(struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select)
Run the given select statement and call &#39;proc&#39; on the resulting values (which must be in particular p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_get_keys()

static void mysql_plugin_get_keys ( void *  cls,
PluginKeyProcessor  proc,
void *  proc_cls 
)
static

Get all of the keys in the datastore.

Parameters
clsclosure
procfunction to call on each key
proc_clsclosure for proc

Definition at line 821 of file plugin_datastore_mysql.c.

References _, GET_ALL_KEYS, Plugin::get_all_keys, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcmp, GNUNET_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_end, GNUNET_MY_result_spec_auto_from_type, GNUNET_MY_result_spec_end, GNUNET_MYSQL_statement_get_stmt(), GNUNET_MYSQL_statements_invalidate(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, Plugin::key, Plugin::mc, plugin, and ret.

Referenced by libgnunet_plugin_datastore_mysql_init().

824 {
825  struct Plugin *plugin = cls;
826  int ret;
827  MYSQL_STMT *statement;
828  unsigned int cnt;
829  struct GNUNET_HashCode key;
830  struct GNUNET_HashCode last;
831  struct GNUNET_MY_QueryParam params_select[] = {
833  };
834  struct GNUNET_MY_ResultSpec results_select[] = {
837  };
838 
839  GNUNET_assert (NULL != proc);
840  statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys);
841  if (GNUNET_OK !=
842  GNUNET_MY_exec_prepared (plugin->mc,
843  plugin->get_all_keys,
844  params_select))
845  {
847  _ ("`%s' for `%s' failed at %s:%d with error: %s\n"),
848  "mysql_stmt_execute",
849  GET_ALL_KEYS,
850  __FILE__,
851  __LINE__,
852  mysql_stmt_error (statement));
854  proc (proc_cls, NULL, 0);
855  return;
856  }
857  memset (&last, 0, sizeof(last)); /* make static analysis happy */
858  ret = GNUNET_YES;
859  cnt = 0;
860  while (ret == GNUNET_YES)
861  {
862  ret = GNUNET_MY_extract_result (plugin->get_all_keys,
863  results_select);
864  if (0 != GNUNET_memcmp (&last,
865  &key))
866  {
867  if (0 != cnt)
868  proc (proc_cls,
869  &last,
870  cnt);
871  cnt = 1;
872  last = key;
873  }
874  else
875  {
876  cnt++;
877  }
878  }
879  if (0 != cnt)
880  proc (proc_cls,
881  &last,
882  cnt);
883  /* finally, let app know we are done */
884  proc (proc_cls,
885  NULL,
886  0);
887  if (GNUNET_SYSERR == ret)
888  {
890  _ ("`%s' failed at %s:%d with error: %s\n"),
891  "mysql_stmt_fetch",
892  __FILE__,
893  __LINE__,
894  mysql_stmt_error (statement));
896  return;
897  }
898 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
#define GNUNET_MY_result_spec_end
End of result speceter specification.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
Definition: mysql.c:478
void GNUNET_MYSQL_statements_invalidate(struct GNUNET_MYSQL_Context *mc)
Close database connection and all prepared statements (we got a DB error).
Definition: mysql.c:341
A 512-bit hashcode.
#define GET_ALL_KEYS
static char * plugin
Solver plugin name as string.
int GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs)
Extract results from a query result according to the given specification.
Definition: my.c:136
struct GNUNET_MYSQL_StatementHandle * get_all_keys
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_MY_result_spec_auto_from_type(dst)
We expect a fixed-size result, with size determined by the type of * dst
#define GNUNET_MY_query_param_end
End of query parameter specification.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expi_proc()

static int expi_proc ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  size,
const void *  data,
enum GNUNET_BLOCK_Type  type,
uint32_t  priority,
uint32_t  anonymity,
uint32_t  replication,
struct GNUNET_TIME_Absolute  expiration,
uint64_t  uid 
)
static

Wrapper for the processor for mysql_plugin_get_expiration().

If no expired value was found, we do a second query for low-priority content.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available
Returns
GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue (continue on call to "next", of course), GNUNET_NO to delete the item and continue (if supported)

Definition at line 944 of file plugin_datastore_mysql.c.

References execute_select(), GNUNET_MY_query_param_end, GNUNET_SYSERR, plugin, ExpiCtx::plugin, ExpiCtx::proc, ExpiCtx::proc_cls, and Plugin::select_priority.

Referenced by mysql_plugin_get_expiration().

954 {
955  struct ExpiCtx *rc = cls;
956  struct Plugin *plugin = rc->plugin;
957  struct GNUNET_MY_QueryParam params_select[] = {
959  };
960 
961  if (NULL == key)
962  {
963  execute_select (plugin,
964  plugin->select_priority,
965  rc->proc,
966  rc->proc_cls,
967  params_select);
968  return GNUNET_SYSERR;
969  }
970  return rc->proc (rc->proc_cls,
971  key,
972  size,
973  data,
974  type,
975  priority,
976  anonymity,
977  replication,
978  expiration,
979  uid);
980 }
void * proc_cls
Closure for proc.
static unsigned int replication
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
Context for expi_proc() function.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
static char * plugin
Solver plugin name as string.
struct GNUNET_MYSQL_StatementHandle * select_priority
#define GNUNET_MY_query_param_end
End of query parameter specification.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handle for a plugin.
Definition: block.c:37
struct Plugin * plugin
Plugin handle.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static unsigned int anonymity
uint32_t data
The data value.
static void execute_select(struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select)
Run the given select statement and call &#39;proc&#39; on the resulting values (which must be in particular p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_get_expiration()

static void mysql_plugin_get_expiration ( void *  cls,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get a random item for expiration.

Call proc with all values ZERO or NULL if the datastore is empty.

Parameters
clsclosure
procfunction to call the value (once only).
proc_clsclosure for proc

Definition at line 992 of file plugin_datastore_mysql.c.

References execute_select(), expi_proc(), GNUNET_MY_query_param_absolute_time(), GNUNET_MY_query_param_end, GNUNET_TIME_absolute_get(), plugin, ExpiCtx::plugin, ExpiCtx::proc, ExpiCtx::proc_cls, and Plugin::select_expiration.

Referenced by libgnunet_plugin_datastore_mysql_init().

995 {
996  struct Plugin *plugin = cls;
997  struct GNUNET_TIME_Absolute now;
998  struct GNUNET_MY_QueryParam params_select[] = {
1001  };
1002  struct ExpiCtx rc;
1003 
1004  rc.plugin = plugin;
1005  rc.proc = proc;
1006  rc.proc_cls = proc_cls;
1007  now = GNUNET_TIME_absolute_get ();
1008  execute_select (plugin,
1009  plugin->select_expiration,
1010  expi_proc,
1011  &rc,
1012  params_select);
1013 }
struct GNUNET_MYSQL_StatementHandle * select_expiration
void * proc_cls
Closure for proc.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
static int expi_proc(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Wrapper for the processor for mysql_plugin_get_expiration().
Context for expi_proc() function.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
static char * plugin
Solver plugin name as string.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
#define GNUNET_MY_query_param_end
End of query parameter specification.
Handle for a plugin.
Definition: block.c:37
struct Plugin * plugin
Plugin handle.
Time for absolute times used by GNUnet, in microseconds.
static void execute_select(struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select)
Run the given select statement and call &#39;proc&#39; on the resulting values (which must be in particular p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_drop()

static void mysql_plugin_drop ( void *  cls)
static

Drop database.

Parameters
clsthe struct Plugin *

Definition at line 1022 of file plugin_datastore_mysql.c.

References GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_MYSQL_statement_run(), GNUNET_OK, Plugin::mc, and plugin.

Referenced by libgnunet_plugin_datastore_mysql_init().

1023 {
1024  struct Plugin *plugin = cls;
1025 
1026  if (GNUNET_OK !=
1027  GNUNET_MYSQL_statement_run (plugin->mc,
1028  "DROP TABLE gn090"))
1029  return; /* error */
1030  plugin->env->duc (plugin->env->cls, 0);
1031 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static char * plugin
Solver plugin name as string.
Handle for a plugin.
Definition: block.c:37
int GNUNET_MYSQL_statement_run(struct GNUNET_MYSQL_Context *mc, const char *sql)
Run a SQL statement.
Definition: mysql.c:415
void * cls
Closure to use for callbacks.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mysql_plugin_remove_key()

static void mysql_plugin_remove_key ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  size,
const void *  data,
PluginRemoveCont  cont,
void *  cont_cls 
)
static

Remove a particular key in the datastore.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
datacontent stored
contcontinuation called with success or failure status
cont_clscontinuation closure for cont

Definition at line 1045 of file plugin_datastore_mysql.c.

References _, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::delete_entry_by_hash_value, Plugin::env, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_MY_exec_prepared(), GNUNET_MY_query_param_auto_from_type, GNUNET_MY_query_param_end, GNUNET_MY_query_param_fixed_size(), GNUNET_MYSQL_statement_get_stmt(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, Plugin::mc, and plugin.

Referenced by libgnunet_plugin_datastore_mysql_init().

1051 {
1052  struct Plugin *plugin = cls;
1053  struct GNUNET_MY_QueryParam params_delete[] = {
1057  };
1058 
1059  if (GNUNET_OK !=
1060  GNUNET_MY_exec_prepared (plugin->mc,
1062  params_delete))
1063  {
1065  "Removing key `%s' from gn090 table failed\n",
1066  GNUNET_h2s (key));
1067  cont (cont_cls,
1068  key,
1069  size,
1070  GNUNET_SYSERR,
1071  _ ("MySQL statement run failure"));
1072  return;
1073  }
1074 
1075  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (
1076  plugin->delete_entry_by_hash_value);
1077  my_ulonglong rows = mysql_stmt_affected_rows (stmt);
1078 
1079  if (0 == rows)
1080  {
1081  cont (cont_cls,
1082  key,
1083  size,
1084  GNUNET_NO,
1085  NULL);
1086  return;
1087  }
1088  plugin->env->duc (plugin->env->cls,
1089  -size);
1090  cont (cont_cls,
1091  key,
1092  size,
1093  GNUNET_OK,
1094  NULL);
1095 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
#define GNUNET_MY_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.FG.
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_hash_value
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:83
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
Definition: mysql.c:478
static char * plugin
Solver plugin name as string.
#define GNUNET_MY_query_param_end
End of query parameter specification.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
void * cls
Closure to use for callbacks.
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_datastore_mysql_init()

void* libgnunet_plugin_datastore_mysql_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe struct GNUNET_DATASTORE_PluginEnvironment *
Returns
our struct Plugin *

Definition at line 1105 of file plugin_datastore_mysql.c.

References _, Plugin::api, GNUNET_DATASTORE_PluginEnvironment::cfg, GNUNET_DATASTORE_PluginEnvironment::cls, GNUNET_DATASTORE_PluginFunctions::cls, DEC_REPL, Plugin::dec_repl, DELETE_ENTRY_BY_HASH_VALUE, Plugin::delete_entry_by_hash_value, DELETE_ENTRY_BY_UID, Plugin::delete_entry_by_uid, GNUNET_DATASTORE_PluginFunctions::drop, Plugin::env, GNUNET_DATASTORE_PluginFunctions::estimate_size, GET_ALL_KEYS, Plugin::get_all_keys, GNUNET_DATASTORE_PluginFunctions::get_expiration, GNUNET_DATASTORE_PluginFunctions::get_key, GNUNET_DATASTORE_PluginFunctions::get_keys, GNUNET_DATASTORE_PluginFunctions::get_replication, Plugin::get_size, GNUNET_DATASTORE_PluginFunctions::get_zero_anonymity, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log_from, GNUNET_MYSQL_context_create(), GNUNET_MYSQL_context_destroy(), GNUNET_new, INSERT_ENTRY, Plugin::insert_entry, Plugin::max_repl, Plugin::mc, MRUNS, mysql_plugin_drop(), mysql_plugin_estimate_size(), mysql_plugin_get_expiration(), mysql_plugin_get_key(), mysql_plugin_get_keys(), mysql_plugin_get_replication(), mysql_plugin_get_zero_anonymity(), mysql_plugin_put(), mysql_plugin_remove_key(), PINIT, plugin, GNUNET_DATASTORE_PluginFunctions::put, GNUNET_DATASTORE_PluginFunctions::remove_key, SELECT_ENTRY, Plugin::select_entry, SELECT_ENTRY_BY_HASH, Plugin::select_entry_by_hash, SELECT_ENTRY_BY_HASH_AND_TYPE, Plugin::select_entry_by_hash_and_type, Plugin::select_expiration, SELECT_IT_EXPIRATION, SELECT_IT_NON_ANONYMOUS, SELECT_IT_PRIORITY, SELECT_IT_REPLICATION, SELECT_MAX_REPL, Plugin::select_priority, Plugin::select_replication, SELECT_SIZE, UPDATE_ENTRY, Plugin::update_entry, and Plugin::zero_iter.

1106 {
1109  struct Plugin *plugin;
1110 
1111  plugin = GNUNET_new (struct Plugin);
1112  plugin->env = env;
1113  plugin->mc = GNUNET_MYSQL_context_create (env->cfg,
1114  "datastore-mysql");
1115  if (NULL == plugin->mc)
1116  {
1117  GNUNET_free (plugin);
1118  return NULL;
1119  }
1120 #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a))
1121 #define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, \
1122  b)))
1123  if (MRUNS
1124  ("CREATE TABLE IF NOT EXISTS gn090 ("
1125  " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1126  " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1127  " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1128  " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1129  " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
1130  " rvalue BIGINT UNSIGNED NOT NULL,"
1131  " hash BINARY(64) NOT NULL DEFAULT '',"
1132  " vhash BINARY(64) NOT NULL DEFAULT '',"
1133  " value BLOB NOT NULL DEFAULT '',"
1134  " uid BIGINT NOT NULL AUTO_INCREMENT,"
1135  " PRIMARY KEY (uid),"
1136  " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1137  " INDEX idx_prio (prio),"
1138  " INDEX idx_repl_rvalue (repl,rvalue),"
1139  " INDEX idx_expire (expire),"
1140  " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1141  ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") ||
1142  PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1145  PINIT (plugin->select_entry, SELECT_ENTRY) ||
1149  PINIT (plugin->get_size, SELECT_SIZE) ||
1150  PINIT (plugin->update_entry, UPDATE_ENTRY) ||
1151  PINIT (plugin->dec_repl, DEC_REPL) ||
1155  PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
1156  PINIT (plugin->get_all_keys, GET_ALL_KEYS) ||
1158  false)
1159  {
1160  GNUNET_MYSQL_context_destroy (plugin->mc);
1161  GNUNET_free (plugin);
1162  return NULL;
1163  }
1164 #undef PINIT
1165 #undef MRUNS
1166 
1168  api->cls = plugin;
1170  api->put = &mysql_plugin_put;
1171  api->get_key = &mysql_plugin_get_key;
1176  api->drop = &mysql_plugin_drop;
1179  _ ("Mysql database running\n"));
1180  return api;
1181 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash_and_type
struct GNUNET_MYSQL_StatementHandle * select_expiration
PluginGetKeys get_keys
Iterate over all keys in the database.
PluginPut put
Function to store an item in the datastore.
#define PINIT(a, b)
PluginGetType get_zero_anonymity
Get datum (of the specified type) with anonymity level zero.
#define MRUNS(a)
struct GNUNET_MYSQL_StatementHandle * insert_entry
struct GNUNET_MYSQL_Context * GNUNET_MYSQL_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Create a mysql context.
Definition: mysql.c:320
#define SELECT_IT_EXPIRATION
#define UPDATE_ENTRY
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_hash_value
#define SELECT_IT_REPLICATION
static void mysql_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
Get all of the keys in the datastore.
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_uid
PluginRemoveKey remove_key
Function to remove an item from the database.
PluginEstimateSize estimate_size
Calculate the current on-disk size of the SQ store.
#define SELECT_IT_PRIORITY
struct GNUNET_MYSQL_StatementHandle * zero_iter
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void mysql_plugin_remove_key(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls)
Remove a particular key in the datastore.
#define DELETE_ENTRY_BY_UID
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
#define SELECT_SIZE
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
PluginGetRandom get_replication
Function to get a random item with high replication score from the database, lowering the item&#39;s repl...
PluginDrop drop
Delete the database.
static void mysql_plugin_get_key(void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Get one of the results for a particular key in the datastore.
static void mysql_plugin_drop(void *cls)
Drop database.
#define DEC_REPL
#define DELETE_ENTRY_BY_HASH_VALUE
PluginGetRandom get_expiration
Function to get a random expired item or, if none are expired, either the oldest entry or one with a ...
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
void GNUNET_MYSQL_context_destroy(struct GNUNET_MYSQL_Context *mc)
Destroy a mysql context.
Definition: mysql.c:368
#define SELECT_MAX_REPL
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define INSERT_ENTRY
Prepared statements.
struct GNUNET_MYSQL_StatementHandle * dec_repl
#define SELECT_ENTRY_BY_HASH_AND_TYPE
struct GNUNET_MYSQL_StatementHandle * max_repl
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
#define GET_ALL_KEYS
static char * plugin
Solver plugin name as string.
#define SELECT_ENTRY_BY_HASH
static void mysql_plugin_estimate_size(void *cls, unsigned long long *estimate)
Get an estimate of how much space the database is currently using.
struct GNUNET_MYSQL_StatementHandle * get_all_keys
struct GNUNET_MYSQL_StatementHandle * select_priority
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void * cls
Closure to use for all of the following callbacks (except "next_request").
struct GNUNET_MYSQL_StatementHandle * select_entry
Handle for a plugin.
Definition: block.c:37
static void mysql_plugin_put(void *cls, const struct GNUNET_HashCode *key, bool absent, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, void *cont_cls)
Store an item in the datastore.
struct GNUNET_MYSQL_StatementHandle * get_size
static void mysql_plugin_get_replication(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for replication.
static void mysql_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
#define SELECT_IT_NON_ANONYMOUS
#define GNUNET_log_from(kind, comp,...)
PluginGetKey get_key
Get a particular datum matching a given hash from the datastore.
struct GNUNET_MYSQL_StatementHandle * update_entry
static void mysql_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Get a zero-anonymity datum from the datastore.
struct GNUNET_MYSQL_StatementHandle * select_replication
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define GNUNET_free(ptr)
Wrapper around free.
#define SELECT_ENTRY
Here is the call graph for this function:

◆ libgnunet_plugin_datastore_mysql_done()

void* libgnunet_plugin_datastore_mysql_done ( void *  cls)

Exit point from the plugin.

Parameters
clsour struct Plugin *
Returns
always NULL

Definition at line 1191 of file plugin_datastore_mysql.c.

References Plugin::api, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_free, GNUNET_MYSQL_context_destroy(), Plugin::mc, and plugin.

1192 {
1193  struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1194  struct Plugin *plugin = api->cls;
1195 
1196  GNUNET_MYSQL_context_destroy (plugin->mc);
1197  GNUNET_free (plugin);
1198  GNUNET_free (api);
1199  return NULL;
1200 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
void GNUNET_MYSQL_context_destroy(struct GNUNET_MYSQL_Context *mc)
Destroy a mysql context.
Definition: mysql.c:368
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
static char * plugin
Solver plugin name as string.
void * cls
Closure to use for all of the following callbacks (except "next_request").
Handle for a plugin.
Definition: block.c:37
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: