aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-06-13 23:40:25 +0200
committerPhil <phil.buschmann@tum.de>2018-06-13 23:40:25 +0200
commit688bd873c3cb463090039f64b9f13b9a029695dc (patch)
treebc74703d4912da712d82f869237057405ad49060 /src
parenta006f82603921d7b6775c7a7be60c7f388c6a927 (diff)
parentc9b52f6ce67209e000d2f679a34c23bd4724b243 (diff)
downloadgnunet-688bd873c3cb463090039f64b9f13b9a029695dc.tar.gz
gnunet-688bd873c3cb463090039f64b9f13b9a029695dc.zip
-Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api
Diffstat (limited to 'src')
-rw-r--r--src/curl/curl.c19
-rw-r--r--src/datacache/plugin_datacache_heap.c3
-rw-r--r--src/datacache/plugin_datacache_postgres.c33
-rw-r--r--src/datacache/test_datacache.c73
-rw-r--r--src/datacache/test_datacache_quota.c31
-rw-r--r--src/dht/gnunet-service-dht_datacache.c5
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c76
-rw-r--r--src/gns/gnunet-service-gns_resolver.c16
-rw-r--r--src/gnsrecord/gnsrecord_crypto.c12
-rw-r--r--src/include/gnunet_curl_lib.h11
-rw-r--r--src/my/my.c26
-rw-r--r--src/my/my_query_helper.c22
-rw-r--r--src/pq/pq_query_helper.c58
-rw-r--r--src/pq/pq_result_helper.c85
-rw-r--r--src/rps/gnunet-rps-profiler.c21
-rw-r--r--src/rps/rps-test_util.c133
-rw-r--r--src/rps/rps-test_util.h8
17 files changed, 529 insertions, 103 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 2d0b09d92..cdd39ab8e 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -448,6 +448,25 @@ download_get_result (struct DownloadBuffer *db,
448 448
449 449
450/** 450/**
451 * Add custom request header.
452 *
453 * @param ctx cURL context.
454 * @param header header string; will be given to the context AS IS.
455 * @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise.
456 */
457int
458GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx,
459 const char *header)
460{
461 ctx->json_header = curl_slist_append (ctx->json_header,
462 header);
463 if (NULL == ctx->json_header)
464 return GNUNET_SYSERR;
465
466 return GNUNET_OK;
467}
468
469/**
451 * Run the main event loop for the Taler interaction. 470 * Run the main event loop for the Taler interaction.
452 * 471 *
453 * @param ctx the library context 472 * @param ctx the library context
diff --git a/src/datacache/plugin_datacache_heap.c b/src/datacache/plugin_datacache_heap.c
index 2a08fc81b..494d1ae17 100644
--- a/src/datacache/plugin_datacache_heap.c
+++ b/src/datacache/plugin_datacache_heap.c
@@ -314,6 +314,9 @@ get_cb (void *cls,
314 if ( (get_ctx->type != val->type) && 314 if ( (get_ctx->type != val->type) &&
315 (GNUNET_BLOCK_TYPE_ANY != get_ctx->type) ) 315 (GNUNET_BLOCK_TYPE_ANY != get_ctx->type) )
316 return GNUNET_OK; 316 return GNUNET_OK;
317 if (0 ==
318 GNUNET_TIME_absolute_get_remaining (val->discard_time).rel_value_us)
319 return GNUNET_OK;
317 if (NULL != get_ctx->iter) 320 if (NULL != get_ctx->iter)
318 ret = get_ctx->iter (get_ctx->iter_cls, 321 ret = get_ctx->iter (get_ctx->iter_cls,
319 key, 322 key,
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c
index 6eeeb5873..ea87acc1f 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -82,12 +82,12 @@ init_connection (struct Plugin *plugin)
82 struct GNUNET_PQ_PreparedStatement ps[] = { 82 struct GNUNET_PQ_PreparedStatement ps[] = {
83 GNUNET_PQ_make_prepare ("getkt", 83 GNUNET_PQ_make_prepare ("getkt",
84 "SELECT discard_time,type,value,path FROM gn011dc " 84 "SELECT discard_time,type,value,path FROM gn011dc "
85 "WHERE key=$1 AND type=$2", 85 "WHERE key=$1 AND type=$2 AND discard_time >= $3",
86 2), 86 3),
87 GNUNET_PQ_make_prepare ("getk", 87 GNUNET_PQ_make_prepare ("getk",
88 "SELECT discard_time,type,value,path FROM gn011dc " 88 "SELECT discard_time,type,value,path FROM gn011dc "
89 "WHERE key=$1", 89 "WHERE key=$1 AND discard_time >= $2",
90 1), 90 2),
91 GNUNET_PQ_make_prepare ("getex", 91 GNUNET_PQ_make_prepare ("getex",
92 "SELECT length(value) AS len,oid,key FROM gn011dc" 92 "SELECT length(value) AS len,oid,key FROM gn011dc"
93 " WHERE discard_time < $1" 93 " WHERE discard_time < $1"
@@ -97,18 +97,15 @@ init_connection (struct Plugin *plugin)
97 "SELECT length(value) AS len,oid,key FROM gn011dc" 97 "SELECT length(value) AS len,oid,key FROM gn011dc"
98 " ORDER BY prox ASC, discard_time ASC LIMIT 1", 98 " ORDER BY prox ASC, discard_time ASC LIMIT 1",
99 0), 99 0),
100 GNUNET_PQ_make_prepare ("getp",
101 "SELECT length(value) AS len,oid,key FROM gn011dc "
102 "ORDER BY discard_time ASC LIMIT 1",
103 0),
104 GNUNET_PQ_make_prepare ("get_random", 100 GNUNET_PQ_make_prepare ("get_random",
105 "SELECT discard_time,type,value,path,key FROM gn011dc " 101 "SELECT discard_time,type,value,path,key FROM gn011dc"
106 "ORDER BY key ASC LIMIT 1 OFFSET $1", 102 " WHERE discard_time >= $1"
107 1), 103 " ORDER BY key ASC LIMIT 1 OFFSET $2",
104 2),
108 GNUNET_PQ_make_prepare ("get_closest", 105 GNUNET_PQ_make_prepare ("get_closest",
109 "SELECT discard_time,type,value,path,key FROM gn011dc " 106 "SELECT discard_time,type,value,path,key FROM gn011dc "
110 "WHERE key>=$1 ORDER BY key ASC LIMIT $2", 107 "WHERE key>=$1 AND discard_time >= $2 ORDER BY key ASC LIMIT $3",
111 1), 108 3),
112 GNUNET_PQ_make_prepare ("delrow", 109 GNUNET_PQ_make_prepare ("delrow",
113 "DELETE FROM gn011dc WHERE oid=$1", 110 "DELETE FROM gn011dc WHERE oid=$1",
114 1), 111 1),
@@ -313,18 +310,22 @@ postgres_plugin_get (void *cls,
313{ 310{
314 struct Plugin *plugin = cls; 311 struct Plugin *plugin = cls;
315 uint32_t type32 = (uint32_t) type; 312 uint32_t type32 = (uint32_t) type;
313 struct GNUNET_TIME_Absolute now;
316 struct GNUNET_PQ_QueryParam paramk[] = { 314 struct GNUNET_PQ_QueryParam paramk[] = {
317 GNUNET_PQ_query_param_auto_from_type (key), 315 GNUNET_PQ_query_param_auto_from_type (key),
316 GNUNET_PQ_query_param_absolute_time (&now),
318 GNUNET_PQ_query_param_end 317 GNUNET_PQ_query_param_end
319 }; 318 };
320 struct GNUNET_PQ_QueryParam paramkt[] = { 319 struct GNUNET_PQ_QueryParam paramkt[] = {
321 GNUNET_PQ_query_param_auto_from_type (key), 320 GNUNET_PQ_query_param_auto_from_type (key),
322 GNUNET_PQ_query_param_uint32 (&type32), 321 GNUNET_PQ_query_param_uint32 (&type32),
322 GNUNET_PQ_query_param_absolute_time (&now),
323 GNUNET_PQ_query_param_end 323 GNUNET_PQ_query_param_end
324 }; 324 };
325 enum GNUNET_DB_QueryStatus res; 325 enum GNUNET_DB_QueryStatus res;
326 struct HandleResultContext hr_ctx; 326 struct HandleResultContext hr_ctx;
327 327
328 now = GNUNET_TIME_absolute_get ();
328 hr_ctx.iter = iter; 329 hr_ctx.iter = iter;
329 hr_ctx.iter_cls = iter_cls; 330 hr_ctx.iter_cls = iter_cls;
330 hr_ctx.key = key; 331 hr_ctx.key = key;
@@ -427,6 +428,7 @@ postgres_plugin_get_random (void *cls,
427{ 428{
428 struct Plugin *plugin = cls; 429 struct Plugin *plugin = cls;
429 uint32_t off; 430 uint32_t off;
431 struct GNUNET_TIME_Absolute now;
430 struct GNUNET_TIME_Absolute expiration_time; 432 struct GNUNET_TIME_Absolute expiration_time;
431 size_t data_size; 433 size_t data_size;
432 void *data; 434 void *data;
@@ -436,6 +438,7 @@ postgres_plugin_get_random (void *cls,
436 uint32_t type; 438 uint32_t type;
437 enum GNUNET_DB_QueryStatus res; 439 enum GNUNET_DB_QueryStatus res;
438 struct GNUNET_PQ_QueryParam params[] = { 440 struct GNUNET_PQ_QueryParam params[] = {
441 GNUNET_PQ_query_param_absolute_time (&now),
439 GNUNET_PQ_query_param_uint32 (&off), 442 GNUNET_PQ_query_param_uint32 (&off),
440 GNUNET_PQ_query_param_end 443 GNUNET_PQ_query_param_end
441 }; 444 };
@@ -459,6 +462,7 @@ postgres_plugin_get_random (void *cls,
459 return 0; 462 return 0;
460 if (NULL == iter) 463 if (NULL == iter)
461 return 1; 464 return 1;
465 now = GNUNET_TIME_absolute_get ();
462 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 466 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
463 plugin->num_items); 467 plugin->num_items);
464 res = GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, 468 res = GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh,
@@ -620,8 +624,10 @@ postgres_plugin_get_closest (void *cls,
620{ 624{
621 struct Plugin *plugin = cls; 625 struct Plugin *plugin = cls;
622 uint32_t num_results32 = (uint32_t) num_results; 626 uint32_t num_results32 = (uint32_t) num_results;
627 struct GNUNET_TIME_Absolute now;
623 struct GNUNET_PQ_QueryParam params[] = { 628 struct GNUNET_PQ_QueryParam params[] = {
624 GNUNET_PQ_query_param_auto_from_type (key), 629 GNUNET_PQ_query_param_auto_from_type (key),
630 GNUNET_PQ_query_param_absolute_time (&now),
625 GNUNET_PQ_query_param_uint32 (&num_results32), 631 GNUNET_PQ_query_param_uint32 (&num_results32),
626 GNUNET_PQ_query_param_end 632 GNUNET_PQ_query_param_end
627 }; 633 };
@@ -630,6 +636,7 @@ postgres_plugin_get_closest (void *cls,
630 636
631 erc.iter = iter; 637 erc.iter = iter;
632 erc.iter_cls = iter_cls; 638 erc.iter_cls = iter_cls;
639 now = GNUNET_TIME_absolute_get ();
633 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, 640 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
634 "get_closest", 641 "get_closest",
635 params, 642 params,
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c
index 12edb62f8..50e45012d 100644
--- a/src/datacache/test_datacache.c
+++ b/src/datacache/test_datacache.c
@@ -44,6 +44,11 @@ checkIt (void *cls,
44 unsigned int path_len, 44 unsigned int path_len,
45 const struct GNUNET_PeerIdentity *path) 45 const struct GNUNET_PeerIdentity *path)
46{ 46{
47 (void) key;
48 (void) type;
49 (void) exp;
50 (void) path_len;
51 (void) path;
47 if (size != sizeof (struct GNUNET_HashCode)) 52 if (size != sizeof (struct GNUNET_HashCode))
48 { 53 {
49 GNUNET_break (0); 54 GNUNET_break (0);
@@ -59,17 +64,22 @@ checkIt (void *cls,
59 64
60 65
61static void 66static void
62run (void *cls, char *const *args, const char *cfgfile, 67run (void *cls,
68 char *const *args,
69 const char *cfgfile,
63 const struct GNUNET_CONFIGURATION_Handle *cfg) 70 const struct GNUNET_CONFIGURATION_Handle *cfg)
64{ 71{
65 struct GNUNET_DATACACHE_Handle *h; 72 struct GNUNET_DATACACHE_Handle *h;
66 struct GNUNET_HashCode k; 73 struct GNUNET_HashCode k;
67 struct GNUNET_HashCode n; 74 struct GNUNET_HashCode n;
68 struct GNUNET_TIME_Absolute exp; 75 struct GNUNET_TIME_Absolute exp;
69 unsigned int i;
70 76
77 (void) cls;
78 (void) args;
79 (void) cfgfile;
71 ok = 0; 80 ok = 0;
72 h = GNUNET_DATACACHE_create (cfg, "testcache"); 81 h = GNUNET_DATACACHE_create (cfg,
82 "testcache");
73 if (h == NULL) 83 if (h == NULL)
74 { 84 {
75 FPRINTF (stderr, 85 FPRINTF (stderr,
@@ -81,7 +91,7 @@ run (void *cls, char *const *args, const char *cfgfile,
81 exp = GNUNET_TIME_absolute_get (); 91 exp = GNUNET_TIME_absolute_get ();
82 exp.abs_value_us += 5 * 60 * 1000 * 1000LL; 92 exp.abs_value_us += 5 * 60 * 1000 * 1000LL;
83 memset (&k, 0, sizeof (struct GNUNET_HashCode)); 93 memset (&k, 0, sizeof (struct GNUNET_HashCode));
84 for (i = 0; i < 100; i++) 94 for (unsigned int i = 0; i < 100; i++)
85 { 95 {
86 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 96 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
87 ASSERT (GNUNET_OK == 97 ASSERT (GNUNET_OK ==
@@ -93,26 +103,43 @@ run (void *cls, char *const *args, const char *cfgfile,
93 0, NULL)); 103 0, NULL));
94 k = n; 104 k = n;
95 } 105 }
96 memset (&k, 0, sizeof (struct GNUNET_HashCode)); 106 memset (&k,
97 for (i = 0; i < 100; i++) 107 0,
108 sizeof (struct GNUNET_HashCode));
109 for (unsigned int i = 0; i < 100; i++)
98 { 110 {
99 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 111 GNUNET_CRYPTO_hash (&k,
100 ASSERT (1 == GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n)); 112 sizeof (struct GNUNET_HashCode),
113 &n);
114 ASSERT (1 == GNUNET_DATACACHE_get (h,
115 &k,
116 1 + i % 16,
117 &checkIt,
118 &n));
101 k = n; 119 k = n;
102 } 120 }
103 121
104 memset (&k, 42, sizeof (struct GNUNET_HashCode)); 122 memset (&k,
105 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); 123 42,
124 sizeof (struct GNUNET_HashCode));
125 GNUNET_CRYPTO_hash (&k,
126 sizeof (struct GNUNET_HashCode),
127 &n);
106 ASSERT (GNUNET_OK == 128 ASSERT (GNUNET_OK ==
107 GNUNET_DATACACHE_put (h, 129 GNUNET_DATACACHE_put (h,
108 &k, 130 &k,
109 GNUNET_YES, 131 GNUNET_YES,
110 sizeof (struct GNUNET_HashCode), 132 sizeof (struct GNUNET_HashCode),
111 (const char *) &n, 792, 133 (const char *) &n,
134 792,
112 GNUNET_TIME_UNIT_FOREVER_ABS, 135 GNUNET_TIME_UNIT_FOREVER_ABS,
113 0, NULL)); 136 0,
114 ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n)); 137 NULL));
115 138 ASSERT (0 != GNUNET_DATACACHE_get (h,
139 &k,
140 792,
141 &checkIt,
142 &n));
116 GNUNET_DATACACHE_destroy (h); 143 GNUNET_DATACACHE_destroy (h);
117 ASSERT (ok == 0); 144 ASSERT (ok == 0);
118 return; 145 return;
@@ -137,16 +164,26 @@ main (int argc, char *argv[])
137 GNUNET_GETOPT_OPTION_END 164 GNUNET_GETOPT_OPTION_END
138 }; 165 };
139 166
167 (void) argc;
140 GNUNET_log_setup ("test-datacache", 168 GNUNET_log_setup ("test-datacache",
141 "WARNING", 169 "WARNING",
142 NULL); 170 NULL);
143 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 171 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
144 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf", 172 GNUNET_snprintf (cfg_name,
173 sizeof (cfg_name),
174 "test_datacache_data_%s.conf",
145 plugin_name); 175 plugin_name);
146 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 176 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
147 "test-datacache", "nohelp", options, &run, NULL); 177 xargv,
178 "test-datacache",
179 "nohelp",
180 options,
181 &run,
182 NULL);
148 if ( (0 != ok) && (77 != ok) ) 183 if ( (0 != ok) && (77 != ok) )
149 FPRINTF (stderr, "Missed some testcases: %d\n", ok); 184 FPRINTF (stderr,
185 "Missed some testcases: %d\n",
186 ok);
150 return ok; 187 return ok;
151} 188}
152 189
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c
index 3d02a7244..21e373608 100644
--- a/src/datacache/test_datacache_quota.c
+++ b/src/datacache/test_datacache_quota.c
@@ -41,7 +41,9 @@ static const char *plugin_name;
41 * some of the data from the last iteration is still there. 41 * some of the data from the last iteration is still there.
42 */ 42 */
43static void 43static void
44run (void *cls, char *const *args, const char *cfgfile, 44run (void *cls,
45 char *const *args,
46 const char *cfgfile,
45 const struct GNUNET_CONFIGURATION_Handle *cfg) 47 const struct GNUNET_CONFIGURATION_Handle *cfg)
46{ 48{
47 struct GNUNET_DATACACHE_Handle *h; 49 struct GNUNET_DATACACHE_Handle *h;
@@ -50,8 +52,12 @@ run (void *cls, char *const *args, const char *cfgfile,
50 char buf[3200]; 52 char buf[3200];
51 struct GNUNET_TIME_Absolute exp; 53 struct GNUNET_TIME_Absolute exp;
52 54
55 (void) cls;
56 (void) args;
57 (void) cfgfile;
53 ok = 0; 58 ok = 0;
54 h = GNUNET_DATACACHE_create (cfg, "testcache"); 59 h = GNUNET_DATACACHE_create (cfg,
60 "testcache");
55 61
56 if (h == NULL) 62 if (h == NULL)
57 { 63 {
@@ -112,7 +118,8 @@ FAILURE:
112 118
113 119
114int 120int
115main (int argc, char *argv[]) 121main (int argc,
122 char *argv[])
116{ 123{
117 char cfg_name[128]; 124 char cfg_name[128];
118 char *const xargv[] = { 125 char *const xargv[] = {
@@ -125,17 +132,27 @@ main (int argc, char *argv[])
125 GNUNET_GETOPT_OPTION_END 132 GNUNET_GETOPT_OPTION_END
126 }; 133 };
127 134
135 (void) argc;
128 GNUNET_log_setup ("test-datacache-quota", 136 GNUNET_log_setup ("test-datacache-quota",
129 "WARNING", 137 "WARNING",
130 NULL); 138 NULL);
131 139
132 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 140 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
133 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf", 141 GNUNET_snprintf (cfg_name,
142 sizeof (cfg_name),
143 "test_datacache_data_%s.conf",
134 plugin_name); 144 plugin_name);
135 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 145 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
136 "test-datacache-quota", "nohelp", options, &run, NULL); 146 xargv,
147 "test-datacache-quota",
148 "nohelp",
149 options,
150 &run,
151 NULL);
137 if (0 != ok) 152 if (0 != ok)
138 FPRINTF (stderr, "Missed some testcases: %d\n", ok); 153 FPRINTF (stderr,
154 "Missed some testcases: %d\n",
155 ok);
139 return ok; 156 return ok;
140} 157}
141 158
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index 1f01387ff..7ad9aa728 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -171,6 +171,11 @@ datacache_get_iterator (void *cls,
171 struct GetRequestContext *ctx = cls; 171 struct GetRequestContext *ctx = cls;
172 enum GNUNET_BLOCK_EvaluationResult eval; 172 enum GNUNET_BLOCK_EvaluationResult eval;
173 173
174 if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
175 {
176 GNUNET_break (0); /* why does datacache return expired values? */
177 return GNUNET_OK; /* skip expired record */
178 }
174 if ( (NULL == data) && 179 if ( (NULL == data) &&
175 (0 == data_size) ) 180 (0 == data_size) )
176 data = &non_null; /* point anywhere, but not to NULL */ 181 data = &non_null; /* point anywhere, but not to NULL */
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 9c1395782..56639448f 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -468,6 +468,7 @@ free_connect_info (void *cls,
468{ 468{
469 struct ConnectInfo *ci = value; 469 struct ConnectInfo *ci = value;
470 470
471 (void) cls;
471 GNUNET_assert (GNUNET_YES == 472 GNUNET_assert (GNUNET_YES ==
472 GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, 473 GNUNET_CONTAINER_multipeermap_remove (all_desired_peers,
473 peer, 474 peer,
@@ -579,7 +580,10 @@ update_desire_strength (void *cls,
579 const struct GNUNET_PeerIdentity *pid, 580 const struct GNUNET_PeerIdentity *pid,
580 void *value) 581 void *value)
581{ 582{
582 try_connect (pid, NULL); 583 (void) cls;
584 (void) value;
585 try_connect (pid,
586 NULL);
583 return GNUNET_YES; 587 return GNUNET_YES;
584} 588}
585 589
@@ -616,6 +620,8 @@ add_known_to_bloom (void *cls,
616 struct GNUNET_BLOCK_Group *bg = cls; 620 struct GNUNET_BLOCK_Group *bg = cls;
617 struct GNUNET_HashCode key_hash; 621 struct GNUNET_HashCode key_hash;
618 622
623 (void) cls;
624 (void) value;
619 GNUNET_CRYPTO_hash (key, 625 GNUNET_CRYPTO_hash (key,
620 sizeof (struct GNUNET_PeerIdentity), 626 sizeof (struct GNUNET_PeerIdentity),
621 &key_hash); 627 &key_hash);
@@ -643,7 +649,8 @@ send_find_peer_message (void *cls)
643 struct GNUNET_BLOCK_Group *bg; 649 struct GNUNET_BLOCK_Group *bg;
644 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 650 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
645 651
646 find_peer_task = NULL; 652 (void) cls;
653 find_peer_task = NULL;
647 if (newly_found_peers > bucket_size) 654 if (newly_found_peers > bucket_size)
648 { 655 {
649 /* If we are finding many peers already, no need to send out our request right now! */ 656 /* If we are finding many peers already, no need to send out our request right now! */
@@ -716,7 +723,8 @@ handle_core_connect (void *cls,
716{ 723{
717 struct PeerInfo *pi; 724 struct PeerInfo *pi;
718 725
719 /* Check for connect to self message */ 726 (void) cls;
727 /* Check for connect to self message */
720 if (0 == memcmp (&my_identity, 728 if (0 == memcmp (&my_identity,
721 peer, 729 peer,
722 sizeof (struct GNUNET_PeerIdentity))) 730 sizeof (struct GNUNET_PeerIdentity)))
@@ -739,13 +747,13 @@ handle_core_connect (void *cls,
739 &pi->phash); 747 &pi->phash);
740 pi->peer_bucket = find_bucket (&pi->phash); 748 pi->peer_bucket = find_bucket (&pi->phash);
741 GNUNET_assert ( (pi->peer_bucket >= 0) && 749 GNUNET_assert ( (pi->peer_bucket >= 0) &&
742 (pi->peer_bucket < MAX_BUCKETS) ); 750 ((unsigned int) pi->peer_bucket < MAX_BUCKETS) );
743 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head, 751 GNUNET_CONTAINER_DLL_insert_tail (k_buckets[pi->peer_bucket].head,
744 k_buckets[pi->peer_bucket].tail, 752 k_buckets[pi->peer_bucket].tail,
745 pi); 753 pi);
746 k_buckets[pi->peer_bucket].peers_size++; 754 k_buckets[pi->peer_bucket].peers_size++;
747 closest_bucket = GNUNET_MAX (closest_bucket, 755 closest_bucket = GNUNET_MAX (closest_bucket,
748 pi->peer_bucket); 756 (unsigned int) pi->peer_bucket);
749 GNUNET_assert (GNUNET_OK == 757 GNUNET_assert (GNUNET_OK ==
750 GNUNET_CONTAINER_multipeermap_put (all_connected_peers, 758 GNUNET_CONTAINER_multipeermap_put (all_connected_peers,
751 pi->id, 759 pi->id,
@@ -783,6 +791,7 @@ handle_core_disconnect (void *cls,
783{ 791{
784 struct PeerInfo *to_remove = internal_cls; 792 struct PeerInfo *to_remove = internal_cls;
785 793
794 (void) cls;
786 /* Check for disconnect from self message */ 795 /* Check for disconnect from self message */
787 if (NULL == to_remove) 796 if (NULL == to_remove)
788 return; 797 return;
@@ -946,23 +955,23 @@ GDS_am_closest_peer (const struct GNUNET_HashCode *key,
946 int bits; 955 int bits;
947 int other_bits; 956 int other_bits;
948 int bucket_num; 957 int bucket_num;
949 int count;
950 struct PeerInfo *pos; 958 struct PeerInfo *pos;
951 959
952 if (0 == memcmp (&my_identity_hash, key, sizeof (struct GNUNET_HashCode))) 960 if (0 == memcmp (&my_identity_hash,
961 key,
962 sizeof (struct GNUNET_HashCode)))
953 return GNUNET_YES; 963 return GNUNET_YES;
954 bucket_num = find_bucket (key); 964 bucket_num = find_bucket (key);
955 GNUNET_assert (bucket_num >= 0); 965 GNUNET_assert (bucket_num >= 0);
956 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, 966 bits = GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
957 key); 967 key);
958 pos = k_buckets[bucket_num].head; 968 pos = k_buckets[bucket_num].head;
959 count = 0; 969 while (NULL != pos)
960 while ((NULL != pos) && (count < bucket_size))
961 { 970 {
962 if ((NULL != bloom) && 971 if ( (NULL != bloom) &&
963 (GNUNET_YES == 972 (GNUNET_YES ==
964 GNUNET_CONTAINER_bloomfilter_test (bloom, 973 GNUNET_CONTAINER_bloomfilter_test (bloom,
965 &pos->phash))) 974 &pos->phash)) )
966 { 975 {
967 pos = pos->next; 976 pos = pos->next;
968 continue; /* Skip already checked entries */ 977 continue; /* Skip already checked entries */
@@ -1594,6 +1603,7 @@ static void
1594core_init (void *cls, 1603core_init (void *cls,
1595 const struct GNUNET_PeerIdentity *identity) 1604 const struct GNUNET_PeerIdentity *identity)
1596{ 1605{
1606 (void) cls;
1597 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1607 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1598 "CORE called, I am %s\n", 1608 "CORE called, I am %s\n",
1599 GNUNET_i2s (identity)); 1609 GNUNET_i2s (identity));
@@ -1619,6 +1629,7 @@ check_dht_p2p_put (void *cls,
1619 uint32_t putlen; 1629 uint32_t putlen;
1620 uint16_t msize; 1630 uint16_t msize;
1621 1631
1632 (void) cls;
1622 msize = ntohs (put->header.size); 1633 msize = ntohs (put->header.size);
1623 putlen = ntohl (put->put_path_length); 1634 putlen = ntohl (put->put_path_length);
1624 if ((msize < 1635 if ((msize <
@@ -1654,7 +1665,17 @@ handle_dht_p2p_put (void *cls,
1654 struct GNUNET_CONTAINER_BloomFilter *bf; 1665 struct GNUNET_CONTAINER_BloomFilter *bf;
1655 struct GNUNET_HashCode test_key; 1666 struct GNUNET_HashCode test_key;
1656 int forwarded; 1667 int forwarded;
1668 struct GNUNET_TIME_Absolute exp_time;
1657 1669
1670 exp_time = GNUNET_TIME_absolute_ntoh (put->expiration_time);
1671 if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us)
1672 {
1673 GNUNET_STATISTICS_update (GDS_stats,
1674 gettext_noop ("# Expired PUTs discarded"),
1675 1,
1676 GNUNET_NO);
1677 return;
1678 }
1658 msize = ntohs (put->header.size); 1679 msize = ntohs (put->header.size);
1659 putlen = ntohl (put->put_path_length); 1680 putlen = ntohl (put->put_path_length);
1660 GNUNET_STATISTICS_update (GDS_stats, 1681 GNUNET_STATISTICS_update (GDS_stats,
@@ -1790,7 +1811,7 @@ handle_dht_p2p_put (void *cls,
1790 putlen = 0; 1811 putlen = 0;
1791 1812
1792 /* give to local clients */ 1813 /* give to local clients */
1793 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1814 GDS_CLIENTS_handle_reply (exp_time,
1794 &put->key, 1815 &put->key,
1795 0, 1816 0,
1796 NULL, 1817 NULL,
@@ -1802,7 +1823,7 @@ handle_dht_p2p_put (void *cls,
1802 /* store locally */ 1823 /* store locally */
1803 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || 1824 if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
1804 (GDS_am_closest_peer (&put->key, bf))) 1825 (GDS_am_closest_peer (&put->key, bf)))
1805 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), 1826 GDS_DATACACHE_handle_put (exp_time,
1806 &put->key, 1827 &put->key,
1807 putlen, 1828 putlen,
1808 pp, 1829 pp,
@@ -1813,7 +1834,7 @@ handle_dht_p2p_put (void *cls,
1813 forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type), 1834 forwarded = GDS_NEIGHBOURS_handle_put (ntohl (put->type),
1814 options, 1835 options,
1815 ntohl (put->desired_replication_level), 1836 ntohl (put->desired_replication_level),
1816 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1837 exp_time,
1817 ntohl (put->hop_count), 1838 ntohl (put->hop_count),
1818 bf, 1839 bf,
1819 &put->key, 1840 &put->key,
@@ -1830,7 +1851,7 @@ handle_dht_p2p_put (void *cls,
1830 ntohl (put->hop_count), 1851 ntohl (put->hop_count),
1831 ntohl (put->desired_replication_level), 1852 ntohl (put->desired_replication_level),
1832 putlen, pp, 1853 putlen, pp,
1833 GNUNET_TIME_absolute_ntoh (put->expiration_time), 1854 exp_time,
1834 &put->key, 1855 &put->key,
1835 payload, 1856 payload,
1836 payload_size); 1857 payload_size);
@@ -1907,9 +1928,9 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
1907 sizeof (struct GNUNET_HashCode))) 1928 sizeof (struct GNUNET_HashCode)))
1908 bucket_idx = closest_bucket; 1929 bucket_idx = closest_bucket;
1909 else 1930 else
1910 bucket_idx = GNUNET_MIN (closest_bucket, 1931 bucket_idx = GNUNET_MIN ((int) closest_bucket,
1911 find_bucket (key)); 1932 find_bucket (key));
1912 if (bucket_idx == GNUNET_SYSERR) 1933 if (bucket_idx < 0)
1913 return; 1934 return;
1914 bucket = &k_buckets[bucket_idx]; 1935 bucket = &k_buckets[bucket_idx];
1915 if (bucket->peers_size == 0) 1936 if (bucket->peers_size == 0)
@@ -2016,6 +2037,7 @@ check_dht_p2p_get (void *cls,
2016 uint32_t xquery_size; 2037 uint32_t xquery_size;
2017 uint16_t msize; 2038 uint16_t msize;
2018 2039
2040 (void) cls;
2019 msize = ntohs (get->header.size); 2041 msize = ntohs (get->header.size);
2020 xquery_size = ntohl (get->xquery_size); 2042 xquery_size = ntohl (get->xquery_size);
2021 if (msize < sizeof (struct PeerGetMessage) + xquery_size) 2043 if (msize < sizeof (struct PeerGetMessage) + xquery_size)
@@ -2203,6 +2225,7 @@ check_dht_p2p_result (void *cls,
2203 uint32_t put_path_length; 2225 uint32_t put_path_length;
2204 uint16_t msize; 2226 uint16_t msize;
2205 2227
2228 (void) cls;
2206 msize = ntohs (prm->header.size); 2229 msize = ntohs (prm->header.size);
2207 put_path_length = ntohl (prm->put_path_length); 2230 put_path_length = ntohl (prm->put_path_length);
2208 get_path_length = ntohl (prm->get_path_length); 2231 get_path_length = ntohl (prm->get_path_length);
@@ -2316,8 +2339,18 @@ handle_dht_p2p_result (void *cls,
2316 uint16_t msize; 2339 uint16_t msize;
2317 size_t data_size; 2340 size_t data_size;
2318 enum GNUNET_BLOCK_Type type; 2341 enum GNUNET_BLOCK_Type type;
2342 struct GNUNET_TIME_Absolute exp_time;
2319 2343
2320 /* parse and validate message */ 2344 /* parse and validate message */
2345 exp_time = GNUNET_TIME_absolute_ntoh (prm->expiration_time);
2346 if (0 == GNUNET_TIME_absolute_get_remaining (exp_time).rel_value_us)
2347 {
2348 GNUNET_STATISTICS_update (GDS_stats,
2349 gettext_noop ("# Expired results discarded"),
2350 1,
2351 GNUNET_NO);
2352 return;
2353 }
2321 msize = ntohs (prm->header.size); 2354 msize = ntohs (prm->header.size);
2322 put_path_length = ntohl (prm->put_path_length); 2355 put_path_length = ntohl (prm->put_path_length);
2323 get_path_length = ntohl (prm->get_path_length); 2356 get_path_length = ntohl (prm->get_path_length);
@@ -2391,7 +2424,6 @@ handle_dht_p2p_result (void *cls,
2391 h); 2424 h);
2392 } 2425 }
2393 2426
2394
2395 /* First, check if 'peer' is already on the path, and if 2427 /* First, check if 'peer' is already on the path, and if
2396 so, truncate it instead of expanding. */ 2428 so, truncate it instead of expanding. */
2397 for (unsigned int i=0;i<=get_path_length;i++) 2429 for (unsigned int i=0;i<=get_path_length;i++)
@@ -2399,7 +2431,7 @@ handle_dht_p2p_result (void *cls,
2399 peer->id, 2431 peer->id,
2400 sizeof (struct GNUNET_PeerIdentity))) 2432 sizeof (struct GNUNET_PeerIdentity)))
2401 { 2433 {
2402 process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), 2434 process_reply_with_path (exp_time,
2403 &prm->key, 2435 &prm->key,
2404 i, 2436 i,
2405 get_path, 2437 get_path,
@@ -2420,7 +2452,7 @@ handle_dht_p2p_result (void *cls,
2420 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2452 get_path_length * sizeof (struct GNUNET_PeerIdentity));
2421 xget_path[get_path_length] = *peer->id; 2453 xget_path[get_path_length] = *peer->id;
2422 2454
2423 process_reply_with_path (GNUNET_TIME_absolute_ntoh (prm->expiration_time), 2455 process_reply_with_path (exp_time,
2424 &prm->key, 2456 &prm->key,
2425 get_path_length + 1, 2457 get_path_length + 1,
2426 xget_path, 2458 xget_path,
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index a90cc4c0e..54c3cba23 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -1377,6 +1377,10 @@ vpn_allocation_cb (void *cls,
1377 } 1377 }
1378 } 1378 }
1379 GNUNET_assert (i < vpn_ctx->rd_count); 1379 GNUNET_assert (i < vpn_ctx->rd_count);
1380 if (0 == vpn_ctx->rd_count)
1381 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1382 _("VPN returned empty result for `%s'\n"),
1383 rh->name);
1380 handle_gns_resolution_result (rh, 1384 handle_gns_resolution_result (rh,
1381 vpn_ctx->rd_count, 1385 vpn_ctx->rd_count,
1382 rd); 1386 rd);
@@ -1859,7 +1863,8 @@ handle_gns_resolution_result (void *cls,
1859 if (0 == rd_count) 1863 if (0 == rd_count)
1860 { 1864 {
1861 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1862 _("GNS lookup failed (zero records found)\n")); 1866 _("GNS lookup failed (zero records found for `%s')\n"),
1867 rh->name);
1863 fail_resolution (rh); 1868 fail_resolution (rh);
1864 return; 1869 return;
1865 } 1870 }
@@ -2370,6 +2375,11 @@ handle_dht_response (void *cls,
2370 fail_resolution (rh); 2375 fail_resolution (rh);
2371 return; 2376 return;
2372 } 2377 }
2378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2379 "Decrypting DHT block of size %u for `%s', expires %s\n",
2380 ntohl (block->purpose.size),
2381 rh->name,
2382 GNUNET_STRINGS_absolute_time_to_string (exp));
2373 if (GNUNET_OK != 2383 if (GNUNET_OK !=
2374 GNUNET_GNSRECORD_block_decrypt (block, 2384 GNUNET_GNSRECORD_block_decrypt (block,
2375 &ac->authority_info.gns_authority, 2385 &ac->authority_info.gns_authority,
@@ -2450,6 +2460,10 @@ handle_gns_namecache_resolution_result (void *cls,
2450{ 2460{
2451 struct GNS_ResolverHandle *rh = cls; 2461 struct GNS_ResolverHandle *rh = cls;
2452 2462
2463 if (0 == rd_count)
2464 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2465 _("GNS namecache returned empty result for `%s'\n"),
2466 rh->name);
2453 handle_gns_resolution_result (rh, 2467 handle_gns_resolution_result (rh,
2454 rd_count, 2468 rd_count,
2455 rd); 2469 rd);
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index 0752086fe..295d31100 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -377,6 +377,8 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
377 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ) 377 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
378 { 378 {
379 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */ 379 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
380 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
381 "Ignoring shadow record\n");
380 break; 382 break;
381 } 383 }
382 } 384 }
@@ -395,6 +397,16 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
395 rd[j] = rd[i]; 397 rd[j] = rd[i];
396 j++; 398 j++;
397 } 399 }
400 else
401 {
402 struct GNUNET_TIME_Absolute at;
403
404 at.abs_value_us = rd[i].expiration_time;
405 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
406 "Excluding record that expired %s (%llu ago)\n",
407 GNUNET_STRINGS_absolute_time_to_string (at),
408 (unsigned long long) rd[i].expiration_time - now.abs_value_us);
409 }
398 } 410 }
399 rd_count = j; 411 rd_count = j;
400 if (NULL != proc) 412 if (NULL != proc)
diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h
index 17e9aeea4..2b2442a52 100644
--- a/src/include/gnunet_curl_lib.h
+++ b/src/include/gnunet_curl_lib.h
@@ -99,6 +99,17 @@ GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx,
99 99
100 100
101/** 101/**
102 * Add custom request header.
103 *
104 * @param ctx cURL context.
105 * @param header header string; will be given to the context AS IS.
106 * @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise.
107 */
108int
109GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx,
110 const char *header);
111
112/**
102 * Run the main event loop for the CURL interaction. 113 * Run the main event loop for the CURL interaction.
103 * 114 *
104 * @param ctx the library context 115 * @param ctx the library context
diff --git a/src/my/my.c b/src/my/my.c
index b9d5c8424..2f4cd3ba3 100644
--- a/src/my/my.c
+++ b/src/my/my.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2016 Inria & GNUnet e.V. 3 Copyright (C) 2016, 2018 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -43,19 +43,20 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
43{ 43{
44 const struct GNUNET_MY_QueryParam *p; 44 const struct GNUNET_MY_QueryParam *p;
45 unsigned int num; 45 unsigned int num;
46 unsigned int i;
47 MYSQL_STMT *stmt; 46 MYSQL_STMT *stmt;
48 47
49 num = 0; 48 num = 0;
50 for (i=0;NULL != params[i].conv;i++) 49 for (unsigned int i=0;NULL != params[i].conv;i++)
51 num += params[i].num_params; 50 num += params[i].num_params;
52 { 51 {
53 MYSQL_BIND qbind[num]; 52 MYSQL_BIND qbind[num];
54 unsigned int off; 53 unsigned int off;
55 54
56 memset (qbind, 0, sizeof(qbind)); 55 memset (qbind,
56 0,
57 sizeof(qbind));
57 off = 0; 58 off = 0;
58 for (i=0;NULL != (p = &params[i])->conv;i++) 59 for (unsigned int i=0;NULL != (p = &params[i])->conv;i++)
59 { 60 {
60 if (GNUNET_OK != 61 if (GNUNET_OK !=
61 p->conv (p->conv_cls, 62 p->conv (p->conv_cls,
@@ -111,9 +112,7 @@ void
111GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, 112GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
112 MYSQL_BIND *qbind) 113 MYSQL_BIND *qbind)
113{ 114{
114 unsigned int i; 115 for (unsigned int i=0; NULL != qp[i].conv ;i++)
115
116 for (i=0; NULL != qp[i].conv ;i++)
117 if (NULL != qp[i].cleaner) 116 if (NULL != qp[i].cleaner)
118 qp[i].cleaner (qp[i].conv_cls, 117 qp[i].cleaner (qp[i].conv_cls,
119 &qbind[i]); 118 &qbind[i]);
@@ -136,7 +135,6 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
136 struct GNUNET_MY_ResultSpec *rs) 135 struct GNUNET_MY_ResultSpec *rs)
137{ 136{
138 unsigned int num_fields; 137 unsigned int num_fields;
139 unsigned int i;
140 int ret; 138 int ret;
141 MYSQL_STMT *stmt; 139 MYSQL_STMT *stmt;
142 140
@@ -153,7 +151,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
153 } 151 }
154 152
155 num_fields = 0; 153 num_fields = 0;
156 for (i=0;NULL != rs[i].pre_conv;i++) 154 for (unsigned int i=0;NULL != rs[i].pre_conv;i++)
157 num_fields += rs[i].num_fields; 155 num_fields += rs[i].num_fields;
158 156
159 if (mysql_stmt_field_count (stmt) != num_fields) 157 if (mysql_stmt_field_count (stmt) != num_fields)
@@ -169,7 +167,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
169 167
170 memset (result, 0, sizeof (MYSQL_BIND) * num_fields); 168 memset (result, 0, sizeof (MYSQL_BIND) * num_fields);
171 field_off = 0; 169 field_off = 0;
172 for (i=0;NULL != rs[i].pre_conv;i++) 170 for (unsigned int i=0;NULL != rs[i].pre_conv;i++)
173 { 171 {
174 struct GNUNET_MY_ResultSpec *rp = &rs[i]; 172 struct GNUNET_MY_ResultSpec *rp = &rs[i];
175 173
@@ -221,7 +219,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
221 return GNUNET_SYSERR; 219 return GNUNET_SYSERR;
222 } 220 }
223 field_off = 0; 221 field_off = 0;
224 for (i=0;NULL != rs[i].post_conv;i++) 222 for (unsigned int i=0;NULL != rs[i].post_conv;i++)
225 { 223 {
226 struct GNUNET_MY_ResultSpec *rp = &rs[i]; 224 struct GNUNET_MY_ResultSpec *rp = &rs[i];
227 225
@@ -256,9 +254,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
256void 254void
257GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs) 255GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs)
258{ 256{
259 unsigned int i; 257 for (unsigned int i=0;NULL != rs[i].post_conv;i++)
260
261 for (i=0;NULL != rs[i].post_conv;i++)
262 if (NULL != rs[i].cleaner) 258 if (NULL != rs[i].cleaner)
263 rs[i].cleaner (rs[i].conv_cls, 259 rs[i].cleaner (rs[i].conv_cls,
264 &rs[i]); 260 &rs[i]);
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c
index c4516715a..b2a893a44 100644
--- a/src/my/my_query_helper.c
+++ b/src/my/my_query_helper.c
@@ -37,6 +37,7 @@ static void
37my_clean_query (void *cls, 37my_clean_query (void *cls,
38 MYSQL_BIND *qbind) 38 MYSQL_BIND *qbind)
39{ 39{
40 (void) cls;
40 GNUNET_free (qbind[0].buffer); 41 GNUNET_free (qbind[0].buffer);
41} 42}
42 43
@@ -54,6 +55,7 @@ my_conv_fixed_size (void *cls,
54 const struct GNUNET_MY_QueryParam *qp, 55 const struct GNUNET_MY_QueryParam *qp,
55 MYSQL_BIND *qbind) 56 MYSQL_BIND *qbind)
56{ 57{
58 (void) cls;
57 GNUNET_assert (1 == qp->num_params); 59 GNUNET_assert (1 == qp->num_params);
58 qbind->buffer = (void *) qp->data; 60 qbind->buffer = (void *) qp->data;
59 qbind->buffer_length = qp->data_len; 61 qbind->buffer_length = qp->data_len;
@@ -99,12 +101,11 @@ my_conv_string (void *cls,
99 const struct GNUNET_MY_QueryParam *qp, 101 const struct GNUNET_MY_QueryParam *qp,
100 MYSQL_BIND *qbind) 102 MYSQL_BIND *qbind)
101{ 103{
104 (void) cls;
102 GNUNET_assert (1 == qp->num_params); 105 GNUNET_assert (1 == qp->num_params);
103
104 qbind->buffer = (void *) qp->data; 106 qbind->buffer = (void *) qp->data;
105 qbind->buffer_length = qp->data_len; 107 qbind->buffer_length = qp->data_len;
106 qbind->buffer_type = MYSQL_TYPE_STRING; 108 qbind->buffer_type = MYSQL_TYPE_STRING;
107
108 return 1; 109 return 1;
109} 110}
110 111
@@ -142,10 +143,12 @@ my_conv_uint16 (void *cls,
142 const struct GNUNET_MY_QueryParam *qp, 143 const struct GNUNET_MY_QueryParam *qp,
143 MYSQL_BIND *qbind) 144 MYSQL_BIND *qbind)
144{ 145{
146 (void) cls;
145 GNUNET_assert (1 == qp->num_params); 147 GNUNET_assert (1 == qp->num_params);
146 qbind->buffer = (void *) qp->data; 148 qbind->buffer = (void *) qp->data;
147 qbind->buffer_length = sizeof (uint16_t); 149 qbind->buffer_length = sizeof (uint16_t);
148 qbind->buffer_type = MYSQL_TYPE_SHORT; 150 qbind->buffer_type = MYSQL_TYPE_SHORT;
151 qbind->is_unsigned = 1;
149 return 1; 152 return 1;
150} 153}
151 154
@@ -184,11 +187,12 @@ my_conv_uint32 (void *cls,
184 const struct GNUNET_MY_QueryParam *qp, 187 const struct GNUNET_MY_QueryParam *qp,
185 MYSQL_BIND *qbind) 188 MYSQL_BIND *qbind)
186{ 189{
190 (void) cls;
187 GNUNET_assert (1 == qp->num_params); 191 GNUNET_assert (1 == qp->num_params);
188 qbind->buffer = (void *) qp->data; 192 qbind->buffer = (void *) qp->data;
189 qbind->buffer_length = sizeof(uint32_t); 193 qbind->buffer_length = sizeof(uint32_t);
190 qbind->buffer_type = MYSQL_TYPE_LONG; 194 qbind->buffer_type = MYSQL_TYPE_LONG;
191 195 qbind->is_unsigned = 1;
192 return 1; 196 return 1;
193} 197}
194 198
@@ -227,10 +231,12 @@ my_conv_uint64 (void *cls,
227 const struct GNUNET_MY_QueryParam *qp, 231 const struct GNUNET_MY_QueryParam *qp,
228 MYSQL_BIND * qbind) 232 MYSQL_BIND * qbind)
229{ 233{
234 (void) cls;
230 GNUNET_assert (1 == qp->num_params); 235 GNUNET_assert (1 == qp->num_params);
231 qbind->buffer = (void *) qp->data; 236 qbind->buffer = (void *) qp->data;
232 qbind->buffer_length = sizeof (uint64_t); 237 qbind->buffer_length = sizeof (uint64_t);
233 qbind->buffer_type = MYSQL_TYPE_LONGLONG; 238 qbind->buffer_type = MYSQL_TYPE_LONGLONG;
239 qbind->is_unsigned = 1;
234 return 1; 240 return 1;
235} 241}
236 242
@@ -273,14 +279,13 @@ my_conv_rsa_public_key (void *cls,
273 char *buf; 279 char *buf;
274 size_t buf_size; 280 size_t buf_size;
275 281
282 (void) cls;
276 GNUNET_assert(1 == qp->num_params); 283 GNUNET_assert(1 == qp->num_params);
277 284 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
278 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf); 285 &buf);
279
280 qbind->buffer = (void *) buf; 286 qbind->buffer = (void *) buf;
281 qbind->buffer_length = buf_size; 287 qbind->buffer_length = buf_size;
282 qbind->buffer_type = MYSQL_TYPE_BLOB; 288 qbind->buffer_type = MYSQL_TYPE_BLOB;
283
284 return 1; 289 return 1;
285} 290}
286 291
@@ -325,14 +330,13 @@ my_conv_rsa_signature (void *cls,
325 char *buf; 330 char *buf;
326 size_t buf_size; 331 size_t buf_size;
327 332
333 (void) cls;
328 GNUNET_assert(1 == qp->num_params); 334 GNUNET_assert(1 == qp->num_params);
329
330 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, 335 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
331 &buf); 336 &buf);
332 qbind->buffer = (void *) buf; 337 qbind->buffer = (void *) buf;
333 qbind->buffer_length = buf_size; 338 qbind->buffer_length = buf_size;
334 qbind->buffer_type = MYSQL_TYPE_BLOB; 339 qbind->buffer_type = MYSQL_TYPE_BLOB;
335
336 return 1; 340 return 1;
337} 341}
338 342
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index 799f82ebe..98f697b5d 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -50,6 +50,8 @@ qconv_fixed (void *cls,
50 void *scratch[], 50 void *scratch[],
51 unsigned int scratch_length) 51 unsigned int scratch_length)
52{ 52{
53 (void) scratch;
54 (void) scratch_length;
53 GNUNET_break (NULL == cls); 55 GNUNET_break (NULL == cls);
54 if (1 != param_length) 56 if (1 != param_length)
55 return -1; 57 return -1;
@@ -117,6 +119,8 @@ qconv_uint16 (void *cls,
117 const uint16_t *u_hbo = data; 119 const uint16_t *u_hbo = data;
118 uint16_t *u_nbo; 120 uint16_t *u_nbo;
119 121
122 (void) scratch;
123 (void) scratch_length;
120 GNUNET_break (NULL == cls); 124 GNUNET_break (NULL == cls);
121 if (1 != param_length) 125 if (1 != param_length)
122 return -1; 126 return -1;
@@ -172,6 +176,8 @@ qconv_uint32 (void *cls,
172 const uint32_t *u_hbo = data; 176 const uint32_t *u_hbo = data;
173 uint32_t *u_nbo; 177 uint32_t *u_nbo;
174 178
179 (void) scratch;
180 (void) scratch_length;
175 GNUNET_break (NULL == cls); 181 GNUNET_break (NULL == cls);
176 if (1 != param_length) 182 if (1 != param_length)
177 return -1; 183 return -1;
@@ -227,6 +233,8 @@ qconv_uint64 (void *cls,
227 const uint64_t *u_hbo = data; 233 const uint64_t *u_hbo = data;
228 uint64_t *u_nbo; 234 uint64_t *u_nbo;
229 235
236 (void) scratch;
237 (void) scratch_length;
230 GNUNET_break (NULL == cls); 238 GNUNET_break (NULL == cls);
231 if (1 != param_length) 239 if (1 != param_length)
232 return -1; 240 return -1;
@@ -371,6 +379,51 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
371 379
372 380
373/** 381/**
382 * Function called to convert input argument into SQL parameters.
383 *
384 * @param cls closure
385 * @param data pointer to input argument
386 * @param data_len number of bytes in @a data (if applicable)
387 * @param[out] param_values SQL data to set
388 * @param[out] param_lengths SQL length data to set
389 * @param[out] param_formats SQL format data to set
390 * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays
391 * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc()
392 * @param scratch_length number of entries left in @a scratch
393 * @return -1 on error, number of offsets used in @a scratch otherwise
394 */
395static int
396qconv_abs_time (void *cls,
397 const void *data,
398 size_t data_len,
399 void *param_values[],
400 int param_lengths[],
401 int param_formats[],
402 unsigned int param_length,
403 void *scratch[],
404 unsigned int scratch_length)
405{
406 const struct GNUNET_TIME_Absolute *u = data;
407 struct GNUNET_TIME_Absolute abs;
408 uint64_t *u_nbo;
409
410 GNUNET_break (NULL == cls);
411 if (1 != param_length)
412 return -1;
413 abs = *u;
414 if (abs.abs_value_us > INT64_MAX)
415 abs.abs_value_us = INT64_MAX;
416 u_nbo = GNUNET_new (uint64_t);
417 scratch[0] = u_nbo;
418 *u_nbo = GNUNET_htonll (abs.abs_value_us);
419 param_values[0] = (void *) u_nbo;
420 param_lengths[0] = sizeof (uint64_t);
421 param_formats[0] = 1;
422 return 1;
423}
424
425
426/**
374 * Generate query parameter for an absolute time value. 427 * Generate query parameter for an absolute time value.
375 * The database must store a 64-bit integer. 428 * The database must store a 64-bit integer.
376 * 429 *
@@ -380,7 +433,10 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
380struct GNUNET_PQ_QueryParam 433struct GNUNET_PQ_QueryParam
381GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 434GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
382{ 435{
383 return GNUNET_PQ_query_param_uint64 (&x->abs_value_us); 436 struct GNUNET_PQ_QueryParam res =
437 { &qconv_abs_time, NULL, x, sizeof (*x), 1 };
438
439 return res;
384} 440}
385 441
386 442
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 3805b8a8d..dc1a1554f 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -38,6 +38,7 @@ clean_varsize_blob (void *cls,
38{ 38{
39 void **dst = rd; 39 void **dst = rd;
40 40
41 (void) cls;
41 if (NULL != *dst) 42 if (NULL != *dst)
42 { 43 {
43 GNUNET_free (*dst); 44 GNUNET_free (*dst);
@@ -72,6 +73,7 @@ extract_varsize_blob (void *cls,
72 void *idst; 73 void *idst;
73 int fnum; 74 int fnum;
74 75
76 (void) cls;
75 *dst_size = 0; 77 *dst_size = 0;
76 *((void **) dst) = NULL; 78 *((void **) dst) = NULL;
77 79
@@ -154,6 +156,7 @@ extract_fixed_blob (void *cls,
154 const char *res; 156 const char *res;
155 int fnum; 157 int fnum;
156 158
159 (void) cls;
157 fnum = PQfnumber (result, 160 fnum = PQfnumber (result,
158 fname); 161 fname);
159 if (fnum < 0) 162 if (fnum < 0)
@@ -237,6 +240,7 @@ extract_rsa_public_key (void *cls,
237 const char *res; 240 const char *res;
238 int fnum; 241 int fnum;
239 242
243 (void) cls;
240 *pk = NULL; 244 *pk = NULL;
241 fnum = PQfnumber (result, 245 fnum = PQfnumber (result,
242 fname); 246 fname);
@@ -284,6 +288,7 @@ clean_rsa_public_key (void *cls,
284{ 288{
285 struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; 289 struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
286 290
291 (void) cls;
287 if (NULL != *pk) 292 if (NULL != *pk)
288 { 293 {
289 GNUNET_CRYPTO_rsa_public_key_free (*pk); 294 GNUNET_CRYPTO_rsa_public_key_free (*pk);
@@ -338,6 +343,7 @@ extract_rsa_signature (void *cls,
338 const char *res; 343 const char *res;
339 int fnum; 344 int fnum;
340 345
346 (void) cls;
341 *sig = NULL; 347 *sig = NULL;
342 fnum = PQfnumber (result, 348 fnum = PQfnumber (result,
343 fname); 349 fname);
@@ -385,6 +391,7 @@ clean_rsa_signature (void *cls,
385{ 391{
386 struct GNUNET_CRYPTO_RsaSignature **sig = rd; 392 struct GNUNET_CRYPTO_RsaSignature **sig = rd;
387 393
394 (void) cls;
388 if (NULL != *sig) 395 if (NULL != *sig)
389 { 396 {
390 GNUNET_CRYPTO_rsa_signature_free (*sig); 397 GNUNET_CRYPTO_rsa_signature_free (*sig);
@@ -439,6 +446,7 @@ extract_string (void *cls,
439 const char *res; 446 const char *res;
440 int fnum; 447 int fnum;
441 448
449 (void) cls;
442 *str = NULL; 450 *str = NULL;
443 fnum = PQfnumber (result, 451 fnum = PQfnumber (result,
444 fname); 452 fname);
@@ -486,6 +494,7 @@ clean_string (void *cls,
486{ 494{
487 char **str = rd; 495 char **str = rd;
488 496
497 (void) cls;
489 if (NULL != *str) 498 if (NULL != *str)
490 { 499 {
491 GNUNET_free (*str); 500 GNUNET_free (*str);
@@ -515,6 +524,71 @@ GNUNET_PQ_result_spec_string (const char *name,
515 524
516 525
517/** 526/**
527 * Extract data from a Postgres database @a result at row @a row.
528 *
529 * @param cls closure
530 * @param result where to extract data from
531 * @param int row to extract data from
532 * @param fname name (or prefix) of the fields to extract from
533 * @param[in,out] dst_size where to store size of result, may be NULL
534 * @param[out] dst where to store the result
535 * @return
536 * #GNUNET_YES if all results could be extracted
537 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
538 */
539static int
540extract_abs_time (void *cls,
541 PGresult *result,
542 int row,
543 const char *fname,
544 size_t *dst_size,
545 void *dst)
546{
547 struct GNUNET_TIME_Absolute *udst = dst;
548 const int64_t *res;
549 int fnum;
550
551 (void) cls;
552 fnum = PQfnumber (result,
553 fname);
554 if (fnum < 0)
555 {
556 GNUNET_break (0);
557 return GNUNET_SYSERR;
558 }
559 if (PQgetisnull (result,
560 row,
561 fnum))
562 {
563 GNUNET_break (0);
564 return GNUNET_SYSERR;
565 }
566 GNUNET_assert (NULL != dst);
567 if (sizeof (struct GNUNET_TIME_Absolute) != *dst_size)
568 {
569 GNUNET_break (0);
570 return GNUNET_SYSERR;
571 }
572 if (sizeof (int64_t) !=
573 PQgetlength (result,
574 row,
575 fnum))
576 {
577 GNUNET_break (0);
578 return GNUNET_SYSERR;
579 }
580 res = (int64_t *) PQgetvalue (result,
581 row,
582 fnum);
583 if (INT64_MAX == *res)
584 *udst = GNUNET_TIME_UNIT_FOREVER_ABS;
585 else
586 udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
587 return GNUNET_OK;
588}
589
590
591/**
518 * Absolute time expected. 592 * Absolute time expected.
519 * 593 *
520 * @param name name of the field in the table 594 * @param name name of the field in the table
@@ -525,8 +599,12 @@ struct GNUNET_PQ_ResultSpec
525GNUNET_PQ_result_spec_absolute_time (const char *name, 599GNUNET_PQ_result_spec_absolute_time (const char *name,
526 struct GNUNET_TIME_Absolute *at) 600 struct GNUNET_TIME_Absolute *at)
527{ 601{
528 return GNUNET_PQ_result_spec_uint64 (name, 602 struct GNUNET_PQ_ResultSpec res =
529 &at->abs_value_us); 603 { &extract_abs_time,
604 NULL,
605 NULL,
606 (void *) at, sizeof (*at), (name), NULL };
607 return res;
530} 608}
531 609
532 610
@@ -572,6 +650,7 @@ extract_uint16 (void *cls,
572 const uint16_t *res; 650 const uint16_t *res;
573 int fnum; 651 int fnum;
574 652
653 (void) cls;
575 fnum = PQfnumber (result, 654 fnum = PQfnumber (result,
576 fname); 655 fname);
577 if (fnum < 0) 656 if (fnum < 0)
@@ -653,6 +732,7 @@ extract_uint32 (void *cls,
653 const uint32_t *res; 732 const uint32_t *res;
654 int fnum; 733 int fnum;
655 734
735 (void) cls;
656 fnum = PQfnumber (result, 736 fnum = PQfnumber (result,
657 fname); 737 fname);
658 if (fnum < 0) 738 if (fnum < 0)
@@ -734,6 +814,7 @@ extract_uint64 (void *cls,
734 const uint64_t *res; 814 const uint64_t *res;
735 int fnum; 815 int fnum;
736 816
817 (void) cls;
737 fnum = PQfnumber (result, 818 fnum = PQfnumber (result,
738 fname); 819 fname);
739 if (fnum < 0) 820 if (fnum < 0)
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index 5ef42187f..4a7a89b15 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -42,6 +42,11 @@
42static uint32_t num_peers; 42static uint32_t num_peers;
43 43
44/** 44/**
45 * @brief numer of bits required to represent the largest peer id
46 */
47static unsigned bits_needed;
48
49/**
45 * How long do we run the test? 50 * How long do we run the test?
46 * In seconds. 51 * In seconds.
47 */ 52 */
@@ -1698,6 +1703,7 @@ profiler_reply_handle (void *cls,
1698 char *file_name; 1703 char *file_name;
1699 char *file_name_dh; 1704 char *file_name_dh;
1700 char *file_name_dhr; 1705 char *file_name_dhr;
1706 char *file_name_dhru;
1701 unsigned int i; 1707 unsigned int i;
1702 struct PendingReply *pending_rep = (struct PendingReply *) cls; 1708 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1703 1709
@@ -1706,6 +1712,7 @@ profiler_reply_handle (void *cls,
1706 file_name = "/tmp/rps/received_ids"; 1712 file_name = "/tmp/rps/received_ids";
1707 file_name_dh = "/tmp/rps/diehard_input"; 1713 file_name_dh = "/tmp/rps/diehard_input";
1708 file_name_dhr = "/tmp/rps/diehard_input_raw"; 1714 file_name_dhr = "/tmp/rps/diehard_input_raw";
1715 file_name_dhru = "/tmp/rps/diehard_input_raw_aligned";
1709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1710 "[%s] got %" PRIu64 " peers:\n", 1717 "[%s] got %" PRIu64 " peers:\n",
1711 GNUNET_i2s (rps_peer->peer_id), 1718 GNUNET_i2s (rps_peer->peer_id),
@@ -1725,8 +1732,12 @@ profiler_reply_handle (void *cls,
1725 "%" PRIu32 "\n", 1732 "%" PRIu32 "\n",
1726 (uint32_t) rcv_rps_peer->index); 1733 (uint32_t) rcv_rps_peer->index);
1727 to_file_raw (file_name_dhr, 1734 to_file_raw (file_name_dhr,
1728 &rcv_rps_peer->index, 1735 (char *) &rcv_rps_peer->index,
1729 sizeof (uint32_t)); 1736 sizeof (uint32_t));
1737 to_file_raw_unaligned (file_name_dhru,
1738 (char *) &rcv_rps_peer->index,
1739 sizeof (uint32_t),
1740 bits_needed);
1730 } 1741 }
1731 default_reply_handle (cls, n, recv_peers); 1742 default_reply_handle (cls, n, recv_peers);
1732} 1743}
@@ -2626,6 +2637,14 @@ run (void *cls,
2626 GNUNET_DISK_directory_create ("/tmp/rps/"); 2637 GNUNET_DISK_directory_create ("/tmp/rps/");
2627 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); 2638 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s);
2628 2639
2640 /* Compute number of bits for representing largest peer id */
2641 for (bits_needed = 1; (bits_needed << 1) < num_peers - 1; bits_needed++)
2642 ;
2643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2644 "Need %u bits to represent largest peer id %" PRIu32 "\n",
2645 bits_needed,
2646 num_peers - 1);
2647
2629 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); 2648 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
2630 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); 2649 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
2631 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); 2650 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index ea55deac5..9a1dfe0d8 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -29,13 +29,26 @@
29 29
30#include <inttypes.h> 30#include <inttypes.h>
31 31
32#define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__)
33 33
34#ifndef TO_FILE 34#ifndef TO_FILE
35#define TO_FILE 35#define TO_FILE
36#endif /* TO_FILE */ 36#endif /* TO_FILE */
37 37
38#ifdef TO_FILE 38#ifdef TO_FILE
39
40#define min(x,y) ((x) > (y) ? (y) : (x))
41
42/**
43 * @brief buffer for storing the unaligned bits for the next write
44 */
45static char buf_unaligned;
46
47/**
48 * @brief number of bits in unaligned buffer
49 */
50static unsigned num_bits_buf_unaligned;
51
39void 52void
40to_file_ (const char *file_name, char *line) 53to_file_ (const char *file_name, char *line)
41{ 54{
@@ -108,11 +121,10 @@ to_file_ (const char *file_name, char *line)
108} 121}
109 122
110void 123void
111to_file_raw (const char *file_name, void *buf, size_t size_buf) 124to_file_raw (const char *file_name, const char *buf, size_t size_buf)
112{ 125{
113 struct GNUNET_DISK_FileHandle *f; 126 struct GNUNET_DISK_FileHandle *f;
114 size_t size2; 127 size_t size_written;
115
116 128
117 if (NULL == (f = GNUNET_DISK_file_open (file_name, 129 if (NULL == (f = GNUNET_DISK_file_open (file_name,
118 GNUNET_DISK_OPEN_APPEND | 130 GNUNET_DISK_OPEN_APPEND |
@@ -129,13 +141,13 @@ to_file_raw (const char *file_name, void *buf, size_t size_buf)
129 return; 141 return;
130 } 142 }
131 143
132 size2 = GNUNET_DISK_file_write (f, buf, size_buf); 144 size_written = GNUNET_DISK_file_write (f, buf, size_buf);
133 if (size_buf != size2) 145 if (size_buf != size_written)
134 { 146 {
135 LOG (GNUNET_ERROR_TYPE_WARNING, 147 LOG (GNUNET_ERROR_TYPE_WARNING,
136 "Unable to write to file! (Size: %u, size2: %u)\n", 148 "Unable to write to file! (Size: %u, size_written: %u)\n",
137 size_buf, 149 size_buf,
138 size2); 150 size_written);
139 151
140 if (GNUNET_YES != GNUNET_DISK_file_close (f)) 152 if (GNUNET_YES != GNUNET_DISK_file_close (f))
141 LOG (GNUNET_ERROR_TYPE_WARNING, 153 LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -143,15 +155,110 @@ to_file_raw (const char *file_name, void *buf, size_t size_buf)
143 155
144 return; 156 return;
145 } 157 }
158}
146 159
147 //if (512 < size_buf) 160void
161to_file_raw_unaligned (const char *file_name,
162 const char *buf,
163 size_t size_buf,
164 unsigned bits_needed)
165{
166 // TODO endianness!
167 GNUNET_assert (size_buf >= (bits_needed/8));
168 //if (0 == num_bits_buf_unaligned)
148 //{ 169 //{
149 // GNUNET_free (output_buffer_p); 170 // if (0 == (bits_needed % 8))
171 // {
172 // to_file_raw (file_name, buf, size_buf);
173 // return;
174 // }
175 // to_file_raw (file_name, buf, size_buf - 1);
176 // buf_unaligned = buf[size_buf - 1];
177 // num_bits_buf_unaligned = bits_needed % 8;
178 // return;
150 //} 179 //}
151 180
152 //if (GNUNET_YES != GNUNET_DISK_file_close (f)) 181 char buf_write[size_buf + 1];
153 // LOG (GNUNET_ERROR_TYPE_WARNING, 182 const unsigned bytes_iter = (0 != bits_needed % 8?
154 // "Unable to close file\n"); 183 (bits_needed/8)+1:
184 bits_needed/8);
185 // TODO what if no iteration happens?
186 unsigned size_buf_write = 0;
187 buf_write[0] = buf_unaligned;
188 /* Iterate over input bytes */
189 for (unsigned i = 0; i < bytes_iter; i++)
190 {
191 /* Number of bits needed in this iteration - 8 for all except last iter */
192 unsigned num_bits_needed_iter;
193 /* Mask for bits to actually use */
194 unsigned mask_bits_needed_iter;
195 char byte_input;
196 /* Number of bits needed to align unaligned byte */
197 unsigned num_bits_to_align;
198 /* Number of bits that are to be moved */
199 unsigned num_bits_to_move;
200 /* Mask for bytes to be moved */
201 char mask_input_to_move;
202 /* Masked bits to be moved */
203 char bits_to_move;
204 /* The amount of bits needed to fit the bits to shift to the nearest spot */
205 unsigned distance_shift_bits;
206 /* Shifted bits on the move */
207 char bits_moving;
208 /* (unaligned) byte being filled with bits */
209 char byte_to_fill;
210 /* mask for needed bits of the input byte that have not been moved */
211 char mask_input_leftover;
212 /* needed bits of the input byte that have not been moved */
213 char byte_input_leftover;
214 unsigned num_bits_leftover;
215 unsigned num_bits_discard;
216 char byte_unaligned_new;
217
218 if ( (bits_needed - (i * 8)) <= 8)
219 {
220 /* last iteration */
221 num_bits_needed_iter = bits_needed - (i * 8);
222 }
223 else
224 {
225 num_bits_needed_iter = 8;
226 }
227 mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1;
228 byte_input = buf[i];
229 byte_input &= mask_bits_needed_iter;
230 num_bits_to_align = 8 - num_bits_buf_unaligned;
231 num_bits_to_move = min (num_bits_to_align, num_bits_needed_iter);
232 mask_input_to_move = ((char) 1 << num_bits_to_move) - 1;
233 bits_to_move = byte_input & mask_input_to_move;
234 distance_shift_bits = num_bits_buf_unaligned;
235 bits_moving = bits_to_move << distance_shift_bits;
236 byte_to_fill = buf_unaligned | bits_moving;
237 if (num_bits_buf_unaligned + num_bits_needed_iter > 8)
238 {
239 /* buf_unaligned was aligned by filling
240 * -> can be written to storage */
241 buf_write[i] = byte_to_fill;
242 size_buf_write++;
243
244 /* store the leftover, unaligned bits in buffer */
245 mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move);
246 byte_input_leftover = byte_input & mask_input_leftover;
247 num_bits_leftover = num_bits_needed_iter - num_bits_to_move;
248 num_bits_discard = 8 - num_bits_needed_iter;
249 byte_unaligned_new = byte_input_leftover >> num_bits_to_move;
250 buf_unaligned = byte_unaligned_new;
251 num_bits_buf_unaligned = num_bits_leftover % 8;
252 }
253 else
254 {
255 /* unaligned buffer still unaligned but 'fuller' */
256 buf_unaligned = byte_to_fill;
257 num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8;
258 }
259 }
260 to_file_raw (file_name, buf_write, size_buf_write);
261 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
155} 262}
156 263
157char * 264char *
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index d42422750..577a2b0a7 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -75,7 +75,13 @@ store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
75 const char *prefix); 75 const char *prefix);
76 76
77void 77void
78to_file_raw (const char *file_name, void *buf, size_t size_buf); 78to_file_raw (const char *file_name, const char *buf, size_t size_buf);
79
80void
81to_file_raw_unaligned (const char *file_name,
82 const char *buf,
83 size_t size_buf,
84 unsigned bits_needed);
79 85
80#endif /* RPS_TEST_UTIL_H */ 86#endif /* RPS_TEST_UTIL_H */
81/* end of gnunet-service-rps.c */ 87/* end of gnunet-service-rps.c */