aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation/test_fragmentation_parallel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fragmentation/test_fragmentation_parallel.c')
-rw-r--r--src/fragmentation/test_fragmentation_parallel.c184
1 files changed, 92 insertions, 92 deletions
diff --git a/src/fragmentation/test_fragmentation_parallel.c b/src/fragmentation/test_fragmentation_parallel.c
index 6db9c55a9..000ca60d2 100644
--- a/src/fragmentation/test_fragmentation_parallel.c
+++ b/src/fragmentation/test_fragmentation_parallel.c
@@ -64,48 +64,48 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task;
64 64
65 65
66static void 66static void
67do_shutdown(void *cls) 67do_shutdown (void *cls)
68{ 68{
69 unsigned int i; 69 unsigned int i;
70 70
71 ret = 0; 71 ret = 0;
72 shutdown_task = NULL; 72 shutdown_task = NULL;
73 GNUNET_DEFRAGMENT_context_destroy(defrag); 73 GNUNET_DEFRAGMENT_context_destroy (defrag);
74 defrag = NULL; 74 defrag = NULL;
75 for (i = 0; i < NUM_MSGS; i++) 75 for (i = 0; i < NUM_MSGS; i++)
76 { 76 {
77 if (frags[i] == NULL) 77 if (frags[i] == NULL)
78 continue; 78 continue;
79 GNUNET_FRAGMENT_context_destroy(frags[i], NULL, NULL); 79 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
80 frags[i] = NULL; 80 frags[i] = NULL;
81 } 81 }
82} 82}
83 83
84 84
85static void 85static void
86proc_msgs(void *cls, const struct GNUNET_MessageHeader *hdr) 86proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
87{ 87{
88 static unsigned int total; 88 static unsigned int total;
89 unsigned int i; 89 unsigned int i;
90 const char *buf; 90 const char *buf;
91 91
92#if DETAILS 92#if DETAILS
93 fprintf(stderr, "%s", "!"); /* message complete, good! */ 93 fprintf (stderr, "%s", "!"); /* message complete, good! */
94#endif 94#endif
95 buf = (const char *)hdr; 95 buf = (const char *) hdr;
96 for (i = sizeof(struct GNUNET_MessageHeader); i < ntohs(hdr->size); i++) 96 for (i = sizeof(struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
97 GNUNET_assert(buf[i] == (char)i); 97 GNUNET_assert (buf[i] == (char) i);
98 total++; 98 total++;
99#if !DETAILS 99#if ! DETAILS
100 if (0 == (total % (NUM_MSGS / 100))) 100 if (0 == (total % (NUM_MSGS / 100)))
101 fprintf(stderr, "%s", "."); 101 fprintf (stderr, "%s", ".");
102#endif 102#endif
103 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ 103 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
104 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) 104 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
105 { 105 {
106 if (NULL == shutdown_task) 106 if (NULL == shutdown_task)
107 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 107 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
108 } 108 }
109} 109}
110 110
111 111
@@ -113,42 +113,42 @@ proc_msgs(void *cls, const struct GNUNET_MessageHeader *hdr)
113 * Process ACK (by passing to fragmenter) 113 * Process ACK (by passing to fragmenter)
114 */ 114 */
115static void 115static void
116proc_acks(void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) 116proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
117{ 117{
118 unsigned int i; 118 unsigned int i;
119 int ret; 119 int ret;
120 120
121 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) 121 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
122 { 122 {
123 ack_drops++; 123 ack_drops++;
124 return; /* random drop */ 124 return; /* random drop */
125 } 125 }
126 for (i = 0; i < NUM_MSGS; i++) 126 for (i = 0; i < NUM_MSGS; i++)
127 {
128 if (frags[i] == NULL)
129 continue;
130 ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr);
131 if (ret == GNUNET_OK)
127 { 132 {
128 if (frags[i] == NULL)
129 continue;
130 ret = GNUNET_FRAGMENT_process_ack(frags[i], hdr);
131 if (ret == GNUNET_OK)
132 {
133#if DETAILS 133#if DETAILS
134 fprintf(stderr, "%s", "@"); /* good ACK */ 134 fprintf (stderr, "%s", "@"); /* good ACK */
135#endif 135#endif
136 GNUNET_FRAGMENT_context_destroy(frags[i], NULL, NULL); 136 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
137 frags[i] = NULL; 137 frags[i] = NULL;
138 acks++; 138 acks++;
139 return; 139 return;
140 } 140 }
141 if (ret == GNUNET_NO) 141 if (ret == GNUNET_NO)
142 { 142 {
143#if DETAILS 143#if DETAILS
144 fprintf(stderr, "%s", "@"); /* good ACK */ 144 fprintf (stderr, "%s", "@"); /* good ACK */
145#endif 145#endif
146 acks++; 146 acks++;
147 return; 147 return;
148 }
149 } 148 }
149 }
150#if DETAILS 150#if DETAILS
151 fprintf(stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */ 151 fprintf (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */
152#endif 152#endif
153} 153}
154 154
@@ -157,37 +157,37 @@ proc_acks(void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
157 * Process fragment (by passing to defrag). 157 * Process fragment (by passing to defrag).
158 */ 158 */
159static void 159static void
160proc_frac(void *cls, const struct GNUNET_MessageHeader *hdr) 160proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
161{ 161{
162 struct GNUNET_FRAGMENT_Context **fc = cls; 162 struct GNUNET_FRAGMENT_Context **fc = cls;
163 int ret; 163 int ret;
164 164
165 GNUNET_FRAGMENT_context_transmission_done(*fc); 165 GNUNET_FRAGMENT_context_transmission_done (*fc);
166 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) 166 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
167 { 167 {
168 frag_drops++; 168 frag_drops++;
169 return; /* random drop */ 169 return; /* random drop */
170 } 170 }
171 if (NULL == defrag) 171 if (NULL == defrag)
172 { 172 {
173 fprintf(stderr, "%s", "E"); /* Error: frag after shutdown!? */ 173 fprintf (stderr, "%s", "E"); /* Error: frag after shutdown!? */
174 return; 174 return;
175 } 175 }
176 ret = GNUNET_DEFRAGMENT_process_fragment(defrag, hdr); 176 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
177 if (ret == GNUNET_NO) 177 if (ret == GNUNET_NO)
178 { 178 {
179#if DETAILS 179#if DETAILS
180 fprintf(stderr, "%s", "?"); /* duplicate fragment */ 180 fprintf (stderr, "%s", "?"); /* duplicate fragment */
181#endif 181#endif
182 dups++; 182 dups++;
183 } 183 }
184 else if (ret == GNUNET_OK) 184 else if (ret == GNUNET_OK)
185 { 185 {
186#if DETAILS 186#if DETAILS
187 fprintf(stderr, "%s", "."); /* good fragment */ 187 fprintf (stderr, "%s", "."); /* good fragment */
188#endif 188#endif
189 fragc++; 189 fragc++;
190 } 190 }
191} 191}
192 192
193 193
@@ -195,35 +195,35 @@ proc_frac(void *cls, const struct GNUNET_MessageHeader *hdr)
195 * Main function run with scheduler. 195 * Main function run with scheduler.
196 */ 196 */
197static void 197static void
198run(void *cls, char *const *args, const char *cfgfile, 198run (void *cls, char *const *args, const char *cfgfile,
199 const struct GNUNET_CONFIGURATION_Handle *cfg) 199 const struct GNUNET_CONFIGURATION_Handle *cfg)
200{ 200{
201 unsigned int i; 201 unsigned int i;
202 struct GNUNET_MessageHeader *msg; 202 struct GNUNET_MessageHeader *msg;
203 char buf[MTU + 32 * 1024]; 203 char buf[MTU + 32 * 1024];
204 204
205 defrag = GNUNET_DEFRAGMENT_context_create(NULL, MTU, NUM_MSGS /* enough space for all */ 205 defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS /* enough space for all */
206 , NULL, &proc_msgs, &proc_acks); 206 , NULL, &proc_msgs, &proc_acks);
207 for (i = 0; i < sizeof(buf); i++) 207 for (i = 0; i < sizeof(buf); i++)
208 buf[i] = (char)i; 208 buf[i] = (char) i;
209 msg = (struct GNUNET_MessageHeader *)buf; 209 msg = (struct GNUNET_MessageHeader *) buf;
210 for (i = 0; i < NUM_MSGS; i++) 210 for (i = 0; i < NUM_MSGS; i++)
211 { 211 {
212 msg->type = htons((uint16_t)i); 212 msg->type = htons ((uint16_t) i);
213 msg->size = 213 msg->size =
214 htons(sizeof(struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); 214 htons (sizeof(struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
215 frags[i] = GNUNET_FRAGMENT_context_create(NULL /* no stats */, 215 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */,
216 MTU, &trackers[i], 216 MTU, &trackers[i],
217 GNUNET_TIME_UNIT_MILLISECONDS, 217 GNUNET_TIME_UNIT_MILLISECONDS,
218 GNUNET_TIME_UNIT_SECONDS, 218 GNUNET_TIME_UNIT_SECONDS,
219 msg, 219 msg,
220 &proc_frac, &frags[i]); 220 &proc_frac, &frags[i]);
221 } 221 }
222} 222}
223 223
224 224
225int 225int
226main(int argc, char *argv[]) 226main (int argc, char *argv[])
227{ 227{
228 struct GNUNET_GETOPT_CommandLineOption options[] = { 228 struct GNUNET_GETOPT_CommandLineOption options[] = {
229 GNUNET_GETOPT_OPTION_END 229 GNUNET_GETOPT_OPTION_END
@@ -238,17 +238,17 @@ main(int argc, char *argv[])
238 }; 238 };
239 unsigned int i; 239 unsigned int i;
240 240
241 GNUNET_log_setup("test-fragmentation", 241 GNUNET_log_setup ("test-fragmentation",
242 "WARNING", 242 "WARNING",
243 NULL); 243 NULL);
244 for (i = 0; i < NUM_MSGS; i++) 244 for (i = 0; i < NUM_MSGS; i++)
245 GNUNET_BANDWIDTH_tracker_init(&trackers[i], NULL, NULL, 245 GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL,
246 GNUNET_BANDWIDTH_value_init((i + 1) * 1024), 246 GNUNET_BANDWIDTH_value_init ((i + 1) * 1024),
247 100); 247 100);
248 GNUNET_PROGRAM_run(5, argv_prog, "test-fragmentation", "nohelp", options, 248 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options,
249 &run, NULL); 249 &run, NULL);
250 fprintf(stderr, 250 fprintf (stderr,
251 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", 251 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
252 fragc, dups, acks, ack_drops); 252 fragc, dups, acks, ack_drops);
253 return ret; 253 return ret;
254} 254}