diff options
Diffstat (limited to 'src/transport/test_transport_api_unreliability.c')
-rw-r--r-- | src/transport/test_transport_api_unreliability.c | 753 |
1 files changed, 375 insertions, 378 deletions
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c index e7cb00274..88df23eb4 100644 --- a/src/transport/test_transport_api_unreliability.c +++ b/src/transport/test_transport_api_unreliability.c | |||
@@ -50,7 +50,7 @@ | |||
50 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise | 50 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise |
51 | * messages may be dropped even for a reliable transport. | 51 | * messages may be dropped even for a reliable transport. |
52 | */ | 52 | */ |
53 | #define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */ | 53 | #define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */ |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * How long until we give up on transmitting the message? | 56 | * How long until we give up on transmitting the message? |
@@ -91,7 +91,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
91 | 91 | ||
92 | static GNUNET_SCHEDULER_TaskIdentifier tct; | 92 | static GNUNET_SCHEDULER_TaskIdentifier tct; |
93 | 93 | ||
94 | struct GNUNET_TRANSPORT_TransmitHandle * th_p2; | 94 | struct GNUNET_TRANSPORT_TransmitHandle *th_p2; |
95 | 95 | ||
96 | static char *key_file_p1; | 96 | static char *key_file_p1; |
97 | static char *cert_file_p1; | 97 | static char *cert_file_p1; |
@@ -123,11 +123,13 @@ set_bit (unsigned int bitIdx) | |||
123 | { | 123 | { |
124 | size_t arraySlot; | 124 | size_t arraySlot; |
125 | unsigned int targetBit; | 125 | unsigned int targetBit; |
126 | if (bitIdx >= sizeof(bitmap) * 8) | 126 | |
127 | { | 127 | if (bitIdx >= sizeof (bitmap) * 8) |
128 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of %d(!?!?)\n", bitIdx, sizeof(bitmap) * 8); | 128 | { |
129 | return; | 129 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of %d(!?!?)\n", |
130 | } | 130 | bitIdx, sizeof (bitmap) * 8); |
131 | return; | ||
132 | } | ||
131 | arraySlot = bitIdx / 8; | 133 | arraySlot = bitIdx / 8; |
132 | targetBit = (1L << (bitIdx % 8)); | 134 | targetBit = (1L << (bitIdx % 8)); |
133 | bitmap[arraySlot] |= targetBit; | 135 | bitmap[arraySlot] |= targetBit; |
@@ -144,10 +146,11 @@ int | |||
144 | get_bit (const char *map, unsigned int bit) | 146 | get_bit (const char *map, unsigned int bit) |
145 | { | 147 | { |
146 | if (bit >= TOTAL_MSGS) | 148 | if (bit >= TOTAL_MSGS) |
147 | { | 149 | { |
148 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit, sizeof(bitmap) * 8); | 150 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit, |
149 | return 0; | 151 | sizeof (bitmap) * 8); |
150 | } | 152 | return 0; |
153 | } | ||
151 | return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; | 154 | return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; |
152 | } | 155 | } |
153 | 156 | ||
@@ -161,13 +164,13 @@ end () | |||
161 | 164 | ||
162 | result = 0; | 165 | result = 0; |
163 | for (i = 0; i < TOTAL_MSGS; i++) | 166 | for (i = 0; i < TOTAL_MSGS; i++) |
167 | { | ||
168 | if (get_bit (bitmap, i) == 0) | ||
164 | { | 169 | { |
165 | if (get_bit(bitmap, i) == 0) | 170 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Did not receive message %d\n", i); |
166 | { | 171 | result = -1; |
167 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Did not receive message %d\n", i); | ||
168 | result = -1; | ||
169 | } | ||
170 | } | 172 | } |
173 | } | ||
171 | 174 | ||
172 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 175 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
173 | GNUNET_SCHEDULER_cancel (die_task); | 176 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -176,22 +179,22 @@ end () | |||
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); |
177 | #endif | 180 | #endif |
178 | if (th_p2 != NULL) | 181 | if (th_p2 != NULL) |
179 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); | 182 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2); |
180 | th_p2 = NULL; | 183 | th_p2 = NULL; |
181 | 184 | ||
182 | GNUNET_TRANSPORT_disconnect (p1.th); | 185 | GNUNET_TRANSPORT_disconnect (p1.th); |
183 | GNUNET_TRANSPORT_disconnect (p2.th); | 186 | GNUNET_TRANSPORT_disconnect (p2.th); |
184 | #if VERBOSE | 187 | #if VERBOSE |
185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
186 | "Transports disconnected, returning success!\n"); | 189 | "Transports disconnected, returning success!\n"); |
187 | #endif | 190 | #endif |
188 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | 191 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; |
189 | GNUNET_asprintf(&value_name, "unreliable_%s", test_name); | 192 | GNUNET_asprintf (&value_name, "unreliable_%s", test_name); |
190 | GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); | 193 | GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta), |
191 | GNUNET_free(value_name); | 194 | "kb/s"); |
195 | GNUNET_free (value_name); | ||
192 | fprintf (stderr, | 196 | fprintf (stderr, |
193 | "\nThroughput was %llu kb/s\n", | 197 | "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); |
194 | total_bytes * 1000 / 1024 / delta); | ||
195 | ok = result; | 198 | ok = result; |
196 | 199 | ||
197 | } | 200 | } |
@@ -203,22 +206,23 @@ end_unreliably () | |||
203 | int i; | 206 | int i; |
204 | int num_failed; | 207 | int num_failed; |
205 | char *value_name; | 208 | char *value_name; |
209 | |||
206 | num_failed = 0; | 210 | num_failed = 0; |
207 | for (i = 0; i < TOTAL_MSGS; i++) | 211 | for (i = 0; i < TOTAL_MSGS; i++) |
212 | { | ||
213 | if (get_bit (bitmap, i) == 0) | ||
208 | { | 214 | { |
209 | if (get_bit(bitmap, i) == 0) | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Did not receive message %d\n", i); |
210 | { | 216 | num_failed++; |
211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Did not receive message %d\n", i); | ||
212 | num_failed++; | ||
213 | } | ||
214 | } | 217 | } |
218 | } | ||
215 | 219 | ||
216 | die_task = GNUNET_SCHEDULER_NO_TASK; | 220 | die_task = GNUNET_SCHEDULER_NO_TASK; |
217 | #if VERBOSE | 221 | #if VERBOSE |
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); |
219 | #endif | 223 | #endif |
220 | if (th_p2 != NULL) | 224 | if (th_p2 != NULL) |
221 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); | 225 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2); |
222 | 226 | ||
223 | GNUNET_TRANSPORT_disconnect (p1.th); | 227 | GNUNET_TRANSPORT_disconnect (p1.th); |
224 | GNUNET_TRANSPORT_disconnect (p2.th); | 228 | GNUNET_TRANSPORT_disconnect (p2.th); |
@@ -228,15 +232,16 @@ end_unreliably () | |||
228 | #endif | 232 | #endif |
229 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; | 233 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; |
230 | fprintf (stderr, | 234 | fprintf (stderr, |
231 | "\nThroughput was %llu kb/s\n", | 235 | "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); |
232 | total_bytes * 1000 / 1024 / delta); | 236 | GNUNET_asprintf (&value_name, "unreliable_%s", test_name); |
233 | GNUNET_asprintf(&value_name, "unreliable_%s", test_name); | 237 | GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta), |
234 | GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); | 238 | "kb/s"); |
235 | GNUNET_free(value_name); | 239 | GNUNET_free (value_name); |
236 | GNUNET_asprintf(&value_name, "unreliable_failed_%s", test_name); | 240 | GNUNET_asprintf (&value_name, "unreliable_failed_%s", test_name); |
237 | GAUGER ("TRANSPORT", value_name, (int)num_failed, "msgs"); | 241 | GAUGER ("TRANSPORT", value_name, (int) num_failed, "msgs"); |
238 | GNUNET_free(value_name); | 242 | GNUNET_free (value_name); |
239 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Had %d failed messages!\n", num_failed); | 243 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Had %d failed messages!\n", |
244 | num_failed); | ||
240 | ok = 0; | 245 | ok = 0; |
241 | 246 | ||
242 | } | 247 | } |
@@ -259,16 +264,15 @@ stop_arm (struct PeerContext *p) | |||
259 | 264 | ||
260 | 265 | ||
261 | static void | 266 | static void |
262 | exchange_hello_last (void *cls, | 267 | exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message) |
263 | const struct GNUNET_MessageHeader *message) | ||
264 | { | 268 | { |
265 | struct PeerContext *me = cls; | 269 | struct PeerContext *me = cls; |
266 | 270 | ||
267 | GNUNET_assert (message != NULL); | 271 | GNUNET_assert (message != NULL); |
268 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
269 | "Exchanging HELLO of size %d with peer (%s)!\n", | 273 | "Exchanging HELLO of size %d with peer (%s)!\n", |
270 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | 274 | (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) |
271 | GNUNET_i2s (&me->id)); | 275 | message), GNUNET_i2s (&me->id)); |
272 | GNUNET_assert (GNUNET_OK == | 276 | GNUNET_assert (GNUNET_OK == |
273 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 277 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) |
274 | message, &me->id)); | 278 | message, &me->id)); |
@@ -278,8 +282,7 @@ exchange_hello_last (void *cls, | |||
278 | 282 | ||
279 | 283 | ||
280 | static void | 284 | static void |
281 | exchange_hello (void *cls, | 285 | exchange_hello (void *cls, const struct GNUNET_MessageHeader *message) |
282 | const struct GNUNET_MessageHeader *message) | ||
283 | { | 286 | { |
284 | struct PeerContext *me = cls; | 287 | struct PeerContext *me = cls; |
285 | 288 | ||
@@ -288,52 +291,47 @@ exchange_hello (void *cls, | |||
288 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 291 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) |
289 | message, &me->id)); | 292 | message, &me->id)); |
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | "Exchanging HELLO of size %d from peer %s!\n", | 294 | "Exchanging HELLO of size %d from peer %s!\n", |
292 | (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), | 295 | (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) |
293 | GNUNET_i2s (&me->id)); | 296 | message), GNUNET_i2s (&me->id)); |
294 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | 297 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); |
295 | } | 298 | } |
296 | 299 | ||
297 | 300 | ||
298 | 301 | ||
299 | static void | 302 | static void |
300 | end_badly (void *cls, | 303 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
301 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
302 | { | 304 | { |
303 | if (test_failed == GNUNET_NO) | 305 | if (test_failed == GNUNET_NO) |
304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 306 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n"); |
305 | "Testcase timeout\n"); | ||
306 | else | 307 | else |
307 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 308 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
308 | "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", | 309 | "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", |
309 | msg_sent, | 310 | msg_sent, msg_scheduled, msg_recv, msg_recv_expected); |
310 | msg_scheduled, | 311 | |
311 | msg_recv, | ||
312 | msg_recv_expected); | ||
313 | |||
314 | GNUNET_break (0); | 312 | GNUNET_break (0); |
315 | if (th_p2 != NULL) | 313 | if (th_p2 != NULL) |
316 | { | 314 | { |
317 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); | 315 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2); |
318 | th_p2 = NULL; | 316 | th_p2 = NULL; |
319 | } | 317 | } |
320 | if (p2_hello_canceled == GNUNET_NO) | 318 | if (p2_hello_canceled == GNUNET_NO) |
321 | { | 319 | { |
322 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); | 320 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); |
323 | p2_hello_canceled = GNUNET_YES; | 321 | p2_hello_canceled = GNUNET_YES; |
324 | } | 322 | } |
325 | if (p1_hello_canceled == GNUNET_NO) | 323 | if (p1_hello_canceled == GNUNET_NO) |
326 | { | 324 | { |
327 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | 325 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); |
328 | p1_hello_canceled = GNUNET_YES; | 326 | p1_hello_canceled = GNUNET_YES; |
329 | } | 327 | } |
330 | GNUNET_TRANSPORT_disconnect (p1.th); | 328 | GNUNET_TRANSPORT_disconnect (p1.th); |
331 | GNUNET_TRANSPORT_disconnect (p2.th); | 329 | GNUNET_TRANSPORT_disconnect (p2.th); |
332 | if (GNUNET_SCHEDULER_NO_TASK != tct) | 330 | if (GNUNET_SCHEDULER_NO_TASK != tct) |
333 | { | 331 | { |
334 | GNUNET_SCHEDULER_cancel (tct); | 332 | GNUNET_SCHEDULER_cancel (tct); |
335 | tct = GNUNET_SCHEDULER_NO_TASK; | 333 | tct = GNUNET_SCHEDULER_NO_TASK; |
336 | } | 334 | } |
337 | ok = 1; | 335 | ok = 1; |
338 | } | 336 | } |
339 | 337 | ||
@@ -368,63 +366,56 @@ notify_receive (void *cls, | |||
368 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 366 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
369 | const struct TestMessage *hdr; | 367 | const struct TestMessage *hdr; |
370 | 368 | ||
371 | hdr = (const struct TestMessage*) message; | 369 | hdr = (const struct TestMessage *) message; |
372 | 370 | ||
373 | if (MTYPE != ntohs (message->type)) | 371 | if (MTYPE != ntohs (message->type)) |
374 | return; | 372 | return; |
375 | msg_recv_expected = n; | 373 | msg_recv_expected = n; |
376 | msg_recv = ntohl(hdr->num); | 374 | msg_recv = ntohl (hdr->num); |
377 | s = get_size (ntohl(hdr->num)); | 375 | s = get_size (ntohl (hdr->num)); |
378 | 376 | ||
379 | if (ntohs (message->size) != s) | 377 | if (ntohs (message->size) != s) |
380 | { | 378 | { |
381 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 379 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
382 | "Expected message %u of size %u, got %u bytes of message %u\n", | 380 | "Expected message %u of size %u, got %u bytes of message %u\n", |
383 | ntohl(hdr->num), s, | 381 | ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num)); |
384 | ntohs (message->size), | 382 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
385 | ntohl (hdr->num)); | 383 | GNUNET_SCHEDULER_cancel (die_task); |
386 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 384 | test_failed = GNUNET_YES; |
387 | GNUNET_SCHEDULER_cancel (die_task); | 385 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
388 | test_failed = GNUNET_YES; | 386 | return; |
389 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 387 | } |
390 | return; | ||
391 | } | ||
392 | 388 | ||
393 | memset (cbuf, ntohl(hdr->num), s - sizeof (struct TestMessage)); | 389 | memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage)); |
394 | if (0 != memcmp (cbuf, | 390 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) |
395 | &hdr[1], | 391 | { |
396 | s - sizeof (struct TestMessage))) | 392 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
397 | { | 393 | "Expected message %u with bits %u, but body did not match\n", |
398 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 394 | ntohl (hdr->num), (unsigned char) n); |
399 | "Expected message %u with bits %u, but body did not match\n", | 395 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
400 | ntohl(hdr->num), (unsigned char) n); | 396 | GNUNET_SCHEDULER_cancel (die_task); |
401 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 397 | test_failed = GNUNET_YES; |
402 | GNUNET_SCHEDULER_cancel (die_task); | 398 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
403 | test_failed = GNUNET_YES; | 399 | return; |
404 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 400 | } |
405 | return; | ||
406 | } | ||
407 | #if VERBOSE | 401 | #if VERBOSE |
408 | if (ntohl(hdr->num) % 5 == 0) | 402 | if (ntohl (hdr->num) % 5 == 0) |
409 | { | 403 | { |
410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
411 | "Got message %u of size %u\n", | 405 | "Got message %u of size %u\n", |
412 | ntohl (hdr->num), | 406 | ntohl (hdr->num), ntohs (message->size)); |
413 | ntohs (message->size)); | 407 | } |
414 | } | ||
415 | #endif | 408 | #endif |
416 | n++; | 409 | n++; |
417 | set_bit(ntohl(hdr->num)); | 410 | set_bit (ntohl (hdr->num)); |
418 | if (0 == (n % (TOTAL_MSGS / 100))) | 411 | if (0 == (n % (TOTAL_MSGS / 100))) |
419 | { | 412 | { |
420 | fprintf (stderr, "."); | 413 | fprintf (stderr, "."); |
421 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 414 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
422 | GNUNET_SCHEDULER_cancel (die_task); | 415 | GNUNET_SCHEDULER_cancel (die_task); |
423 | test_failed = GNUNET_YES; | 416 | test_failed = GNUNET_YES; |
424 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 417 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
425 | &end_badly, | 418 | } |
426 | NULL); | ||
427 | } | ||
428 | if (n == TOTAL_MSGS) | 419 | if (n == TOTAL_MSGS) |
429 | end (); | 420 | end (); |
430 | } | 421 | } |
@@ -442,63 +433,62 @@ notify_ready (void *cls, size_t size, void *buf) | |||
442 | th_p2 = NULL; | 433 | th_p2 = NULL; |
443 | 434 | ||
444 | if (buf == NULL) | 435 | if (buf == NULL) |
445 | { | 436 | { |
446 | GNUNET_break (0); | 437 | GNUNET_break (0); |
447 | ok = 42; | 438 | ok = 42; |
448 | return 0; | 439 | return 0; |
449 | } | 440 | } |
450 | ret = 0; | 441 | ret = 0; |
451 | s = get_size (n); | 442 | s = get_size (n); |
452 | GNUNET_assert (size >= s); | 443 | GNUNET_assert (size >= s); |
453 | GNUNET_assert (buf != NULL); | 444 | GNUNET_assert (buf != NULL); |
454 | cbuf = buf; | 445 | cbuf = buf; |
455 | do | 446 | do |
456 | { | 447 | { |
457 | hdr.header.size = htons (s); | 448 | hdr.header.size = htons (s); |
458 | hdr.header.type = htons (MTYPE); | 449 | hdr.header.type = htons (MTYPE); |
459 | hdr.num = htonl (n); | 450 | hdr.num = htonl (n); |
460 | msg_sent = n; | 451 | msg_sent = n; |
461 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 452 | memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); |
462 | ret += sizeof (struct TestMessage); | 453 | ret += sizeof (struct TestMessage); |
463 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | 454 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); |
464 | ret += s - sizeof (struct TestMessage); | 455 | ret += s - sizeof (struct TestMessage); |
465 | #if VERBOSE | 456 | #if VERBOSE |
466 | if (n % 5000 == 0) | 457 | if (n % 5000 == 0) |
467 | { | 458 | { |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 459 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
469 | "Sending message %u of size %u\n", | 460 | "Sending message %u of size %u\n", n, s); |
470 | n, | ||
471 | s); | ||
472 | } | ||
473 | #endif | ||
474 | n++; | ||
475 | s = get_size (n); | ||
476 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | ||
477 | break; /* sometimes pack buffer full, sometimes not */ | ||
478 | } | 461 | } |
462 | #endif | ||
463 | n++; | ||
464 | s = get_size (n); | ||
465 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | ||
466 | break; /* sometimes pack buffer full, sometimes not */ | ||
467 | } | ||
479 | while (size - ret >= s); | 468 | while (size - ret >= s); |
480 | if (n < TOTAL_MSGS) | 469 | if (n < TOTAL_MSGS) |
481 | { | 470 | { |
482 | th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | 471 | th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, |
483 | &p1.id, | 472 | &p1.id, |
484 | s, 0, TIMEOUT, | 473 | s, 0, TIMEOUT, |
485 | ¬ify_ready, | 474 | ¬ify_ready, NULL); |
486 | NULL); | ||
487 | msg_scheduled = n; | 475 | msg_scheduled = n; |
488 | } | 476 | } |
489 | else | 477 | else |
490 | { | 478 | { |
491 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent!!\n"); | 479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
492 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 480 | "All messages scheduled to be sent!!\n"); |
493 | GNUNET_SCHEDULER_cancel(die_task); | 481 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
494 | die_task = GNUNET_SCHEDULER_add_delayed (UNRELIABLE_TIMEOUT, &end_unreliably, NULL); | 482 | GNUNET_SCHEDULER_cancel (die_task); |
495 | } | 483 | die_task = |
484 | GNUNET_SCHEDULER_add_delayed (UNRELIABLE_TIMEOUT, &end_unreliably, | ||
485 | NULL); | ||
486 | } | ||
496 | if (n % 5000 == 0) | 487 | if (n % 5000 == 0) |
497 | { | 488 | { |
498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
499 | "Returning total message block of size %u\n", | 490 | "Returning total message block of size %u\n", ret); |
500 | ret); | 491 | } |
501 | } | ||
502 | total_bytes += ret; | 492 | total_bytes += ret; |
503 | return ret; | 493 | return ret; |
504 | } | 494 | } |
@@ -511,14 +501,13 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
511 | connected--; | 501 | connected--; |
512 | #if VERBOSE | 502 | #if VERBOSE |
513 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
514 | "Peer `%4s' disconnected (%p)!\n", | 504 | "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); |
515 | GNUNET_i2s (peer), cls); | ||
516 | #endif | 505 | #endif |
517 | if (th_p2 != NULL) | 506 | if (th_p2 != NULL) |
518 | { | 507 | { |
519 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2); | 508 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2); |
520 | th_p2 = NULL; | 509 | th_p2 = NULL; |
521 | } | 510 | } |
522 | } | 511 | } |
523 | 512 | ||
524 | 513 | ||
@@ -530,57 +519,57 @@ notify_connect (void *cls, | |||
530 | uint32_t ats_count) | 519 | uint32_t ats_count) |
531 | { | 520 | { |
532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
533 | "Peer `%4s' connected to us (%p)!\n", | 522 | "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); |
534 | GNUNET_i2s (peer), | ||
535 | cls); | ||
536 | if (cls == &p1) | 523 | if (cls == &p1) |
524 | { | ||
525 | GNUNET_TRANSPORT_set_quota (p1.th, | ||
526 | &p2.id, | ||
527 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * | ||
528 | 1024), | ||
529 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * | ||
530 | 1024)); | ||
531 | start_time = GNUNET_TIME_absolute_get (); | ||
532 | connected++; | ||
533 | } | ||
534 | else | ||
535 | { | ||
536 | GNUNET_TRANSPORT_set_quota (p2.th, | ||
537 | &p1.id, | ||
538 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * | ||
539 | 1024), | ||
540 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * | ||
541 | 1024)); | ||
542 | connected++; | ||
543 | } | ||
544 | if (2 == connected) | ||
545 | { | ||
546 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
537 | { | 547 | { |
538 | GNUNET_TRANSPORT_set_quota (p1.th, | 548 | GNUNET_SCHEDULER_cancel (die_task); |
539 | &p2.id, | ||
540 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), | ||
541 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); | ||
542 | start_time = GNUNET_TIME_absolute_get (); | ||
543 | connected++; | ||
544 | } | 549 | } |
545 | else | 550 | if (GNUNET_SCHEDULER_NO_TASK != tct) |
546 | { | 551 | { |
547 | GNUNET_TRANSPORT_set_quota (p2.th, | 552 | GNUNET_SCHEDULER_cancel (tct); |
548 | &p1.id, | 553 | tct = GNUNET_SCHEDULER_NO_TASK; |
549 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), | ||
550 | GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); | ||
551 | connected++; | ||
552 | } | 554 | } |
553 | if (2 == connected) | 555 | if (p2_hello_canceled == GNUNET_NO) |
554 | { | 556 | { |
555 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 557 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); |
556 | { | 558 | p2_hello_canceled = GNUNET_YES; |
557 | GNUNET_SCHEDULER_cancel (die_task); | ||
558 | } | ||
559 | if (GNUNET_SCHEDULER_NO_TASK != tct) | ||
560 | { | ||
561 | GNUNET_SCHEDULER_cancel (tct); | ||
562 | tct = GNUNET_SCHEDULER_NO_TASK; | ||
563 | } | ||
564 | if (p2_hello_canceled == GNUNET_NO) | ||
565 | { | ||
566 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); | ||
567 | p2_hello_canceled = GNUNET_YES; | ||
568 | } | ||
569 | if (p1_hello_canceled == GNUNET_NO) | ||
570 | { | ||
571 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | ||
572 | p1_hello_canceled = GNUNET_YES; | ||
573 | } | ||
574 | |||
575 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
576 | &end_badly, NULL); | ||
577 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | ||
578 | &p1.id, | ||
579 | get_size (0), 0, TIMEOUT, | ||
580 | ¬ify_ready, | ||
581 | NULL); | ||
582 | |||
583 | } | 559 | } |
560 | if (p1_hello_canceled == GNUNET_NO) | ||
561 | { | ||
562 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); | ||
563 | p1_hello_canceled = GNUNET_YES; | ||
564 | } | ||
565 | |||
566 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
567 | GNUNET_TRANSPORT_notify_transmit_ready (p2.th, | ||
568 | &p1.id, | ||
569 | get_size (0), 0, TIMEOUT, | ||
570 | ¬ify_ready, NULL); | ||
571 | |||
572 | } | ||
584 | } | 573 | } |
585 | 574 | ||
586 | 575 | ||
@@ -591,31 +580,31 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
591 | p->cfg = GNUNET_CONFIGURATION_create (); | 580 | p->cfg = GNUNET_CONFIGURATION_create (); |
592 | 581 | ||
593 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 582 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
594 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) | 583 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) |
595 | { | 584 | { |
596 | GNUNET_assert (GNUNET_OK == | 585 | GNUNET_assert (GNUNET_OK == |
597 | GNUNET_CONFIGURATION_get_value_string (p->cfg, | 586 | GNUNET_CONFIGURATION_get_value_string (p->cfg, |
598 | "PATHS", "SERVICEHOME", | 587 | "PATHS", |
599 | &p->servicehome)); | 588 | "SERVICEHOME", |
600 | GNUNET_DISK_directory_remove (p->servicehome); | 589 | &p->servicehome)); |
601 | } | 590 | GNUNET_DISK_directory_remove (p->servicehome); |
591 | } | ||
602 | 592 | ||
603 | 593 | ||
604 | #if START_ARM | 594 | #if START_ARM |
605 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, | 595 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, |
606 | "gnunet-service-arm", | 596 | "gnunet-service-arm", |
607 | "gnunet-service-arm", | 597 | "gnunet-service-arm", |
608 | #if VERBOSE_ARM | 598 | #if VERBOSE_ARM |
609 | "-L", "DEBUG", | 599 | "-L", "DEBUG", |
610 | #endif | 600 | #endif |
611 | "-c", cfgname, NULL); | 601 | "-c", cfgname, NULL); |
612 | #endif | 602 | #endif |
613 | 603 | ||
614 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, | 604 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, |
615 | p, | 605 | p, |
616 | ¬ify_receive, | 606 | ¬ify_receive, |
617 | ¬ify_connect, | 607 | ¬ify_connect, ¬ify_disconnect); |
618 | ¬ify_disconnect); | ||
619 | GNUNET_assert (p->th != NULL); | 608 | GNUNET_assert (p->th != NULL); |
620 | } | 609 | } |
621 | 610 | ||
@@ -637,32 +626,32 @@ get_path_from_PATH (char *binary) | |||
637 | 626 | ||
638 | p = getenv ("PATH"); | 627 | p = getenv ("PATH"); |
639 | if (p == NULL) | 628 | if (p == NULL) |
640 | { | 629 | { |
641 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 630 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
642 | _("PATH environment variable is unset.\n")); | 631 | _("PATH environment variable is unset.\n")); |
643 | return NULL; | 632 | return NULL; |
644 | } | 633 | } |
645 | path = GNUNET_strdup (p); /* because we write on it */ | 634 | path = GNUNET_strdup (p); /* because we write on it */ |
646 | buf = GNUNET_malloc (strlen (path) + 20); | 635 | buf = GNUNET_malloc (strlen (path) + 20); |
647 | pos = path; | 636 | pos = path; |
648 | 637 | ||
649 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) | 638 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) |
650 | { | 639 | { |
651 | *end = '\0'; | 640 | *end = '\0'; |
652 | sprintf (buf, "%s/%s", pos, binary); | 641 | sprintf (buf, "%s/%s", pos, binary); |
653 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | 642 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) |
654 | { | ||
655 | GNUNET_free (path); | ||
656 | return buf; | ||
657 | } | ||
658 | pos = end + 1; | ||
659 | } | ||
660 | sprintf (buf, "%s/%s", pos, binary); | ||
661 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
662 | { | 643 | { |
663 | GNUNET_free (path); | 644 | GNUNET_free (path); |
664 | return buf; | 645 | return buf; |
665 | } | 646 | } |
647 | pos = end + 1; | ||
648 | } | ||
649 | sprintf (buf, "%s/%s", pos, binary); | ||
650 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
651 | { | ||
652 | GNUNET_free (path); | ||
653 | return buf; | ||
654 | } | ||
666 | GNUNET_free (buf); | 655 | GNUNET_free (buf); |
667 | GNUNET_free (path); | 656 | GNUNET_free (path); |
668 | return NULL; | 657 | return NULL; |
@@ -679,16 +668,18 @@ get_path_from_PATH (char *binary) | |||
679 | * can be run properly, GNUNET_NO otherwise | 668 | * can be run properly, GNUNET_NO otherwise |
680 | */ | 669 | */ |
681 | static int | 670 | static int |
682 | check_gnunet_nat_binary(char *binary) | 671 | check_gnunet_nat_binary (char *binary) |
683 | { | 672 | { |
684 | struct stat statbuf; | 673 | struct stat statbuf; |
685 | char *p; | 674 | char *p; |
675 | |||
686 | #ifdef MINGW | 676 | #ifdef MINGW |
687 | SOCKET rawsock; | 677 | SOCKET rawsock; |
688 | #endif | 678 | #endif |
689 | 679 | ||
690 | #ifdef MINGW | 680 | #ifdef MINGW |
691 | char *binaryexe; | 681 | char *binaryexe; |
682 | |||
692 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); | 683 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); |
693 | p = get_path_from_PATH (binaryexe); | 684 | p = get_path_from_PATH (binaryexe); |
694 | free (binaryexe); | 685 | free (binaryexe); |
@@ -696,36 +687,34 @@ check_gnunet_nat_binary(char *binary) | |||
696 | p = get_path_from_PATH (binary); | 687 | p = get_path_from_PATH (binary); |
697 | #endif | 688 | #endif |
698 | if (p == NULL) | 689 | if (p == NULL) |
699 | { | 690 | { |
700 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 691 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
701 | _("Could not find binary `%s' in PATH!\n"), | 692 | _("Could not find binary `%s' in PATH!\n"), binary); |
702 | binary); | 693 | return GNUNET_NO; |
703 | return GNUNET_NO; | 694 | } |
704 | } | ||
705 | if (0 != STAT (p, &statbuf)) | 695 | if (0 != STAT (p, &statbuf)) |
706 | { | 696 | { |
707 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 697 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
708 | _("stat (%s) failed: %s\n"), | 698 | _("stat (%s) failed: %s\n"), p, STRERROR (errno)); |
709 | p, | 699 | GNUNET_free (p); |
710 | STRERROR (errno)); | 700 | return GNUNET_SYSERR; |
711 | GNUNET_free (p); | 701 | } |
712 | return GNUNET_SYSERR; | ||
713 | } | ||
714 | GNUNET_free (p); | 702 | GNUNET_free (p); |
715 | #ifndef MINGW | 703 | #ifndef MINGW |
716 | if ( (0 != (statbuf.st_mode & S_ISUID)) && | 704 | if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) |
717 | (statbuf.st_uid == 0) ) | ||
718 | return GNUNET_YES; | 705 | return GNUNET_YES; |
719 | return GNUNET_NO; | 706 | return GNUNET_NO; |
720 | #else | 707 | #else |
721 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); | 708 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); |
722 | if (INVALID_SOCKET == rawsock) | 709 | if (INVALID_SOCKET == rawsock) |
723 | { | 710 | { |
724 | DWORD err = GetLastError (); | 711 | DWORD err = GetLastError (); |
725 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 712 | |
726 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err); | 713 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
727 | return GNUNET_NO; /* not running as administrator */ | 714 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", |
728 | } | 715 | err); |
716 | return GNUNET_NO; /* not running as administrator */ | ||
717 | } | ||
729 | closesocket (rawsock); | 718 | closesocket (rawsock); |
730 | return GNUNET_YES; | 719 | return GNUNET_YES; |
731 | #endif | 720 | #endif |
@@ -733,18 +722,13 @@ check_gnunet_nat_binary(char *binary) | |||
733 | 722 | ||
734 | 723 | ||
735 | static void | 724 | static void |
736 | try_connect (void *cls, | 725 | try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
737 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
738 | { | 726 | { |
739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n"); |
740 | "Asking peers to connect...\n"); | 728 | GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); |
741 | GNUNET_TRANSPORT_try_connect (p2.th, | 729 | GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); |
742 | &p1.id); | ||
743 | GNUNET_TRANSPORT_try_connect (p1.th, | ||
744 | &p2.id); | ||
745 | tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 730 | tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
746 | &try_connect, | 731 | &try_connect, NULL); |
747 | NULL); | ||
748 | } | 732 | } |
749 | 733 | ||
750 | 734 | ||
@@ -754,48 +738,46 @@ run (void *cls, | |||
754 | char *const *args, | 738 | char *const *args, |
755 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 739 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
756 | { | 740 | { |
757 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 741 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
758 | &end_badly, | ||
759 | NULL); | ||
760 | if (is_tcp) | 742 | if (is_tcp) |
761 | { | 743 | { |
762 | setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); | 744 | setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); |
763 | setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); | 745 | setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); |
764 | } | 746 | } |
765 | else if (is_http) | 747 | else if (is_http) |
766 | { | 748 | { |
767 | setup_peer (&p1, "test_transport_api_rel_http_peer1.conf"); | 749 | setup_peer (&p1, "test_transport_api_rel_http_peer1.conf"); |
768 | setup_peer (&p2, "test_transport_api_rel_http_peer2.conf"); | 750 | setup_peer (&p2, "test_transport_api_rel_http_peer2.conf"); |
769 | } | 751 | } |
770 | else if (is_https) | 752 | else if (is_https) |
771 | { | 753 | { |
772 | setup_peer (&p1, "test_transport_api_rel_https_peer1.conf"); | 754 | setup_peer (&p1, "test_transport_api_rel_https_peer1.conf"); |
773 | setup_peer (&p2, "test_transport_api_rel_https_peer2.conf"); | 755 | setup_peer (&p2, "test_transport_api_rel_https_peer2.conf"); |
774 | } | 756 | } |
775 | else if (is_udp) | 757 | else if (is_udp) |
776 | { | 758 | { |
777 | setup_peer (&p1, "test_transport_api_udp_peer1.conf"); | 759 | setup_peer (&p1, "test_transport_api_udp_peer1.conf"); |
778 | setup_peer (&p2, "test_transport_api_udp_peer2.conf"); | 760 | setup_peer (&p2, "test_transport_api_udp_peer2.conf"); |
779 | } | 761 | } |
780 | else if (is_unix) | 762 | else if (is_unix) |
781 | { | 763 | { |
782 | setup_peer (&p1, "test_transport_api_unix_peer1.conf"); | 764 | setup_peer (&p1, "test_transport_api_unix_peer1.conf"); |
783 | setup_peer (&p2, "test_transport_api_unix_peer2.conf"); | 765 | setup_peer (&p2, "test_transport_api_unix_peer2.conf"); |
784 | } | 766 | } |
785 | else if (is_tcp_nat) | 767 | else if (is_tcp_nat) |
786 | { | 768 | { |
787 | setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf"); | 769 | setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf"); |
788 | setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf"); | 770 | setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf"); |
789 | } | 771 | } |
790 | else if (is_wlan) | 772 | else if (is_wlan) |
791 | { | 773 | { |
792 | setup_peer (&p1, "test_transport_api_wlan_peer1.conf"); | 774 | setup_peer (&p1, "test_transport_api_wlan_peer1.conf"); |
793 | setup_peer (&p2, "test_transport_api_wlan_peer2.conf"); | 775 | setup_peer (&p2, "test_transport_api_wlan_peer2.conf"); |
794 | } | 776 | } |
795 | else | 777 | else |
796 | GNUNET_assert (0); | 778 | GNUNET_assert (0); |
797 | GNUNET_assert(p1.th != NULL); | 779 | GNUNET_assert (p1.th != NULL); |
798 | GNUNET_assert(p2.th != NULL); | 780 | GNUNET_assert (p2.th != NULL); |
799 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | 781 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); |
800 | p1_hello_canceled = GNUNET_NO; | 782 | p1_hello_canceled = GNUNET_NO; |
801 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | 783 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); |
@@ -820,15 +802,17 @@ check () | |||
820 | }; | 802 | }; |
821 | 803 | ||
822 | #if WRITECONFIG | 804 | #if WRITECONFIG |
823 | setTransportOptions("test_transport_api_data.conf"); | 805 | setTransportOptions ("test_transport_api_data.conf"); |
824 | #endif | 806 | #endif |
825 | ok = 1; | 807 | ok = 1; |
826 | 808 | ||
827 | if ((GNUNET_YES == is_tcp_nat) && (check_gnunet_nat_binary("gnunet-nat-server") != GNUNET_YES)) | 809 | if ((GNUNET_YES == is_tcp_nat) && |
828 | { | 810 | (check_gnunet_nat_binary ("gnunet-nat-server") != GNUNET_YES)) |
829 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Not running NAT test case, binaries not properly installed.\n"); | 811 | { |
830 | return 0; | 812 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
831 | } | 813 | "Not running NAT test case, binaries not properly installed.\n"); |
814 | return 0; | ||
815 | } | ||
832 | 816 | ||
833 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 817 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
834 | argv, "test-transport-api-unreliability", "nohelp", | 818 | argv, "test-transport-api-unreliability", "nohelp", |
@@ -839,53 +823,66 @@ check () | |||
839 | if (is_https) | 823 | if (is_https) |
840 | { | 824 | { |
841 | struct stat sbuf; | 825 | struct stat sbuf; |
842 | if (0 == stat (cert_file_p1, &sbuf )) | 826 | |
827 | if (0 == stat (cert_file_p1, &sbuf)) | ||
843 | { | 828 | { |
844 | if (0 == remove(cert_file_p1)) | 829 | if (0 == remove (cert_file_p1)) |
845 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p1); | 830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
831 | "Successfully removed existing certificate file `%s'\n", | ||
832 | cert_file_p1); | ||
846 | else | 833 | else |
847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p1); | 834 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n", |
835 | cert_file_p1); | ||
848 | } | 836 | } |
849 | 837 | ||
850 | if (0 == stat (key_file_p1, &sbuf )) | 838 | if (0 == stat (key_file_p1, &sbuf)) |
851 | { | 839 | { |
852 | if (0 == remove(key_file_p1)) | 840 | if (0 == remove (key_file_p1)) |
853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p1); | 841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
842 | "Successfully removed private key file `%s'\n", | ||
843 | key_file_p1); | ||
854 | else | 844 | else |
855 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p1); | 845 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
846 | "Failed to private key file `%s'\n", key_file_p1); | ||
856 | } | 847 | } |
857 | 848 | ||
858 | if (0 == stat (cert_file_p2, &sbuf )) | 849 | if (0 == stat (cert_file_p2, &sbuf)) |
859 | { | 850 | { |
860 | if (0 == remove(cert_file_p2)) | 851 | if (0 == remove (cert_file_p2)) |
861 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p2); | 852 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
853 | "Successfully removed existing certificate file `%s'\n", | ||
854 | cert_file_p2); | ||
862 | else | 855 | else |
863 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p2); | 856 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n", |
857 | cert_file_p2); | ||
864 | } | 858 | } |
865 | 859 | ||
866 | if (0 == stat (key_file_p2, &sbuf )) | 860 | if (0 == stat (key_file_p2, &sbuf)) |
867 | { | 861 | { |
868 | if (0 == remove(key_file_p2)) | 862 | if (0 == remove (key_file_p2)) |
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p2); | 863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
864 | "Successfully removed private key file `%s'\n", | ||
865 | key_file_p2); | ||
870 | else | 866 | else |
871 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p2); | 867 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
868 | "Failed to private key file `%s'\n", key_file_p2); | ||
872 | } | 869 | } |
873 | GNUNET_free(key_file_p1); | 870 | GNUNET_free (key_file_p1); |
874 | GNUNET_free(key_file_p2); | 871 | GNUNET_free (key_file_p2); |
875 | GNUNET_free(cert_file_p1); | 872 | GNUNET_free (cert_file_p1); |
876 | GNUNET_free(cert_file_p2); | 873 | GNUNET_free (cert_file_p2); |
877 | } | 874 | } |
878 | 875 | ||
879 | if (p1.servicehome != NULL) | 876 | if (p1.servicehome != NULL) |
880 | { | 877 | { |
881 | GNUNET_DISK_directory_remove (p1.servicehome); | 878 | GNUNET_DISK_directory_remove (p1.servicehome); |
882 | GNUNET_free(p1.servicehome); | 879 | GNUNET_free (p1.servicehome); |
883 | } | 880 | } |
884 | if (p2.servicehome != NULL) | 881 | if (p2.servicehome != NULL) |
885 | { | 882 | { |
886 | GNUNET_DISK_directory_remove (p2.servicehome); | 883 | GNUNET_DISK_directory_remove (p2.servicehome); |
887 | GNUNET_free(p2.servicehome); | 884 | GNUNET_free (p2.servicehome); |
888 | } | 885 | } |
889 | return ok; | 886 | return ok; |
890 | } | 887 | } |
891 | 888 | ||
@@ -900,40 +897,40 @@ main (int argc, char *argv[]) | |||
900 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1"); | 897 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1"); |
901 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2"); | 898 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2"); |
902 | 899 | ||
903 | if (strstr(argv[0], "tcp_nat") != NULL) | 900 | if (strstr (argv[0], "tcp_nat") != NULL) |
904 | { | 901 | { |
905 | is_tcp_nat = GNUNET_YES; | 902 | is_tcp_nat = GNUNET_YES; |
906 | GNUNET_asprintf(&test_name, "tcp_nat"); | 903 | GNUNET_asprintf (&test_name, "tcp_nat"); |
907 | } | 904 | } |
908 | else if (strstr(argv[0], "tcp") != NULL) | 905 | else if (strstr (argv[0], "tcp") != NULL) |
909 | { | 906 | { |
910 | is_tcp = GNUNET_YES; | 907 | is_tcp = GNUNET_YES; |
911 | GNUNET_asprintf(&test_name, "tcp"); | 908 | GNUNET_asprintf (&test_name, "tcp"); |
912 | } | 909 | } |
913 | else if (strstr(argv[0], "https") != NULL) | 910 | else if (strstr (argv[0], "https") != NULL) |
914 | { | 911 | { |
915 | is_https = GNUNET_YES; | 912 | is_https = GNUNET_YES; |
916 | GNUNET_asprintf(&test_name, "https"); | 913 | GNUNET_asprintf (&test_name, "https"); |
917 | } | 914 | } |
918 | else if (strstr(argv[0], "http") != NULL) | 915 | else if (strstr (argv[0], "http") != NULL) |
919 | { | 916 | { |
920 | is_http = GNUNET_YES; | 917 | is_http = GNUNET_YES; |
921 | GNUNET_asprintf(&test_name, "http"); | 918 | GNUNET_asprintf (&test_name, "http"); |
922 | } | 919 | } |
923 | else if (strstr(argv[0], "udp") != NULL) | 920 | else if (strstr (argv[0], "udp") != NULL) |
924 | { | 921 | { |
925 | is_udp = GNUNET_YES; | 922 | is_udp = GNUNET_YES; |
926 | GNUNET_asprintf(&test_name, "udp"); | 923 | GNUNET_asprintf (&test_name, "udp"); |
927 | } | 924 | } |
928 | else if (strstr(argv[0], "unix") != NULL) | 925 | else if (strstr (argv[0], "unix") != NULL) |
929 | { | 926 | { |
930 | is_unix = GNUNET_YES; | 927 | is_unix = GNUNET_YES; |
931 | GNUNET_asprintf(&test_name, "unix"); | 928 | GNUNET_asprintf (&test_name, "unix"); |
932 | } | 929 | } |
933 | else if (strstr(argv[0], "wlan") != NULL) | 930 | else if (strstr (argv[0], "wlan") != NULL) |
934 | { | 931 | { |
935 | is_wlan = GNUNET_YES; | 932 | is_wlan = GNUNET_YES; |
936 | } | 933 | } |
937 | GNUNET_log_setup ("test-transport-api-unreliability", | 934 | GNUNET_log_setup ("test-transport-api-unreliability", |
938 | #if VERBOSE | 935 | #if VERBOSE |
939 | "DEBUG", | 936 | "DEBUG", |
@@ -943,7 +940,7 @@ main (int argc, char *argv[]) | |||
943 | NULL); | 940 | NULL); |
944 | ret = check (); | 941 | ret = check (); |
945 | 942 | ||
946 | GNUNET_free_non_null(test_name); | 943 | GNUNET_free_non_null (test_name); |
947 | return ret; | 944 | return ret; |
948 | } | 945 | } |
949 | 946 | ||