aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-12-26 02:21:17 +0900
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-12-26 02:21:17 +0900
commitc1cf4ec20a9a3f5e804e83986dbdb8b8a0bb9ce5 (patch)
tree384eb2d9f28d9a425728dab1644a398aba83b933 /src
parent025568d66f1b4bf4007d8effdd73e3f36f26f78b (diff)
parent1a4bd09e63df2300845fcb9bfa150f28943b9aea (diff)
downloadgnunet-c1cf4ec20a9a3f5e804e83986dbdb8b8a0bb9ce5.tar.gz
gnunet-c1cf4ec20a9a3f5e804e83986dbdb8b8a0bb9ce5.zip
merge
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_common.h14
-rw-r--r--src/transport/test_communicator_basic.c57
-rw-r--r--src/transport/transport_api2_communication.c6
-rw-r--r--src/util/.gitignore1
-rw-r--r--src/util/common_allocation.c27
-rw-r--r--src/util/common_endian.c8
-rw-r--r--src/util/perf_malloc.c39
7 files changed, 109 insertions, 43 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 3ac186e0b..36f9eee4a 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -997,6 +997,11 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
997 997
998/* ************************* endianess conversion ****************** */ 998/* ************************* endianess conversion ****************** */
999 999
1000#ifdef htonbe64
1001
1002#define GNUNET_htonll(n) htobe64 (n)
1003
1004#else
1000/** 1005/**
1001 * Convert unsigned 64-bit integer to network byte order. 1006 * Convert unsigned 64-bit integer to network byte order.
1002 * 1007 *
@@ -1008,7 +1013,14 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind);
1008uint64_t 1013uint64_t
1009GNUNET_htonll (uint64_t n); 1014GNUNET_htonll (uint64_t n);
1010 1015
1016#endif
1017
1011 1018
1019#ifdef be64toh
1020
1021#define GNUNET_ntohll(n) be64toh (n)
1022
1023#else
1012/** 1024/**
1013 * Convert unsigned 64-bit integer to host byte order. 1025 * Convert unsigned 64-bit integer to host byte order.
1014 * 1026 *
@@ -1020,6 +1032,8 @@ GNUNET_htonll (uint64_t n);
1020uint64_t 1032uint64_t
1021GNUNET_ntohll (uint64_t n); 1033GNUNET_ntohll (uint64_t n);
1022 1034
1035#endif
1036
1023 1037
1024/** 1038/**
1025 * Convert double to network byte order. 1039 * Convert double to network byte order.
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c
index 4dba9d50c..db396ba66 100644
--- a/src/transport/test_communicator_basic.c
+++ b/src/transport/test_communicator_basic.c
@@ -64,6 +64,8 @@ static struct GNUNET_TIME_Absolute start_short;
64 64
65static struct GNUNET_TIME_Absolute start_long; 65static struct GNUNET_TIME_Absolute start_long;
66 66
67static struct GNUNET_TIME_Absolute timeout;
68
67static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; 69static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc;
68 70
69#define SHORT_MESSAGE_SIZE 128 71#define SHORT_MESSAGE_SIZE 128
@@ -74,7 +76,7 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc;
74 76
75#define FIXME_DEAD_BURST_RUNS 1 77#define FIXME_DEAD_BURST_RUNS 1
76 78
77#define TOTAL_ITERATIONS 10 79#define TOTAL_ITERATIONS 20
78 80
79static unsigned int iterations_left = TOTAL_ITERATIONS; 81static unsigned int iterations_left = TOTAL_ITERATIONS;
80 82
@@ -196,6 +198,14 @@ static void
196latency_timeout (void *cls) 198latency_timeout (void *cls)
197{ 199{
198 to_task = NULL; 200 to_task = NULL;
201 if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0)
202 {
203 to_task = GNUNET_SCHEDULER_add_at (timeout,
204 &latency_timeout,
205 NULL);
206 return;
207 }
208
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
200 "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", 210 "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n",
201 phase, num_sent, num_received); 211 phase, num_sent, num_received);
@@ -220,10 +230,7 @@ size_test (void *cls)
220 GNUNET_free (payload); 230 GNUNET_free (payload);
221 ack += 5; 231 ack += 5;
222 num_sent++; 232 num_sent++;
223 if (NULL == to_task) 233 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
224 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
225 &latency_timeout,
226 NULL);
227 if (ack < 64000) 234 if (ack < 64000)
228 active_task = GNUNET_SCHEDULER_add_now (&size_test, 235 active_task = GNUNET_SCHEDULER_add_now (&size_test,
229 NULL); 236 NULL);
@@ -242,10 +249,7 @@ long_test (void *cls)
242 LONG_MESSAGE_SIZE); 249 LONG_MESSAGE_SIZE);
243 num_sent++; 250 num_sent++;
244 GNUNET_free (payload); 251 GNUNET_free (payload);
245 if (NULL == to_task) 252 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
246 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
247 &latency_timeout,
248 NULL);
249 if (num_sent == BURST_PACKETS) 253 if (num_sent == BURST_PACKETS)
250 return; 254 return;
251 active_task = GNUNET_SCHEDULER_add_now (&long_test, 255 active_task = GNUNET_SCHEDULER_add_now (&long_test,
@@ -265,10 +269,7 @@ short_test (void *cls)
265 SHORT_MESSAGE_SIZE); 269 SHORT_MESSAGE_SIZE);
266 num_sent++; 270 num_sent++;
267 GNUNET_free (payload); 271 GNUNET_free (payload);
268 if (NULL == to_task) 272 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
269 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
270 &latency_timeout,
271 NULL);
272 if (num_sent >= BURST_PACKETS) 273 if (num_sent >= BURST_PACKETS)
273 return; 274 return;
274 active_task = GNUNET_SCHEDULER_add_now (&short_test, 275 active_task = GNUNET_SCHEDULER_add_now (&short_test,
@@ -300,6 +301,11 @@ add_queue_cb (void *cls,
300 start_short = GNUNET_TIME_absolute_get (); 301 start_short = GNUNET_TIME_absolute_get ();
301 my_tc = tc_queue; 302 my_tc = tc_queue;
302 phase = TP_BURST_SHORT; 303 phase = TP_BURST_SHORT;
304 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
305 GNUNET_assert (NULL == to_task);
306 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
307 &latency_timeout,
308 NULL);
303 GNUNET_assert (NULL == active_task); 309 GNUNET_assert (NULL == active_task);
304 active_task = GNUNET_SCHEDULER_add_now (&short_test, 310 active_task = GNUNET_SCHEDULER_add_now (&short_test,
305 NULL); 311 NULL);
@@ -347,6 +353,8 @@ incoming_message_cb (void *cls,
347 "unexpected receiver...\n"); 353 "unexpected receiver...\n");
348 return; 354 return;
349 } 355 }
356 /* Reset timeout */
357 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
350 switch (phase) 358 switch (phase)
351 { 359 {
352 case TP_BURST_SHORT: 360 case TP_BURST_SHORT:
@@ -374,11 +382,6 @@ incoming_message_cb (void *cls,
374 num_sent = 0; 382 num_sent = 0;
375 avg_latency = 0; 383 avg_latency = 0;
376 num_received = 0; 384 num_received = 0;
377 if (NULL != to_task)
378 {
379 GNUNET_SCHEDULER_cancel (to_task);
380 to_task = NULL;
381 }
382 active_task = GNUNET_SCHEDULER_add_now (&long_test, 385 active_task = GNUNET_SCHEDULER_add_now (&long_test,
383 NULL); 386 NULL);
384 } 387 }
@@ -414,11 +417,6 @@ incoming_message_cb (void *cls,
414 num_received = 0; 417 num_received = 0;
415 num_sent = 0; 418 num_sent = 0;
416 avg_latency = 0; 419 avg_latency = 0;
417 if (NULL != to_task)
418 {
419 GNUNET_SCHEDULER_cancel (to_task);
420 to_task = NULL;
421 }
422 active_task = GNUNET_SCHEDULER_add_now (&size_test, 420 active_task = GNUNET_SCHEDULER_add_now (&size_test,
423 NULL); 421 NULL);
424 } 422 }
@@ -440,11 +438,6 @@ incoming_message_cb (void *cls,
440 num_received = 0; 438 num_received = 0;
441 num_sent = 0; 439 num_sent = 0;
442 avg_latency = 0; 440 avg_latency = 0;
443 if (NULL != to_task)
444 {
445 GNUNET_SCHEDULER_cancel (to_task);
446 to_task = NULL;
447 }
448 iterations_left--; 441 iterations_left--;
449 if (0 != iterations_left) 442 if (0 != iterations_left)
450 { 443 {
@@ -460,14 +453,6 @@ incoming_message_cb (void *cls,
460 break; 453 break;
461 } 454 }
462 } 455 }
463 /* Reset timeout */
464 if (NULL != to_task)
465 {
466 GNUNET_SCHEDULER_cancel (to_task);
467 to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
468 &latency_timeout,
469 NULL);
470 }
471} 456}
472 457
473 458
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index de5b42c3f..9df9424da 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -872,7 +872,7 @@ GNUNET_TRANSPORT_communicator_receive (
872 { 872 {
873 GNUNET_log ( 873 GNUNET_log (
874 GNUNET_ERROR_TYPE_WARNING, 874 GNUNET_ERROR_TYPE_WARNING,
875 "Dropping message: transprot is too slow, queue length %llu exceeded\n", 875 "Dropping message: transport is too slow, queue length %llu exceeded\n",
876 ch->max_queue_length); 876 ch->max_queue_length);
877 return GNUNET_NO; 877 return GNUNET_NO;
878 } 878 }
@@ -888,6 +888,10 @@ GNUNET_TRANSPORT_communicator_receive (
888 im->expected_address_validity = 888 im->expected_address_validity =
889 GNUNET_TIME_relative_hton (expected_addr_validity); 889 GNUNET_TIME_relative_hton (expected_addr_validity);
890 im->sender = *sender; 890 im->sender = *sender;
891 // FIXME: this is expensive, would be better if we would
892 // re-design the API to allow us to create the envelope first,
893 // and then have the application fill in the body so we do
894 // not have to memcpy()
891 memcpy (&im[1], msg, msize); 895 memcpy (&im[1], msg, msize);
892 if (NULL != cb) 896 if (NULL != cb)
893 { 897 {
diff --git a/src/util/.gitignore b/src/util/.gitignore
index dfa6c7947..01ebcc834 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -74,3 +74,4 @@ test_regex
74test_tun 74test_tun
75gnunet-timeout 75gnunet-timeout
76python27_location 76python27_location
77perf_malloc
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 137af7b85..35c557000 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -265,6 +265,30 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
265 ptr = &((size_t *) ptr)[-1]; 265 ptr = &((size_t *) ptr)[-1];
266 mem_used = mem_used - *((size_t *) ptr) + n; 266 mem_used = mem_used - *((size_t *) ptr) + n;
267#endif 267#endif
268#if defined(M_SIZE)
269#if ENABLE_POISONING
270 {
271 uint64_t *base = ptr;
272 size_t s = M_SIZE (ptr);
273
274 if (s > n)
275 {
276 const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
277 char *cbase = ptr;
278
279 GNUNET_memcpy (&cbase[n],
280 &baadfood,
281 GNUNET_MIN (8 - (n % 8),
282 s - n));
283 for (size_t i = 1 + (n + 7) / 8; i < s / 8; i++)
284 base[i] = baadfood;
285 GNUNET_memcpy (&base[s / 8],
286 &baadfood,
287 s % 8);
288 }
289 }
290#endif
291#endif
268 ptr = realloc (ptr, n); 292 ptr = realloc (ptr, n);
269 if ((NULL == ptr) && (n > 0)) 293 if ((NULL == ptr) && (n > 0))
270 { 294 {
@@ -316,9 +340,8 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
316 const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL); 340 const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
317 uint64_t *base = ptr; 341 uint64_t *base = ptr;
318 size_t s = M_SIZE (ptr); 342 size_t s = M_SIZE (ptr);
319 size_t i;
320 343
321 for (i = 0; i < s / 8; i++) 344 for (size_t i = 0; i < s / 8; i++)
322 base[i] = baadfood; 345 base[i] = baadfood;
323 GNUNET_memcpy (&base[s / 8], &baadfood, s % 8); 346 GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
324 } 347 }
diff --git a/src/util/common_endian.c b/src/util/common_endian.c
index fa7d99d85..d69cc1da5 100644
--- a/src/util/common_endian.c
+++ b/src/util/common_endian.c
@@ -31,6 +31,7 @@
31#define LOG(kind, ...) GNUNET_log_from (kind, "util-common-endian", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from (kind, "util-common-endian", __VA_ARGS__)
32 32
33 33
34#ifndef htonbe64
34uint64_t 35uint64_t
35GNUNET_htonll (uint64_t n) 36GNUNET_htonll (uint64_t n)
36{ 37{
@@ -44,6 +45,10 @@ GNUNET_htonll (uint64_t n)
44} 45}
45 46
46 47
48#endif
49
50
51#ifndef be64toh
47uint64_t 52uint64_t
48GNUNET_ntohll (uint64_t n) 53GNUNET_ntohll (uint64_t n)
49{ 54{
@@ -57,6 +62,9 @@ GNUNET_ntohll (uint64_t n)
57} 62}
58 63
59 64
65#endif
66
67
60/** 68/**
61 * Convert double to network-byte-order. 69 * Convert double to network-byte-order.
62 * @param d the value in network byte order 70 * @param d the value in network byte order
diff --git a/src/util/perf_malloc.c b/src/util/perf_malloc.c
index 727e15979..6582505c8 100644
--- a/src/util/perf_malloc.c
+++ b/src/util/perf_malloc.c
@@ -28,13 +28,12 @@
28#include <gauger.h> 28#include <gauger.h>
29 29
30static uint64_t 30static uint64_t
31perfMalloc () 31perf_malloc ()
32{ 32{
33 size_t i;
34 uint64_t ret; 33 uint64_t ret;
35 34
36 ret = 0; 35 ret = 0;
37 for (i = 1; i < 1024 * 1024; i += 1024) 36 for (size_t i = 1; i < 1024 * 1024; i += 1024)
38 { 37 {
39 ret += i; 38 ret += i;
40 GNUNET_free (GNUNET_malloc (i)); 39 GNUNET_free (GNUNET_malloc (i));
@@ -43,6 +42,32 @@ perfMalloc ()
43} 42}
44 43
45 44
45static uint64_t
46perf_realloc ()
47{
48 uint64_t ret;
49
50 ret = 0;
51 for (size_t i = 10; i < 1024 * 1024 / 5; i += 1024)
52 {
53 char *ptr;
54
55 ret += i;
56 ptr = GNUNET_malloc (i);
57 memset (ptr, 1, i);
58 ptr = GNUNET_realloc (ptr, i + 5);
59 for (size_t j=0;j<i;j++)
60 GNUNET_assert (1 == ptr[j]);
61 memset (ptr, 6, i + 5);
62 ptr = GNUNET_realloc (ptr, i - 5);
63 for (size_t j=0;j<i-5;j++)
64 GNUNET_assert (6 == ptr[j]);
65 GNUNET_free (ptr);
66 }
67 return ret;
68}
69
70
46int 71int
47main (int argc, char *argv[]) 72main (int argc, char *argv[])
48{ 73{
@@ -50,7 +75,7 @@ main (int argc, char *argv[])
50 uint64_t kb; 75 uint64_t kb;
51 76
52 start = GNUNET_TIME_absolute_get (); 77 start = GNUNET_TIME_absolute_get ();
53 kb = perfMalloc (); 78 kb = perf_malloc ();
54 printf ("Malloc perf took %s\n", 79 printf ("Malloc perf took %s\n",
55 GNUNET_STRINGS_relative_time_to_string ( 80 GNUNET_STRINGS_relative_time_to_string (
56 GNUNET_TIME_absolute_get_duration (start), 81 GNUNET_TIME_absolute_get_duration (start),
@@ -59,6 +84,12 @@ main (int argc, char *argv[])
59 kb / 1024 / (1 84 kb / 1024 / (1
60 + GNUNET_TIME_absolute_get_duration 85 + GNUNET_TIME_absolute_get_duration
61 (start).rel_value_us / 1000LL), "kb/ms"); 86 (start).rel_value_us / 1000LL), "kb/ms");
87 start = GNUNET_TIME_absolute_get ();
88 kb = perf_realloc ();
89 printf ("Realloc perf took %s\n",
90 GNUNET_STRINGS_relative_time_to_string (
91 GNUNET_TIME_absolute_get_duration (start),
92 GNUNET_YES));
62 return 0; 93 return 0;
63} 94}
64 95