GNUnet  0.10.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)   (NULL == (a = GNUNET_MYSQL_statement_prepare(plugin->mc, 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 146 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 149 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 152 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 158 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 160 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 166 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 174 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 183 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 190 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 193 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 196 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 204 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 210 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 215 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 224 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 231 of file plugin_datastore_mysql.c.

◆ MRUNS

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

◆ PINIT

#define PINIT (   a,
 
)    (NULL == (a = GNUNET_MYSQL_statement_prepare(plugin->mc, b)))

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 241 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().

243 {
244  int ret;
245  uint64_t uid64 = (uint64_t)uid;
246  struct GNUNET_MY_QueryParam params_delete[] = {
249  };
250 
252  "Deleting value %llu from gn090 table\n",
253  uid);
254  ret = GNUNET_MY_exec_prepared(plugin->mc,
255  plugin->delete_entry_by_uid,
256  params_delete);
257  if (ret >= 0)
258  {
259  return GNUNET_OK;
260  }
262  "Deleting value %llu from gn090 table failed\n",
263  (unsigned long long)uid);
264  return ret;
265 }
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:84
#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
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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 276 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().

278 {
279  struct Plugin *plugin = cls;
280  uint64_t total;
281  int ret;
282  struct GNUNET_MY_QueryParam params_get[] = {
284  };
285  struct GNUNET_MY_ResultSpec results_get[] = {
288  };
289 
290  ret = GNUNET_MY_exec_prepared(plugin->mc,
291  plugin->get_size,
292  params_get);
293  *estimate = 0;
294  total = UINT64_MAX;
295  if ((GNUNET_OK == ret) &&
296  (GNUNET_OK ==
298  results_get)))
299  {
300  *estimate = (unsigned long long)total;
302  "Size estimate for MySQL payload is %lld\n",
303  (long long)total);
304  GNUNET_assert(UINT64_MAX != total);
307  NULL));
308  }
309 }
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:84
#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
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
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 329 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().

341 {
342  struct Plugin *plugin = cls;
343  uint64_t lexpiration = expiration.abs_value_us;
344  struct GNUNET_HashCode vhash;
345 
347  size,
348  &vhash);
349  if (!absent)
350  {
351  struct GNUNET_MY_QueryParam params_update[] = {
352  GNUNET_MY_query_param_uint32(&priority),
354  GNUNET_MY_query_param_uint64(&lexpiration),
358  };
359 
360  if (GNUNET_OK !=
361  GNUNET_MY_exec_prepared(plugin->mc,
362  plugin->update_entry,
363  params_update))
364  {
365  cont(cont_cls,
366  key,
367  size,
369  _("MySQL statement run failure"));
370  return;
371  }
372 
373  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->update_entry);
374  my_ulonglong rows = mysql_stmt_affected_rows(stmt);
375 
378  NULL));
379  if (0 != rows)
380  {
381  cont(cont_cls,
382  key,
383  size,
384  GNUNET_NO,
385  NULL);
386  return;
387  }
388  }
389 
391  UINT64_MAX);
392  struct GNUNET_MY_QueryParam params_insert[] = {
395  GNUNET_MY_query_param_uint32(&priority),
397  GNUNET_MY_query_param_uint64(&lexpiration),
403  };
404 
405  if (size > MAX_DATUM_SIZE)
406  {
407  GNUNET_break(0);
408  cont(cont_cls, key, size, GNUNET_SYSERR, _("Data too large"));
409  return;
410  }
411 
412  if (GNUNET_OK !=
413  GNUNET_MY_exec_prepared(plugin->mc,
414  plugin->insert_entry,
415  params_insert))
416  {
417  cont(cont_cls,
418  key,
419  size,
421  _("MySQL statement run failure"));
422  return;
423  }
425  "Inserted value `%s' with size %u into gn090 table\n",
426  GNUNET_h2s(key),
427  (unsigned int)size);
428  if (size > 0)
429  plugin->env->duc(plugin->env->cls,
430  size);
433  NULL));
434  cont(cont_cls,
435  key,
436  size,
437  GNUNET_OK,
438  NULL);
439 }
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:84
#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
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
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:477
A 512-bit hashcode.
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:66
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 453 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().

458 {
459  int ret;
460  uint32_t replication;
461  uint32_t type;
462  uint32_t priority;
463  uint32_t anonymity;
464  uint64_t uid;
465  size_t value_size;
466  void *value;
467  struct GNUNET_HashCode key;
469  struct GNUNET_MY_ResultSpec results_select[] = {
470  GNUNET_MY_result_spec_uint32(&replication),
472  GNUNET_MY_result_spec_uint32(&priority),
473  GNUNET_MY_result_spec_uint32(&anonymity),
476  GNUNET_MY_result_spec_variable_size(&value, &value_size),
479  };
480 
481  ret = GNUNET_MY_exec_prepared(plugin->mc,
482  stmt,
483  params_select);
484  if (GNUNET_OK != ret)
485  {
486  proc(proc_cls,
487  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
488  return;
489  }
490 
491  ret = GNUNET_MY_extract_result(stmt,
492  results_select);
493  if (GNUNET_OK != ret)
494  {
495  proc(proc_cls,
496  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
497  return;
498  }
499 
501  "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
502  (unsigned int)value_size,
503  GNUNET_h2s(&key),
504  (unsigned int)priority,
505  (unsigned int)anonymity,
507  GNUNET_assert(value_size < MAX_DATUM_SIZE);
510  NULL));
511  ret = proc(proc_cls,
512  &key,
513  value_size,
514  value,
515  type,
516  priority,
517  anonymity,
518  replication,
519  expiration,
520  uid);
521  GNUNET_MY_cleanup_result(results_select);
522  if (GNUNET_NO == ret)
523  {
524  do_delete_entry(plugin, uid);
525  if (0 != value_size)
526  plugin->env->duc(plugin->env->cls,
527  -value_size);
528  }
529 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
static char * expiration
Credential TTL.
#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
#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
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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.
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:741
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 546 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().

553 {
554  struct Plugin *plugin = cls;
555  uint64_t rvalue;
556 
557  if (random)
558  {
560  UINT64_MAX);
561  next_uid = 0;
562  }
563  else
564  rvalue = 0;
565 
566  if (NULL == key)
567  {
568  struct GNUNET_MY_QueryParam params_select[] = {
569  GNUNET_MY_query_param_uint64(&next_uid),
573  };
574 
575  execute_select(plugin,
576  plugin->select_entry,
577  proc,
578  proc_cls,
579  params_select);
580  }
581  else if (type != GNUNET_BLOCK_TYPE_ANY)
582  {
583  struct GNUNET_MY_QueryParam params_select[] = {
586  GNUNET_MY_query_param_uint64(&next_uid),
590  };
591 
592  execute_select(plugin,
594  proc,
595  proc_cls,
596  params_select);
597  }
598  else
599  {
600  struct GNUNET_MY_QueryParam params_select[] = {
602  GNUNET_MY_query_param_uint64(&next_uid),
606  };
607 
608  execute_select(plugin,
609  plugin->select_entry_by_hash,
610  proc,
611  proc_cls,
612  params_select);
613  }
614 }
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:84
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
#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 629 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().

634 {
635  struct Plugin *plugin = cls;
636  uint32_t typei = (uint32_t)type;
637 
638  struct GNUNET_MY_QueryParam params_zero_iter[] = {
640  GNUNET_MY_query_param_uint64(&next_uid),
642  };
643 
644  execute_select(plugin,
645  plugin->zero_iter,
646  proc,
647  proc_cls,
648  params_zero_iter);
649 }
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:84
struct GNUNET_MYSQL_StatementHandle * zero_iter
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
#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 694 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().

704 {
705  struct ReplCtx *rc = cls;
706  struct Plugin *plugin = rc->plugin;
707  int ret;
708  int iret;
709 
710  ret = rc->proc(rc->proc_cls,
711  key,
712  size,
713  data,
714  type,
715  priority,
716  anonymity,
717  replication,
718  expiration,
719  uid);
720  if (NULL != key)
721  {
722  struct GNUNET_MY_QueryParam params_proc[] = {
725  };
726 
727  iret = GNUNET_MY_exec_prepared(plugin->mc,
728  plugin->dec_repl,
729  params_proc);
730  if (GNUNET_SYSERR == iret)
731  {
733  "Failed to reduce replication counter\n");
734  return GNUNET_SYSERR;
735  }
736  }
737  return ret;
738 }
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:84
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
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_MYSQL_StatementHandle * dec_repl
#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:66
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 753 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().

756 {
757  struct Plugin *plugin = cls;
758  uint64_t rvalue;
759  uint32_t repl;
760  struct ReplCtx rc;
761  struct GNUNET_MY_QueryParam params_get[] = {
763  };
764  struct GNUNET_MY_ResultSpec results_get[] = {
767  };
768  struct GNUNET_MY_QueryParam params_select[] = {
774  };
775 
776  rc.plugin = plugin;
777  rc.proc = proc;
778  rc.proc_cls = proc_cls;
779 
780  if (1 !=
781  GNUNET_MY_exec_prepared(plugin->mc,
782  plugin->max_repl,
783  params_get))
784  {
785  proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
786  return;
787  }
788 
789  if (GNUNET_OK !=
791  results_get))
792  {
793  proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
794  return;
795  }
798  NULL));
800  UINT64_MAX);
801 
802  execute_select(plugin,
803  plugin->select_replication,
804  &repl_proc,
805  &rc,
806  params_select);
807 }
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:84
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...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
struct GNUNET_MYSQL_StatementHandle * max_repl
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 818 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().

821 {
822  struct Plugin *plugin = cls;
823  int ret;
824  MYSQL_STMT *statement;
825  unsigned int cnt;
826  struct GNUNET_HashCode key;
827  struct GNUNET_HashCode last;
828  struct GNUNET_MY_QueryParam params_select[] = {
830  };
831  struct GNUNET_MY_ResultSpec results_select[] = {
834  };
835 
836  GNUNET_assert(NULL != proc);
837  statement = GNUNET_MYSQL_statement_get_stmt(plugin->get_all_keys);
838  if (GNUNET_OK !=
839  GNUNET_MY_exec_prepared(plugin->mc,
840  plugin->get_all_keys,
841  params_select))
842  {
844  _("`%s' for `%s' failed at %s:%d with error: %s\n"),
845  "mysql_stmt_execute",
846  GET_ALL_KEYS,
847  __FILE__,
848  __LINE__,
849  mysql_stmt_error(statement));
851  proc(proc_cls, NULL, 0);
852  return;
853  }
854  memset(&last, 0, sizeof(last)); /* make static analysis happy */
855  ret = GNUNET_YES;
856  cnt = 0;
857  while (ret == GNUNET_YES)
858  {
860  results_select);
861  if (0 != GNUNET_memcmp(&last,
862  &key))
863  {
864  if (0 != cnt)
865  proc(proc_cls,
866  &last,
867  cnt);
868  cnt = 1;
869  last = key;
870  }
871  else
872  {
873  cnt++;
874  }
875  }
876  if (0 != cnt)
877  proc(proc_cls,
878  &last,
879  cnt);
880  /* finally, let app know we are done */
881  proc(proc_cls,
882  NULL,
883  0);
884  if (GNUNET_SYSERR == ret)
885  {
887  _("`%s' failed at %s:%d with error: %s\n"),
888  "mysql_stmt_fetch",
889  __FILE__,
890  __LINE__,
891  mysql_stmt_error(statement));
893  return;
894  }
895 }
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:84
#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
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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:477
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:340
A 512-bit hashcode.
#define GET_ALL_KEYS
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 941 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().

951 {
952  struct ExpiCtx *rc = cls;
953  struct Plugin *plugin = rc->plugin;
954  struct GNUNET_MY_QueryParam params_select[] = {
956  };
957 
958  if (NULL == key)
959  {
960  execute_select(plugin,
961  plugin->select_priority,
962  rc->proc,
963  rc->proc_cls,
964  params_select);
965  return GNUNET_SYSERR;
966  }
967  return rc->proc(rc->proc_cls,
968  key,
969  size,
970  data,
971  type,
972  priority,
973  anonymity,
974  replication,
975  expiration,
976  uid);
977 }
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:84
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Context for expi_proc() function.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
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:66
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 989 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().

992 {
993  struct Plugin *plugin = cls;
994  struct GNUNET_TIME_Absolute now;
995  struct GNUNET_MY_QueryParam params_select[] = {
998  };
999  struct ExpiCtx rc;
1000 
1001  rc.plugin = plugin;
1002  rc.proc = proc;
1003  rc.proc_cls = proc_cls;
1004  now = GNUNET_TIME_absolute_get();
1005  execute_select(plugin,
1006  plugin->select_expiration,
1007  expi_proc,
1008  &rc,
1009  params_select);
1010 }
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:84
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().
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Context for expi_proc() function.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
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 1019 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().

1020 {
1021  struct Plugin *plugin = cls;
1022 
1023  if (GNUNET_OK !=
1025  "DROP TABLE gn090"))
1026  return; /* error */
1027  plugin->env->duc(plugin->env->cls, 0);
1028 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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:414
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 1042 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().

1048 {
1049  struct Plugin *plugin = cls;
1050  struct GNUNET_MY_QueryParam params_delete[] = {
1054  };
1055 
1056  if (GNUNET_OK !=
1057  GNUNET_MY_exec_prepared(plugin->mc,
1059  params_delete))
1060  {
1062  "Removing key `%s' from gn090 table failed\n",
1063  GNUNET_h2s(key));
1064  cont(cont_cls,
1065  key,
1066  size,
1067  GNUNET_SYSERR,
1068  _("MySQL statement run failure"));
1069  return;
1070  }
1071 
1072  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->delete_entry_by_hash_value);
1073  my_ulonglong rows = mysql_stmt_affected_rows(stmt);
1074 
1075  if (0 == rows)
1076  {
1077  cont(cont_cls,
1078  key,
1079  size,
1080  GNUNET_NO,
1081  NULL);
1082  return;
1083  }
1084  plugin->env->duc(plugin->env->cls,
1085  -size);
1086  cont(cont_cls,
1087  key,
1088  size,
1089  GNUNET_OK,
1090  NULL);
1091 }
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:84
#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
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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:477
#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:66
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 1101 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.

1102 {
1105  struct Plugin *plugin;
1106 
1107  plugin = GNUNET_new(struct Plugin);
1108  plugin->env = env;
1109  plugin->mc = GNUNET_MYSQL_context_create(env->cfg,
1110  "datastore-mysql");
1111  if (NULL == plugin->mc)
1112  {
1113  GNUNET_free(plugin);
1114  return NULL;
1115  }
1116 #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run(plugin->mc, a))
1117 #define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare(plugin->mc, b)))
1118  if (MRUNS
1119  ("CREATE TABLE IF NOT EXISTS gn090 ("
1120  " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1121  " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1122  " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1123  " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1124  " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
1125  " rvalue BIGINT UNSIGNED NOT NULL,"
1126  " hash BINARY(64) NOT NULL DEFAULT '',"
1127  " vhash BINARY(64) NOT NULL DEFAULT '',"
1128  " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT,"
1129  " PRIMARY KEY (uid),"
1130  " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1131  " INDEX idx_prio (prio),"
1132  " INDEX idx_repl_rvalue (repl,rvalue),"
1133  " INDEX idx_expire (expire),"
1134  " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1135  ") ENGINE=InnoDB") || MRUNS("SET AUTOCOMMIT = 1") ||
1136  PINIT(plugin->insert_entry, INSERT_ENTRY) ||
1139  PINIT(plugin->select_entry, SELECT_ENTRY) ||
1143  PINIT(plugin->get_size, SELECT_SIZE) ||
1144  PINIT(plugin->update_entry, UPDATE_ENTRY) ||
1145  PINIT(plugin->dec_repl, DEC_REPL) ||
1149  PINIT(plugin->max_repl, SELECT_MAX_REPL) ||
1150  PINIT(plugin->get_all_keys, GET_ALL_KEYS) ||
1152  false)
1153  {
1155  GNUNET_free(plugin);
1156  return NULL;
1157  }
1158 #undef PINIT
1159 #undef MRUNS
1160 
1162  api->cls = plugin;
1164  api->put = &mysql_plugin_put;
1165  api->get_key = &mysql_plugin_get_key;
1170  api->drop = &mysql_plugin_drop;
1173  _("Mysql database running\n"));
1174  return api;
1175 }
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:319
#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:46
#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 struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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:367
#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
#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 1185 of file plugin_datastore_mysql.c.

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

1186 {
1187  struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1188  struct Plugin *plugin = api->cls;
1189 
1191  GNUNET_free(plugin);
1192  GNUNET_free(api);
1193  return NULL;
1194 }
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void GNUNET_MYSQL_context_destroy(struct GNUNET_MYSQL_Context *mc)
Destroy a mysql context.
Definition: mysql.c:367
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
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: