aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-06-01 13:39:00 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-06-01 13:39:00 +0000
commitbfcc2705ca4a4eabb389c3694829bf697c9b9da3 (patch)
treef314ec00651a4e96ff6056dae7dcfe05370993d6 /src/transport/test_plugin_transport_http.c
parentbef69365a14f57dff5a73e1a1fb38f10fc4e067f (diff)
downloadgnunet-bfcc2705ca4a4eabb389c3694829bf697c9b9da3.tar.gz
gnunet-bfcc2705ca4a4eabb389c3694829bf697c9b9da3.zip
Diffstat (limited to 'src/transport/test_plugin_transport_http.c')
-rw-r--r--src/transport/test_plugin_transport_http.c212
1 files changed, 186 insertions, 26 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 75af179ab..dbbb91e36 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -52,7 +52,7 @@
52/** 52/**
53 * How long until we give up on transmitting the message? 53 * How long until we give up on transmitting the message?
54 */ 54 */
55#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) 55#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
56 56
57/** 57/**
58 * How long between recieve and send? 58 * How long between recieve and send?
@@ -60,6 +60,17 @@
60#define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 60#define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
61 61
62/** 62/**
63 * Message to send using http
64 */
65struct HTTP_Message
66{
67 char *buf;
68 size_t pos;
69 size_t size;
70 size_t len;
71};
72
73/**
63 * Our public key. 74 * Our public key.
64 */ 75 */
65/* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */ 76/* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
@@ -184,6 +195,15 @@ CURL *curl_handle;
184 */ 195 */
185static CURLM *multi_handle; 196static CURLM *multi_handle;
186 197
198/**
199 * Test message to send
200 */
201struct HTTP_Message * msg;
202
203/**
204 * The task sending data
205 */
206static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
187 207
188/** 208/**
189 * Shutdown testcase 209 * Shutdown testcase
@@ -191,12 +211,20 @@ static CURLM *multi_handle;
191static void 211static void
192shutdown_clean () 212shutdown_clean ()
193{ 213{
214 curl_multi_cleanup(multi_handle);
215
194 if (ti_send != GNUNET_SCHEDULER_NO_TASK) 216 if (ti_send != GNUNET_SCHEDULER_NO_TASK)
195 { 217 {
196 GNUNET_SCHEDULER_cancel(sched,ti_send); 218 GNUNET_SCHEDULER_cancel(sched,ti_send);
197 ti_send = GNUNET_SCHEDULER_NO_TASK; 219 ti_send = GNUNET_SCHEDULER_NO_TASK;
198 } 220 }
199 221
222 if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
223 {
224 GNUNET_SCHEDULER_cancel(sched,http_task_send);
225 http_task_send = GNUNET_SCHEDULER_NO_TASK;
226 }
227
200 if (ti_timeout != GNUNET_SCHEDULER_NO_TASK) 228 if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
201 { 229 {
202 GNUNET_SCHEDULER_cancel(sched,ti_timeout); 230 GNUNET_SCHEDULER_cancel(sched,ti_timeout);
@@ -206,6 +234,12 @@ shutdown_clean ()
206 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http", api)); 234 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http", api));
207 235
208 GNUNET_SCHEDULER_shutdown(sched); 236 GNUNET_SCHEDULER_shutdown(sched);
237
238
239
240 //GNUNET_free(msg);
241 //GNUNET_free(msg->buf);
242
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n"); 243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
210 exit(fail); 244 exit(fail);
211 return; 245 return;
@@ -273,17 +307,6 @@ receive (void *cls,
273 return GNUNET_TIME_UNIT_ZERO; 307 return GNUNET_TIME_UNIT_ZERO;
274} 308}
275 309
276/**
277 * Message to send using http
278 */
279struct HTTP_Message
280{
281 char *buf;
282 size_t pos;
283 size_t size;
284 size_t len;
285};
286
287 int done; 310 int done;
288static size_t 311static size_t
289putBuffer (void *stream, size_t size, size_t nmemb, void *ptr) 312putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
@@ -311,26 +334,163 @@ static size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
311 return size * nmemb; 334 return size * nmemb;
312} 335}
313 336
337static size_t send_prepare( void );
338
339static void send_execute (void *cls,
340 const struct GNUNET_SCHEDULER_TaskContext *tc)
341{
342 int running;
343 struct CURLMsg *msg;
344 CURLMcode mret;
345
346 http_task_send = GNUNET_SCHEDULER_NO_TASK;
347 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
348 return;
349
350 do
351 {
352 running = 0;
353 mret = curl_multi_perform (multi_handle, &running);
354 if (running == 0)
355 {
356 do
357 {
358
359 msg = curl_multi_info_read (multi_handle, &running);
360 GNUNET_break (msg != NULL);
361 if (msg == NULL)
362 break;
363 /* get session for affected curl handle */
364 //cs = find_session_by_curlhandle (msg->easy_handle);
365 //GNUNET_assert ( cs != NULL );
366 switch (msg->msg)
367 {
368
369 case CURLMSG_DONE:
370 if ( (msg->data.result != CURLE_OK) &&
371 (msg->data.result != CURLE_GOT_NOTHING) )
372 {
373
374 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
375 _("curl failed for `%s' at %s:%d: `%s'\n"),
376 "curl_multi_perform",
377 __FILE__,
378 __LINE__,
379 curl_easy_strerror (msg->data.result));
380 /* sending msg failed*/
381 //if ( NULL != cs->transmit_cont)
382 // cs->transmit_cont (NULL,&cs->sender,GNUNET_SYSERR);
383 }
384 else
385 {
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
387 "Send completed.\n");
388 //if (GNUNET_OK != remove_http_message(cs, cs->pending_outbound_msg))
389 //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'", GNUNET_i2s(&cs->sender));
390
391 curl_easy_cleanup(curl_handle);
392 curl_handle=NULL;
393 shutdown_clean();
394
395 }
396 return;
397 default:
398 break;
399 }
400
401 }
402 while ( (running > 0) );
403 }
404 }
405 while (mret == CURLM_CALL_MULTI_PERFORM);
406 send_prepare();
407}
408
314/** 409/**
315 * function to send data to server 410 * Function setting up file descriptors and scheduling task to run
411 * @param ses session to send data to
412 * @return bytes sent to peer
316 */ 413 */
317static int send_data(struct HTTP_Message *msg, char * url) 414static size_t send_prepare( void )
318{ 415{
319 struct HTTP_Message cbc; 416 fd_set rs;
417 fd_set ws;
418 fd_set es;
419 int max;
420 struct GNUNET_NETWORK_FDSet *grs;
421 struct GNUNET_NETWORK_FDSet *gws;
422 long to;
423 CURLMcode mret;
424
425 max = -1;
426 FD_ZERO (&rs);
427 FD_ZERO (&ws);
428 FD_ZERO (&es);
429 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
430 if (mret != CURLM_OK)
431 {
432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
433 _("%s failed at %s:%d: `%s'\n"),
434 "curl_multi_fdset", __FILE__, __LINE__,
435 curl_multi_strerror (mret));
436 return -1;
437 }
438 mret = curl_multi_timeout (multi_handle, &to);
439 if (mret != CURLM_OK)
440 {
441 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
442 _("%s failed at %s:%d: `%s'\n"),
443 "curl_multi_timeout", __FILE__, __LINE__,
444 curl_multi_strerror (mret));
445 return -1;
446 }
320 447
448 grs = GNUNET_NETWORK_fdset_create ();
449 gws = GNUNET_NETWORK_fdset_create ();
450 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
451 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
452 http_task_send = GNUNET_SCHEDULER_add_select (sched,
453 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
454 GNUNET_SCHEDULER_NO_TASK,
455 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0),
456 grs,
457 gws,
458 &send_execute,
459 NULL);
460 GNUNET_NETWORK_fdset_destroy (gws);
461 GNUNET_NETWORK_fdset_destroy (grs);
462
463 /* FIXME: return bytes REALLY sent */
464 return 0;
465}
321 466
467/**
468 * function to send data to server
469 */
470static int send_data(struct HTTP_Message *msg, char * url)
471{
472 //return GNUNET_OK;
473 curl_handle = curl_easy_init();
474 if( NULL == curl_handle)
475 {
476 printf("easy_init failed \n");
477 return GNUNET_SYSERR;
478 }
479 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
322 curl_easy_setopt(curl_handle, CURLOPT_URL, url); 480 curl_easy_setopt(curl_handle, CURLOPT_URL, url);
323 curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L); 481 curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
324 curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &copyBuffer); 482 curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &copyBuffer);
325 curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, &cbc); 483 curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, msg);
326 curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &putBuffer); 484 curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &putBuffer);
327 curl_easy_setopt (curl_handle, CURLOPT_READDATA, &cbc); 485 curl_easy_setopt (curl_handle, CURLOPT_READDATA, msg);
328 curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len); 486 curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len);
329 //curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, (timeout.value / 1000 )); 487 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
330 //curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); 488 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
331 489
332 curl_multi_add_handle(multi_handle, curl_handle); 490 curl_multi_add_handle(multi_handle, curl_handle);
333 491
492 send_prepare();
493
334 return GNUNET_OK; 494 return GNUNET_OK;
335} 495}
336 496
@@ -462,7 +622,7 @@ static void pretty_printer_cb (void *cls,
462{ 622{
463 if (NULL==address) 623 if (NULL==address)
464 return; 624 return;
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returnedp pretty address: `%s'\n",address); 625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned pretty address: `%s'\n",address);
466 fail_pretty_printer_count++; 626 fail_pretty_printer_count++;
467} 627}
468 628
@@ -596,20 +756,20 @@ run (void *cls,
596 /* test sending to client */ 756 /* test sending to client */
597 multi_handle = curl_multi_init(); 757 multi_handle = curl_multi_init();
598 758
599
600 /*building messages */ 759 /*building messages */
601 struct HTTP_Message msg; 760 msg = GNUNET_malloc (sizeof (struct HTTP_Message));
602 761 msg->size = 2048;
603 762 msg->pos = 0;
604 res = send_data (&msg, "http://localhost:12389/"); 763 msg->buf = GNUNET_malloc (2048);
605 764
765 res = send_data (msg, "http://localhost:12389/");
606 766
607 /* testing finished, shutting down */ 767 /* testing finished, shutting down */
608 if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) ) 768 if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) )
609 fail = 0; 769 fail = 0;
610 else 770 else
611 fail = 1; 771 fail = 1;
612 shutdown_clean(); 772 //shutdown_clean();
613 return; 773 return;
614} 774}
615 775