aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-01 15:01:00 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-01 15:01:00 +0000
commit8863f49f1842bb15df2c3ab574b15292df6290c4 (patch)
treeef198c06010ae97626eae12f01b3ddb3463d432e /src
parent1f36ef73e4b6516832ffb40f11be0d2cacb3e0fe (diff)
downloadgnunet-8863f49f1842bb15df2c3ab574b15292df6290c4.tar.gz
gnunet-8863f49f1842bb15df2c3ab574b15292df6290c4.zip
-fixing minor bugs, code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_http.c56
-rw-r--r--src/transport/plugin_transport_http_client.c114
-rw-r--r--src/transport/plugin_transport_http_server.c50
-rw-r--r--src/transport/test_transport_api_reliability.c2
4 files changed, 97 insertions, 125 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index d55cdb76b..d99f531b7 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -268,13 +268,10 @@ http_plugin_address_pretty_printer (void *cls, const char *type,
268static int 268static int
269http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) 269http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
270{ 270{
271
272 struct Plugin *plugin = cls; 271 struct Plugin *plugin = cls;
273 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head; 272 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
274 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head; 273 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
275 274
276
277
278 GNUNET_assert (cls != NULL); 275 GNUNET_assert (cls != NULL);
279 if ((addrlen != sizeof (struct sockaddr_in)) || 276 if ((addrlen != sizeof (struct sockaddr_in)) ||
280 (addrlen != sizeof (struct sockaddr_in6))) 277 (addrlen != sizeof (struct sockaddr_in6)))
@@ -358,11 +355,12 @@ http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
358 * @param added length of created address 355 * @param added length of created address
359 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 356 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
360 */ 357 */
361int http_string_to_address (void *cls, 358int
362 const char *addr, 359http_string_to_address (void *cls,
363 uint16_t addrlen, 360 const char *addr,
364 void **buf, 361 uint16_t addrlen,
365 size_t *added) 362 void **buf,
363 size_t *added)
366{ 364{
367#if !BUILD_HTTPS 365#if !BUILD_HTTPS
368 char *protocol = "http"; 366 char *protocol = "http";
@@ -425,7 +423,7 @@ int http_string_to_address (void *cls,
425 (*added) = sizeof (struct IPv4HttpAddress); 423 (*added) = sizeof (struct IPv4HttpAddress);
426 return GNUNET_OK; 424 return GNUNET_OK;
427 } 425 }
428 else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6)) 426 if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
429 { 427 {
430 http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress)); 428 http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
431 http_6addr->u6_port = addr_6.sin6_port; 429 http_6addr->u6_port = addr_6.sin6_port;
@@ -434,18 +432,14 @@ int http_string_to_address (void *cls,
434 (*added) = sizeof (struct IPv6HttpAddress); 432 (*added) = sizeof (struct IPv6HttpAddress);
435 return GNUNET_OK; 433 return GNUNET_OK;
436 } 434 }
437 else 435 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
438 { 436 "Invalid address string `%s' to convert to address\n",
439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 437 addr_str);
440 "Invalid address string `%s' to convert to address\n", 438 GNUNET_break (0);
441 addr_str); 439 return GNUNET_SYSERR;
442 GNUNET_break (0);
443 return GNUNET_SYSERR;
444 }
445} 440}
446 441
447 442
448
449/** 443/**
450 * Function called for a quick conversion of the binary address to 444 * Function called for a quick conversion of the binary address to
451 * a numeric address. Note that the caller must not free the 445 * a numeric address. Note that the caller must not free the
@@ -513,6 +507,7 @@ http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
513 return rbuf; 507 return rbuf;
514} 508}
515 509
510
516struct Session * 511struct Session *
517lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 512lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
518 struct Session *session, const void *addr, size_t addrlen, 513 struct Session *session, const void *addr, size_t addrlen,
@@ -526,11 +521,11 @@ lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *tar
526 { 521 {
527#if 0 522#if 0
528 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 523 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
529 "Comparing peer `%s' address `%s' len %i session %X to \n", 524 "Comparing peer `%s' address `%s' len %i session %p to \n",
530 GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen, 525 GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen,
531 session); 526 session);
532 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 527 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
533 "peer `%s' address `%s' len %i session %X \n\n", 528 "peer `%s' address `%s' len %i session %p \n\n",
534 GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen), 529 GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen),
535 t->addrlen, t); 530 t->addrlen, t);
536 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n", 531 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n",
@@ -558,6 +553,7 @@ lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *tar
558 return NULL; 553 return NULL;
559} 554}
560 555
556
561struct Session * 557struct Session *
562lookup_session (struct Plugin *plugin, 558lookup_session (struct Plugin *plugin,
563 const struct GNUNET_HELLO_Address *address) 559 const struct GNUNET_HELLO_Address *address)
@@ -572,6 +568,7 @@ lookup_session (struct Plugin *plugin,
572 return NULL; 568 return NULL;
573} 569}
574 570
571
575int 572int
576exist_session (struct Plugin *plugin, struct Session *s) 573exist_session (struct Plugin *plugin, struct Session *s)
577{ 574{
@@ -589,7 +586,6 @@ exist_session (struct Plugin *plugin, struct Session *s)
589} 586}
590 587
591 588
592
593void 589void
594delete_session (struct Session *s) 590delete_session (struct Session *s)
595{ 591{
@@ -606,6 +602,7 @@ delete_session (struct Session *s)
606 GNUNET_free (s); 602 GNUNET_free (s);
607} 603}
608 604
605
609struct Session * 606struct Session *
610create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 607create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
611 const void *addr, size_t addrlen) 608 const void *addr, size_t addrlen)
@@ -626,7 +623,6 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
626} 623}
627 624
628 625
629
630void 626void
631notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, 627notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
632 struct Session *s) 628 struct Session *s)
@@ -638,6 +634,7 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
638 delete_session (s); 634 delete_session (s);
639} 635}
640 636
637
641/** 638/**
642 * Creates a new outbound session the transport service will use to send data to the 639 * Creates a new outbound session the transport service will use to send data to the
643 * peer 640 * peer
@@ -646,7 +643,6 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
646 * @param address the address 643 * @param address the address
647 * @return the session or NULL of max connections exceeded 644 * @return the session or NULL of max connections exceeded
648 */ 645 */
649
650static struct Session * 646static struct Session *
651http_get_session (void *cls, 647http_get_session (void *cls,
652 const struct GNUNET_HELLO_Address *address) 648 const struct GNUNET_HELLO_Address *address)
@@ -730,6 +726,7 @@ http_get_session (void *cls,
730 return s; 726 return s;
731} 727}
732 728
729
733/** 730/**
734 * Function that can be used by the transport service to transmit 731 * Function that can be used by the transport service to transmit
735 * a message using the plugin. Note that in the case of a 732 * a message using the plugin. Note that in the case of a
@@ -791,7 +788,6 @@ http_plugin_send (void *cls,
791 } 788 }
792 789
793 /* create new message and schedule */ 790 /* create new message and schedule */
794
795 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); 791 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
796 msg->next = NULL; 792 msg->next = NULL;
797 msg->size = msgbuf_size; 793 msg->size = msgbuf_size;
@@ -875,6 +871,7 @@ http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
875 } 871 }
876} 872}
877 873
874
878static void * 875static void *
879find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen) 876find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen)
880{ 877{
@@ -933,6 +930,7 @@ find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addr
933 return NULL; 930 return NULL;
934} 931}
935 932
933
936static void 934static void
937nat_add_address (void *cls, int add_remove, const struct sockaddr *addr, 935nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
938 socklen_t addrlen) 936 socklen_t addrlen)
@@ -993,6 +991,7 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
993 991
994} 992}
995 993
994
996static void 995static void
997nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr, 996nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
998 socklen_t addrlen) 997 socklen_t addrlen)
@@ -1044,9 +1043,9 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
1044 default: 1043 default:
1045 return; 1044 return;
1046 } 1045 }
1047
1048} 1046}
1049 1047
1048
1050/** 1049/**
1051 * Our external IP address/port mapping has changed. 1050 * Our external IP address/port mapping has changed.
1052 * 1051 *
@@ -1079,6 +1078,7 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
1079 } 1078 }
1080} 1079}
1081 1080
1081
1082void 1082void
1083http_check_ipv6 (struct Plugin *plugin) 1083http_check_ipv6 (struct Plugin *plugin)
1084{ 1084{
@@ -1112,6 +1112,7 @@ http_check_ipv6 (struct Plugin *plugin)
1112 } 1112 }
1113} 1113}
1114 1114
1115
1115int 1116int
1116http_get_addresses (struct Plugin *plugin, const char *serviceName, 1117http_get_addresses (struct Plugin *plugin, const char *serviceName,
1117 const struct GNUNET_CONFIGURATION_Handle *cfg, 1118 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -1322,6 +1323,7 @@ start_report_addresses (struct Plugin *plugin)
1322 } 1323 }
1323} 1324}
1324 1325
1326
1325static void 1327static void
1326stop_report_addresses (struct Plugin *plugin) 1328stop_report_addresses (struct Plugin *plugin)
1327{ 1329{
@@ -1349,6 +1351,7 @@ stop_report_addresses (struct Plugin *plugin)
1349 } 1351 }
1350} 1352}
1351 1353
1354
1352static int 1355static int
1353configure_plugin (struct Plugin *plugin) 1356configure_plugin (struct Plugin *plugin)
1354{ 1357{
@@ -1504,6 +1507,7 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1504 1507
1505} 1508}
1506 1509
1510
1507/** 1511/**
1508 * Start session timeout 1512 * Start session timeout
1509 */ 1513 */
@@ -1521,6 +1525,7 @@ start_session_timeout (struct Session *s)
1521 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 1525 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1522} 1526}
1523 1527
1528
1524/** 1529/**
1525 * Increment session timeout due to activity 1530 * Increment session timeout due to activity
1526 */ 1531 */
@@ -1539,6 +1544,7 @@ reschedule_session_timeout (struct Session *s)
1539 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 1544 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1540} 1545}
1541 1546
1547
1542/** 1548/**
1543 * Cancel timeout 1549 * Cancel timeout
1544 */ 1550 */
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 79f70bb6c..179c9580e 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2002--2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -55,10 +55,10 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls)
55 } 55 }
56#if BUILD_HTTPS 56#if BUILD_HTTPS
57 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https", 57 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https",
58 "Client: %X - %s", cls, text); 58 "Client: %p - %s", cls, text);
59#else 59#else
60 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http", 60 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http",
61 "Client: %X - %s", cls, text); 61 "Client: %p - %s", cls, text);
62#endif 62#endif
63 } 63 }
64 return 0; 64 return 0;
@@ -73,6 +73,7 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls)
73static void 73static void
74client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 74client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
75 75
76
76/** 77/**
77 * Function setting up file descriptors and scheduling task to run 78 * Function setting up file descriptors and scheduling task to run
78 * 79 *
@@ -99,7 +100,6 @@ client_schedule (struct Plugin *plugin, int now)
99 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 100 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
100 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; 101 plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
101 } 102 }
102
103 max = -1; 103 max = -1;
104 FD_ZERO (&rs); 104 FD_ZERO (&rs);
105 FD_ZERO (&ws); 105 FD_ZERO (&ws);
@@ -154,24 +154,22 @@ client_send (struct Session *s, struct HTTP_Message *msg)
154 GNUNET_break (0); 154 GNUNET_break (0);
155 return GNUNET_SYSERR; 155 return GNUNET_SYSERR;
156 } 156 }
157
158 if (s->client_put_paused == GNUNET_YES) 157 if (s->client_put_paused == GNUNET_YES)
159 { 158 {
160 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, 159 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
161 "Client: %X was suspended, unpausing\n", s->client_put); 160 "Client: %p was suspended, unpausing\n", s->client_put);
162 s->client_put_paused = GNUNET_NO; 161 s->client_put_paused = GNUNET_NO;
163 curl_easy_pause (s->client_put, CURLPAUSE_CONT); 162 curl_easy_pause (s->client_put, CURLPAUSE_CONT);
164 } 163 }
165
166 client_schedule (s->plugin, GNUNET_YES); 164 client_schedule (s->plugin, GNUNET_YES);
167 165
168 return GNUNET_OK; 166 return GNUNET_OK;
169} 167}
170 168
171 169
172
173/** 170/**
174 * Task performing curl operations 171 * Task performing curl operations
172 *
175 * @param cls plugin as closure 173 * @param cls plugin as closure
176 * @param tc gnunet scheduler task context 174 * @param tc gnunet scheduler task context
177 */ 175 */
@@ -228,7 +226,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
228 if (msg->msg == CURLMSG_DONE) 226 if (msg->msg == CURLMSG_DONE)
229 { 227 {
230 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 228 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
231 "Client: %X connection to '%s' %s ended with reason %i: `%s'\n", 229 "Client: %p connection to '%s' %s ended with reason %i: `%s'\n",
232 msg->easy_handle, GNUNET_i2s (&s->target), 230 msg->easy_handle, GNUNET_i2s (&s->target),
233 http_plugin_address_to_string (NULL, s->addr, 231 http_plugin_address_to_string (NULL, s->addr,
234 s->addrlen), 232 s->addrlen),
@@ -236,7 +234,11 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
236 curl_easy_strerror (msg->data.result)); 234 curl_easy_strerror (msg->data.result));
237 235
238 client_disconnect (s); 236 client_disconnect (s);
239 //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); 237 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
238 plugin->name,
239 "Notifying about ended session to peer `%s' `%s'\n",
240 GNUNET_i2s (&s->target),
241 http_plugin_address_to_string (plugin, s->addr, s->addrlen));
240 notify_session_end (plugin, &s->target, s); 242 notify_session_end (plugin, &s->target, s);
241 } 243 }
242 } 244 }
@@ -245,6 +247,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
245 client_schedule (plugin, GNUNET_NO); 247 client_schedule (plugin, GNUNET_NO);
246} 248}
247 249
250
248int 251int
249client_disconnect (struct Session *s) 252client_disconnect (struct Session *s)
250{ 253{
@@ -263,7 +266,7 @@ client_disconnect (struct Session *s)
263 if (s->client_put != NULL) 266 if (s->client_put != NULL)
264 { 267 {
265 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 268 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
266 "Client: %X Deleting outbound PUT session to peer `%s'\n", 269 "Client: %p Deleting outbound PUT session to peer `%s'\n",
267 s->client_put, GNUNET_i2s (&s->target)); 270 s->client_put, GNUNET_i2s (&s->target));
268 271
269 mret = curl_multi_remove_handle (plugin->client_mh, s->client_put); 272 mret = curl_multi_remove_handle (plugin->client_mh, s->client_put);
@@ -287,7 +290,7 @@ client_disconnect (struct Session *s)
287 if (s->client_get != NULL) 290 if (s->client_get != NULL)
288 { 291 {
289 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 292 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
290 "Client: %X Deleting outbound GET session to peer `%s'\n", 293 "Client: %p Deleting outbound GET session to peer `%s'\n",
291 s->client_get, GNUNET_i2s (&s->target)); 294 s->client_get, GNUNET_i2s (&s->target));
292 295
293 mret = curl_multi_remove_handle (plugin->client_mh, s->client_get); 296 mret = curl_multi_remove_handle (plugin->client_mh, s->client_get);
@@ -362,6 +365,7 @@ client_receive_mst_cb (void *cls, void *client,
362 return GNUNET_OK; 365 return GNUNET_OK;
363} 366}
364 367
368
365static void 369static void
366client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 370client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
367{ 371{
@@ -372,29 +376,26 @@ client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
372 GNUNET_break (0); 376 GNUNET_break (0);
373 return; 377 return;
374 } 378 }
375
376 s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; 379 s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
377
378 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 380 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
379 return; 381 return;
380
381 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, 382 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
382 "Client: %X Waking up receive handle\n", s->client_get); 383 "Client: %p Waking up receive handle\n", s->client_get);
383
384 if (s->client_get != NULL) 384 if (s->client_get != NULL)
385 curl_easy_pause (s->client_get, CURLPAUSE_CONT); 385 curl_easy_pause (s->client_get, CURLPAUSE_CONT);
386
387} 386}
388 387
388
389/** 389/**
390* Callback method used with libcurl 390 * Callback method used with libcurl
391* Method is called when libcurl needs to write data during sending 391 * Method is called when libcurl needs to write data during sending
392* @param stream pointer where to write data 392 *
393* @param size size of an individual element 393 * @param stream pointer where to write data
394* @param nmemb count of elements that can be written to the buffer 394 * @param size size of an individual element
395* @param cls destination pointer, passed to the libcurl handle 395 * @param nmemb count of elements that can be written to the buffer
396* @return bytes read from stream 396 * @param cls destination pointer, passed to the libcurl handle
397*/ 397 * @return bytes read from stream
398 */
398static size_t 399static size_t
399client_receive (void *stream, size_t size, size_t nmemb, void *cls) 400client_receive (void *stream, size_t size, size_t nmemb, void *cls)
400{ 401{
@@ -413,7 +414,7 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls)
413 struct GNUNET_TIME_Relative delta = 414 struct GNUNET_TIME_Relative delta =
414 GNUNET_TIME_absolute_get_difference (now, s->next_receive); 415 GNUNET_TIME_absolute_get_difference (now, s->next_receive);
415 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 416 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
416 "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n", 417 "Client: %p No inbound bandwidth available! Next read was delayed for %llu ms\n",
417 s->client_get, delta.rel_value); 418 s->client_get, delta.rel_value);
418 if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) 419 if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
419 { 420 {
@@ -424,19 +425,17 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls)
424 GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s); 425 GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
425 return CURLPAUSE_ALL; 426 return CURLPAUSE_ALL;
426 } 427 }
427 428 if (NULL == s->msg_tk)
428
429 if (s->msg_tk == NULL)
430 s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); 429 s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
431
432 GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO); 430 GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO);
433
434 return len; 431 return len;
435} 432}
436 433
434
437/** 435/**
438 * Callback method used with libcurl 436 * Callback method used with libcurl
439 * Method is called when libcurl needs to read data during sending 437 * Method is called when libcurl needs to read data during sending
438 *
440 * @param stream pointer where to write data 439 * @param stream pointer where to write data
441 * @param size size of an individual element 440 * @param size size of an individual element
442 * @param nmemb count of elements that can be written to the buffer 441 * @param nmemb count of elements that can be written to the buffer
@@ -448,67 +447,46 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
448{ 447{
449 struct Session *s = cls; 448 struct Session *s = cls;
450 struct Plugin *plugin = s->plugin; 449 struct Plugin *plugin = s->plugin;
450 struct HTTP_Message *msg = s->msg_head;
451 size_t bytes_sent = 0; 451 size_t bytes_sent = 0;
452 size_t len; 452 size_t len;
453 453
454 if (GNUNET_YES != exist_session(plugin, s)) 454 if (GNUNET_YES != exist_session(plugin, s))
455 { 455 {
456 GNUNET_break (0); 456 GNUNET_break (0);
457 return GNUNET_SYSERR; 457 return 0;
458 } 458 }
459 459 if (NULL == msg)
460 struct HTTP_Message *msg = s->msg_head;
461
462 if (msg == NULL)
463 { 460 {
464 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 461 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
465 "Client: %X Nothing to send! Suspending PUT handle!\n", 462 "Client: %p Nothing to send! Suspending PUT handle!\n",
466 s->client_put); 463 s->client_put);
467 s->client_put_paused = GNUNET_YES; 464 s->client_put_paused = GNUNET_YES;
468 return CURL_READFUNC_PAUSE; 465 return CURL_READFUNC_PAUSE;
469 } 466 }
470
471 GNUNET_assert (msg != NULL);
472 /* data to send */ 467 /* data to send */
473 if (msg->pos < msg->size) 468 GNUNET_assert (msg->pos < msg->size);
474 { 469 /* calculate how much fits in buffer */
475 /* data fit in buffer */ 470 bytes_sent = GNUNET_MIN (msg->size - msg->pos,
476 if ((msg->size - msg->pos) <= (size * nmemb)) 471 size * nmemb);
477 { 472 memcpy (stream, &msg->buf[msg->pos], len);
478 len = (msg->size - msg->pos); 473 msg->pos += len;
479 memcpy (stream, &msg->buf[msg->pos], len); 474 bytes_sent = len;
480 msg->pos += len;
481 bytes_sent = len;
482 }
483 else
484 {
485 len = size * nmemb;
486 memcpy (stream, &msg->buf[msg->pos], len);
487 msg->pos += len;
488 bytes_sent = len;
489 }
490 }
491 /* no data to send */
492 else
493 {
494 GNUNET_assert (0);
495 bytes_sent = 0;
496 }
497
498 if (msg->pos == msg->size) 475 if (msg->pos == msg->size)
499 { 476 {
500 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 477 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
501 "Client: %X Message with %u bytes sent, removing message from queue\n", 478 "Client: %p Message with %u bytes sent, removing message from queue\n",
502 s->client_put, msg->size, msg->pos); 479 s->client_put, msg->size, msg->pos);
503 /* Calling transmit continuation */ 480 /* Calling transmit continuation */
481 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
504 if (NULL != msg->transmit_cont) 482 if (NULL != msg->transmit_cont)
505 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); 483 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
506 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
507 GNUNET_free (msg); 484 GNUNET_free (msg);
508 } 485 }
509 return bytes_sent; 486 return bytes_sent;
510} 487}
511 488
489
512int 490int
513client_connect (struct Session *s) 491client_connect (struct Session *s)
514{ 492{
@@ -631,6 +609,7 @@ client_connect (struct Session *s)
631 return res; 609 return res;
632} 610}
633 611
612
634int 613int
635client_start (struct Plugin *plugin) 614client_start (struct Plugin *plugin)
636{ 615{
@@ -651,6 +630,7 @@ client_start (struct Plugin *plugin)
651 return res; 630 return res;
652} 631}
653 632
633
654void 634void
655client_stop (struct Plugin *plugin) 635client_stop (struct Plugin *plugin)
656{ 636{
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index d57ce88b9..4a6e8c18f 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -163,10 +163,8 @@ server_load_certificate (struct Plugin *plugin)
163 GNUNET_free_non_null (plugin->cert); 163 GNUNET_free_non_null (plugin->cert);
164 plugin->cert = NULL; 164 plugin->cert = NULL;
165 165
166#if VERBOSE_SERVER
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
168 "No usable TLS certificate found, creating certificate\n"); 167 "No usable TLS certificate found, creating certificate\n");
169#endif
170 errno = 0; 168 errno = 0;
171 cert_creation = 169 cert_creation =
172 GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, 170 GNUNET_OS_start_process (GNUNET_NO, NULL, NULL,
@@ -230,7 +228,6 @@ server_load_certificate (struct Plugin *plugin)
230 * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait 228 * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait
231 * until timeout 229 * until timeout
232 */ 230 */
233
234static void 231static void
235server_reschedule (struct Plugin *plugin, struct MHD_Daemon *server, int now) 232server_reschedule (struct Plugin *plugin, struct MHD_Daemon *server, int now)
236{ 233{
@@ -302,6 +299,7 @@ server_receive_mst_cb (void *cls, void *client,
302 return GNUNET_OK; 299 return GNUNET_OK;
303} 300}
304 301
302
305/** 303/**
306 * Callback called by MHD when it needs data to send 304 * Callback called by MHD when it needs data to send
307 * @param cls current session 305 * @param cls current session
@@ -314,44 +312,32 @@ static ssize_t
314server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) 312server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
315{ 313{
316 struct Session *s = cls; 314 struct Session *s = cls;
315 ssize_t bytes_read = 0;
316 struct HTTP_Message *msg;
317
317 GNUNET_assert (NULL != p); 318 GNUNET_assert (NULL != p);
318 if (GNUNET_NO == exist_session(p, s)) 319 if (GNUNET_NO == exist_session(p, s))
319 return 0; 320 return 0;
320
321 struct HTTP_Message *msg;
322 int bytes_read = 0;
323
324 //static int c = 0;
325 msg = s->msg_head; 321 msg = s->msg_head;
326 if (msg != NULL) 322 if (NULL != msg)
327 { 323 {
328 /* sending */ 324 /* sending */
329 if ((msg->size - msg->pos) <= max) 325 bytes_read = GNUNET_MIN (msg->size - msg->pos,
330 { 326 max);
331 memcpy (buf, &msg->buf[msg->pos], (msg->size - msg->pos)); 327 memcpy (buf, &msg->buf[msg->pos], bytes_read);
332 bytes_read = msg->size - msg->pos; 328 msg->pos += bytes_read;
333 msg->pos += (msg->size - msg->pos);
334 }
335 else
336 {
337 memcpy (buf, &msg->buf[msg->pos], max);
338 msg->pos += max;
339 bytes_read = max;
340 }
341 329
342 /* removing message */ 330 /* removing message */
343 if (msg->pos == msg->size) 331 if (msg->pos == msg->size)
344 { 332 {
333 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
345 if (NULL != msg->transmit_cont) 334 if (NULL != msg->transmit_cont)
346 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); 335 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
347 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
348 GNUNET_free (msg); 336 GNUNET_free (msg);
349 } 337 }
350 } 338 }
351
352 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, 339 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
353 "Server: %X: sent %u bytes\n", s, bytes_read); 340 "Server: %p: sent %u bytes\n", s, bytes_read);
354
355 return bytes_read; 341 return bytes_read;
356} 342}
357 343
@@ -585,7 +571,7 @@ found:
585 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000); 571 int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
586 572
587 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 573 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
588 "Server: Setting timeout for %X to %u sec.\n", sc, to); 574 "Server: Setting timeout for %p to %u sec.\n", sc, to);
589 MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to); 575 MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to);
590 576
591 struct MHD_Daemon *d = NULL; 577 struct MHD_Daemon *d = NULL;
@@ -707,7 +693,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
707 if ((s->next_receive.abs_value <= now.abs_value)) 693 if ((s->next_receive.abs_value <= now.abs_value))
708 { 694 {
709 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 695 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
710 "Server: %X: PUT with %u bytes forwarded to MST\n", s, 696 "Server: %p: PUT with %u bytes forwarded to MST\n", s,
711 *upload_data_size); 697 *upload_data_size);
712 if (s->msg_tk == NULL) 698 if (s->msg_tk == NULL)
713 { 699 {
@@ -727,7 +713,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
727 { 713 {
728 t = s->server_recv; 714 t = s->server_recv;
729 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 715 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
730 "Server: Setting timeout for %X to %u sec.\n", t, 716 "Server: Setting timeout for %p to %u sec.\n", t,
731 to); 717 to);
732 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 718 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
733 to); 719 to);
@@ -736,7 +722,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
736 { 722 {
737 t = s->server_send; 723 t = s->server_send;
738 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 724 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
739 "Server: Setting timeout for %X to %u sec.\n", t, 725 "Server: Setting timeout for %p to %u sec.\n", t,
740 to); 726 to);
741 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 727 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
742 to); 728 to);
@@ -754,7 +740,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
754 else 740 else
755 { 741 {
756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
757 "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", 743 "Server: %p no inbound bandwidth available! Next read was delayed by %llu ms\n",
758 s, now.abs_value - s->next_receive.abs_value); 744 s, now.abs_value - s->next_receive.abs_value);
759 } 745 }
760 return MHD_YES; 746 return MHD_YES;
@@ -790,7 +776,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
790 { 776 {
791 777
792 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 778 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
793 "Server: %X peer `%s' GET on address `%s' disconnected\n", 779 "Server: %p peer `%s' GET on address `%s' disconnected\n",
794 s->server_send, GNUNET_i2s (&s->target), 780 s->server_send, GNUNET_i2s (&s->target),
795 http_plugin_address_to_string (NULL, s->addr, s->addrlen)); 781 http_plugin_address_to_string (NULL, s->addr, s->addrlen));
796 s->server_send = NULL; 782 s->server_send = NULL;
@@ -807,7 +793,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
807 if (sc->direction == _RECEIVE) 793 if (sc->direction == _RECEIVE)
808 { 794 {
809 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 795 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
810 "Server: %X peer `%s' PUT on address `%s' disconnected\n", 796 "Server: %p peer `%s' PUT on address `%s' disconnected\n",
811 s->server_recv, GNUNET_i2s (&s->target), 797 s->server_recv, GNUNET_i2s (&s->target),
812 http_plugin_address_to_string (NULL, s->addr, s->addrlen)); 798 http_plugin_address_to_string (NULL, s->addr, s->addrlen));
813 s->server_recv = NULL; 799 s->server_recv = NULL;
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index f719a42af..759241c52 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -243,7 +243,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
243 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) 243 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
244 { 244 {
245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 "Expected message %u with bits %u, but body did not match\n", n, 246 "Expected message %u with bits %u, but body did not match at position %u\n", n,
247 (unsigned char) n); 247 (unsigned char) n);
248 if (die_task != GNUNET_SCHEDULER_NO_TASK) 248 if (die_task != GNUNET_SCHEDULER_NO_TASK)
249 GNUNET_SCHEDULER_cancel (die_task); 249 GNUNET_SCHEDULER_cancel (die_task);