aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-08-30 15:28:30 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-08-30 15:28:30 +0000
commitba8a1ce1e673694a7bafb15d1fe70417bcf41a06 (patch)
tree61425f2beefcf2ff27616f8db378f59ef92863eb
parent1b70d33f033d80ddfa5fe7bf89f695bced0d5e13 (diff)
downloadgnunet-ba8a1ce1e673694a7bafb15d1fe70417bcf41a06.tar.gz
gnunet-ba8a1ce1e673694a7bafb15d1fe70417bcf41a06.zip
ported unreliability to transport testing
-rw-r--r--src/transport/test_transport_api_reliability.c6
-rw-r--r--src/transport/test_transport_api_unreliability.c671
-rw-r--r--src/transport/test_transport_api_unreliability_udp_peer1.conf31
-rw-r--r--src/transport/test_transport_api_unreliability_udp_peer2.conf31
-rw-r--r--src/transport/test_transport_api_unreliability_unix_peer1.conf29
-rw-r--r--src/transport/test_transport_api_unreliability_unix_peer2.conf29
-rw-r--r--src/transport/test_transport_api_unreliability_wlan_peer1.conf30
-rw-r--r--src/transport/test_transport_api_unreliability_wlan_peer2.conf30
8 files changed, 372 insertions, 485 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index debda3c9c..4cacf9c11 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -378,7 +378,7 @@ run (void *cls, char *const *args, const char *cfgfile,
378static int 378static int
379check () 379check ()
380{ 380{
381 static char *const argv[] = { "test-transport-api", 381 static char *const argv[] = { "test-transport-api-reliability",
382 "-c", 382 "-c",
383 "test_transport_api_data.conf", 383 "test_transport_api_data.conf",
384#if VERBOSE 384#if VERBOSE
@@ -395,7 +395,7 @@ check ()
395#endif 395#endif
396 ok = 1; 396 ok = 1;
397 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 397 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
398 "test-transport-api", "nohelp", options, &run, &ok); 398 "test-transport-api-reliability", "nohelp", options, &run, &ok);
399 399
400 return ok; 400 return ok;
401} 401}
@@ -406,7 +406,7 @@ main (int argc, char *argv[])
406 int ret; 406 int ret;
407 int nat_res; 407 int nat_res;
408 408
409 GNUNET_log_setup ("test-transport-api", 409 GNUNET_log_setup ("test-transport-api-reliability",
410#if VERBOSE 410#if VERBOSE
411 "DEBUG", 411 "DEBUG",
412#else 412#else
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index 32ebea221..74afc9c90 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -46,262 +46,116 @@
46#define START_ARM GNUNET_YES 46#define START_ARM GNUNET_YES
47 47
48/** 48/**
49 * Note that this value must not significantly exceed
50 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
51 * messages may be dropped even for a reliable transport.
52 */
53#define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */
54
55/**
56 * How long until we give up on transmitting the message? 49 * How long until we give up on transmitting the message?
57 */ 50 */
58#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) 51#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
59
60#define UNRELIABLE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
61
62#define MTYPE 12345
63
64static struct PeerContext p1;
65
66static struct PeerContext p2;
67 52
68static int ok; 53static int ok;
69 54
70static int is_tcp; 55static GNUNET_SCHEDULER_TaskIdentifier die_task;
71
72static int is_tcp_nat;
73
74static int is_http;
75
76static int is_https;
77
78static int is_udp;
79 56
80static int is_unix; 57struct PeerContext *p1;
81 58
82static int is_wlan; 59struct PeerContext *p2;
83 60
84static int connected; 61struct GNUNET_TRANSPORT_TransmitHandle *th;
85 62
86static unsigned long long total_bytes; 63char *cfg_file_p1;
87 64
88static struct GNUNET_TIME_Absolute start_time; 65char *cfg_file_p2;
89
90static GNUNET_SCHEDULER_TaskIdentifier die_task;
91 66
92static GNUNET_SCHEDULER_TaskIdentifier tct; 67/*
68 * Testcase specific declarations
69 */
93 70
94struct GNUNET_TRANSPORT_TransmitHandle *th_p2; 71/**
72 * Note that this value must not significantly exceed
73 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
74 * messages may be dropped even for a reliable transport.
75 */
76#define TOTAL_MSGS (1024 * 3)
95 77
96static char *key_file_p1; 78#define MTYPE 12345
97static char *cert_file_p1;
98 79
99static char *key_file_p2; 80struct TestMessage
100static char *cert_file_p2; 81{
82 struct GNUNET_MessageHeader header;
83 uint32_t num;
84};
101 85
102static char *test_name; 86static char *test_name;
103 87
104static char bitmap[TOTAL_MSGS / 8];
105
106static int msg_scheduled; 88static int msg_scheduled;
107static int msg_sent; 89static int msg_sent;
108static int msg_recv_expected; 90static int msg_recv_expected;
109static int msg_recv; 91static int msg_recv;
110 92
111static int p1_hello_canceled;
112static int p2_hello_canceled;
113
114static int test_failed; 93static int test_failed;
115 94
116/** 95static unsigned long long total_bytes;
117 * Sets a bit active in the bitmap.
118 *
119 * @param bitIdx which bit to set
120 */
121static void
122set_bit (unsigned int bitIdx)
123{
124 size_t arraySlot;
125 unsigned int targetBit;
126 96
127 if (bitIdx >= sizeof (bitmap) * 8) 97static struct GNUNET_TIME_Absolute start_time;
128 {
129 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of %d(!?!?)\n",
130 bitIdx, sizeof (bitmap) * 8);
131 return;
132 }
133 arraySlot = bitIdx / 8;
134 targetBit = (1L << (bitIdx % 8));
135 bitmap[arraySlot] |= targetBit;
136}
137 98
138/** 99static char bitmap[TOTAL_MSGS / 8];
139 * Obtain a bit from bitmap. 100
140 * @param map the bitmap 101/*
141 * @param bit index from bitmap 102 * END Testcase specific declarations
142 *
143 * @return Bit \a bit from hashcode \a code
144 */ 103 */
104
105#if VERBOSE
106#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
107#else
108#define OKPP do { ok++; } while (0)
109#endif
110
145int 111int
146get_bit (const char *map, unsigned int bit) 112get_bit (const char *map, unsigned int bit);
147{
148 if (bit >= TOTAL_MSGS)
149 {
150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit,
151 sizeof (bitmap) * 8);
152 return 0;
153 }
154 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0;
155}
156 113
157static void 114static void
158end () 115end ()
159{ 116{
160 unsigned long long delta; 117 unsigned long long delta;
161 int i;
162 int result;
163 char *value_name;
164 118
165 result = 0; 119 char *value_name;
166 for (i = 0; i < TOTAL_MSGS; i++)
167 {
168 if (get_bit (bitmap, i) == 0)
169 {
170 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Did not receive message %d\n", i);
171 result = -1;
172 }
173 }
174 120
175 if (GNUNET_SCHEDULER_NO_TASK != die_task) 121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
176 GNUNET_SCHEDULER_cancel (die_task);
177 die_task = GNUNET_SCHEDULER_NO_TASK;
178#if VERBOSE
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
180#endif
181 if (th_p2 != NULL)
182 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
183 th_p2 = NULL;
184 122
185 GNUNET_TRANSPORT_disconnect (p1.th);
186 GNUNET_TRANSPORT_disconnect (p2.th);
187#if VERBOSE
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "Transports disconnected, returning success!\n");
190#endif
191 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 123 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
192 GNUNET_asprintf (&value_name, "unreliable_%s", test_name);
193 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
194 "kb/s");
195 GNUNET_free (value_name);
196 fprintf (stderr, "\nThroughput was %llu kb/s\n", 124 fprintf (stderr, "\nThroughput was %llu kb/s\n",
197 total_bytes * 1000 / 1024 / delta); 125 total_bytes * 1000 / 1024 / delta);
198 ok = result; 126 GNUNET_asprintf(&value_name, "unreliable_%s", test_name);
127 GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s");
128 GNUNET_free(value_name);
199 129
200} 130 if (die_task != GNUNET_SCHEDULER_NO_TASK)
131 GNUNET_SCHEDULER_cancel (die_task);
201 132
202static void 133 if (th != NULL)
203end_unreliably () 134 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
204{ 135 th = NULL;
205 unsigned long long delta; 136
206 int i; 137 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
207 int num_failed; 138 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
208 char *value_name;
209 139
210 num_failed = 0; 140 ok = 0;
141
142 int i;
211 for (i = 0; i < TOTAL_MSGS; i++) 143 for (i = 0; i < TOTAL_MSGS; i++)
212 { 144 {
213 if (get_bit (bitmap, i) == 0) 145 if (get_bit (bitmap, i) == 0)
214 { 146 {
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Did not receive message %d\n", i); 147 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Did not receive message %d\n", i);
216 num_failed++; 148 ok = -1;
217 } 149 }
218 } 150 }
219
220 die_task = GNUNET_SCHEDULER_NO_TASK;
221#if VERBOSE
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
223#endif
224 if (th_p2 != NULL)
225 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
226
227 GNUNET_TRANSPORT_disconnect (p1.th);
228 GNUNET_TRANSPORT_disconnect (p2.th);
229#if VERBOSE
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
231 "Transports disconnected, returning success!\n");
232#endif
233 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
234 fprintf (stderr, "\nThroughput was %llu kb/s\n",
235 total_bytes * 1000 / 1024 / delta);
236 GNUNET_asprintf (&value_name, "unreliable_%s", test_name);
237 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
238 "kb/s");
239 GNUNET_free (value_name);
240 GNUNET_asprintf (&value_name, "unreliable_failed_%s", test_name);
241 GAUGER ("TRANSPORT", value_name, (int) num_failed, "msgs");
242 GNUNET_free (value_name);
243 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Had %d failed messages!\n",
244 num_failed);
245 ok = 0;
246
247}
248
249
250
251static void
252stop_arm (struct PeerContext *p)
253{
254#if START_ARM
255 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
256 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
257 GNUNET_OS_process_wait (p->arm_proc);
258 GNUNET_OS_process_close (p->arm_proc);
259 p->arm_proc = NULL;
260#endif
261 GNUNET_CONFIGURATION_destroy (p->cfg);
262} 151}
263 152
264
265
266static void
267exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
268{
269 struct PeerContext *me = cls;
270
271 GNUNET_assert (message != NULL);
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Exchanging HELLO of size %d with peer (%s)!\n",
274 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
275 message), GNUNET_i2s (&me->id));
276 GNUNET_assert (GNUNET_OK ==
277 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
278 message, &me->id));
279 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
280}
281
282
283
284static void 153static void
285exchange_hello (void *cls, const struct GNUNET_MessageHeader *message) 154end_badly ()
286{ 155{
287 struct PeerContext *me = cls; 156 die_task = GNUNET_SCHEDULER_NO_TASK;
288 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
289 GNUNET_assert (message != NULL);
290 GNUNET_assert (GNUNET_OK ==
291 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
292 message, &me->id));
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
294 "Exchanging HELLO of size %d from peer %s!\n",
295 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
296 message), GNUNET_i2s (&me->id));
297 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
298}
299
300
301 158
302static void
303end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
304{
305 if (test_failed == GNUNET_NO) 159 if (test_failed == GNUNET_NO)
306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n"); 160 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n");
307 else 161 else
@@ -309,39 +163,17 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
309 "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", 163 "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
310 msg_sent, msg_scheduled, msg_recv, msg_recv_expected); 164 msg_sent, msg_scheduled, msg_recv, msg_recv_expected);
311 165
312 GNUNET_break (0); 166 if (th != NULL)
313 if (th_p2 != NULL) 167 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
314 { 168 th = NULL;
315 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
316 th_p2 = NULL;
317 }
318 if (p2_hello_canceled == GNUNET_NO)
319 {
320 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
321 p2_hello_canceled = GNUNET_YES;
322 }
323 if (p1_hello_canceled == GNUNET_NO)
324 {
325 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
326 p1_hello_canceled = GNUNET_YES;
327 }
328 GNUNET_TRANSPORT_disconnect (p1.th);
329 GNUNET_TRANSPORT_disconnect (p2.th);
330 if (GNUNET_SCHEDULER_NO_TASK != tct)
331 {
332 GNUNET_SCHEDULER_cancel (tct);
333 tct = GNUNET_SCHEDULER_NO_TASK;
334 }
335 ok = 1;
336}
337 169
170 if (p1 != NULL)
171 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
172 if (p2 != NULL)
173 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
338 174
339 175 ok = GNUNET_SYSERR;
340struct TestMessage 176}
341{
342 struct GNUNET_MessageHeader header;
343 uint32_t num;
344};
345 177
346 178
347static unsigned int 179static unsigned int
@@ -354,6 +186,48 @@ get_size (unsigned int iter)
354} 186}
355 187
356 188
189/**
190 * Sets a bit active in the bitmap.
191 *
192 * @param bitIdx which bit to set
193 */
194static void
195set_bit (unsigned int bitIdx)
196{
197 size_t arraySlot;
198 unsigned int targetBit;
199
200 if (bitIdx >= sizeof (bitmap) * 8)
201 {
202 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of %d(!?!?)\n",
203 bitIdx, sizeof (bitmap) * 8);
204 return;
205 }
206 arraySlot = bitIdx / 8;
207 targetBit = (1L << (bitIdx % 8));
208 bitmap[arraySlot] |= targetBit;
209}
210
211/**
212 * Obtain a bit from bitmap.
213 * @param map the bitmap
214 * @param bit index from bitmap
215 *
216 * @return Bit \a bit from hashcode \a code
217 */
218int
219get_bit (const char *map, unsigned int bit)
220{
221 if (bit >= TOTAL_MSGS)
222 {
223 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit,
224 sizeof (bitmap) * 8);
225 return 0;
226 }
227 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0;
228}
229
230
357static void 231static void
358notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 232notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
359 const struct GNUNET_MessageHeader *message, 233 const struct GNUNET_MessageHeader *message,
@@ -361,6 +235,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
361 uint32_t ats_count) 235 uint32_t ats_count)
362{ 236{
363 static int n; 237 static int n;
238
364 unsigned int s; 239 unsigned int s;
365 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 240 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
366 const struct TestMessage *hdr; 241 const struct TestMessage *hdr;
@@ -428,7 +303,7 @@ notify_ready (void *cls, size_t size, void *buf)
428 unsigned int s; 303 unsigned int s;
429 unsigned int ret; 304 unsigned int ret;
430 305
431 th_p2 = NULL; 306 th = NULL;
432 307
433 if (buf == NULL) 308 if (buf == NULL)
434 { 309 {
@@ -457,6 +332,7 @@ notify_ready (void *cls, size_t size, void *buf)
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n, 332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n,
458 s); 333 s);
459 } 334 }
335
460#endif 336#endif
461 n++; 337 n++;
462 s = get_size (n); 338 s = get_size (n);
@@ -466,8 +342,8 @@ notify_ready (void *cls, size_t size, void *buf)
466 while (size - ret >= s); 342 while (size - ret >= s);
467 if (n < TOTAL_MSGS) 343 if (n < TOTAL_MSGS)
468 { 344 {
469 th_p2 = 345 th =
470 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, s, 0, TIMEOUT, 346 GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, 0, TIMEOUT,
471 &notify_ready, NULL); 347 &notify_ready, NULL);
472 msg_scheduled = n; 348 msg_scheduled = n;
473 } 349 }
@@ -478,7 +354,7 @@ notify_ready (void *cls, size_t size, void *buf)
478 if (GNUNET_SCHEDULER_NO_TASK != die_task) 354 if (GNUNET_SCHEDULER_NO_TASK != die_task)
479 GNUNET_SCHEDULER_cancel (die_task); 355 GNUNET_SCHEDULER_cancel (die_task);
480 die_task = 356 die_task =
481 GNUNET_SCHEDULER_add_delayed (UNRELIABLE_TIMEOUT, &end_unreliably, 357 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
482 NULL); 358 NULL);
483 } 359 }
484 if (n % 5000 == 0) 360 if (n % 5000 == 0)
@@ -491,182 +367,82 @@ notify_ready (void *cls, size_t size, void *buf)
491} 367}
492 368
493 369
494
495static void
496notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
497{
498 connected--;
499#if VERBOSE
500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
501 GNUNET_i2s (peer), cls);
502#endif
503 if (th_p2 != NULL)
504 {
505 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
506 th_p2 = NULL;
507 }
508}
509
510
511
512static void 370static void
513notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, 371notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
514 const struct GNUNET_TRANSPORT_ATS_Information *ats, 372 const struct GNUNET_TRANSPORT_ATS_Information *ats,
515 uint32_t ats_count) 373 uint32_t ats_count)
516{ 374{
375
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", 376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
518 GNUNET_i2s (peer), cls); 377 GNUNET_i2s (peer), cls);
519 if (cls == &p1) 378
379 if (cls == p1)
520 { 380 {
521 GNUNET_TRANSPORT_set_quota (p1.th, &p2.id, 381 GNUNET_TRANSPORT_set_quota (p1->th, &p2->id,
522 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 382 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
523 1024), 383 1024),
524 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 384 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
525 1024)); 385 1024));
526 start_time = GNUNET_TIME_absolute_get ();
527 connected++;
528 } 386 }
529 else 387 else if (cls == p2)
530 { 388 {
531 GNUNET_TRANSPORT_set_quota (p2.th, &p1.id, 389 GNUNET_TRANSPORT_set_quota (p2->th, &p1->id,
532 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 390 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
533 1024), 391 1024),
534 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 392 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
535 1024)); 393 1024));
536 connected++;
537 }
538 if (2 == connected)
539 {
540 if (GNUNET_SCHEDULER_NO_TASK != die_task)
541 {
542 GNUNET_SCHEDULER_cancel (die_task);
543 }
544 if (GNUNET_SCHEDULER_NO_TASK != tct)
545 {
546 GNUNET_SCHEDULER_cancel (tct);
547 tct = GNUNET_SCHEDULER_NO_TASK;
548 }
549 if (p2_hello_canceled == GNUNET_NO)
550 {
551 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
552 p2_hello_canceled = GNUNET_YES;
553 }
554 if (p1_hello_canceled == GNUNET_NO)
555 {
556 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
557 p1_hello_canceled = GNUNET_YES;
558 }
559
560 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
561 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, get_size (0), 0,
562 TIMEOUT, &notify_ready, NULL);
563
564 } 394 }
565} 395}
566 396
567 397
568static void 398static void
569setup_peer (struct PeerContext *p, const char *cfgname) 399notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
570{ 400{
571 memset (p, 0, sizeof (*p)); 401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
572 p->cfg = GNUNET_CONFIGURATION_create (); 402 GNUNET_i2s (peer), cls);
573
574 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
575 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
576 {
577 GNUNET_assert (GNUNET_OK ==
578 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS",
579 "SERVICEHOME",
580 &p->servicehome));
581 GNUNET_DISK_directory_remove (p->servicehome);
582 }
583
584
585#if START_ARM
586 p->arm_proc =
587 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
588 "gnunet-service-arm",
589#if VERBOSE_ARM
590 "-L", "DEBUG",
591#endif
592 "-c", cfgname, NULL);
593#endif
594
595 p->th =
596 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, &notify_receive,
597 &notify_connect, &notify_disconnect);
598 GNUNET_assert (p->th != NULL);
599} 403}
600 404
601static void 405static void
602try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 406sendtask ()
603{ 407{
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n"); 408 start_time = GNUNET_TIME_absolute_get ();
605 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 409 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), 0,
606 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 410 TIMEOUT, &notify_ready, NULL);
607 tct =
608 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
609 NULL);
610} 411}
611 412
413static void
414testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
415{
416 char *p1_c = strdup (GNUNET_i2s (&p1->id));
417
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c,
419 GNUNET_i2s (&p2->id));
420 GNUNET_free (p1_c);
612 421
422 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
423 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
424}
613 425
614static void 426static void
615run (void *cls, char *const *args, const char *cfgfile, 427run (void *cls, char *const *args, const char *cfgfile,
616 const struct GNUNET_CONFIGURATION_Handle *cfg) 428 const struct GNUNET_CONFIGURATION_Handle *cfg)
617{ 429{
618 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 430 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
619 if (is_tcp)
620 {
621 setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
622 setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
623 }
624 else if (is_http)
625 {
626 setup_peer (&p1, "test_transport_api_rel_http_peer1.conf");
627 setup_peer (&p2, "test_transport_api_rel_http_peer2.conf");
628 }
629 else if (is_https)
630 {
631 setup_peer (&p1, "test_transport_api_rel_https_peer1.conf");
632 setup_peer (&p2, "test_transport_api_rel_https_peer2.conf");
633 }
634 else if (is_udp)
635 {
636 setup_peer (&p1, "test_transport_api_udp_peer1.conf");
637 setup_peer (&p2, "test_transport_api_udp_peer2.conf");
638 }
639 else if (is_unix)
640 {
641 setup_peer (&p1, "test_transport_api_unix_peer1.conf");
642 setup_peer (&p2, "test_transport_api_unix_peer2.conf");
643 }
644 else if (is_tcp_nat)
645 {
646 setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
647 setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
648 }
649 else if (is_wlan)
650 {
651 setup_peer (&p1, "test_transport_api_wlan_peer1.conf");
652 setup_peer (&p2, "test_transport_api_wlan_peer2.conf");
653 }
654 else
655 GNUNET_assert (0);
656 GNUNET_assert (p1.th != NULL);
657 GNUNET_assert (p2.th != NULL);
658 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
659 p1_hello_canceled = GNUNET_NO;
660 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
661 p2_hello_canceled = GNUNET_NO;
662 tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
663}
664 431
432 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
433 &notify_connect, &notify_disconnect,
434 NULL);
435 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
436 &notify_connect, &notify_disconnect,
437 NULL);
438
439 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
440}
665 441
666static int 442static int
667check () 443check ()
668{ 444{
669 char *const argv[] = { "test-transport-api-unreliability", 445 static char *const argv[] = { "test-transport-api-unreliability",
670 "-c", 446 "-c",
671 "test_transport_api_data.conf", 447 "test_transport_api_data.conf",
672#if VERBOSE 448#if VERBOSE
@@ -674,133 +450,27 @@ check ()
674#endif 450#endif
675 NULL 451 NULL
676 }; 452 };
677 struct GNUNET_GETOPT_CommandLineOption options[] = { 453 static struct GNUNET_GETOPT_CommandLineOption options[] = {
678 GNUNET_GETOPT_OPTION_END 454 GNUNET_GETOPT_OPTION_END
679 }; 455 };
680 456
681#if WRITECONFIG 457#if WRITECONFIG
682 setTransportOptions ("test_transport_api_data.conf"); 458 setTransportOptions ("test_transport_api_data.conf");
683#endif 459#endif
684 ok = 1; 460 ok = GNUNET_SYSERR;
685 461
686 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 462 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
687 "test-transport-api-unreliability", "nohelp", options, 463 "test-transport-api-unreliability", "nohelp", options, &run, &ok);
688 &run, &ok);
689 stop_arm (&p1);
690 stop_arm (&p2);
691
692 if (is_https)
693 {
694 struct stat sbuf;
695
696 if (0 == stat (cert_file_p1, &sbuf))
697 {
698 if (0 == remove (cert_file_p1))
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "Successfully removed existing certificate file `%s'\n",
701 cert_file_p1);
702 else
703 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",
704 cert_file_p1);
705 }
706
707 if (0 == stat (key_file_p1, &sbuf))
708 {
709 if (0 == remove (key_file_p1))
710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
711 "Successfully removed private key file `%s'\n",
712 key_file_p1);
713 else
714 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
715 "Failed to private key file `%s'\n", key_file_p1);
716 }
717 464
718 if (0 == stat (cert_file_p2, &sbuf))
719 {
720 if (0 == remove (cert_file_p2))
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722 "Successfully removed existing certificate file `%s'\n",
723 cert_file_p2);
724 else
725 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",
726 cert_file_p2);
727 }
728
729 if (0 == stat (key_file_p2, &sbuf))
730 {
731 if (0 == remove (key_file_p2))
732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
733 "Successfully removed private key file `%s'\n",
734 key_file_p2);
735 else
736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
737 "Failed to private key file `%s'\n", key_file_p2);
738 }
739 GNUNET_free (key_file_p1);
740 GNUNET_free (key_file_p2);
741 GNUNET_free (cert_file_p1);
742 GNUNET_free (cert_file_p2);
743 }
744
745 if (p1.servicehome != NULL)
746 {
747 GNUNET_DISK_directory_remove (p1.servicehome);
748 GNUNET_free (p1.servicehome);
749 }
750 if (p2.servicehome != NULL)
751 {
752 GNUNET_DISK_directory_remove (p2.servicehome);
753 GNUNET_free (p2.servicehome);
754 }
755 return ok; 465 return ok;
756} 466}
757 467
758
759int 468int
760main (int argc, char *argv[]) 469main (int argc, char *argv[])
761{ 470{
762 int ret; 471 int ret;
763 int nat_res; 472 int nat_res;
764 473
765 test_failed = GNUNET_NO;
766
767 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
768 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
769
770 if (strstr (argv[0], "tcp_nat") != NULL)
771 {
772 is_tcp_nat = GNUNET_YES;
773 GNUNET_asprintf (&test_name, "tcp_nat");
774 }
775 else if (strstr (argv[0], "tcp") != NULL)
776 {
777 is_tcp = GNUNET_YES;
778 GNUNET_asprintf (&test_name, "tcp");
779 }
780 else if (strstr (argv[0], "https") != NULL)
781 {
782 is_https = GNUNET_YES;
783 GNUNET_asprintf (&test_name, "https");
784 }
785 else if (strstr (argv[0], "http") != NULL)
786 {
787 is_http = GNUNET_YES;
788 GNUNET_asprintf (&test_name, "http");
789 }
790 else if (strstr (argv[0], "udp") != NULL)
791 {
792 is_udp = GNUNET_YES;
793 GNUNET_asprintf (&test_name, "udp");
794 }
795 else if (strstr (argv[0], "unix") != NULL)
796 {
797 is_unix = GNUNET_YES;
798 GNUNET_asprintf (&test_name, "unix");
799 }
800 else if (strstr (argv[0], "wlan") != NULL)
801 {
802 is_wlan = GNUNET_YES;
803 }
804 GNUNET_log_setup ("test-transport-api-unreliability", 474 GNUNET_log_setup ("test-transport-api-unreliability",
805#if VERBOSE 475#if VERBOSE
806 "DEBUG", 476 "DEBUG",
@@ -809,6 +479,41 @@ main (int argc, char *argv[])
809#endif 479#endif
810 NULL); 480 NULL);
811 481
482 char *pch = strdup (argv[0]);
483 char *backup = pch;
484 char *filename = NULL;
485 char *dotexe;
486 char *src_name = strdup (__FILE__);
487 char *split = NULL;
488
489 /* get executable filename */
490 pch = strtok (pch, "/");
491 while (pch != NULL)
492 {
493 pch = strtok (NULL, "/");
494 if (pch != NULL)
495 filename = pch;
496 }
497 /* remove "lt-" */
498 filename = strstr (filename, "tes");
499 if (NULL != (dotexe = strstr (filename, ".exe")))
500 dotexe[0] = '\0';
501
502 /* create cfg filename */
503 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
504 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
505
506 split = strstr (src_name, ".");
507 if (split != NULL)
508 {
509 split[0] = '\0';
510 test_name = strdup(&filename[strlen(src_name)+1]);
511 }
512 else
513 test_name = NULL;
514
515 GNUNET_free (src_name);
516 GNUNET_free (backup);
812 517
813 if ((strstr (argv[0], "tcp_nat") != NULL) || (strstr (argv[0], "udp_nat") != NULL)) 518 if ((strstr (argv[0], "tcp_nat") != NULL) || (strstr (argv[0], "udp_nat") != NULL))
814 { 519 {
@@ -830,10 +535,12 @@ main (int argc, char *argv[])
830 return 0; 535 return 0;
831 } 536 }
832 } 537 }
833
834 ret = check (); 538 ret = check ();
835 539
540 GNUNET_free (cfg_file_p1);
541 GNUNET_free (cfg_file_p2);
836 GNUNET_free_non_null (test_name); 542 GNUNET_free_non_null (test_name);
543
837 return ret; 544 return ret;
838} 545}
839 546
diff --git a/src/transport/test_transport_api_unreliability_udp_peer1.conf b/src/transport/test_transport_api_unreliability_udp_peer1.conf
new file mode 100644
index 000000000..b57bdee53
--- /dev/null
+++ b/src/transport/test_transport_api_unreliability_udp_peer1.conf
@@ -0,0 +1,31 @@
1@INLINE@ test_transport_defaults.conf
2[PATHS]
3SERVICEHOME = /tmp/test-transport/api-udp-p1/
4DEFAULTCONFIG = test_transport_api_udp_peer1.conf
5
6[transport-udp]
7PORT = 12040
8MAX_BPS = 50000000
9
10[arm]
11PORT = 12045
12UNIXPATH = /tmp/gnunet-p1-service-arm.sock
13
14[statistics]
15PORT = 12044
16UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
17
18[resolver]
19PORT = 12043
20UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
21
22[peerinfo]
23PORT = 12042
24UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
25
26[transport]
27PORT = 12041
28PLUGINS = udp
29UNIXPATH = /tmp/gnunet-p1-service-transport.sock
30
31
diff --git a/src/transport/test_transport_api_unreliability_udp_peer2.conf b/src/transport/test_transport_api_unreliability_udp_peer2.conf
new file mode 100644
index 000000000..cf54000e6
--- /dev/null
+++ b/src/transport/test_transport_api_unreliability_udp_peer2.conf
@@ -0,0 +1,31 @@
1@INLINE@ test_transport_defaults.conf
2[PATHS]
3SERVICEHOME = /tmp/test-transport/api-udp-p2/
4DEFAULTCONFIG = test_transport_api_udp_peer2.conf
5
6[transport-udp]
7PORT = 12050
8MAX_BPS = 50000000
9
10[arm]
11PORT = 12055
12UNIXPATH = /tmp/gnunet-p2-service-arm.sock
13
14[statistics]
15PORT = 12054
16UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
17
18[resolver]
19PORT = 12053
20UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
21
22[peerinfo]
23PORT = 12052
24UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
25
26[transport]
27PORT = 12051
28PLUGINS = udp
29UNIXPATH = /tmp/gnunet-p2-service-transport.sock
30
31
diff --git a/src/transport/test_transport_api_unreliability_unix_peer1.conf b/src/transport/test_transport_api_unreliability_unix_peer1.conf
new file mode 100644
index 000000000..c6b2d2a68
--- /dev/null
+++ b/src/transport/test_transport_api_unreliability_unix_peer1.conf
@@ -0,0 +1,29 @@
1@INLINE@ test_transport_defaults.conf
2[PATHS]
3SERVICEHOME = /tmp/test-transport/api-unix-p1/
4DEFAULTCONFIG = test_transport_api_unix_peer1.conf
5
6[arm]
7PORT = 12125
8UNIXPATH = /tmp/gnunet-p1-service-arm.sock
9
10[statistics]
11PORT = 12124
12UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
13
14[resolver]
15PORT = 12123
16UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
17
18[peerinfo]
19PORT = 12122
20UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
21
22[transport]
23PORT = 12121
24PLUGINS = unix
25UNIXPATH = /tmp/gnunet-p1-service-transport.sock
26
27[transport-unix]
28PORT = 12120
29
diff --git a/src/transport/test_transport_api_unreliability_unix_peer2.conf b/src/transport/test_transport_api_unreliability_unix_peer2.conf
new file mode 100644
index 000000000..bed415b65
--- /dev/null
+++ b/src/transport/test_transport_api_unreliability_unix_peer2.conf
@@ -0,0 +1,29 @@
1@INLINE@ test_transport_defaults.conf
2[PATHS]
3SERVICEHOME = /tmp/test-transport/api-unix-p2/
4DEFAULTCONFIG = test_transport_api_unix_peer2.conf
5
6[arm]
7PORT = 12135
8UNIXPATH = /tmp/gnunet-p2-service-arm.sock
9
10[statistics]
11PORT = 12134
12UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
13
14[resolver]
15PORT = 12133
16UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
17
18[peerinfo]
19PORT = 12132
20UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
21
22[transport]
23PORT = 12131
24PLUGINS = unix
25UNIXPATH = /tmp/gnunet-p2-service-transport.sock
26
27[transport-unix]
28PORT = 12131
29
diff --git a/src/transport/test_transport_api_unreliability_wlan_peer1.conf b/src/transport/test_transport_api_unreliability_wlan_peer1.conf
new file mode 100644
index 000000000..704fd55b1
--- /dev/null
+++ b/src/transport/test_transport_api_unreliability_wlan_peer1.conf
@@ -0,0 +1,30 @@
1@INLINE@ test_transport_defaults.conf
2[PATHS]
3SERVICEHOME = /tmp/test-transport/api-wlan-p1/
4DEFAULTCONFIG = test_transport_api_wlan_peer1.conf
5
6[transport-wlan]
7TESTMODE = 1
8
9[arm]
10PORT = 12164
11UNIXPATH = /tmp/gnunet-p1-service-arm.sock
12
13[statistics]
14PORT = 12163
15UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
16
17[resolver]
18PORT = 12162
19UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
20
21[peerinfo]
22PORT = 12161
23UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
24
25[transport]
26PORT = 12160
27PLUGINS = wlan
28UNIXPATH = /tmp/gnunet-p1-service-transport.sock
29
30
diff --git a/src/transport/test_transport_api_unreliability_wlan_peer2.conf b/src/transport/test_transport_api_unreliability_wlan_peer2.conf
new file mode 100644
index 000000000..2ab9811ea
--- /dev/null
+++ b/src/transport/test_transport_api_unreliability_wlan_peer2.conf
@@ -0,0 +1,30 @@
1@INLINE@ test_transport_defaults.conf
2[PATHS]
3SERVICEHOME = /tmp/test-transport/api-wlan-p2/
4DEFAULTCONFIG = test_transport_api_wlan_peer2.conf
5
6[transport-wlan]
7INTERFACE = mon1
8TESTMODE = 2
9
10[arm]
11PORT = 12174
12UNIXPATH = /tmp/gnunet-p2-service-arm.sock
13
14[statistics]
15PORT = 12173
16UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
17
18[resolver]
19PORT = 12172
20UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
21
22[peerinfo]
23PORT = 12171
24UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
25
26[transport]
27PORT = 12170
28PLUGINS = wlan
29UNIXPATH = /tmp/gnunet-p2-service-transport.sock
30