aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2017-03-13 20:35:18 +0100
committerxrs <xrs@mail36.net>2017-03-13 20:35:18 +0100
commit9f68c9e7d383061abbc81d1590abf25cde2305fe (patch)
tree971a0188e84878f43c2074def4ac3531c73acba6
parent501c1f7794be6e8a2ea15200dbdadd4c066edb89 (diff)
parent8691934f57063bfa5032f4e34836ecbcb3d761e9 (diff)
downloadgnunet-9f68c9e7d383061abbc81d1590abf25cde2305fe.tar.gz
gnunet-9f68c9e7d383061abbc81d1590abf25cde2305fe.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Conflicts: src/multicast/test_multicast_2peers.c
-rw-r--r--src/datacache/plugin_datacache_sqlite.c3
-rw-r--r--src/gns/gnunet-gns-proxy.c14
-rw-r--r--src/include/gnunet_multicast_service.h4
-rw-r--r--src/multicast/Makefile.am6
-rw-r--r--src/multicast/test_multicast_2peers.c66
-rw-r--r--src/multicast/test_multicast_multipeer.c56
-rw-r--r--src/namestore/plugin_namestore_sqlite.c394
-rw-r--r--src/sq/test_sq.c20
-rw-r--r--src/util/mq.c24
-rw-r--r--src/util/test_common_allocation.c73
10 files changed, 392 insertions, 268 deletions
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 5cc48b26c..dd79d0125 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -758,7 +758,8 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
758 LOG_SQLITE (plugin->dbh, 758 LOG_SQLITE (plugin->dbh,
759 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 759 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
760 "sq_prepare"); 760 "sq_prepare");
761 (void) sqlite3_close (plugin->dbh); 761 GNUNET_break (SQLITE_OK ==
762 sqlite3_close (plugin->dbh));
762 GNUNET_free (plugin); 763 GNUNET_free (plugin);
763 return NULL; 764 return NULL;
764 } 765 }
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 6eb87a95e..c336848ce 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -865,7 +865,8 @@ check_ssl_certificate (struct Socks5Request *s5r)
865 const char *name; 865 const char *name;
866 866
867 s5r->ssl_checked = GNUNET_YES; 867 s5r->ssl_checked = GNUNET_YES;
868 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "XXXXXX\n"); 868 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
869 "Checking SSL certificate\n");
869 if (CURLE_OK != 870 if (CURLE_OK !=
870 curl_easy_getinfo (s5r->curl, 871 curl_easy_getinfo (s5r->curl,
871 CURLINFO_TLS_SESSION, 872 CURLINFO_TLS_SESSION,
@@ -1882,19 +1883,22 @@ mhd_connection_cb (void *cls,
1882 { 1883 {
1883 if (GNUNET_NETWORK_get_fd (s5r->sock) == sock) 1884 if (GNUNET_NETWORK_get_fd (s5r->sock) == sock)
1884 { 1885 {
1885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Context set...\n"); 1886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1887 "Context set...\n");
1888 s5r->ssl_checked = GNUNET_NO;
1886 *con_cls = s5r; 1889 *con_cls = s5r;
1887 break; 1890 break;
1888 } 1891 }
1889 } 1892 }
1890 s5r->ssl_checked = GNUNET_NO;
1891 break; 1893 break;
1892 case MHD_CONNECTION_NOTIFY_CLOSED: 1894 case MHD_CONNECTION_NOTIFY_CLOSED:
1893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection closed... cleaning up\n"); 1895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1896 "Connection closed... cleaning up\n");
1894 s5r = *con_cls; 1897 s5r = *con_cls;
1895 if (NULL == s5r) 1898 if (NULL == s5r)
1896 { 1899 {
1897 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection stale!\n"); 1900 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1901 "Connection stale!\n");
1898 return; 1902 return;
1899 } 1903 }
1900 cleanup_s5r (s5r); 1904 cleanup_s5r (s5r);
diff --git a/src/include/gnunet_multicast_service.h b/src/include/gnunet_multicast_service.h
index 3829a7040..5645207dd 100644
--- a/src/include/gnunet_multicast_service.h
+++ b/src/include/gnunet_multicast_service.h
@@ -617,6 +617,7 @@ GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
617 * data. If 0 is returned in @a data_size the transmission is paused, 617 * data. If 0 is returned in @a data_size the transmission is paused,
618 * and can be resumed with GNUNET_MULTICAST_origin_to_all_resume(). 618 * and can be resumed with GNUNET_MULTICAST_origin_to_all_resume().
619 * #GNUNET_YES if this completes the transmission (all data supplied) 619 * #GNUNET_YES if this completes the transmission (all data supplied)
620 * @deprecated should move to MQ-style API!
620 */ 621 */
621typedef int 622typedef int
622(*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls, 623(*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls,
@@ -647,6 +648,7 @@ struct GNUNET_MULTICAST_OriginTransmitHandle;
647 * Closure for @a notify. 648 * Closure for @a notify.
648 * 649 *
649 * @return NULL on error (i.e. request already pending). 650 * @return NULL on error (i.e. request already pending).
651 * @deprecated should move to MQ-style API!
650 */ 652 */
651struct GNUNET_MULTICAST_OriginTransmitHandle * 653struct GNUNET_MULTICAST_OriginTransmitHandle *
652GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin, 654GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
@@ -854,6 +856,7 @@ GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member,
854 * data. If 0 is returned in @a data_size the transmission is paused, 856 * data. If 0 is returned in @a data_size the transmission is paused,
855 * and can be resumed with GNUNET_MULTICAST_member_to_origin_resume(). 857 * and can be resumed with GNUNET_MULTICAST_member_to_origin_resume().
856 * #GNUNET_YES if this completes the transmission (all data supplied) 858 * #GNUNET_YES if this completes the transmission (all data supplied)
859 * @deprecated should move to MQ-style API!
857 */ 860 */
858typedef int 861typedef int
859(*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls, 862(*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls,
@@ -880,6 +883,7 @@ struct GNUNET_MULTICAST_MemberTransmitHandle;
880 * Closure for @a notify. 883 * Closure for @a notify.
881 * 884 *
882 * @return Handle to cancel request, NULL on error (i.e. request already pending). 885 * @return Handle to cancel request, NULL on error (i.e. request already pending).
886 * @deprecated should move to MQ-style API!
883 */ 887 */
884struct GNUNET_MULTICAST_MemberTransmitHandle * 888struct GNUNET_MULTICAST_MemberTransmitHandle *
885GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member, 889GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member,
diff --git a/src/multicast/Makefile.am b/src/multicast/Makefile.am
index 2a00a7a02..8a754d3db 100644
--- a/src/multicast/Makefile.am
+++ b/src/multicast/Makefile.am
@@ -51,9 +51,9 @@ gnunet_service_multicast_LDADD = \
51 $(GN_LIBINTL) 51 $(GN_LIBINTL)
52 52
53check_PROGRAMS = \ 53check_PROGRAMS = \
54 test_multicast \ 54 test_multicast_multipeer
55 test_multicast_2peers 55# test_multicast
56# test_multicast_multipeer 56# test_multicast_2peers
57 57
58if ENABLE_TEST_RUN 58if ENABLE_TEST_RUN
59AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@}; export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; unset XDG_DATA_HOME; unset XDG_CONFIG_HOME; 59AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@}; export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; unset XDG_DATA_HOME; unset XDG_CONFIG_HOME;
diff --git a/src/multicast/test_multicast_2peers.c b/src/multicast/test_multicast_2peers.c
index 9d1f42063..8ce4d585f 100644
--- a/src/multicast/test_multicast_2peers.c
+++ b/src/multicast/test_multicast_2peers.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file multicast/test_multicast_2peers.c 22 * @file multicast/test_multicast_2peers.c
23 * @brief Tests for the Multicast API with two peers doing the ping 23 * @brief Tests for the Multicast API with two peers doing the ping
24 * pong test. 24 * pong test.
25 * @author xrs 25 * @author xrs
26 */ 26 */
@@ -118,16 +118,17 @@ member_join_request (void *cls,
118} 118}
119 119
120 120
121int notify (void *cls, 121static int
122 size_t *data_size, 122notify (void *cls,
123 void *data) 123 size_t *data_size,
124 void *data)
124{ 125{
125 126
126 char text[] = "ping"; 127 char text[] = "ping";
127 *data_size = strlen(text)+1; 128 *data_size = strlen(text)+1;
128 GNUNET_memcpy(data, text, *data_size); 129 GNUNET_memcpy(data, text, *data_size);
129 130
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 131 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
131 "Member sents message to origin: %s\n", text); 132 "Member sents message to origin: %s\n", text);
132 133
133 return GNUNET_YES; 134 return GNUNET_YES;
@@ -142,26 +143,30 @@ member_join_decision (void *cls,
142 const struct GNUNET_PeerIdentity *relays, 143 const struct GNUNET_PeerIdentity *relays,
143 const struct GNUNET_MessageHeader *join_msg) 144 const struct GNUNET_MessageHeader *join_msg)
144{ 145{
145 struct GNUNET_MULTICAST_MemberTransmitHandle *req; 146 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
146 147 "Member received a decision from origin: %s\n",
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 148 (GNUNET_YES == is_admitted)
148 "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); 149 ? "accepted"
149 150 : "rejected");
151
150 if (GNUNET_YES == is_admitted) 152 if (GNUNET_YES == is_admitted)
151 { 153 {
154 struct GNUNET_MULTICAST_MemberTransmitHandle *req;
155
156 // FIXME: move to MQ-style API!
152 req = GNUNET_MULTICAST_member_to_origin (member, 157 req = GNUNET_MULTICAST_member_to_origin (member,
153 0, 158 0,
154 notify, 159 &notify,
155 NULL); 160 NULL);
156 } 161 }
157} 162}
158 163
159 164
160static void 165static void
161member_message (void *cls, 166member_message (void *cls,
162 const struct GNUNET_MULTICAST_MessageHeader *msg) 167 const struct GNUNET_MULTICAST_MessageHeader *msg)
163{ 168{
164 if (0 != strncmp ("pong", (char *)&msg[1], 4)) 169 if (0 != strncmp ("pong", (char *)&msg[1], 4))
165 { 170 {
166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "member did not receive pong\n"); 171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "member did not receive pong\n");
167 result = GNUNET_SYSERR; 172 result = GNUNET_SYSERR;
@@ -187,19 +192,19 @@ origin_join_request (void *cls,
187 192
188 uint8_t data_size = ntohs (join_msg->size); 193 uint8_t data_size = ntohs (join_msg->size);
189 194
190 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 195 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
191 "origin got a join request...\n"); 196 "origin got a join request...\n");
192 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 197 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
193 "origin receives: '%s'\n", (char *)&join_msg[1]); 198 "origin receives: '%s'\n", (char *)&join_msg[1]);
194 199
195 char data[] = "Come in!"; 200 const char data[] = "Come in!";
196 data_size = strlen (data) + 1; 201 data_size = strlen (data) + 1;
197 join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); 202 join_resp = GNUNET_malloc (sizeof (join_resp) + data_size);
198 join_resp->size = htons (sizeof (join_resp) + data_size); 203 join_resp->size = htons (sizeof (join_resp) + data_size);
199 join_resp->type = htons (123); 204 join_resp->type = htons (123);
200 GNUNET_memcpy (&join_resp[1], data, data_size); 205 GNUNET_memcpy (&join_resp[1], data, data_size);
201 206
202 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 207 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
203 "origin sends: '%s'\n", data); 208 "origin sends: '%s'\n", data);
204 209
205 GNUNET_MULTICAST_join_decision (jh, 210 GNUNET_MULTICAST_join_decision (jh,
@@ -207,23 +212,23 @@ origin_join_request (void *cls,
207 0, 212 0,
208 NULL, 213 NULL,
209 join_resp); 214 join_resp);
210 215 GNUNET_free (join_resp);
211 result = GNUNET_OK; 216 result = GNUNET_OK;
212} 217}
213 218
214 219
215int 220int
216origin_notify (void *cls, 221origin_notify (void *cls,
217 size_t *data_size, 222 size_t *data_size,
218 void *data) 223 void *data)
219{ 224{
220 char text[] = "pong"; 225 char text[] = "pong";
221 *data_size = strlen(text)+1; 226 *data_size = strlen(text)+1;
222 memcpy(data, text, *data_size); 227 memcpy(data, text, *data_size);
223 228
224 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text); 229 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text);
225 230
226 return GNUNET_YES; 231 return GNUNET_YES;
227} 232}
228 233
229 234
@@ -232,8 +237,8 @@ origin_request (void *cls,
232 const struct GNUNET_MULTICAST_RequestHeader *req) 237 const struct GNUNET_MULTICAST_RequestHeader *req)
233{ 238{
234 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]); 239 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]);
235 240
236 if (0 != strncmp ("ping", (char *)&req[1], 4)) 241 if (0 != strncmp ("ping", (char *)&req[1], 4))
237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); 242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request");
238 243
239 GNUNET_MULTICAST_origin_to_all (origin, 244 GNUNET_MULTICAST_origin_to_all (origin,
@@ -246,7 +251,7 @@ origin_request (void *cls,
246 251
247static void 252static void
248origin_message (void *cls, 253origin_message (void *cls,
249 const struct GNUNET_MULTICAST_MessageHeader *msg) 254 const struct GNUNET_MULTICAST_MessageHeader *msg)
250{ 255{
251 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); 256 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n");
252} 257}
@@ -288,11 +293,12 @@ multicast_ca1 (void *cls,
288 const struct GNUNET_CONFIGURATION_Handle *cfg) 293 const struct GNUNET_CONFIGURATION_Handle *cfg)
289{ 294{
290 struct GNUNET_MessageHeader *join_msg; 295 struct GNUNET_MessageHeader *join_msg;
296 void *ret;
291 297
292 // Get members keys 298 // Get members keys
293 member_key = GNUNET_CRYPTO_ecdsa_key_create (); 299 member_key = GNUNET_CRYPTO_ecdsa_key_create ();
294 GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); 300 GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key);
295 301
296 char data[] = "Hi, can I enter?"; 302 char data[] = "Hi, can I enter?";
297 uint8_t data_size = strlen (data) + 1; 303 uint8_t data_size = strlen (data) + 1;
298 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); 304 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size);
@@ -303,7 +309,7 @@ multicast_ca1 (void *cls,
303 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 309 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
304 "Members tries to join multicast group\n"); 310 "Members tries to join multicast group\n");
305 311
306 return GNUNET_MULTICAST_member_join (cfg, 312 ret = GNUNET_MULTICAST_member_join (cfg,
307 &group_pub_key, 313 &group_pub_key,
308 member_key, 314 member_key,
309 peer_id[0], 315 peer_id[0],
@@ -316,6 +322,8 @@ multicast_ca1 (void *cls,
316 NULL, /* no test for member_replay_msg */ 322 NULL, /* no test for member_replay_msg */
317 member_message, 323 member_message,
318 NULL); 324 NULL);
325 GNUNET_free (join_msg);
326 return ret;
319} 327}
320 328
321 329
@@ -327,7 +335,7 @@ peer_information_cb (void *cls,
327{ 335{
328 int i = (int) (long) cls; 336 int i = (int) (long) cls;
329 337
330 if (NULL == pinfo) 338 if (NULL == pinfo)
331 { 339 {
332 result = GNUNET_SYSERR; 340 result = GNUNET_SYSERR;
333 GNUNET_SCHEDULER_shutdown (); 341 GNUNET_SCHEDULER_shutdown ();
@@ -341,7 +349,7 @@ peer_information_cb (void *cls,
341 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 349 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
342 "Create member peer\n"); 350 "Create member peer\n");
343 351
344 if (0 == i) 352 if (0 == i)
345 { 353 {
346 /* connect to multicast service of member */ 354 /* connect to multicast service of member */
347 op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ 355 op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index 266c87a16..c2078abf9 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -38,8 +38,9 @@
38struct multicast_peer 38struct multicast_peer
39{ 39{
40 int peer; /* peer number */ 40 int peer; /* peer number */
41 struct GNUNET_TESTBED_Operation *op; 41 struct GNUNET_TESTBED_Operation *op; /* not yet in use */
42 struct GNUNET_TESTBED_Operation *pi_op; 42 struct GNUNET_TESTBED_Operation *pi_op; /* not yet in use */
43 uint8_t test_ok;
43}; 44};
44 45
45static void service_connect (void *cls, 46static void service_connect (void *cls,
@@ -49,12 +50,14 @@ static void service_connect (void *cls,
49 50
50static struct multicast_peer **mc_peers; 51static struct multicast_peer **mc_peers;
51static struct GNUNET_TESTBED_Peer **peers; 52static struct GNUNET_TESTBED_Peer **peers;
53
54// FIXME: refactor
52static struct GNUNET_TESTBED_Operation *op[NUM_PEERS]; 55static struct GNUNET_TESTBED_Operation *op[NUM_PEERS];
53static struct GNUNET_TESTBED_Operation *pi_op[NUM_PEERS]; 56static struct GNUNET_TESTBED_Operation *pi_op[NUM_PEERS];
54static const struct GNUNET_PeerIdentity *peer_id[NUM_PEERS]; 57static const struct GNUNET_PeerIdentity *peer_id[NUM_PEERS];
55 58
56static struct GNUNET_MULTICAST_Origin *origin; 59static struct GNUNET_MULTICAST_Origin *origin;
57static struct GNUNET_MULTICAST_Member *member[NUM_PEERS]; 60static struct GNUNET_MULTICAST_Member *member[NUM_PEERS]; /* first element always empty */
58 61
59static struct GNUNET_SCHEDULER_Task *timeout_tid; 62static struct GNUNET_SCHEDULER_Task *timeout_tid;
60 63
@@ -70,7 +73,6 @@ static struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key[NUM_PEERS];
70 */ 73 */
71static int result; 74static int result;
72 75
73
74/** 76/**
75 * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.). 77 * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.).
76 * Cleans up. 78 * Cleans up.
@@ -132,6 +134,7 @@ member_join_request (void *cls,
132 134
133} 135}
134 136
137
135static int 138static int
136notify (void *cls, 139notify (void *cls,
137 size_t *data_size, 140 size_t *data_size,
@@ -174,6 +177,7 @@ member_join_decision (void *cls,
174 } 177 }
175} 178}
176 179
180
177static void 181static void
178member_replay_frag () 182member_replay_frag ()
179{ 183{
@@ -181,6 +185,7 @@ member_replay_frag ()
181 "member replay frag...\n"); 185 "member replay frag...\n");
182} 186}
183 187
188
184static void 189static void
185member_replay_msg () 190member_replay_msg ()
186{ 191{
@@ -188,17 +193,42 @@ member_replay_msg ()
188 "member replay msg...\n"); 193 "member replay msg...\n");
189} 194}
190 195
196
191static void 197static void
192member_message () 198member_message (void *cls,
199 const struct GNUNET_MULTICAST_MessageHeader *msg)
193{ 200{
201 struct multicast_peer *mc_peer = (struct multicast_peer*)cls;
202
203 if (0 != strncmp ("pong", (char *)&msg[1], 4))
204 {
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 "peer #%i did not receive pong\n",
207 mc_peer->peer);
208
209 result = GNUNET_SYSERR;
210 GNUNET_SCHEDULER_shutdown ();
211 }
212
194 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 213 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
195 "member message...\n"); 214 "peer #%i receives: %s\n",
215 mc_peer->peer,
216 (char *)&msg[1]);
217
218 mc_peer->test_ok = GNUNET_OK;
219
220 // FIXME: ugly test function
221 /*
222 for (int i=1; i<NUM_PEERS; i++)
223 if (!mc_peers[i]->test_ok)
224 return;
196 225
197 // FIXME: not finished here
198 result = GNUNET_YES; 226 result = GNUNET_YES;
199 GNUNET_SCHEDULER_shutdown (); 227 GNUNET_SCHEDULER_shutdown();
228 */
200} 229}
201 230
231
202static void 232static void
203origin_join_request (void *cls, 233origin_join_request (void *cls,
204 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, 234 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
@@ -233,6 +263,7 @@ origin_join_request (void *cls,
233 result = GNUNET_OK; 263 result = GNUNET_OK;
234} 264}
235 265
266
236static void 267static void
237origin_replay_frag (void *cls, 268origin_replay_frag (void *cls,
238 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, 269 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
@@ -243,6 +274,7 @@ origin_replay_frag (void *cls,
243 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n"); 274 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n");
244} 275}
245 276
277
246static void 278static void
247origin_replay_msg (void *cls, 279origin_replay_msg (void *cls,
248 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, 280 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
@@ -288,6 +320,7 @@ origin_request (void *cls,
288 cls); 320 cls);
289} 321}
290 322
323
291static void 324static void
292origin_message (void *cls, 325origin_message (void *cls,
293 const struct GNUNET_MULTICAST_MessageHeader *msg) 326 const struct GNUNET_MULTICAST_MessageHeader *msg)
@@ -295,6 +328,7 @@ origin_message (void *cls,
295 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); 328 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n");
296} 329}
297 330
331
298static void 332static void
299multicast_da (void *cls, 333multicast_da (void *cls,
300 void *op_result) 334 void *op_result)
@@ -375,6 +409,7 @@ multicast_ca (void *cls,
375 } 409 }
376} 410}
377 411
412
378static void 413static void
379peer_information_cb (void *cls, 414peer_information_cb (void *cls,
380 struct GNUNET_TESTBED_Operation *operation, 415 struct GNUNET_TESTBED_Operation *operation,
@@ -452,7 +487,7 @@ service_connect (void *cls,
452 } 487 }
453 else 488 else
454 { 489 {
455 member[mc_peer->peer-1] = ca_result; 490 member[mc_peer->peer] = ca_result;
456 } 491 }
457} 492}
458 493
@@ -500,6 +535,7 @@ testbed_master (void *cls,
500 { 535 {
501 mc_peers[i] = GNUNET_new (struct multicast_peer); 536 mc_peers[i] = GNUNET_new (struct multicast_peer);
502 mc_peers[i]->peer = i; 537 mc_peers[i]->peer = i;
538 mc_peers[i]->test_ok = GNUNET_NO;
503 } 539 }
504 540
505 op[0] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ 541 op[0] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */
@@ -517,7 +553,7 @@ testbed_master (void *cls,
517 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ 553 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */
518 554
519 /* Schedule the shutdown task with a delay of a few Seconds */ 555 /* Schedule the shutdown task with a delay of a few Seconds */
520 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), 556 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80),
521 &timeout_task, NULL); 557 &timeout_task, NULL);
522} 558}
523 559
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index d64ce10a8..5c3533506 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -1,6 +1,6 @@
1 /* 1 /*
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2009-2013 GNUnet e.V. 3 * Copyright (C) 2009-2017 GNUnet e.V.
4 * 4 *
5 * GNUnet is free software; you can redistribute it and/or modify 5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published 6 * it under the terms of the GNU General Public License as published
@@ -28,6 +28,7 @@
28#include "gnunet_namestore_plugin.h" 28#include "gnunet_namestore_plugin.h"
29#include "gnunet_namestore_service.h" 29#include "gnunet_namestore_service.h"
30#include "gnunet_gnsrecord_lib.h" 30#include "gnunet_gnsrecord_lib.h"
31#include "gnunet_sq_lib.h"
31#include "namestore.h" 32#include "namestore.h"
32#include <sqlite3.h> 33#include <sqlite3.h>
33 34
@@ -113,16 +114,24 @@ struct Plugin
113 * @return 0 on success 114 * @return 0 on success
114 */ 115 */
115static int 116static int
116sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt) 117sq_prepare (sqlite3 *dbh,
118 const char *zSql,
119 sqlite3_stmt **ppStmt)
117{ 120{
118 char *dummy; 121 char *dummy;
119 int result; 122 int result;
120 123
121 result = 124 result =
122 sqlite3_prepare_v2 (dbh, zSql, strlen (zSql), ppStmt, 125 sqlite3_prepare_v2 (dbh,
126 zSql,
127 strlen (zSql),
128 ppStmt,
123 (const char **) &dummy); 129 (const char **) &dummy);
124 LOG (GNUNET_ERROR_TYPE_DEBUG, 130 LOG (GNUNET_ERROR_TYPE_DEBUG,
125 "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result); 131 "Prepared `%s' / %p: %d\n",
132 zSql,
133 *ppStmt,
134 result);
126 return result; 135 return result;
127} 136}
128 137
@@ -275,38 +284,41 @@ database_setup (struct Plugin *plugin)
275 284
276 create_indices (plugin->dbh); 285 create_indices (plugin->dbh);
277 286
278 if ((sq_prepare 287 if ( (SQLITE_OK !=
279 (plugin->dbh, 288 sq_prepare (plugin->dbh,
280 "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label)" 289 "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label)"
281 " VALUES (?, ?, ?, ?, ?, ?)", 290 " VALUES (?, ?, ?, ?, ?, ?)",
282 &plugin->store_records) != SQLITE_OK) || 291 &plugin->store_records)) ||
283 (sq_prepare 292 (SQLITE_OK !=
284 (plugin->dbh, 293 sq_prepare (plugin->dbh,
285 "DELETE FROM ns097records WHERE zone_private_key=? AND label=?", 294 "DELETE FROM ns097records WHERE zone_private_key=? AND label=?",
286 &plugin->delete_records) != SQLITE_OK) || 295 &plugin->delete_records)) ||
287 (sq_prepare 296 (SQLITE_OK !=
288 (plugin->dbh, 297 sq_prepare (plugin->dbh,
289 "SELECT record_count,record_data,label" 298 "SELECT record_count,record_data,label"
290 " FROM ns097records WHERE zone_private_key=? AND pkey=?", 299 " FROM ns097records WHERE zone_private_key=? AND pkey=?",
291 &plugin->zone_to_name) != SQLITE_OK) || 300 &plugin->zone_to_name)) ||
292 (sq_prepare 301 (SQLITE_OK !=
293 (plugin->dbh, 302 sq_prepare (plugin->dbh,
294 "SELECT record_count,record_data,label" 303 "SELECT record_count,record_data,label"
295 " FROM ns097records WHERE zone_private_key=? ORDER BY rvalue LIMIT 1 OFFSET ?", 304 " FROM ns097records WHERE zone_private_key=?"
296 &plugin->iterate_zone) != SQLITE_OK) || 305 " ORDER BY rvalue LIMIT 1 OFFSET ?",
297 (sq_prepare 306 &plugin->iterate_zone)) ||
298 (plugin->dbh, 307 (SQLITE_OK !=
299 "SELECT record_count,record_data,label,zone_private_key" 308 sq_prepare (plugin->dbh,
300 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?", 309 "SELECT record_count,record_data,label,zone_private_key"
301 &plugin->iterate_all_zones) != SQLITE_OK) || 310 " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?",
302 (sq_prepare 311 &plugin->iterate_all_zones)) ||
303 (plugin->dbh, 312 (SQLITE_OK !=
304 "SELECT record_count,record_data,label,zone_private_key" 313 sq_prepare (plugin->dbh,
305 " FROM ns097records WHERE zone_private_key=? AND label=?", 314 "SELECT record_count,record_data,label,zone_private_key"
306 &plugin->lookup_label) != SQLITE_OK) 315 " FROM ns097records WHERE zone_private_key=? AND label=?",
307 ) 316 &plugin->lookup_label))
317 )
308 { 318 {
309 LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling"); 319 LOG_SQLITE (plugin,
320 GNUNET_ERROR_TYPE_ERROR,
321 "precompiling");
310 return GNUNET_SYSERR; 322 return GNUNET_SYSERR;
311 } 323 }
312 return GNUNET_OK; 324 return GNUNET_OK;
@@ -341,21 +353,30 @@ database_shutdown (struct Plugin *plugin)
341 { 353 {
342 LOG (GNUNET_ERROR_TYPE_WARNING, 354 LOG (GNUNET_ERROR_TYPE_WARNING,
343 _("Tried to close sqlite without finalizing all prepared statements.\n")); 355 _("Tried to close sqlite without finalizing all prepared statements.\n"));
344 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 356 stmt = sqlite3_next_stmt (plugin->dbh,
345 while (stmt != NULL) 357 NULL);
358 while (NULL != stmt)
346 { 359 {
347 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", 360 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
348 "Closing statement %p\n", stmt); 361 "sqlite",
362 "Closing statement %p\n",
363 stmt);
349 result = sqlite3_finalize (stmt); 364 result = sqlite3_finalize (stmt);
350 if (result != SQLITE_OK) 365 if (result != SQLITE_OK)
351 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", 366 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
352 "Failed to close statement %p: %d\n", stmt, result); 367 "sqlite",
353 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 368 "Failed to close statement %p: %d\n",
369 stmt,
370 result);
371 stmt = sqlite3_next_stmt (plugin->dbh,
372 NULL);
354 } 373 }
355 result = sqlite3_close (plugin->dbh); 374 result = sqlite3_close (plugin->dbh);
356 } 375 }
357 if (SQLITE_OK != result) 376 if (SQLITE_OK != result)
358 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); 377 LOG_SQLITE (plugin,
378 GNUNET_ERROR_TYPE_ERROR,
379 "sqlite3_close");
359 380
360 GNUNET_free_non_null (plugin->fn); 381 GNUNET_free_non_null (plugin->fn);
361} 382}
@@ -407,7 +428,13 @@ namestore_sqlite_store_records (void *cls,
407 return GNUNET_SYSERR; 428 return GNUNET_SYSERR;
408 } 429 }
409 { 430 {
431 /* First delete 'old' records */
410 char data[data_size]; 432 char data[data_size];
433 struct GNUNET_SQ_QueryParam dparams[] = {
434 GNUNET_SQ_query_param_auto_from_type (zone_key),
435 GNUNET_SQ_query_param_string (label),
436 GNUNET_SQ_query_param_end
437 };
411 438
412 if (data_size != 439 if (data_size !=
413 GNUNET_GNSRECORD_records_serialize (rd_count, 440 GNUNET_GNSRECORD_records_serialize (rd_count,
@@ -418,92 +445,71 @@ namestore_sqlite_store_records (void *cls,
418 GNUNET_break (0); 445 GNUNET_break (0);
419 return GNUNET_SYSERR; 446 return GNUNET_SYSERR;
420 } 447 }
421 448 if (GNUNET_OK !=
422 /* First delete 'old' records */ 449 GNUNET_SQ_bind (plugin->delete_records,
423 if ((SQLITE_OK != 450 dparams))
424 sqlite3_bind_blob (plugin->delete_records,
425 1,
426 zone_key,
427 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
428 SQLITE_STATIC)) ||
429 (SQLITE_OK !=
430 sqlite3_bind_text (plugin->delete_records,
431 2,
432 label,
433 -1,
434 SQLITE_STATIC)))
435 { 451 {
436 LOG_SQLITE (plugin, 452 LOG_SQLITE (plugin,
437 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 453 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
438 "sqlite3_bind_XXXX"); 454 "sqlite3_bind_XXXX");
439 if (SQLITE_OK != sqlite3_reset (plugin->delete_records)) 455 GNUNET_SQ_reset (plugin->dbh,
440 LOG_SQLITE (plugin, 456 plugin->delete_records);
441 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
442 "sqlite3_reset");
443 return GNUNET_SYSERR; 457 return GNUNET_SYSERR;
444 458
445 } 459 }
446 n = sqlite3_step (plugin->delete_records); 460 n = sqlite3_step (plugin->delete_records);
447 if (SQLITE_OK != sqlite3_reset (plugin->delete_records)) 461 GNUNET_SQ_reset (plugin->dbh,
448 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 462 plugin->delete_records);
449 "sqlite3_reset");
450 463
451 if (0 != rd_count) 464 if (0 != rd_count)
452 { 465 {
453 if ((SQLITE_OK != 466 uint32_t rd_count32 = (uint32_t) rd_count;
454 sqlite3_bind_blob (plugin->store_records, 467 struct GNUNET_SQ_QueryParam sparams[] = {
455 1, 468 GNUNET_SQ_query_param_auto_from_type (zone_key),
456 zone_key, 469 GNUNET_SQ_query_param_auto_from_type (&rvalue),
457 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 470 GNUNET_SQ_query_param_uint64 (&rvalue),
458 SQLITE_STATIC)) || 471 GNUNET_SQ_query_param_uint32 (&rd_count32),
459 (SQLITE_OK != 472 GNUNET_SQ_query_param_fixed_size (data, data_size),
460 sqlite3_bind_blob (plugin->store_records, 473 GNUNET_SQ_query_param_string (label),
461 2, 474 GNUNET_SQ_query_param_end
462 &pkey, 475 };
463 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), 476
464 SQLITE_STATIC)) || 477 if (GNUNET_OK !=
465 (SQLITE_OK != 478 GNUNET_SQ_bind (plugin->store_records,
466 sqlite3_bind_int64 (plugin->store_records, 3, rvalue)) || 479 sparams))
467 (SQLITE_OK !=
468 sqlite3_bind_int (plugin->store_records, 4, rd_count)) ||
469 (SQLITE_OK !=
470 sqlite3_bind_blob (plugin->store_records, 5,
471 data, data_size,
472 SQLITE_STATIC)) ||
473 (SQLITE_OK !=
474 sqlite3_bind_text (plugin->store_records, 6,
475 label, -1,
476 SQLITE_STATIC)))
477 { 480 {
478 LOG_SQLITE (plugin, 481 LOG_SQLITE (plugin,
479 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 482 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
480 "sqlite3_bind_XXXX"); 483 "sqlite3_bind_XXXX");
481 if (SQLITE_OK != sqlite3_reset (plugin->store_records)) 484 GNUNET_SQ_reset (plugin->dbh,
482 LOG_SQLITE (plugin, 485 plugin->store_records);
483 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
484 "sqlite3_reset");
485 return GNUNET_SYSERR; 486 return GNUNET_SYSERR;
486 } 487 }
487 n = sqlite3_step (plugin->store_records); 488 n = sqlite3_step (plugin->store_records);
488 if (SQLITE_OK != sqlite3_reset (plugin->store_records)) 489 GNUNET_SQ_reset (plugin->dbh,
489 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 490 plugin->store_records);
490 "sqlite3_reset");
491 } 491 }
492 } 492 }
493 switch (n) 493 switch (n)
494 { 494 {
495 case SQLITE_DONE: 495 case SQLITE_DONE:
496 if (0 != rd_count) 496 if (0 != rd_count)
497 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Record stored\n"); 497 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
498 "sqlite",
499 "Record stored\n");
498 else 500 else
499 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Record deleted\n"); 501 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
502 "sqlite",
503 "Record deleted\n");
500 return GNUNET_OK; 504 return GNUNET_OK;
501 case SQLITE_BUSY: 505 case SQLITE_BUSY:
502 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 506 LOG_SQLITE (plugin,
507 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
503 "sqlite3_step"); 508 "sqlite3_step");
504 return GNUNET_NO; 509 return GNUNET_NO;
505 default: 510 default:
506 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 511 LOG_SQLITE (plugin,
512 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
507 "sqlite3_step"); 513 "sqlite3_step");
508 return GNUNET_SYSERR; 514 return GNUNET_SYSERR;
509 } 515 }
@@ -526,37 +532,47 @@ static int
526get_record_and_call_iterator (struct Plugin *plugin, 532get_record_and_call_iterator (struct Plugin *plugin,
527 sqlite3_stmt *stmt, 533 sqlite3_stmt *stmt,
528 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 534 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
529 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) 535 GNUNET_NAMESTORE_RecordIterator iter,
536 void *iter_cls)
530{ 537{
531 unsigned int record_count; 538 uint32_t record_count;
532 size_t data_size; 539 size_t data_size;
533 const char *data; 540 void *data;
534 const char *label; 541 char *label;
542 struct GNUNET_CRYPTO_EcdsaPrivateKey zk;
535 int ret; 543 int ret;
536 int sret; 544 int sret;
537 545
538 ret = GNUNET_NO; 546 ret = GNUNET_NO;
539 if (SQLITE_ROW == (sret = sqlite3_step (stmt))) 547 if (SQLITE_ROW == (sret = sqlite3_step (stmt)))
540 { 548 {
541 record_count = sqlite3_column_int (stmt, 0); 549 struct GNUNET_SQ_ResultSpec rs[] = {
542 data_size = sqlite3_column_bytes (stmt, 1); 550 GNUNET_SQ_result_spec_uint32 (&record_count),
543 data = sqlite3_column_blob (stmt, 1); 551 GNUNET_SQ_result_spec_variable_size (&data, &data_size),
544 label = (const char*) sqlite3_column_text (stmt, 2); 552 GNUNET_SQ_result_spec_string (&label),
553 GNUNET_SQ_result_spec_end
554 };
555 struct GNUNET_SQ_ResultSpec rsx[] = {
556 GNUNET_SQ_result_spec_uint32 (&record_count),
557 GNUNET_SQ_result_spec_variable_size (&data, &data_size),
558 GNUNET_SQ_result_spec_string (&label),
559 GNUNET_SQ_result_spec_auto_from_type (&zk),
560 GNUNET_SQ_result_spec_end
561 };
562
545 if (NULL == zone_key) 563 if (NULL == zone_key)
546 { 564 {
547 /* must be "iterate_all_zones", got one extra return value */ 565 zone_key = &zk;
548 if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) != 566 ret = GNUNET_SQ_extract_result (stmt,
549 sqlite3_column_bytes (stmt, 3)) 567 rsx);
550 { 568 }
551 GNUNET_break (0); 569 else
552 ret = GNUNET_SYSERR; 570 {
553 } 571 ret = GNUNET_SQ_extract_result (stmt,
554 else 572 rs);
555 {
556 zone_key = sqlite3_column_blob (stmt, 3);
557 }
558 } 573 }
559 if (record_count > 64 * 1024) 574 if ( (GNUNET_OK != ret) ||
575 (record_count > 64 * 1024) )
560 { 576 {
561 /* sanity check, don't stack allocate far too much just 577 /* sanity check, don't stack allocate far too much just
562 because database might contain a large value here */ 578 because database might contain a large value here */
@@ -568,32 +584,40 @@ get_record_and_call_iterator (struct Plugin *plugin,
568 struct GNUNET_GNSRECORD_Data rd[record_count]; 584 struct GNUNET_GNSRECORD_Data rd[record_count];
569 585
570 if (GNUNET_OK != 586 if (GNUNET_OK !=
571 GNUNET_GNSRECORD_records_deserialize (data_size, data, 587 GNUNET_GNSRECORD_records_deserialize (data_size,
572 record_count, rd)) 588 data,
589 record_count,
590 rd))
573 { 591 {
574 GNUNET_break (0); 592 GNUNET_break (0);
575 ret = GNUNET_SYSERR; 593 ret = GNUNET_SYSERR;
576 } 594 }
577 else if (NULL != zone_key) 595 else
578 { 596 {
579 if (NULL != iter) 597 if (NULL != iter)
580 iter (iter_cls, zone_key, label, record_count, rd); 598 iter (iter_cls,
599 zone_key,
600 label,
601 record_count,
602 rd);
581 ret = GNUNET_YES; 603 ret = GNUNET_YES;
582 } 604 }
583 } 605 }
606 GNUNET_SQ_cleanup_result (rs);
584 } 607 }
585 else 608 else
586 { 609 {
587 if (SQLITE_DONE != sret) 610 if (SQLITE_DONE != sret)
588 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); 611 LOG_SQLITE (plugin,
612 GNUNET_ERROR_TYPE_ERROR,
613 "sqlite_step");
589 } 614 }
590 if (SQLITE_OK != sqlite3_reset (stmt)) 615 GNUNET_SQ_reset (plugin->dbh,
591 LOG_SQLITE (plugin, 616 stmt);
592 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
593 "sqlite3_reset");
594 return ret; 617 return ret;
595} 618}
596 619
620
597/** 621/**
598 * Lookup records in the datastore for which we are the authority. 622 * Lookup records in the datastore for which we are the authority.
599 * 623 *
@@ -606,37 +630,35 @@ get_record_and_call_iterator (struct Plugin *plugin,
606 */ 630 */
607static int 631static int
608namestore_sqlite_lookup_records (void *cls, 632namestore_sqlite_lookup_records (void *cls,
609 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, 633 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
610 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) 634 const char *label,
635 GNUNET_NAMESTORE_RecordIterator iter,
636 void *iter_cls)
611{ 637{
612 struct Plugin *plugin = cls; 638 struct Plugin *plugin = cls;
613 sqlite3_stmt *stmt; 639 struct GNUNET_SQ_QueryParam params[] = {
614 int err; 640 GNUNET_SQ_query_param_auto_from_type (zone),
641 GNUNET_SQ_query_param_string (label),
642 GNUNET_SQ_query_param_end
643 };
615 644
616 if (NULL == zone) 645 if (NULL == zone)
617 {
618 return GNUNET_SYSERR; 646 return GNUNET_SYSERR;
619 } 647 if (GNUNET_OK !=
620 else 648 GNUNET_SQ_bind (plugin->lookup_label,
621 { 649 params))
622 stmt = plugin->lookup_label;
623 err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1,
624 zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
625 SQLITE_STATIC)) ||
626 (SQLITE_OK != sqlite3_bind_text (stmt, 2,
627 label, -1, SQLITE_STATIC)) );
628 }
629 if (err)
630 { 650 {
631 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 651 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
632 "sqlite3_bind_XXXX"); 652 "sqlite3_bind_XXXX");
633 if (SQLITE_OK != sqlite3_reset (stmt)) 653 GNUNET_SQ_reset (plugin->dbh,
634 LOG_SQLITE (plugin, 654 plugin->lookup_label);
635 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
636 "sqlite3_reset");
637 return GNUNET_SYSERR; 655 return GNUNET_SYSERR;
638 } 656 }
639 return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls); 657 return get_record_and_call_iterator (plugin,
658 plugin->lookup_label,
659 zone,
660 iter,
661 iter_cls);
640} 662}
641 663
642 664
@@ -655,7 +677,8 @@ static int
655namestore_sqlite_iterate_records (void *cls, 677namestore_sqlite_iterate_records (void *cls,
656 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 678 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
657 uint64_t offset, 679 uint64_t offset,
658 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) 680 GNUNET_NAMESTORE_RecordIterator iter,
681 void *iter_cls)
659{ 682{
660 struct Plugin *plugin = cls; 683 struct Plugin *plugin = cls;
661 sqlite3_stmt *stmt; 684 sqlite3_stmt *stmt;
@@ -663,30 +686,41 @@ namestore_sqlite_iterate_records (void *cls,
663 686
664 if (NULL == zone) 687 if (NULL == zone)
665 { 688 {
689 struct GNUNET_SQ_QueryParam params[] = {
690 GNUNET_SQ_query_param_uint64 (&offset),
691 GNUNET_SQ_query_param_end
692 };
693
666 stmt = plugin->iterate_all_zones; 694 stmt = plugin->iterate_all_zones;
667 err = (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, 695 err = GNUNET_SQ_bind (stmt,
668 offset)); 696 params);
669 } 697 }
670 else 698 else
671 { 699 {
700 struct GNUNET_SQ_QueryParam params[] = {
701 GNUNET_SQ_query_param_auto_from_type (zone),
702 GNUNET_SQ_query_param_uint64 (&offset),
703 GNUNET_SQ_query_param_end
704 };
705
672 stmt = plugin->iterate_zone; 706 stmt = plugin->iterate_zone;
673 err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, 707 err = GNUNET_SQ_bind (stmt,
674 zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 708 params);
675 SQLITE_STATIC)) ||
676 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2,
677 offset)) );
678 } 709 }
679 if (err) 710 if (GNUNET_OK != err)
680 { 711 {
681 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 712 LOG_SQLITE (plugin,
713 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
682 "sqlite3_bind_XXXX"); 714 "sqlite3_bind_XXXX");
683 if (SQLITE_OK != sqlite3_reset (stmt)) 715 GNUNET_SQ_reset (plugin->dbh,
684 LOG_SQLITE (plugin, 716 stmt);
685 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
686 "sqlite3_reset");
687 return GNUNET_SYSERR; 717 return GNUNET_SYSERR;
688 } 718 }
689 return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls); 719 return get_record_and_call_iterator (plugin,
720 stmt,
721 zone,
722 iter,
723 iter_cls);
690} 724}
691 725
692 726
@@ -708,29 +742,31 @@ namestore_sqlite_zone_to_name (void *cls,
708 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) 742 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
709{ 743{
710 struct Plugin *plugin = cls; 744 struct Plugin *plugin = cls;
711 sqlite3_stmt *stmt; 745 struct GNUNET_SQ_QueryParam params[] = {
746 GNUNET_SQ_query_param_auto_from_type (zone),
747 GNUNET_SQ_query_param_auto_from_type (value_zone),
748 GNUNET_SQ_query_param_end
749 };
712 750
713 stmt = plugin->zone_to_name; 751 if (GNUNET_OK !=
714 if ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, 752 GNUNET_SQ_bind (plugin->zone_to_name,
715 zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 753 params))
716 SQLITE_STATIC)) ||
717 (SQLITE_OK != sqlite3_bind_blob (stmt, 2,
718 value_zone, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
719 SQLITE_STATIC)) )
720 { 754 {
721 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 755 LOG_SQLITE (plugin,
756 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
722 "sqlite3_bind_XXXX"); 757 "sqlite3_bind_XXXX");
723 if (SQLITE_OK != sqlite3_reset (stmt)) 758 GNUNET_SQ_reset (plugin->dbh,
724 LOG_SQLITE (plugin, 759 plugin->zone_to_name);
725 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
726 "sqlite3_reset");
727 return GNUNET_SYSERR; 760 return GNUNET_SYSERR;
728 } 761 }
729 LOG (GNUNET_ERROR_TYPE_DEBUG, 762 LOG (GNUNET_ERROR_TYPE_DEBUG,
730 "Performing reverse lookup for `%s'\n", 763 "Performing reverse lookup for `%s'\n",
731 GNUNET_GNSRECORD_z2s (value_zone)); 764 GNUNET_GNSRECORD_z2s (value_zone));
732 765 return get_record_and_call_iterator (plugin,
733 return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls); 766 plugin->zone_to_name,
767 zone,
768 iter,
769 iter_cls);
734} 770}
735 771
736 772
diff --git a/src/sq/test_sq.c b/src/sq/test_sq.c
index e6896861e..713809030 100644
--- a/src/sq/test_sq.c
+++ b/src/sq/test_sq.c
@@ -253,8 +253,12 @@ main(int argc,
253 { 253 {
254 fprintf (stderr, 254 fprintf (stderr,
255 "Failed to create table\n"); 255 "Failed to create table\n");
256 sqlite3_close (dbh); 256 GNUNET_break (SQLITE_OK ==
257 unlink ("test.db"); 257 sqlite3_close (dbh));
258 if (0 != unlink ("test.db"))
259 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
260 "unlink",
261 "test.db");
258 return 1; 262 return 1;
259 } 263 }
260 264
@@ -266,12 +270,14 @@ main(int argc,
266 { 270 {
267 fprintf (stderr, 271 fprintf (stderr,
268 "Failed to drop table\n"); 272 "Failed to drop table\n");
269 sqlite3_close (dbh); 273 ret = 1;
270 unlink ("test.db");
271 return 1;
272 } 274 }
273 sqlite3_close (dbh); 275 GNUNET_break (SQLITE_OK ==
274 unlink ("test.db"); 276 sqlite3_close (dbh));
277 if (0 != unlink ("test.db"))
278 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
279 "unlink",
280 "test.db");
275 return ret; 281 return ret;
276} 282}
277 283
diff --git a/src/util/mq.c b/src/util/mq.c
index 79e2d0455..25cf24e11 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -811,22 +811,40 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
811 mq->assoc_id = 1; 811 mq->assoc_id = 1;
812 } 812 }
813 id = mq->assoc_id++; 813 id = mq->assoc_id++;
814 GNUNET_CONTAINER_multihashmap32_put (mq->assoc_map, id, assoc_data, 814 GNUNET_assert (GNUNET_OK ==
815 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 815 GNUNET_CONTAINER_multihashmap32_put (mq->assoc_map,
816 id,
817 assoc_data,
818 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
816 return id; 819 return id;
817} 820}
818 821
819 822
823/**
824 * Get the data associated with a @a request_id in a queue
825 *
826 * @param mq the message queue with the association
827 * @param request_id the request id we are interested in
828 * @return the associated data
829 */
820void * 830void *
821GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, 831GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
822 uint32_t request_id) 832 uint32_t request_id)
823{ 833{
824 if (NULL == mq->assoc_map) 834 if (NULL == mq->assoc_map)
825 return NULL; 835 return NULL;
826 return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id); 836 return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map,
837 request_id);
827} 838}
828 839
829 840
841/**
842 * Remove the association for a @a request_id
843 *
844 * @param mq the message queue with the association
845 * @param request_id the request id we want to remove
846 * @return the associated data
847 */
830void * 848void *
831GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, 849GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq,
832 uint32_t request_id) 850 uint32_t request_id)
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index 4ef98b629..4d1b6fe7d 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2005, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2005, 2006, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -25,6 +25,7 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27 27
28
28static int 29static int
29check () 30check ()
30{ 31{
@@ -95,47 +96,57 @@ check ()
95 if (ptrs[0] != NULL) 96 if (ptrs[0] != NULL)
96 return 9; 97 return 9;
97 98
98 /* GNUNET_new_array_2d tests */ 99 /* GNUNET_new_array_2d tests */
99 a2 = GNUNET_new_array_2d (17, 22, unsigned int); 100 a2 = GNUNET_new_array_2d (17, 22, unsigned int);
100 for (i = 0; i < 17; i++) 101 for (i = 0; i < 17; i++)
101 { 102 {
102 for (j = 0; j < 22; j++) 103 for (j = 0; j < 22; j++)
103 { 104 {
104 if (0 != a2[i][j]) 105 if (0 != a2[i][j])
105 return 10; 106 {
106 a2[i][j] = i * 100 + j; 107 GNUNET_free (a2);
107 } 108 return 10;
108 } 109 }
109 free (a2); 110 a2[i][j] = i * 100 + j;
110 111 }
111 /* GNUNET_new_array_3d tests */ 112 }
112 a3 = GNUNET_new_array_3d (2, 3, 4, char); 113 GNUNET_free (a2);
113 for (i = 0; i < 2; i++)
114 {
115 for (j = 0; j < 3; j++)
116 {
117 for (k = 0; k < 4; k++)
118 {
119 if (0 != a3[i][j][k])
120 return 11;
121 a3[i][j][k] = i * 100 + j * 10 + k;
122 }
123 }
124 }
125 free (a3);
126 114
115 /* GNUNET_new_array_3d tests */
116 a3 = GNUNET_new_array_3d (2, 3, 4, char);
117 for (i = 0; i < 2; i++)
118 {
119 for (j = 0; j < 3; j++)
120 {
121 for (k = 0; k < 4; k++)
122 {
123 if (0 != a3[i][j][k])
124 {
125 GNUNET_free (a3);
126 return 11;
127 }
128 a3[i][j][k] = i * 100 + j * 10 + k;
129 }
130 }
131 }
132 GNUNET_free (a3);
127 return 0; 133 return 0;
128} 134}
129 135
136
130int 137int
131main (int argc, char *argv[]) 138main (int argc, char *argv[])
132{ 139{
133 int ret; 140 int ret;
134 141
135 GNUNET_log_setup ("test-common-allocation", "WARNING", NULL); 142 GNUNET_log_setup ("test-common-allocation",
143 "WARNING",
144 NULL);
136 ret = check (); 145 ret = check ();
137 if (ret != 0) 146 if (ret != 0)
138 FPRINTF (stderr, "ERROR %d.\n", ret); 147 FPRINTF (stderr,
148 "ERROR %d.\n",
149 ret);
139 return ret; 150 return ret;
140} 151}
141 152