GNUnet  0.10.x
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_my_lib.h"
125 
126 #define MAX_DATUM_SIZE 65536
127 
128 
132 struct Plugin
133 {
138 
143 
147 #define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
149 
150 #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
152 
153 #define DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 "\
154  "WHERE hash = ? AND "\
155  "value = ? "\
156  "LIMIT 1"
158 
159 #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid"
160 
161 #define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 "\
162  "WHERE uid >= ? AND "\
163  "(rvalue >= ? OR 0 = ?) "\
164  "ORDER BY uid LIMIT 1"
166 
167 #define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 "\
168  "FORCE INDEX (idx_hash_type_uid) "\
169  "WHERE hash=? AND "\
170  "uid >= ? AND "\
171  "(rvalue >= ? OR 0 = ?) "\
172  "ORDER BY uid LIMIT 1"
174 
175 #define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 "\
176  "FORCE INDEX (idx_hash_type_uid) "\
177  "WHERE hash = ? AND "\
178  "type = ? AND "\
179  "uid >= ? AND "\
180  "(rvalue >= ? OR 0 = ?) "\
181  "ORDER BY uid LIMIT 1"
183 
184 #define UPDATE_ENTRY "UPDATE gn090 SET "\
185  "prio = prio + ?, "\
186  "repl = repl + ?, "\
187  "expire = GREATEST(expire, ?) "\
188  "WHERE hash = ? AND vhash = ?"
190 
191 #define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"
193 
194 #define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090"
196 
197 #define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 "\
198  "FORCE INDEX (idx_anonLevel_type_rvalue) "\
199  "WHERE anonLevel=0 AND "\
200  "type=? AND "\
201  "uid >= ? "\
202  "ORDER BY uid LIMIT 1"
204 
205 #define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 "\
206  "FORCE INDEX (idx_expire) "\
207  "WHERE expire < ? "\
208  "ORDER BY expire ASC LIMIT 1"
210 
211 #define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 "\
212  "FORCE INDEX (idx_prio) "\
213  "ORDER BY prio ASC LIMIT 1"
215 
216 #define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 "\
217  "FORCE INDEX (idx_repl_rvalue) "\
218  "WHERE repl=? AND "\
219  " (rvalue>=? OR"\
220  " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) "\
221  "ORDER BY rvalue ASC "\
222  "LIMIT 1"
224 
225 #define SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090"
227 
228 #define GET_ALL_KEYS "SELECT hash from gn090"
230 
231 };
232 
233 #define MAX_PARAM 16
234 
242 static int
244  unsigned long long uid)
245 {
246  int ret;
247  uint64_t uid64 = (uint64_t) uid;
248  struct GNUNET_MY_QueryParam params_delete[] = {
251  };
252 
254  "Deleting value %llu from gn090 table\n",
255  uid);
256  ret = GNUNET_MY_exec_prepared (plugin->mc,
257  plugin->delete_entry_by_uid,
258  params_delete);
259  if (ret >= 0)
260  {
261  return GNUNET_OK;
262  }
264  "Deleting value %llu from gn090 table failed\n",
265  (unsigned long long) uid);
266  return ret;
267 }
268 
269 
277 static void
279  unsigned long long *estimate)
280 {
281  struct Plugin *plugin = cls;
282  uint64_t total;
283  int ret;
284  struct GNUNET_MY_QueryParam params_get[] = {
286  };
287  struct GNUNET_MY_ResultSpec results_get[] = {
290  };
291 
292  ret = GNUNET_MY_exec_prepared (plugin->mc,
293  plugin->get_size,
294  params_get);
295  *estimate = 0;
296  total = UINT64_MAX;
297  if ( (GNUNET_OK == ret) &&
298  (GNUNET_OK ==
300  results_get)) )
301  {
302  *estimate = (unsigned long long) total;
304  "Size estimate for MySQL payload is %lld\n",
305  (long long) total);
306  GNUNET_assert (UINT64_MAX != total);
309  NULL));
310  }
311 }
312 
313 
330 static void
331 mysql_plugin_put (void *cls,
332  const struct GNUNET_HashCode *key,
333  bool absent,
334  uint32_t size,
335  const void *data,
336  enum GNUNET_BLOCK_Type type,
337  uint32_t priority,
338  uint32_t anonymity,
339  uint32_t replication,
341  PluginPutCont cont,
342  void *cont_cls)
343 {
344  struct Plugin *plugin = cls;
345  uint64_t lexpiration = expiration.abs_value_us;
346  struct GNUNET_HashCode vhash;
347 
348  GNUNET_CRYPTO_hash (data,
349  size,
350  &vhash);
351  if (!absent)
352  {
353  struct GNUNET_MY_QueryParam params_update[] = {
354  GNUNET_MY_query_param_uint32 (&priority),
355  GNUNET_MY_query_param_uint32 (&replication),
356  GNUNET_MY_query_param_uint64 (&lexpiration),
360  };
361 
362  if (GNUNET_OK !=
363  GNUNET_MY_exec_prepared (plugin->mc,
364  plugin->update_entry,
365  params_update))
366  {
367  cont (cont_cls,
368  key,
369  size,
371  _("MySQL statement run failure"));
372  return;
373  }
374 
375  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->update_entry);
376  my_ulonglong rows = mysql_stmt_affected_rows (stmt);
377 
380  NULL));
381  if (0 != rows)
382  {
383  cont (cont_cls,
384  key,
385  size,
386  GNUNET_NO,
387  NULL);
388  return;
389  }
390  }
391 
393  UINT64_MAX);
394  struct GNUNET_MY_QueryParam params_insert[] = {
395  GNUNET_MY_query_param_uint32 (&replication),
397  GNUNET_MY_query_param_uint32 (&priority),
398  GNUNET_MY_query_param_uint32 (&anonymity),
399  GNUNET_MY_query_param_uint64 (&lexpiration),
400  GNUNET_MY_query_param_uint64 (&lrvalue),
405  };
406 
407  if (size > MAX_DATUM_SIZE)
408  {
409  GNUNET_break (0);
410  cont (cont_cls, key, size, GNUNET_SYSERR, _("Data too large"));
411  return;
412  }
413 
414  if (GNUNET_OK !=
415  GNUNET_MY_exec_prepared (plugin->mc,
416  plugin->insert_entry,
417  params_insert))
418  {
419  cont (cont_cls,
420  key,
421  size,
423  _("MySQL statement run failure"));
424  return;
425  }
427  "Inserted value `%s' with size %u into gn090 table\n",
428  GNUNET_h2s (key),
429  (unsigned int) size);
430  if (size > 0)
431  plugin->env->duc (plugin->env->cls,
432  size);
435  NULL));
436  cont (cont_cls,
437  key,
438  size,
439  GNUNET_OK,
440  NULL);
441 }
442 
443 
454 static void
456  struct GNUNET_MYSQL_StatementHandle *stmt,
458  void *proc_cls,
459  struct GNUNET_MY_QueryParam *params_select)
460 {
461  int ret;
462  uint32_t replication;
463  uint32_t type;
464  uint32_t priority;
465  uint32_t anonymity;
466  uint64_t uid;
467  size_t value_size;
468  void *value;
469  struct GNUNET_HashCode key;
470  struct GNUNET_TIME_Absolute expiration;
471  struct GNUNET_MY_ResultSpec results_select[] = {
472  GNUNET_MY_result_spec_uint32 (&replication),
474  GNUNET_MY_result_spec_uint32 (&priority),
475  GNUNET_MY_result_spec_uint32 (&anonymity),
478  GNUNET_MY_result_spec_variable_size (&value, &value_size),
481  };
482 
483  ret = GNUNET_MY_exec_prepared (plugin->mc,
484  stmt,
485  params_select);
486  if (GNUNET_OK != ret)
487  {
488  proc (proc_cls,
489  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
490  return;
491  }
492 
493  ret = GNUNET_MY_extract_result (stmt,
494  results_select);
495  if (GNUNET_OK != ret)
496  {
497  proc (proc_cls,
498  NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
499  return;
500  }
501 
503  "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
504  (unsigned int) value_size,
505  GNUNET_h2s (&key),
506  (unsigned int) priority,
507  (unsigned int) anonymity,
509  GNUNET_assert (value_size < MAX_DATUM_SIZE);
512  NULL));
513  ret = proc (proc_cls,
514  &key,
515  value_size,
516  value,
517  type,
518  priority,
519  anonymity,
520  replication,
521  expiration,
522  uid);
523  GNUNET_MY_cleanup_result (results_select);
524  if (GNUNET_NO == ret)
525  {
526  do_delete_entry (plugin, uid);
527  if (0 != value_size)
528  plugin->env->duc (plugin->env->cls,
529  - value_size);
530  }
531 }
532 
533 
547 static void
549  uint64_t next_uid,
550  bool random,
551  const struct GNUNET_HashCode *key,
552  enum GNUNET_BLOCK_Type type,
554  void *proc_cls)
555 {
556  struct Plugin *plugin = cls;
557  uint64_t rvalue;
558 
559  if (random)
560  {
562  UINT64_MAX);
563  next_uid = 0;
564  }
565  else
566  rvalue = 0;
567 
568  if (NULL == key)
569  {
570  struct GNUNET_MY_QueryParam params_select[] = {
571  GNUNET_MY_query_param_uint64 (&next_uid),
575  };
576 
577  execute_select (plugin,
578  plugin->select_entry,
579  proc,
580  proc_cls,
581  params_select);
582  }
583  else if (type != GNUNET_BLOCK_TYPE_ANY)
584  {
585  struct GNUNET_MY_QueryParam params_select[] = {
588  GNUNET_MY_query_param_uint64 (&next_uid),
592  };
593 
594  execute_select (plugin,
596  proc,
597  proc_cls,
598  params_select);
599  }
600  else
601  {
602  struct GNUNET_MY_QueryParam params_select[] = {
604  GNUNET_MY_query_param_uint64 (&next_uid),
608  };
609 
610  execute_select (plugin,
611  plugin->select_entry_by_hash,
612  proc,
613  proc_cls,
614  params_select);
615  }
616 }
617 
618 
630 static void
632  uint64_t next_uid,
633  enum GNUNET_BLOCK_Type type,
635  void *proc_cls)
636 {
637  struct Plugin *plugin = cls;
638  uint32_t typei = (uint32_t) type;
639 
640  struct GNUNET_MY_QueryParam params_zero_iter[] = {
642  GNUNET_MY_query_param_uint64 (&next_uid),
644  };
645 
646  execute_select (plugin,
647  plugin->zero_iter,
648  proc,
649  proc_cls,
650  params_zero_iter);
651 }
652 
653 
657 struct ReplCtx
658 {
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 !=
785  GNUNET_MY_exec_prepared (plugin->mc,
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 !=
795  results_get))
796  {
797  proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
798  return;
799  }
802  NULL));
804  UINT64_MAX);
805 
806  execute_select (plugin,
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 !=
843  GNUNET_MY_exec_prepared (plugin->mc,
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 {
907 
911  struct Plugin *plugin;
912 
917 
921  void *proc_cls;
922 };
923 
924 
925 
946 static int
947 expi_proc (void *cls,
948  const struct GNUNET_HashCode *key,
949  uint32_t size,
950  const void *data,
951  enum GNUNET_BLOCK_Type type,
952  uint32_t priority,
953  uint32_t anonymity,
954  uint32_t replication,
956  uint64_t uid)
957 {
958  struct ExpiCtx *rc = cls;
959  struct Plugin *plugin = rc->plugin;
960  struct GNUNET_MY_QueryParam params_select[] = {
962  };
963 
964  if (NULL == key)
965  {
966  execute_select (plugin,
967  plugin->select_priority,
968  rc->proc,
969  rc->proc_cls,
970  params_select);
971  return GNUNET_SYSERR;
972  }
973  return rc->proc (rc->proc_cls,
974  key,
975  size,
976  data,
977  type,
978  priority,
979  anonymity,
980  replication,
981  expiration,
982  uid);
983 }
984 
985 
994 static void
997  void *proc_cls)
998 {
999  struct Plugin *plugin = cls;
1000  struct GNUNET_TIME_Absolute now;
1001  struct GNUNET_MY_QueryParam params_select[] = {
1004  };
1005  struct ExpiCtx rc;
1006 
1007  rc.plugin = plugin;
1008  rc.proc = proc;
1009  rc.proc_cls = proc_cls;
1010  now = GNUNET_TIME_absolute_get ();
1011  execute_select (plugin,
1012  plugin->select_expiration,
1013  expi_proc,
1014  &rc,
1015  params_select);
1016 }
1017 
1018 
1024 static void
1026 {
1027  struct Plugin *plugin = cls;
1028 
1029  if (GNUNET_OK !=
1030  GNUNET_MYSQL_statement_run (plugin->mc,
1031  "DROP TABLE gn090"))
1032  return; /* error */
1033  plugin->env->duc (plugin->env->cls, 0);
1034 }
1035 
1036 
1047 static void
1049  const struct GNUNET_HashCode *key,
1050  uint32_t size,
1051  const void *data,
1052  PluginRemoveCont cont,
1053  void *cont_cls)
1054 {
1055  struct Plugin *plugin = cls;
1056  struct GNUNET_MY_QueryParam params_delete[] = {
1058  GNUNET_MY_query_param_fixed_size (data, size),
1060  };
1061 
1062  if (GNUNET_OK !=
1063  GNUNET_MY_exec_prepared (plugin->mc,
1065  params_delete))
1066  {
1068  "Removing key `%s' from gn090 table failed\n",
1069  GNUNET_h2s (key));
1070  cont (cont_cls,
1071  key,
1072  size,
1073  GNUNET_SYSERR,
1074  _("MySQL statement run failure"));
1075  return;
1076  }
1077 
1078  MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->delete_entry_by_hash_value);
1079  my_ulonglong rows = mysql_stmt_affected_rows (stmt);
1080 
1081  if (0 == rows)
1082  {
1083  cont (cont_cls,
1084  key,
1085  size,
1086  GNUNET_NO,
1087  NULL);
1088  return;
1089  }
1090  plugin->env->duc (plugin->env->cls,
1091  -size);
1092  cont (cont_cls,
1093  key,
1094  size,
1095  GNUNET_OK,
1096  NULL);
1097 }
1098 
1099 
1106 void *
1108 {
1111  struct Plugin *plugin;
1112 
1113  plugin = GNUNET_new (struct Plugin);
1114  plugin->env = env;
1115  plugin->mc = GNUNET_MYSQL_context_create (env->cfg,
1116  "datastore-mysql");
1117  if (NULL == plugin->mc)
1118  {
1119  GNUNET_free (plugin);
1120  return NULL;
1121  }
1122 #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a) )
1123 #define PINIT(a,b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, 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 ''," " uid BIGINT NOT NULL AUTO_INCREMENT,"
1135  " PRIMARY KEY (uid),"
1136  " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1137  " INDEX idx_prio (prio),"
1138  " INDEX idx_repl_rvalue (repl,rvalue),"
1139  " INDEX idx_expire (expire),"
1140  " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1141  ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") ||
1142  PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1145  PINIT (plugin->select_entry, SELECT_ENTRY) ||
1149  PINIT (plugin->get_size, SELECT_SIZE) ||
1150  PINIT (plugin->update_entry, UPDATE_ENTRY) ||
1151  PINIT (plugin->dec_repl, DEC_REPL) ||
1155  PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
1156  PINIT (plugin->get_all_keys, GET_ALL_KEYS) ||
1158  false)
1159  {
1160  GNUNET_MYSQL_context_destroy (plugin->mc);
1161  GNUNET_free (plugin);
1162  return NULL;
1163  }
1164 #undef PINIT
1165 #undef MRUNS
1166 
1168  api->cls = plugin;
1170  api->put = &mysql_plugin_put;
1171  api->get_key = &mysql_plugin_get_key;
1176  api->drop = &mysql_plugin_drop;
1179  _("Mysql database running\n"));
1180  return api;
1181 }
1182 
1183 
1190 void *
1192 {
1194  struct Plugin *plugin = api->cls;
1195 
1196  GNUNET_MYSQL_context_destroy (plugin->mc);
1197  GNUNET_free (plugin);
1198  GNUNET_free (api);
1199  return NULL;
1200 }
1201 
1202 /* end of plugin_datastore_mysql.c */
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 GNUNET_MY_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
int(* 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.
#define PINIT(a, b)
void * proc_cls
Closure for proc.
PluginGetType get_zero_anonymity
Get datum (of the specified type) with anonymity level zero.
static char * expiration
Credential TTL.
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.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define MRUNS(a)
void * proc_cls
Closure for proc.
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:331
Any type of block, used as a wildcard when searching.
#define SELECT_IT_EXPIRATION
#define UPDATE_ENTRY
#define GNUNET_MY_result_spec_end
End of result speceter specification.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
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.
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_hash_value
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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.
void * libgnunet_plugin_datastore_mysql_done(void *cls)
Exit point from the plugin.
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_uid
PluginRemoveKey remove_key
Function to remove an item from the database.
char * key
TLS key.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
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
PluginEstimateSize estimate_size
Calculate the current on-disk size of the SQ store.
#define SELECT_IT_PRIORITY
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:81
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:78
struct GNUNET_MYSQL_StatementHandle * zero_iter
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle for a prepared statement.
Definition: mysql.c:114
void * libgnunet_plugin_datastore_mysql_init(void *cls)
Entry point for the plugin.
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 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.
void(* PluginPutCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Put continuation.
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 DELETE_ENTRY_BY_UID
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
#define SELECT_SIZE
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
PluginGetRandom get_replication
Function to get a random item with high replication score from the database, lowering the item&#39;s repl...
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().
PluginDrop drop
Delete the database.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
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
static char * value
Value of the record to add/remove.
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
void(* PluginKeyProcessor)(void *cls, const struct GNUNET_HashCode *key, unsigned int count)
An processor over a set of keys stored in the datastore.
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:379
#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.
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
Context for expi_proc() function.
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
Definition: mysql.c:489
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:352
struct GNUNET_MYSQL_StatementHandle * dec_repl
#define SELECT_ENTRY_BY_HASH_AND_TYPE
PluginDatumProcessor proc
Function to call for the result (or the NULL).
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 ...
A 512-bit hashcode.
#define GET_ALL_KEYS
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
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 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
#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:79
Context for repl_proc() function.
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint32(uint32_t *u32)
uint32_t expected
Mysql context.
Definition: mysql.c:76
void(* PluginRemoveCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Remove continuation.
void * cls
Closure to use for all of the following callbacks (except "next_request").
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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
unsigned long long size
Size of all values we&#39;re storing.
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:426
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 Plugin * plugin
Plugin handle.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
#define GNUNET_log(kind,...)
#define MAX_DATUM_SIZE
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.
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.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void mysql_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
static unsigned int anonymity
#define SELECT_IT_NON_ANONYMOUS
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:792
#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
uint32_t data
The data value.
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
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size(void **dst, size_t *ptr_size)
Variable-size result expected.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define GNUNET_free(ptr)
Wrapper around free.
static int do_delete_entry(struct Plugin *plugin, unsigned long long uid)
Delete an entry from the gn090 table.
#define SELECT_ENTRY
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...