diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-31 22:04:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-31 22:04:58 +0000 |
commit | 5cd32557ec0517ead0afe2c71d1e0a14b0027dd6 (patch) | |
tree | f79d2517ef45bcd4685623390e9954e086578eb3 /src/core | |
parent | 5848ebddf1977bbe346550b77a305e4f5d243e95 (diff) | |
download | gnunet-5cd32557ec0517ead0afe2c71d1e0a14b0027dd6.tar.gz gnunet-5cd32557ec0517ead0afe2c71d1e0a14b0027dd6.zip |
short timeout, transmission based on receiving to avoid reordering and overflowing queues
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/test_core_api_reliability.c | 89 |
1 files changed, 64 insertions, 25 deletions
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 3e4b81bef..a88c05f43 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | #include "gnunet_constants.h" | ||
29 | #include "gnunet_arm_service.h" | 30 | #include "gnunet_arm_service.h" |
30 | #include "gnunet_core_service.h" | 31 | #include "gnunet_core_service.h" |
31 | #include "gnunet_getopt_lib.h" | 32 | #include "gnunet_getopt_lib.h" |
@@ -43,6 +44,13 @@ | |||
43 | */ | 44 | */ |
44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
45 | 46 | ||
47 | /** | ||
48 | * What delay do we request from the core service for transmission? | ||
49 | * Any value smaller than the CORK delay will disable CORKing, which | ||
50 | * is what we want here. | ||
51 | */ | ||
52 | #define FAST_TIMEOUT GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2) | ||
53 | |||
46 | #define MTYPE 12345 | 54 | #define MTYPE 12345 |
47 | 55 | ||
48 | 56 | ||
@@ -108,9 +116,13 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
108 | unsigned long long delta; | 116 | unsigned long long delta; |
109 | 117 | ||
110 | GNUNET_CORE_disconnect (p1.ch); | 118 | GNUNET_CORE_disconnect (p1.ch); |
119 | p1.ch = NULL; | ||
111 | GNUNET_CORE_disconnect (p2.ch); | 120 | GNUNET_CORE_disconnect (p2.ch); |
121 | p2.ch = NULL; | ||
112 | GNUNET_TRANSPORT_disconnect (p1.th); | 122 | GNUNET_TRANSPORT_disconnect (p1.th); |
123 | p1.th = NULL; | ||
113 | GNUNET_TRANSPORT_disconnect (p2.th); | 124 | GNUNET_TRANSPORT_disconnect (p2.th); |
125 | p2.th = NULL; | ||
114 | delta = GNUNET_TIME_absolute_get_duration (start_time).value; | 126 | delta = GNUNET_TIME_absolute_get_duration (start_time).value; |
115 | fprintf (stderr, | 127 | fprintf (stderr, |
116 | "\nThroughput was %llu kb/s\n", | 128 | "\nThroughput was %llu kb/s\n", |
@@ -124,9 +136,13 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
124 | { | 136 | { |
125 | GNUNET_break (0); | 137 | GNUNET_break (0); |
126 | GNUNET_CORE_disconnect (p1.ch); | 138 | GNUNET_CORE_disconnect (p1.ch); |
139 | p1.ch = NULL; | ||
127 | GNUNET_CORE_disconnect (p2.ch); | 140 | GNUNET_CORE_disconnect (p2.ch); |
141 | p2.ch = NULL; | ||
128 | GNUNET_TRANSPORT_disconnect (p1.th); | 142 | GNUNET_TRANSPORT_disconnect (p1.th); |
143 | p1.th = NULL; | ||
129 | GNUNET_TRANSPORT_disconnect (p2.th); | 144 | GNUNET_TRANSPORT_disconnect (p2.th); |
145 | p2.th = NULL; | ||
130 | ok = 42; | 146 | ok = 42; |
131 | } | 147 | } |
132 | 148 | ||
@@ -187,6 +203,12 @@ outbound_notify (void *cls, | |||
187 | static GNUNET_SCHEDULER_TaskIdentifier err_task; | 203 | static GNUNET_SCHEDULER_TaskIdentifier err_task; |
188 | 204 | ||
189 | 205 | ||
206 | static size_t | ||
207 | transmit_ready (void *cls, size_t size, void *buf); | ||
208 | |||
209 | static int tr_n; | ||
210 | |||
211 | |||
190 | static int | 212 | static int |
191 | process_mtype (void *cls, | 213 | process_mtype (void *cls, |
192 | const struct GNUNET_PeerIdentity *peer, | 214 | const struct GNUNET_PeerIdentity *peer, |
@@ -238,6 +260,17 @@ process_mtype (void *cls, | |||
238 | GNUNET_SCHEDULER_cancel (sched, err_task); | 260 | GNUNET_SCHEDULER_cancel (sched, err_task); |
239 | GNUNET_SCHEDULER_add_now (sched, &terminate_task, NULL); | 261 | GNUNET_SCHEDULER_add_now (sched, &terminate_task, NULL); |
240 | } | 262 | } |
263 | else | ||
264 | { | ||
265 | if (n == tr_n) | ||
266 | GNUNET_break (NULL != | ||
267 | GNUNET_CORE_notify_transmit_ready (p1.ch, | ||
268 | 0, | ||
269 | FAST_TIMEOUT, | ||
270 | &p2.id, | ||
271 | sizeof (struct GNUNET_MessageHeader), | ||
272 | &transmit_ready, &p1)); | ||
273 | } | ||
241 | return GNUNET_OK; | 274 | return GNUNET_OK; |
242 | } | 275 | } |
243 | 276 | ||
@@ -251,52 +284,58 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
251 | static size_t | 284 | static size_t |
252 | transmit_ready (void *cls, size_t size, void *buf) | 285 | transmit_ready (void *cls, size_t size, void *buf) |
253 | { | 286 | { |
254 | static int n; | ||
255 | char *cbuf = buf; | 287 | char *cbuf = buf; |
256 | struct TestMessage hdr; | 288 | struct TestMessage hdr; |
257 | unsigned int s; | 289 | unsigned int s; |
258 | unsigned int ret; | 290 | unsigned int ret; |
259 | 291 | ||
292 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); | ||
260 | if (buf == NULL) | 293 | if (buf == NULL) |
261 | { | 294 | { |
262 | GNUNET_break (0); | 295 | if (p1.ch != NULL) |
263 | ok = 42; | 296 | GNUNET_break (NULL != |
297 | GNUNET_CORE_notify_transmit_ready (p1.ch, | ||
298 | 0, | ||
299 | FAST_TIMEOUT, | ||
300 | &p2.id, | ||
301 | sizeof (struct GNUNET_MessageHeader), | ||
302 | &transmit_ready, &p1)); | ||
264 | return 0; | 303 | return 0; |
265 | } | 304 | } |
305 | GNUNET_assert (tr_n < TOTAL_MSGS); | ||
266 | ret = 0; | 306 | ret = 0; |
267 | s = get_size (n); | 307 | s = get_size (tr_n); |
268 | GNUNET_assert (size >= s); | 308 | GNUNET_assert (size >= s); |
269 | GNUNET_assert (buf != NULL); | 309 | GNUNET_assert (buf != NULL); |
270 | cbuf = buf; | 310 | cbuf = buf; |
271 | do | 311 | do |
272 | { | 312 | { |
313 | #if VERBOSE | ||
314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
315 | "Sending message %u of size %u at offset %u\n", | ||
316 | tr_n, | ||
317 | s, | ||
318 | ret); | ||
319 | #endif | ||
273 | hdr.header.size = htons (s); | 320 | hdr.header.size = htons (s); |
274 | hdr.header.type = htons (MTYPE); | 321 | hdr.header.type = htons (MTYPE); |
275 | hdr.num = htonl (n); | 322 | hdr.num = htonl (tr_n); |
276 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 323 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
277 | ret += sizeof (struct TestMessage); | 324 | ret += sizeof (struct TestMessage); |
278 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | 325 | memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage)); |
279 | ret += s - sizeof (struct TestMessage); | 326 | ret += s - sizeof (struct TestMessage); |
280 | #if VERBOSE | 327 | tr_n++; |
281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 328 | s = get_size (tr_n); |
282 | "Sending message %u of size %u\n", | ||
283 | n, | ||
284 | s); | ||
285 | #endif | ||
286 | n++; | ||
287 | s = get_size (n); | ||
288 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 329 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
289 | break; /* sometimes pack buffer full, sometimes not */ | 330 | break; /* sometimes pack buffer full, sometimes not */ |
290 | } | 331 | } |
291 | while (size - ret >= s); | 332 | while (size - ret >= s); |
292 | if (n < TOTAL_MSGS) | 333 | GNUNET_SCHEDULER_cancel (sched, err_task); |
293 | GNUNET_break (NULL != | 334 | err_task = |
294 | GNUNET_CORE_notify_transmit_ready (p1.ch, | 335 | GNUNET_SCHEDULER_add_delayed (sched, |
295 | 0, | 336 | TIMEOUT, |
296 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), | 337 | &terminate_task_error, |
297 | &p2.id, | 338 | NULL); |
298 | sizeof (struct GNUNET_MessageHeader), | ||
299 | &transmit_ready, &p1)); | ||
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
301 | "Returning total message block of size %u\n", | 340 | "Returning total message block of size %u\n", |
302 | ret); | 341 | ret); |
@@ -315,7 +354,7 @@ init_notify (void *cls, | |||
315 | struct PeerContext *p = cls; | 354 | struct PeerContext *p = cls; |
316 | 355 | ||
317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
318 | "Core connection to `%4s' established\n", | 357 | "Connection to CORE service of `%4s' established\n", |
319 | GNUNET_i2s (my_identity)); | 358 | GNUNET_i2s (my_identity)); |
320 | GNUNET_assert (server != NULL); | 359 | GNUNET_assert (server != NULL); |
321 | p->id = *my_identity; | 360 | p->id = *my_identity; |
@@ -346,14 +385,14 @@ init_notify (void *cls, | |||
346 | GNUNET_i2s (&p2.id)); | 385 | GNUNET_i2s (&p2.id)); |
347 | err_task = | 386 | err_task = |
348 | GNUNET_SCHEDULER_add_delayed (sched, | 387 | GNUNET_SCHEDULER_add_delayed (sched, |
349 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | 388 | TIMEOUT, |
350 | &terminate_task_error, | 389 | &terminate_task_error, |
351 | NULL); | 390 | NULL); |
352 | start_time = GNUNET_TIME_absolute_get (); | 391 | start_time = GNUNET_TIME_absolute_get (); |
353 | GNUNET_break (NULL != | 392 | GNUNET_break (NULL != |
354 | GNUNET_CORE_notify_transmit_ready (p1.ch, | 393 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
355 | 0, | 394 | 0, |
356 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45), | 395 | TIMEOUT, |
357 | &p2.id, | 396 | &p2.id, |
358 | sizeof (struct GNUNET_MessageHeader), | 397 | sizeof (struct GNUNET_MessageHeader), |
359 | &transmit_ready, &p1)); | 398 | &transmit_ready, &p1)); |