X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ffragmentation%2Ftest_fragmentation.c;h=cbfb8efe456df8f647eaee1a67fc0e1f4dd4c306;hb=6d754e6c89fda8cb0da00c4152ffc6dcc707e6ce;hp=8a9af04e794fe065451b679fb538755b70019094;hpb=6ce274c7e9fb01c76dc904d907fce9c893d0fc44;p=oweals%2Fgnunet.git diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c index 8a9af04e7..cbfb8efe4 100644 --- a/src/fragmentation/test_fragmentation.c +++ b/src/fragmentation/test_fragmentation.c @@ -25,14 +25,14 @@ #include "platform.h" #include "gnunet_fragmentation_lib.h" -#define VERBOSE GNUNET_NO +#define VERBOSE GNUNET_EXTRA_LOGGING #define DETAILS GNUNET_NO /** * Number of messages to transmit (note: each uses ~32k memory!) */ -#define NUM_MSGS 500 +#define NUM_MSGS 5000 /** * MTU to force on fragmentation (must be > 1k + 12) @@ -42,9 +42,9 @@ /** * Simulate dropping of 1 out of how many messages? (must be > 1) */ -#define DROPRATE 2 +#define DROPRATE 10 -static int ret = 1; +static int ret = 1; static unsigned int dups; @@ -62,38 +62,51 @@ static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS]; static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; +static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; + static void -proc_msgs (void *cls, - const struct GNUNET_MessageHeader *hdr) +do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + unsigned int i; + + ret = 0; + shutdown_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_DEFRAGMENT_context_destroy (defrag); + defrag = NULL; + for (i = 0; i < NUM_MSGS; i++) + { + if (frags[i] == NULL) + continue; + GNUNET_FRAGMENT_context_destroy (frags[i]); + frags[i] = NULL; + } +} + + +static void +proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) { static unsigned int total; unsigned int i; const char *buf; #if DETAILS - fprintf (stderr, "!"); /* message complete, good! */ + FPRINTF (stderr, "%s", "!"); /* message complete, good! */ #endif - buf = (const char*) hdr; - for (i=sizeof (struct GNUNET_MessageHeader);isize);i++) + buf = (const char *) hdr; + for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) GNUNET_assert (buf[i] == (char) i); total++; #if ! DETAILS if (0 == (total % (NUM_MSGS / 100))) - fprintf (stderr, "."); + FPRINTF (stderr, "%s", "."); #endif - if (total == NUM_MSGS) - { - ret = 0; - GNUNET_DEFRAGMENT_context_destroy (defrag); - defrag = NULL; - for (i=0;i= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) + { + if (GNUNET_SCHEDULER_NO_TASK == shutdown_task) + shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); + } } @@ -101,44 +114,42 @@ proc_msgs (void *cls, * Process ACK (by passing to fragmenter) */ static void -proc_acks (void *cls, - const struct GNUNET_MessageHeader *hdr) +proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) { unsigned int i; int ret; if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) - { - ack_drops++; - return; /* random drop */ - } - for (i=0;itype = htons ((uint16_t) i); - msg->size = htons (MTU + 1 + (17 * i) % (32 * 1024)); - frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */, - MTU, - &trackers[i], - GNUNET_TIME_UNIT_SECONDS, - msg, - &proc_frac, - NULL); - } + msg = (struct GNUNET_MessageHeader *) buf; + for (i = 0; i < NUM_MSGS; i++) + { + msg->type = htons ((uint16_t) i); + msg->size = + htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); + frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ , + MTU, &trackers[i], + GNUNET_TIME_UNIT_SECONDS, msg, + &proc_frac, &frags[i]); + } } @@ -243,16 +248,14 @@ main (int argc, char *argv[]) "WARNING", #endif NULL); - for (i=0;i