GNUnet  0.19.3
plugin_datastore_mysql.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2009, 2010, 2011 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
120 #include "platform.h"
121 #include "gnunet_datastore_plugin.h"
122 #include "gnunet_util_lib.h"
123 #include "gnunet_mysql_lib.h"
124 #include "gnunet_mysql_compat.h"
125 #include "gnunet_my_lib.h"
126 
127 #define MAX_DATUM_SIZE 65536
128 
129 
133 struct Plugin
134 {
139 
144 
148 #define INSERT_ENTRY \
149  "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
151 
152 #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
154 
155 #define DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 " \
156  "WHERE hash = ? AND " \
157  "value = ? " \
158  "LIMIT 1"
160 
161 #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid"
162 
163 #define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 " \
164  "WHERE uid >= ? AND " \
165  "(rvalue >= ? OR 0 = ?) " \
166  "ORDER BY uid LIMIT 1"
168 
169 #define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 " \
170  "FORCE INDEX (idx_hash_type_uid) " \
171  "WHERE hash=? AND " \
172  "uid >= ? AND " \
173  "(rvalue >= ? OR 0 = ?) " \
174  "ORDER BY uid LIMIT 1"
176 
177 #define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 " \
178  "FORCE INDEX (idx_hash_type_uid) " \
179  "WHERE hash = ? AND " \
180  "type = ? AND " \
181  "uid >= ? AND " \
182  "(rvalue >= ? OR 0 = ?) " \
183  "ORDER BY uid LIMIT 1"
185 
186 #define UPDATE_ENTRY "UPDATE gn090 SET " \
187  "prio = prio + ?, " \
188  "repl = repl + ?, " \
189  "expire = GREATEST(expire, ?) " \
190  "WHERE hash = ? AND vhash = ?"
192 
193 #define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"
195 
196 #define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090"
198 
199 #define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 " \
200  "FORCE INDEX (idx_anonLevel_type_rvalue) " \
201  "WHERE anonLevel=0 AND " \
202  "type=? AND " \
203  "uid >= ? " \
204  "ORDER BY uid LIMIT 1"
206 
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"
212 
213 #define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 " \
214  "FORCE INDEX (idx_prio) " \
215  "ORDER BY prio ASC LIMIT 1"
217 
218 #define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 " \
219  "FORCE INDEX (idx_repl_rvalue) " \
220  "WHERE repl=? AND " \
221  " (rvalue>=? OR" \
222  " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) " \
223  "ORDER BY rvalue ASC " \
224  "LIMIT 1"
226 
227 #define SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090"
229 
230 #define GET_ALL_KEYS "SELECT hash from gn090"
232 };
233 
234 #define MAX_PARAM 16
235 
243 static int
245  unsigned long long uid)
246 {
247  int ret;
248  uint64_t uid64 = (uint64_t) uid;
249  struct GNUNET_MY_QueryParam params_delete[] = {
252  };
253 
255  "Deleting value %llu from gn090 table\n",
256  uid);
258  plugin->delete_entry_by_uid,
259  params_delete);
260  if (ret >= 0)
261  {
262  return GNUNET_OK;
263  }
265  "Deleting value %llu from gn090 table failed\n",
266  (unsigned long long) uid);
267  return ret;
268 }
269 
270 
278 static void
280  unsigned long long *estimate)
281 {
282  struct Plugin *plugin = cls;
283  uint64_t total;
284  int ret;
285  struct GNUNET_MY_QueryParam params_get[] = {
287  };
288  struct GNUNET_MY_ResultSpec results_get[] = {
291  };
292 
294  plugin->get_size,
295  params_get);
296  *estimate = 0;
297  total = UINT64_MAX;
298  if ((GNUNET_OK == ret) &&
299  (GNUNET_OK ==
300  GNUNET_MY_extract_result (plugin->get_size,
301  results_get)))
302  {
303  *estimate = (unsigned long long) total;
305  "Size estimate for MySQL payload is %lld\n",
306  (long long) total);
307  GNUNET_assert (UINT64_MAX != total);
309  GNUNET_MY_extract_result (plugin->get_size,
310  NULL));
311  }
312 }
313 
314 
331 static void
332 mysql_plugin_put (void *cls,
333  const struct GNUNET_HashCode *key,
334  bool absent,
335  uint32_t size,
336  const void *data,
337  enum GNUNET_BLOCK_Type type,
338  uint32_t priority,
339  uint32_t anonymity,
340  uint32_t replication,
342  PluginPutCont cont,
343  void *cont_cls)
344 {
345  struct Plugin *plugin = cls;
346  uint64_t lexpiration = expiration.abs_value_us;
347  struct GNUNET_HashCode vhash;
348 
350  size,
351  &vhash);
352  if (! absent)
353  {
354  struct GNUNET_MY_QueryParam params_update[] = {
355  GNUNET_MY_query_param_uint32 (&priority),
357  GNUNET_MY_query_param_uint64 (&lexpiration),
361  };
362 
363  if (GNUNET_OK !=
365  plugin->update_entry,
366  params_update))
367  {
368  cont (cont_cls,
369  key,
370  size,
372  _ ("MySQL statement run failure"));
373  return;
374  }
375 
376  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->update_entry);
377  my_ulonglong rows = mysql_stmt_affected_rows (stmt);
378 
380  GNUNET_MY_extract_result (plugin->update_entry,
381  NULL));
382  if (0 != rows)
383  {
384  cont (cont_cls,
385  key,
386  size,
387  GNUNET_NO,
388  NULL);
389  return;
390  }
391  }
392 
394  UINT64_MAX);
395  struct GNUNET_MY_QueryParam params_insert[] = {
398  GNUNET_MY_query_param_uint32 (&priority),
400  GNUNET_MY_query_param_uint64 (&lexpiration),
401  GNUNET_MY_query_param_uint64 (&lrvalue),
406  };
407 
408  if (size > MAX_DATUM_SIZE)
409  {
410  GNUNET_break (0);
411  cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
412  return;
413  }
414 
415  if (GNUNET_OK !=
417  plugin->insert_entry,
418  params_insert))
419  {
420  cont (cont_cls,
421  key,
422  size,
424  _ ("MySQL statement run failure"));
425  return;
426  }
428  "Inserted value `%s' with size %u into gn090 table\n",
429  GNUNET_h2s (key),
430  (unsigned int) size);
431  if (size > 0)
432  plugin->env->duc (plugin->env->cls,
433  size);
435  GNUNET_MY_extract_result (plugin->insert_entry,
436  NULL));
437  cont (cont_cls,
438  key,
439  size,
440  GNUNET_OK,
441  NULL);
442 }
443 
444 
455 static void
457  struct GNUNET_MYSQL_StatementHandle *stmt,
459  void *proc_cls,
460  struct GNUNET_MY_QueryParam *params_select)
461 {
462  int ret;
463  uint32_t replication;
464  uint32_t type;
465  uint32_t priority;
466  uint32_t anonymity;
467  uint64_t uid;
468  size_t value_size;
469  void *value;
470  struct GNUNET_HashCode key;
472  struct GNUNET_MY_ResultSpec results_select[] = {
475  GNUNET_MY_result_spec_uint32 (&priority),
482  };
483 
485  stmt,
486  params_select);
487  if (GNUNET_OK != ret)
488  {
489  proc (proc_cls,
490  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
491  return;
492  }
493 
495  results_select);
496  if (GNUNET_OK != ret)
497  {
498  proc (proc_cls,
499  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
500  return;
501  }
502 
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,
506  GNUNET_h2s (&key),
507  (unsigned int) priority,
508  (unsigned int) anonymity,
510  GNUNET_assert (value_size < MAX_DATUM_SIZE);
513  NULL));
514  ret = proc (proc_cls,
515  &key,
516  value_size,
517  value,
518  type,
519  priority,
520  anonymity,
521  replication,
522  expiration,
523  uid);
524  GNUNET_MY_cleanup_result (results_select);
525  if (GNUNET_NO == ret)
526  {
527  do_delete_entry (plugin, uid);
528  if (0 != value_size)
529  plugin->env->duc (plugin->env->cls,
530  -value_size);
531  }
532 }
533 
534 
548 static void
550  uint64_t next_uid,
551  bool random,
552  const struct GNUNET_HashCode *key,
553  enum GNUNET_BLOCK_Type type,
555  void *proc_cls)
556 {
557  struct Plugin *plugin = cls;
558  uint64_t rvalue;
559 
560  if (random)
561  {
563  UINT64_MAX);
564  next_uid = 0;
565  }
566  else
567  rvalue = 0;
568 
569  if (NULL == key)
570  {
571  struct GNUNET_MY_QueryParam params_select[] = {
572  GNUNET_MY_query_param_uint64 (&next_uid),
576  };
577 
579  plugin->select_entry,
580  proc,
581  proc_cls,
582  params_select);
583  }
584  else if (type != GNUNET_BLOCK_TYPE_ANY)
585  {
586  struct GNUNET_MY_QueryParam params_select[] = {
589  GNUNET_MY_query_param_uint64 (&next_uid),
593  };
594 
596  plugin->select_entry_by_hash_and_type,
597  proc,
598  proc_cls,
599  params_select);
600  }
601  else
602  {
603  struct GNUNET_MY_QueryParam params_select[] = {
605  GNUNET_MY_query_param_uint64 (&next_uid),
609  };
610 
612  plugin->select_entry_by_hash,
613  proc,
614  proc_cls,
615  params_select);
616  }
617 }
618 
619 
631 static void
633  uint64_t next_uid,
634  enum GNUNET_BLOCK_Type type,
636  void *proc_cls)
637 {
638  struct Plugin *plugin = cls;
639  uint32_t typei = (uint32_t) type;
640 
641  struct GNUNET_MY_QueryParam params_zero_iter[] = {
643  GNUNET_MY_query_param_uint64 (&next_uid),
645  };
646 
648  plugin->zero_iter,
649  proc,
650  proc_cls,
651  params_zero_iter);
652 }
653 
654 
658 struct ReplCtx
659 {
663  struct Plugin *plugin;
664 
669 
673  void *proc_cls;
674 };
675 
676 
697 static int
698 repl_proc (void *cls,
699  const struct GNUNET_HashCode *key,
700  uint32_t size,
701  const void *data,
702  enum GNUNET_BLOCK_Type type,
703  uint32_t priority,
704  uint32_t anonymity,
705  uint32_t replication,
707  uint64_t uid)
708 {
709  struct ReplCtx *rc = cls;
710  struct Plugin *plugin = rc->plugin;
711  int ret;
712  int iret;
713 
714  ret = rc->proc (rc->proc_cls,
715  key,
716  size,
717  data,
718  type,
719  priority,
720  anonymity,
721  replication,
722  expiration,
723  uid);
724  if (NULL != key)
725  {
726  struct GNUNET_MY_QueryParam params_proc[] = {
729  };
730 
731  iret = GNUNET_MY_exec_prepared (plugin->mc,
732  plugin->dec_repl,
733  params_proc);
734  if (GNUNET_SYSERR == iret)
735  {
737  "Failed to reduce replication counter\n");
738  return GNUNET_SYSERR;
739  }
740  }
741  return ret;
742 }
743 
744 
756 static void
759  void *proc_cls)
760 {
761  struct Plugin *plugin = cls;
762  uint64_t rvalue;
763  uint32_t repl;
764  struct ReplCtx rc;
765  struct GNUNET_MY_QueryParam params_get[] = {
767  };
768  struct GNUNET_MY_ResultSpec results_get[] = {
771  };
772  struct GNUNET_MY_QueryParam params_select[] = {
778  };
779 
780  rc.plugin = plugin;
781  rc.proc = proc;
782  rc.proc_cls = proc_cls;
783 
784  if (1 !=
786  plugin->max_repl,
787  params_get))
788  {
789  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
790  return;
791  }
792 
793  if (GNUNET_OK !=
794  GNUNET_MY_extract_result (plugin->max_repl,
795  results_get))
796  {
797  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
798  return;
799  }
801  GNUNET_MY_extract_result (plugin->max_repl,
802  NULL));
804  UINT64_MAX);
805 
807  plugin->select_replication,
808  &repl_proc,
809  &rc,
810  params_select);
811 }
812 
813 
821 static void
823  PluginKeyProcessor proc,
824  void *proc_cls)
825 {
826  struct Plugin *plugin = cls;
827  int ret;
828  MYSQL_STMT *statement;
829  unsigned int cnt;
830  struct GNUNET_HashCode key;
831  struct GNUNET_HashCode last;
832  struct GNUNET_MY_QueryParam params_select[] = {
834  };
835  struct GNUNET_MY_ResultSpec results_select[] = {
838  };
839 
840  GNUNET_assert (NULL != proc);
841  statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys);
842  if (GNUNET_OK !=
844  plugin->get_all_keys,
845  params_select))
846  {
848  _ ("`%s' for `%s' failed at %s:%d with error: %s\n"),
849  "mysql_stmt_execute",
850  GET_ALL_KEYS,
851  __FILE__,
852  __LINE__,
853  mysql_stmt_error (statement));
855  proc (proc_cls, NULL, 0);
856  return;
857  }
858  memset (&last, 0, sizeof(last)); /* make static analysis happy */
859  ret = GNUNET_YES;
860  cnt = 0;
861  while (ret == GNUNET_YES)
862  {
863  ret = GNUNET_MY_extract_result (plugin->get_all_keys,
864  results_select);
865  if (0 != GNUNET_memcmp (&last,
866  &key))
867  {
868  if (0 != cnt)
869  proc (proc_cls,
870  &last,
871  cnt);
872  cnt = 1;
873  last = key;
874  }
875  else
876  {
877  cnt++;
878  }
879  }
880  if (0 != cnt)
881  proc (proc_cls,
882  &last,
883  cnt);
884  /* finally, let app know we are done */
885  proc (proc_cls,
886  NULL,
887  0);
888  if (GNUNET_SYSERR == ret)
889  {
891  _ ("`%s' failed at %s:%d with error: %s\n"),
892  "mysql_stmt_fetch",
893  __FILE__,
894  __LINE__,
895  mysql_stmt_error (statement));
897  return;
898  }
899 }
900 
901 
905 struct ExpiCtx
906 {
910  struct Plugin *plugin;
911 
916 
920  void *proc_cls;
921 };
922 
923 
944 static int
945 expi_proc (void *cls,
946  const struct GNUNET_HashCode *key,
947  uint32_t size,
948  const void *data,
949  enum GNUNET_BLOCK_Type type,
950  uint32_t priority,
951  uint32_t anonymity,
952  uint32_t replication,
954  uint64_t uid)
955 {
956  struct ExpiCtx *rc = cls;
957  struct Plugin *plugin = rc->plugin;
958  struct GNUNET_MY_QueryParam params_select[] = {
960  };
961 
962  if (NULL == key)
963  {
965  plugin->select_priority,
966  rc->proc,
967  rc->proc_cls,
968  params_select);
969  return GNUNET_SYSERR;
970  }
971  return rc->proc (rc->proc_cls,
972  key,
973  size,
974  data,
975  type,
976  priority,
977  anonymity,
978  replication,
979  expiration,
980  uid);
981 }
982 
983 
992 static void
995  void *proc_cls)
996 {
997  struct Plugin *plugin = cls;
998  struct GNUNET_TIME_Absolute now = { 0 };
999  struct GNUNET_MY_QueryParam params_select[] = {
1002  };
1003  struct ExpiCtx rc;
1004 
1005  rc.plugin = plugin;
1006  rc.proc = proc;
1007  rc.proc_cls = proc_cls;
1008  now = GNUNET_TIME_absolute_get ();
1010  plugin->select_expiration,
1011  expi_proc,
1012  &rc,
1013  params_select);
1014 }
1015 
1016 
1022 static void
1024 {
1025  struct Plugin *plugin = cls;
1026 
1027  if (GNUNET_OK !=
1029  "DROP TABLE gn090"))
1030  return; /* error */
1031  plugin->env->duc (plugin->env->cls, 0);
1032 }
1033 
1034 
1045 static void
1047  const struct GNUNET_HashCode *key,
1048  uint32_t size,
1049  const void *data,
1050  PluginRemoveCont cont,
1051  void *cont_cls)
1052 {
1053  struct Plugin *plugin = cls;
1054  struct GNUNET_MY_QueryParam params_delete[] = {
1058  };
1059 
1060  if (GNUNET_OK !=
1062  plugin->delete_entry_by_hash_value,
1063  params_delete))
1064  {
1066  "Removing key `%s' from gn090 table failed\n",
1067  GNUNET_h2s (key));
1068  cont (cont_cls,
1069  key,
1070  size,
1071  GNUNET_SYSERR,
1072  _ ("MySQL statement run failure"));
1073  return;
1074  }
1075 
1076  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (
1077  plugin->delete_entry_by_hash_value);
1078  my_ulonglong rows = mysql_stmt_affected_rows (stmt);
1079 
1080  if (0 == rows)
1081  {
1082  cont (cont_cls,
1083  key,
1084  size,
1085  GNUNET_NO,
1086  NULL);
1087  return;
1088  }
1089  plugin->env->duc (plugin->env->cls,
1090  -size);
1091  cont (cont_cls,
1092  key,
1093  size,
1094  GNUNET_OK,
1095  NULL);
1096 }
1097 
1098 
1105 void *
1107 {
1110  struct Plugin *plugin;
1111 
1112  plugin = GNUNET_new (struct Plugin);
1113  plugin->env = env;
1115  "datastore-mysql");
1116  if (NULL == plugin->mc)
1117  {
1118  GNUNET_free (plugin);
1119  return NULL;
1120  }
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, \
1123  b)))
1124  if (MRUNS
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") ||
1143  PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1144  PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
1145  PINIT (plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) ||
1146  PINIT (plugin->select_entry, SELECT_ENTRY) ||
1147  PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
1148  PINIT (plugin->select_entry_by_hash_and_type,
1150  PINIT (plugin->get_size, SELECT_SIZE) ||
1151  PINIT (plugin->update_entry, UPDATE_ENTRY) ||
1152  PINIT (plugin->dec_repl, DEC_REPL) ||
1153  PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) ||
1154  PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) ||
1155  PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
1156  PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
1157  PINIT (plugin->get_all_keys, GET_ALL_KEYS) ||
1158  PINIT (plugin->select_replication, SELECT_IT_REPLICATION) ||
1159  false)
1160  {
1162  GNUNET_free (plugin);
1163  return NULL;
1164  }
1165 #undef PINIT
1166 #undef MRUNS
1167 
1169  api->cls = plugin;
1170  api->estimate_size = &mysql_plugin_estimate_size;
1171  api->put = &mysql_plugin_put;
1173  api->get_replication = &mysql_plugin_get_replication;
1174  api->get_expiration = &mysql_plugin_get_expiration;
1175  api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity;
1176  api->get_keys = &mysql_plugin_get_keys;
1177  api->drop = &mysql_plugin_drop;
1178  api->remove_key = &mysql_plugin_remove_key;
1180  _ ("Mysql database running\n"));
1181  return api;
1182 }
1183 
1184 
1191 void *
1193 {
1194  struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1195  struct Plugin *plugin = api->cls;
1196 
1198  GNUNET_free (plugin);
1199  GNUNET_free (api);
1200  return NULL;
1201 }
1202 
1203 
1204 /* end of plugin_datastore_mysql.c */
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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.
Definition: gnunet-abd.c:96
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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.
Definition: crypto_hash.c:41
#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.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#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
@ GNUNET_ERROR_TYPE_INFO
#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().
Definition: my.c:261
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
Definition: mysql.c:478
struct GNUNET_MYSQL_Context * GNUNET_MYSQL_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Create a mysql context.
Definition: mysql.c:321
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:342
#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.
Definition: mysql.c:369
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:43
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.
Definition: my.c:137
#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.
Definition: mysql.c:416
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:616
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#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
#define DEC_REPL
#define SELECT_ENTRY
#define GET_ALL_KEYS
static void mysql_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
Get all of the keys in the datastore.
#define SELECT_SIZE
#define PINIT(a, b)
#define UPDATE_ENTRY
#define MAX_DATUM_SIZE
#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.
#define SELECT_MAX_REPL
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...
#define MRUNS(a)
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").
A 512-bit hashcode.
Mysql context.
Definition: mysql.c:77
Handle for a prepared statement.
Definition: mysql.c:114
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:93
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.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_MYSQL_StatementHandle * get_all_keys
struct GNUNET_MYSQL_StatementHandle * get_size
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
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