aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/plugin_transport_http.c9
-rw-r--r--src/transport/test_plugin_transport_http.c83
2 files changed, 22 insertions, 70 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index b58164368..ece212483 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -38,6 +38,8 @@
38#include "microhttpd.h" 38#include "microhttpd.h"
39#include <curl/curl.h> 39#include <curl/curl.h>
40 40
41
42#define DEBUG_CURL GNUNET_CURL
41#define DEBUG_HTTP GNUNET_NO 43#define DEBUG_HTTP GNUNET_NO
42 44
43/** 45/**
@@ -614,7 +616,7 @@ accessHandlerCallback (void *cls,
614 struct GNUNET_MessageHeader * gn_msg = NULL; 616 struct GNUNET_MessageHeader * gn_msg = NULL;
615 /*check message and forward here */ 617 /*check message and forward here */
616 /* checking size */ 618 /* checking size */
617 if (cs->pending_inbound_msg->pos > sizeof (struct GNUNET_MessageHeader)) 619 if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader))
618 { 620 {
619 gn_msg = GNUNET_malloc (cs->pending_inbound_msg->pos); 621 gn_msg = GNUNET_malloc (cs->pending_inbound_msg->pos);
620 memcpy (gn_msg,cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos); 622 memcpy (gn_msg,cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos);
@@ -869,8 +871,9 @@ static ssize_t send_select_init (struct Session* ses )
869 url = GNUNET_malloc( 7 + strlen(ses->ip) + 7 + strlen ((char *) &(ses->hash)) + 1); 871 url = GNUNET_malloc( 7 + strlen(ses->ip) + 7 + strlen ((char *) &(ses->hash)) + 1);
870 /* FIXME: use correct port number */ 872 /* FIXME: use correct port number */
871 GNUNET_asprintf(&url,"http://%s:%u/%s",ses->ip,12389, (char *) &(ses->hash)); 873 GNUNET_asprintf(&url,"http://%s:%u/%s",ses->ip,12389, (char *) &(ses->hash));
872 874#if DEBUG_CURL
873 /* curl_easy_setopt(ses->curl_handle, CURLOPT_VERBOSE, 1L); */ 875 curl_easy_setopt(ses->curl_handle, CURLOPT_VERBOSE, 1L);
876#endif
874 curl_easy_setopt(ses->curl_handle, CURLOPT_URL, url); 877 curl_easy_setopt(ses->curl_handle, CURLOPT_URL, url);
875 curl_easy_setopt(ses->curl_handle, CURLOPT_PUT, 1L); 878 curl_easy_setopt(ses->curl_handle, CURLOPT_PUT, 1L);
876 curl_easy_setopt(ses->curl_handle, CURLOPT_READFUNCTION, send_read_callback); 879 curl_easy_setopt(ses->curl_handle, CURLOPT_READFUNCTION, send_read_callback);
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 78b6f3c77..2c72cea7d 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -255,7 +255,7 @@ static GNUNET_SCHEDULER_TaskIdentifier ti_timeout;
255 255
256static GNUNET_SCHEDULER_TaskIdentifier ti_send; 256static GNUNET_SCHEDULER_TaskIdentifier ti_send;
257 257
258const struct GNUNET_PeerIdentity * p; 258//const struct GNUNET_PeerIdentity * p;
259 259
260/** 260/**
261 * buffer for data to send 261 * buffer for data to send
@@ -310,21 +310,6 @@ static struct HTTP_Transfer test_too_short_ident;
310static struct HTTP_Transfer test_too_long_ident; 310static struct HTTP_Transfer test_too_long_ident;
311 311
312/** 312/**
313 * Test: connect to peer and send message bigger then content length
314 */
315static struct HTTP_Transfer test_msg_too_big;
316
317/**
318 * Test: connect to peer and send message bigger GNUNET_SERVER_MAX_MESSAGE_SIZE
319 */
320//static struct HTTP_Transfer test_msg_bigger_max;
321
322/**
323 * Test: connect to peer and send message smaller then content length
324 */
325//static struct HTTP_Transfer test_msg_too_small;
326
327/**
328 * Test: connect to peer with valid peer identification 313 * Test: connect to peer with valid peer identification
329 */ 314 */
330static struct HTTP_Transfer test_valid_ident; 315static struct HTTP_Transfer test_valid_ident;
@@ -334,11 +319,6 @@ static struct HTTP_Transfer test_valid_ident;
334 */ 319 */
335static int fail; 320static int fail;
336 321
337/**
338 * Recieved message already returned to sender?
339 */
340static int sent;
341
342CURL *curl_handle; 322CURL *curl_handle;
343 323
344/** 324/**
@@ -406,7 +386,6 @@ shutdown_clean ()
406} 386}
407 387
408 388
409#if 0
410/** 389/**
411 * Continuation called after plugin send message 390 * Continuation called after plugin send message
412 * @cls closure 391 * @cls closure
@@ -421,8 +400,8 @@ static void task_send_cont (void *cls,
421 fail = GNUNET_NO; 400 fail = GNUNET_NO;
422 shutdown_clean(); 401 shutdown_clean();
423} 402}
424#endif
425 403
404#if 0
426/** 405/**
427 * Task sending recieved message back to peer 406 * Task sending recieved message back to peer
428 * @cls closure 407 * @cls closure
@@ -448,7 +427,7 @@ task_send (void *cls,
448 */ 427 */
449 sent = GNUNET_YES; 428 sent = GNUNET_YES;
450} 429}
451 430#endif
452 431
453/** 432/**
454 * Recieves messages from plugin, in real world transport 433 * Recieves messages from plugin, in real world transport
@@ -463,34 +442,15 @@ receive (void *cls,
463 uint16_t sender_address_len) 442 uint16_t sender_address_len)
464{ 443{
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from peer `%s' with type %u and length %u\n", GNUNET_i2s(peer),ntohs(message->type),ntohs(message->size)); 444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from peer `%s' with type %u and length %u\n", GNUNET_i2s(peer),ntohs(message->type),ntohs(message->size));
466
467 /* take recieved message and send it back to peer */
468
469
470 p = peer;
471 void * c = (void *) message;
472 ti_send =GNUNET_SCHEDULER_add_delayed (sched, WAIT_INTERVALL, &task_send, c);
473
474 return GNUNET_TIME_UNIT_ZERO; 445 return GNUNET_TIME_UNIT_ZERO;
475} 446}
476 447
477static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr) 448static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr)
478{ 449{
479 unsigned int len; 450 unsigned int len;
480 struct HTTP_Transfer * test = (struct HTTP_Transfer *) ptr;
481 451
482 len = buffer_out.len; 452 len = buffer_out.len;
483 453
484 if (test == &test_msg_too_big)
485 {
486 if (buffer_out.pos > len)
487 return 0;
488 if ( (2*len) < (size * nmemb))
489 memcpy(stream, buffer_out.buf, 2* len);
490 buffer_out.pos = 2* len;
491 return 2* len;
492 }
493
494 if (( buffer_out.pos == len) || (len > (size * nmemb))) 454 if (( buffer_out.pos == len) || (len > (size * nmemb)))
495 return 0; 455 return 0;
496 memcpy(stream, buffer_out.buf, len); 456 memcpy(stream, buffer_out.buf, len);
@@ -924,31 +884,24 @@ static void run_connection_tests( void )
924 884
925 return; 885 return;
926 } 886 }
927/*
928 if (test_msg_too_big.test_executed == GNUNET_NO)
929 {
930 struct GNUNET_CRYPTO_HashAsciiEncoded result;
931 unsigned int c;
932 887
933 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result);
934 host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result));
935 GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result);
936 888
937 buffer_out.len = 50; 889 struct GNUNET_MessageHeader msg;
938 c = 0; 890 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
939 for (c=0; c<100; c++) 891 msg.size=htons(sizeof(struct GNUNET_MessageHeader));
940 buffer_out.buf[c] = 'A'; 892 msg.type=htons(13);
893 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
941 894
942 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with message bigger content length.\n")); 895 api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,NULL, 0, GNUNET_NO, &task_send_cont, NULL);
943 test_msg_too_big.test_executed = GNUNET_YES;
944 send_data ( &test_msg_too_big, host_str);
945 GNUNET_free (host_str);
946 896
947 return; 897 /*
948 } 898 msg.size=htons(2);
949*/ 899 msg.type=htons(13);
900 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
901
902 api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,NULL, 0, GNUNET_NO, &task_send_cont, NULL);
903 */
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); 904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
951 shutdown_clean();
952} 905}
953 906
954 907
@@ -1125,10 +1078,6 @@ run (void *cls,
1125 test_valid_ident.test_executed = GNUNET_NO; 1078 test_valid_ident.test_executed = GNUNET_NO;
1126 test_valid_ident.test_failed = GNUNET_YES; 1079 test_valid_ident.test_failed = GNUNET_YES;
1127 1080
1128 /* Test: connecting with valid identification */
1129 test_msg_too_big.test_executed = GNUNET_NO;
1130 test_msg_too_big.test_failed = GNUNET_YES;
1131
1132 run_connection_tests(); 1081 run_connection_tests();
1133 1082
1134 /* testing finished */ 1083 /* testing finished */