aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-07-27 08:11:05 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-07-27 08:11:05 +0000
commitb8ef328458e45ecb6de5d7364670379265a137d8 (patch)
tree294a9ba6444b9b47ff7deea8b23483c1c8468758 /src/psycstore
parent429a9283e567fb98c76c0029f16a369fa0b7a8ab (diff)
downloadgnunet-b8ef328458e45ecb6de5d7364670379265a137d8.tar.gz
gnunet-b8ef328458e45ecb6de5d7364670379265a137d8.zip
start to fix fragment_get function
Diffstat (limited to 'src/psycstore')
-rw-r--r--src/psycstore/plugin_psycstore_mysql.c151
1 files changed, 59 insertions, 92 deletions
diff --git a/src/psycstore/plugin_psycstore_mysql.c b/src/psycstore/plugin_psycstore_mysql.c
index 6e6b9ac13..51708c4a6 100644
--- a/src/psycstore/plugin_psycstore_mysql.c
+++ b/src/psycstore/plugin_psycstore_mysql.c
@@ -309,7 +309,7 @@ database_setup (struct Plugin *plugin)
309 309
310 GNUNET_MYSQL_statement_run (plugin->mc, 310 GNUNET_MYSQL_statement_run (plugin->mc,
311 "CREATE TABLE IF NOT EXISTS channels (\n" 311 "CREATE TABLE IF NOT EXISTS channels (\n"
312 " id INT,\n" 312 " id INT AUTO_INCREMENT,\n"
313 " pub_key BLOB,\n" 313 " pub_key BLOB,\n"
314 " max_state_message_id INT,\n" 314 " max_state_message_id INT,\n"
315 " state_hash_message_id INT,\n" 315 " state_hash_message_id INT,\n"
@@ -319,7 +319,7 @@ database_setup (struct Plugin *plugin)
319 319
320 GNUNET_MYSQL_statement_run (plugin->mc, 320 GNUNET_MYSQL_statement_run (plugin->mc,
321 "CREATE TABLE IF NOT EXISTS slaves (\n" 321 "CREATE TABLE IF NOT EXISTS slaves (\n"
322 " id INT,\n" 322 " id INT AUTO_INCREMENT,\n"
323 " pub_key BLOB,\n" 323 " pub_key BLOB,\n"
324 " PRIMARY KEY(id),\n" 324 " PRIMARY KEY(id),\n"
325 " UNIQUE KEY(pub_key(5))\n" 325 " UNIQUE KEY(pub_key(5))\n"
@@ -886,11 +886,6 @@ membership_test (void *cls,
886 886
887 int ret = GNUNET_SYSERR; 887 int ret = GNUNET_SYSERR;
888 888
889 if (NULL == plugin->select_membership)
890 {
891 fprintf(stderr, "Erreur plugin->select_membership\n");
892 }
893
894 struct GNUNET_MY_QueryParam params_select[] = { 889 struct GNUNET_MY_QueryParam params_select[] = {
895 GNUNET_MY_query_param_auto_from_type (channel_key), 890 GNUNET_MY_query_param_auto_from_type (channel_key),
896 GNUNET_MY_query_param_auto_from_type (slave_key), 891 GNUNET_MY_query_param_auto_from_type (slave_key),
@@ -898,7 +893,7 @@ membership_test (void *cls,
898 GNUNET_MY_query_param_end 893 GNUNET_MY_query_param_end
899 }; 894 };
900 895
901 if (GNUNET_MY_exec_prepared (plugin->mc, 896 if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc,
902 stmt, 897 stmt,
903 params_select)) 898 params_select))
904 { 899 {
@@ -918,8 +913,9 @@ membership_test (void *cls,
918 case GNUNET_NO: 913 case GNUNET_NO:
919 ret = GNUNET_NO; 914 ret = GNUNET_NO;
920 break; 915 break;
921 case GNUNET_YES: 916 case GNUNET_OK:
922 ret = GNUNET_YES; 917 ret = GNUNET_YES;
918 break;
923 default: 919 default:
924 LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 920 LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
925 "mysql extract_result", stmt); 921 "mysql extract_result", stmt);
@@ -989,7 +985,7 @@ fragment_store (void *cls,
989 GNUNET_MY_query_param_end 985 GNUNET_MY_query_param_end
990 }; 986 };
991 987
992 if (GNUNET_MY_exec_prepared (plugin->mc, 988 if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc,
993 stmt, 989 stmt,
994 params_insert)) 990 params_insert))
995 { 991 {
@@ -1066,7 +1062,8 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt,
1066 uint64_t group_generation; 1062 uint64_t group_generation;
1067 void *buf; 1063 void *buf;
1068 size_t buf_size; 1064 size_t buf_size;
1069 int ret; 1065 int ret = GNUNET_SYSERR;
1066 int sql_ret;
1070 uint64_t flags; 1067 uint64_t flags;
1071 struct GNUNET_MULTICAST_MessageHeader msg; 1068 struct GNUNET_MULTICAST_MessageHeader msg;
1072 struct GNUNET_MULTICAST_MessageHeader *mp; 1069 struct GNUNET_MULTICAST_MessageHeader *mp;
@@ -1079,6 +1076,7 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt,
1079 size_t purpose_size; 1076 size_t purpose_size;
1080 uint32_t msg_flags; 1077 uint32_t msg_flags;
1081 1078
1079
1082 struct GNUNET_MY_ResultSpec results[] = { 1080 struct GNUNET_MY_ResultSpec results[] = {
1083 GNUNET_MY_result_spec_uint32 (&hop_counter), 1081 GNUNET_MY_result_spec_uint32 (&hop_counter),
1084 GNUNET_MY_result_spec_variable_size (&signature, &signature_size), 1082 GNUNET_MY_result_spec_variable_size (&signature, &signature_size),
@@ -1094,41 +1092,48 @@ fragment_row (struct GNUNET_MYSQL_StatementHandle *stmt,
1094 GNUNET_MY_result_spec_end 1092 GNUNET_MY_result_spec_end
1095 }; 1093 };
1096 1094
1097 if (GNUNET_OK != 1095 sql_ret = GNUNET_MY_extract_result (stmt,
1098 GNUNET_MY_extract_result (stmt, 1096 results);
1099 results)) 1097 switch (sql_ret)
1100 { 1098 {
1101 LOG_MYSQL(plugin, 1099 case GNUNET_NO:
1102 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1100 if (ret != GNUNET_OK)
1103 "mysql extract_result", 1101 ret = GNUNET_NO;
1104 stmt); 1102 break;
1105 return GNUNET_SYSERR; 1103 case GNUNET_OK:
1104
1105 mp = GNUNET_malloc (sizeof (msg) + buf_size);
1106 *mp = msg;
1107 mp->hop_counter = hop_counter;
1108 GNUNET_memcpy (&mp->signature,
1109 signature,
1110 signature_size);
1111 GNUNET_memcpy (&mp->purpose,
1112 purpose,
1113 purpose_size);
1114 mp->fragment_id = GNUNET_htonll (fragment_id);
1115 mp->fragment_offset = GNUNET_htonllk (fragment_offset);
1116 mp->message_id = GNUNET_htonllk (message_id);
1117 mp->group_generation = GNUNET_htonllk (group_generation);
1118 mp->flags = msg_flags;
1119
1120 GNUNET_memcpy (&mp[1],
1121 buf,
1122 buf_size);
1123 ret = cb (cb_cls,
1124 mp,
1125 (enum GNUNET_PSYCSTORE_MessageFlags) flags);
1126 if (ret != GNUNET_YES)
1127 sql_ret = GNUNET_NO;
1128 GNUNET_free (mp);
1129 break;
1130 default:
1131 LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1132 "mysql extract_result", stmt);
1106 } 1133 }
1107 1134
1108 mp = GNUNET_malloc (sizeof (msg) + buf_size); 1135// GNUNET_MY_cleanup_result (results);
1109 *mp = msg; 1136
1110
1111 mp->hop_counter = hop_counter;
1112 GNUNET_memcpy (&mp->signature,
1113 signature,
1114 signature_size);
1115 GNUNET_memcpy (&mp->purpose,
1116 purpose,
1117 purpose_size);
1118 mp->fragment_id = GNUNET_htonll (fragment_id);
1119 mp->fragment_offset = GNUNET_htonllk (fragment_offset);
1120 mp->message_id = GNUNET_htonllk (message_id);
1121 mp->group_generation = GNUNET_htonllk (group_generation);
1122 mp->flags = msg_flags;
1123
1124 GNUNET_memcpy (&mp[1],
1125 buf,
1126 buf_size);
1127 ret = cb (cb_cls,
1128 mp,
1129 (enum GNUNET_PSYCSTORE_MessageFlags) flags);
1130 GNUNET_free (mp);
1131 GNUNET_MY_cleanup_result (results);
1132 return ret; 1137 return ret;
1133} 1138}
1134 1139
@@ -1142,60 +1147,22 @@ fragment_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stm
1142 int ret = GNUNET_SYSERR; 1147 int ret = GNUNET_SYSERR;
1143 int sql_ret; 1148 int sql_ret;
1144 1149
1145 uint32_t hop_counter = 0;
1146 void *signature = NULL;
1147 void *purpose = NULL;
1148 uint64_t fragment_id = 0 ;
1149 uint64_t fragment_offset = 0;
1150 uint64_t message_id = 0;
1151 uint64_t group_generation = 0;
1152 uint32_t flags = 0;
1153 uint64_t data8;
1154
1155 struct GNUNET_MULTICAST_MessageHeader *msg 1150 struct GNUNET_MULTICAST_MessageHeader *msg
1156 = GNUNET_malloc (sizeof (*msg) + 0); 1151 = GNUNET_malloc (sizeof (*msg) + 0);
1157 1152
1158 struct GNUNET_MY_ResultSpec results[] = { 1153 sql_ret = GNUNET_MY_exec_prepared (plugin->mc,
1159 GNUNET_MY_result_spec_uint32 (&hop_counter), 1154 stmt,
1160 GNUNET_MY_result_spec_auto_from_type (&signature), 1155 params);
1161 GNUNET_MY_result_spec_auto_from_type (&purpose), 1156 switch(sql_ret)
1162 GNUNET_MY_result_spec_uint64 (&fragment_id),
1163 GNUNET_MY_result_spec_uint64 (&fragment_offset),
1164 GNUNET_MY_result_spec_uint64 (&message_id),
1165 GNUNET_MY_result_spec_uint64 (&group_generation),
1166 GNUNET_MY_result_spec_uint32 (&flags),
1167 GNUNET_MY_result_spec_uint64 (&data8),
1168 GNUNET_MY_result_spec_auto_from_type (&msg[1]),
1169 GNUNET_MY_result_spec_end
1170 };
1171
1172 do
1173 { 1157 {
1174 GNUNET_MY_exec_prepared (plugin->mc, 1158 case GNUNET_YES:
1175 stmt, 1159 ret = fragment_row (stmt, cb, cb_cls);
1176 params); 1160 break;
1177 1161 default:
1178 sql_ret = GNUNET_MY_extract_result (stmt, 1162 LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1179 results); 1163 "mysql exec_prepared", stmt);
1180 switch (sql_ret)
1181 {
1182 case GNUNET_NO:
1183 if (ret != GNUNET_OK)
1184 ret = GNUNET_NO;
1185 break;
1186 case GNUNET_YES:
1187 ret = fragment_row (stmt, cb, cb_cls);
1188 (*returned_fragments)++;
1189 if (ret != GNUNET_YES)
1190 sql_ret = GNUNET_NO;
1191 break;
1192 default:
1193 LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1194 "mysql extract_result", stmt);
1195 }
1196 } 1164 }
1197 while (sql_ret == GNUNET_YES); 1165
1198
1199 return ret; 1166 return ret;
1200} 1167}
1201 1168