127 #define MAX_DATUM_SIZE 65536
148 #define INSERT_ENTRY \
149 "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
152 #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
155 #define DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 " \
156 "WHERE hash = ? AND " \
161 #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid"
163 #define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 " \
164 "WHERE uid >= ? AND " \
165 "(rvalue >= ? OR 0 = ?) " \
166 "ORDER BY uid LIMIT 1"
169 #define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 " \
170 "FORCE INDEX (idx_hash_type_uid) " \
171 "WHERE hash=? AND " \
173 "(rvalue >= ? OR 0 = ?) " \
174 "ORDER BY uid LIMIT 1"
177 #define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 " \
178 "FORCE INDEX (idx_hash_type_uid) " \
179 "WHERE hash = ? AND " \
182 "(rvalue >= ? OR 0 = ?) " \
183 "ORDER BY uid LIMIT 1"
186 #define UPDATE_ENTRY "UPDATE gn090 SET " \
187 "prio = prio + ?, " \
188 "repl = repl + ?, " \
189 "expire = GREATEST(expire, ?) " \
190 "WHERE hash = ? AND vhash = ?"
193 #define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"
196 #define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090"
199 #define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 " \
200 "FORCE INDEX (idx_anonLevel_type_rvalue) " \
201 "WHERE anonLevel=0 AND " \
204 "ORDER BY uid LIMIT 1"
207 #define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 " \
208 "FORCE INDEX (idx_expire) " \
209 "WHERE expire < ? " \
210 "ORDER BY expire ASC LIMIT 1"
213 #define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 " \
214 "FORCE INDEX (idx_prio) " \
215 "ORDER BY prio ASC LIMIT 1"
218 #define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 " \
219 "FORCE INDEX (idx_repl_rvalue) " \
220 "WHERE repl=? AND " \
222 " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) " \
223 "ORDER BY rvalue ASC " \
227 #define SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090"
230 #define GET_ALL_KEYS "SELECT hash from gn090"
245 unsigned long long uid)
248 uint64_t uid64 = (uint64_t) uid;
255 "Deleting value %llu from gn090 table\n",
258 plugin->delete_entry_by_uid,
265 "Deleting value %llu from gn090 table failed\n",
266 (
unsigned long long) uid);
280 unsigned long long *estimate)
303 *estimate = (
unsigned long long) total;
305 "Size estimate for MySQL payload is %lld\n",
346 uint64_t lexpiration =
expiration.abs_value_us;
372 _ (
"MySQL statement run failure"));
377 my_ulonglong rows = mysql_stmt_affected_rows (stmt);
424 _ (
"MySQL statement run failure"));
428 "Inserted value `%s' with size %u into gn090 table\n",
430 (
unsigned int)
size);
504 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
505 (
unsigned int) value_size,
507 (
unsigned int) priority,
514 ret = proc (proc_cls,
596 plugin->select_entry_by_hash_and_type,
612 plugin->select_entry_by_hash,
639 uint32_t typei = (uint32_t)
type;
737 "Failed to reduce replication counter\n");
807 plugin->select_replication,
828 MYSQL_STMT *statement;
848 _ (
"`%s' for `%s' failed at %s:%d with error: %s\n"),
849 "mysql_stmt_execute",
853 mysql_stmt_error (statement));
855 proc (proc_cls, NULL, 0);
858 memset (&last, 0,
sizeof(last));
891 _ (
"`%s' failed at %s:%d with error: %s\n"),
895 mysql_stmt_error (statement));
1010 plugin->select_expiration,
1029 "DROP TABLE gn090"))
1062 plugin->delete_entry_by_hash_value,
1066 "Removing key `%s' from gn090 table failed\n",
1072 _ (
"MySQL statement run failure"));
1077 plugin->delete_entry_by_hash_value);
1078 my_ulonglong rows = mysql_stmt_affected_rows (stmt);
1121 #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a))
1122 #define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, \
1125 (
"CREATE TABLE IF NOT EXISTS gn090 ("
1126 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1127 " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1128 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1129 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1130 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
1131 " rvalue BIGINT UNSIGNED NOT NULL,"
1132 " hash BINARY(64) NOT NULL DEFAULT '',"
1133 " vhash BINARY(64) NOT NULL DEFAULT '',"
1134 " value BLOB NOT NULL DEFAULT '',"
1135 " uid BIGINT NOT NULL AUTO_INCREMENT,"
1136 " PRIMARY KEY (uid),"
1137 " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1138 " INDEX idx_prio (prio),"
1139 " INDEX idx_repl_rvalue (repl,rvalue),"
1140 " INDEX idx_expire (expire),"
1141 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1142 ") ENGINE=InnoDB") ||
MRUNS (
"SET AUTOCOMMIT = 1") ||
1180 _ (
"Mysql database running\n"));
struct GNUNET_MQ_Envelope * env
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
static char * expiration
Credential TTL.
static int ret
Return value of the commandline.
struct TestcasePlugin * plugin
The process handle to the testbed service.
static unsigned int replication
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int anonymity
uint32_t data
The data value.
static char * value
Value of the record to add/remove.
API for the database backend plugins.
Helper library to access a MySQL database.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
enum GNUNET_GenericReturnValue(* PluginDatumProcessor)(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)
An processor over a set of items stored in the datastore.
void(* PluginPutCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Put continuation.
void(* PluginKeyProcessor)(void *cls, const struct GNUNET_HashCode *key, unsigned int count)
An processor over a set of keys stored in the datastore.
void(* PluginRemoveCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Remove continuation.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
#define GNUNET_log(kind,...)
#define GNUNET_log_from(kind, comp,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
Absolute time expected.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size(void **dst, size_t *ptr_size)
Variable-size result expected.
#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.
void GNUNET_MY_cleanup_result(struct GNUNET_MY_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_MY_extract_result().
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
struct GNUNET_MYSQL_Context * GNUNET_MYSQL_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Create a mysql context.
void GNUNET_MYSQL_statements_invalidate(struct GNUNET_MYSQL_Context *mc)
Close database connection and all prepared statements (we got a DB error).
#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_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.
void GNUNET_MYSQL_context_destroy(struct GNUNET_MYSQL_Context *mc)
Destroy a mysql context.
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.
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_MY_ResultSpec GNUNET_MY_result_spec_uint32(uint32_t *u32)
uint32_t expected
#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.
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.
#define GNUNET_MY_query_param_end
End of query parameter specification.
int GNUNET_MYSQL_statement_run(struct GNUNET_MYSQL_Context *mc, const char *sql)
Run a SQL statement.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static unsigned int size
Size of the "table".
#define SELECT_IT_REPLICATION
void * libgnunet_plugin_datastore_mysql_init(void *cls)
Entry point for the plugin.
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().
static void mysql_plugin_estimate_size(void *cls, unsigned long long *estimate)
Get an estimate of how much space the database is currently using.
#define SELECT_IT_EXPIRATION
static void mysql_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
Get all of the keys in the datastore.
#define DELETE_ENTRY_BY_HASH_VALUE
#define SELECT_IT_NON_ANONYMOUS
#define SELECT_ENTRY_BY_HASH
#define SELECT_IT_PRIORITY
#define INSERT_ENTRY
Prepared statements.
static void mysql_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
static void mysql_plugin_get_replication(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for replication.
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_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.
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.
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 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 p...
static int do_delete_entry(struct Plugin *plugin, unsigned long long uid)
Delete an entry from the gn090 table.
#define SELECT_ENTRY_BY_HASH_AND_TYPE
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.
static void mysql_plugin_drop(void *cls)
Drop database.
void * libgnunet_plugin_datastore_mysql_done(void *cls)
Exit point from the plugin.
#define DELETE_ENTRY_BY_UID
Context for expi_proc() function.
struct Plugin * plugin
Plugin handle.
void * proc_cls
Closure for proc.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
void * cls
Closure for all of the callbacks.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
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 prepared statement.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_MYSQL_StatementHandle * get_all_keys
struct GNUNET_MYSQL_StatementHandle * get_size
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
struct GNUNET_MYSQL_StatementHandle * dec_repl
struct GNUNET_MYSQL_StatementHandle * select_replication
struct GNUNET_MYSQL_StatementHandle * max_repl
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_uid
struct GNUNET_MYSQL_StatementHandle * update_entry
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash_and_type
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_hash_value
struct GNUNET_MYSQL_StatementHandle * select_priority
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash
struct GNUNET_MYSQL_StatementHandle * zero_iter
struct GNUNET_MYSQL_StatementHandle * insert_entry
struct GNUNET_MYSQL_StatementHandle * select_expiration
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
struct GNUNET_MYSQL_StatementHandle * select_entry
Context for repl_proc() function.
void * proc_cls
Closure for proc.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
struct Plugin * plugin
Plugin handle.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model