aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-05-31 07:53:21 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-05-31 07:53:21 +0000
commit9c94d4241e499cedfb7696f18793dba8c722e26b (patch)
treeef502bb12512eec4f63168b46bd0fa8af7c5a147 /src
parentbab7caf0e4eb892e7e69b5d78346d5af78c56780 (diff)
downloadgnunet-9c94d4241e499cedfb7696f18793dba8c722e26b.tar.gz
gnunet-9c94d4241e499cedfb7696f18793dba8c722e26b.zip
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_http.c83
1 files changed, 69 insertions, 14 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 923c2bcf0..d67ac75eb 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -290,13 +290,32 @@ static struct Session * find_session_by_pi( const struct GNUNET_PeerIdentity *pe
290} 290}
291 291
292/** 292/**
293 * Finds a http session in our linked list using libcurl handle as a key
294 * Needed when sending data with libcurl to differentiate between sessions
295 * @param peer peeridentity
296 * @return http session corresponding to peer identity
297 */
298static struct Session * find_session_by_curlhandle( CURL* handle )
299{
300 struct Session * cur;
301
302 cur = plugin->sessions;
303 while (cur != NULL)
304 {
305 if ( handle == cur->curl_handle )
306 return cur;
307 cur = plugin->sessions->next;
308 }
309 return NULL;
310}
311
312/**
293 * Create a new session 313 * Create a new session
294 * 314 *
295 * @param address address the peer is using 315 * @param address address the peer is using
296 * @peer peer identity 316 * @peer peer identity
297 * @return created session object 317 * @return created session object
298 */ 318 */
299
300static struct Session * create_session (struct sockaddr_in *address, const struct GNUNET_PeerIdentity *peer) 319static struct Session * create_session (struct sockaddr_in *address, const struct GNUNET_PeerIdentity *peer)
301{ 320{
302 struct sockaddr_in *addrin; 321 struct sockaddr_in *addrin;
@@ -354,12 +373,10 @@ acceptPolicyCallback (void *cls,
354 const struct sockaddr *addr, socklen_t addr_len) 373 const struct sockaddr *addr, socklen_t addr_len)
355{ 374{
356 /* Every connection is accepted, nothing more to do here */ 375 /* Every connection is accepted, nothing more to do here */
357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connect!\n");
358 return MHD_YES; 376 return MHD_YES;
359} 377}
360 378
361 379
362
363/** 380/**
364 * Process GET or PUT request received via MHD. For 381 * Process GET or PUT request received via MHD. For
365 * GET, queue response that will send back our pending 382 * GET, queue response that will send back our pending
@@ -623,9 +640,8 @@ http_daemon_prepare (struct MHD_Daemon *daemon_handle)
623 * Call MHD to process pending requests and then go back 640 * Call MHD to process pending requests and then go back
624 * and schedule the next run. 641 * and schedule the next run.
625 */ 642 */
626static void 643static void http_daemon_run (void *cls,
627http_daemon_run (void *cls, 644 const struct GNUNET_SCHEDULER_TaskContext *tc)
628 const struct GNUNET_SCHEDULER_TaskContext *tc)
629{ 645{
630 struct MHD_Daemon *daemon_handle = cls; 646 struct MHD_Daemon *daemon_handle = cls;
631 647
@@ -638,8 +654,6 @@ http_daemon_run (void *cls,
638 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 654 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
639 return; 655 return;
640 656
641
642
643 GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); 657 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
644 if (daemon_handle == http_daemon_v4) 658 if (daemon_handle == http_daemon_v4)
645 http_task_v4 = http_daemon_prepare (daemon_handle); 659 http_task_v4 = http_daemon_prepare (daemon_handle);
@@ -650,6 +664,9 @@ http_daemon_run (void *cls,
650 664
651/** 665/**
652 * Removes a message from the linked list of messages 666 * Removes a message from the linked list of messages
667 * @param ses session to remove message from
668 * @param msg message to remove
669 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
653 */ 670 */
654 671
655static int remove_http_message(struct Session * ses, struct HTTP_Message * msg) 672static int remove_http_message(struct Session * ses, struct HTTP_Message * msg)
@@ -688,6 +705,15 @@ static int remove_http_message(struct Session * ses, struct HTTP_Message * msg)
688} 705}
689 706
690 707
708/**
709 * Callback method used with libcurl
710 * Method is called when libcurl needs to read data during sending
711 * @param stream pointer where to write data
712 * @param size_t size of an individual element
713 * @param nmemb count of elements that can be written to the buffer
714 * @param ptr source pointer, passed to the libcurl handle
715 * @return bytes written to stream
716 */
691static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void *ptr) 717static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void *ptr)
692{ 718{
693 struct Session * ses = ptr; 719 struct Session * ses = ptr;
@@ -708,12 +734,20 @@ static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void *
708 return bytes_sent; 734 return bytes_sent;
709} 735}
710 736
711 737/**
712static size_t send_write_callback( void *ptr, size_t size, size_t nmemb, void *stream) 738* Callback method used with libcurl
739* Method is called when libcurl needs to write data during sending
740* @param stream pointer where to write data
741* @param size_t size of an individual element
742* @param nmemb count of elements that can be written to the buffer
743* @param ptr destination pointer, passed to the libcurl handle
744* @return bytes read from stream
745*/
746static size_t send_write_callback( void *stream, size_t size, size_t nmemb, void *ptr)
713{ 747{
714 char * data = malloc(size*nmemb +1); 748 char * data = malloc(size*nmemb +1);
715 749
716 memcpy( data, ptr, size*nmemb); 750 memcpy( data, stream, size*nmemb);
717 data[size*nmemb] = '\0'; 751 data[size*nmemb] = '\0';
718 /* Just a dummy print for the response recieved for the PUT message */ 752 /* Just a dummy print for the response recieved for the PUT message */
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * nmemb, data); 753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * nmemb, data);
@@ -722,8 +756,18 @@ static size_t send_write_callback( void *ptr, size_t size, size_t nmemb, void *s
722 756
723} 757}
724 758
759/**
760 * Function setting up file descriptors and scheduling task to run
761 * @param ses session to send data to
762 * @return bytes sent to peer
763 */
725static size_t send_prepare(struct Session* session ); 764static size_t send_prepare(struct Session* session );
726 765
766/**
767 * Function setting up curl handle and selecting message to send
768 * @param ses session to send data to
769 * @return bytes sent to peer
770 */
727static ssize_t send_select_init (struct Session* ses ) 771static ssize_t send_select_init (struct Session* ses )
728{ 772{
729 char * url; 773 char * url;
@@ -769,7 +813,7 @@ static void send_execute (void *cls,
769 int running; 813 int running;
770 struct CURLMsg *msg; 814 struct CURLMsg *msg;
771 CURLMcode mret; 815 CURLMcode mret;
772 struct Session * cs = cls; 816 struct Session * cs = NULL;
773 817
774 http_task_send = GNUNET_SCHEDULER_NO_TASK; 818 http_task_send = GNUNET_SCHEDULER_NO_TASK;
775 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 819 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -779,7 +823,6 @@ static void send_execute (void *cls,
779 { 823 {
780 running = 0; 824 running = 0;
781 mret = curl_multi_perform (multi_handle, &running); 825 mret = curl_multi_perform (multi_handle, &running);
782 //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"send_execute %u\n", running);
783 if (running == 0) 826 if (running == 0)
784 { 827 {
785 do 828 do
@@ -789,11 +832,17 @@ static void send_execute (void *cls,
789 GNUNET_break (msg != NULL); 832 GNUNET_break (msg != NULL);
790 if (msg == NULL) 833 if (msg == NULL)
791 break; 834 break;
835 /* get session for affected curl handle */
836 cs = find_session_by_curlhandle (msg->easy_handle);
837 GNUNET_assert ( cs != NULL );
792 switch (msg->msg) 838 switch (msg->msg)
793 { 839 {
840
794 case CURLMSG_DONE: 841 case CURLMSG_DONE:
795 if ( (msg->data.result != CURLE_OK) && 842 if ( (msg->data.result != CURLE_OK) &&
796 (msg->data.result != CURLE_GOT_NOTHING) ) 843 (msg->data.result != CURLE_GOT_NOTHING) )
844 {
845
797 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 846 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
798 _("%s failed for `%s' at %s:%d: `%s'\n"), 847 _("%s failed for `%s' at %s:%d: `%s'\n"),
799 "curl_multi_perform", 848 "curl_multi_perform",
@@ -801,6 +850,8 @@ static void send_execute (void *cls,
801 __FILE__, 850 __FILE__,
802 __LINE__, 851 __LINE__,
803 curl_easy_strerror (msg->data.result)); 852 curl_easy_strerror (msg->data.result));
853 /* sending msg failed*/
854 }
804 else 855 else
805 { 856 {
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -832,6 +883,11 @@ static void send_execute (void *cls,
832} 883}
833 884
834 885
886/**
887 * Function setting up file descriptors and scheduling task to run
888 * @param ses session to send data to
889 * @return bytes sent to peer
890 */
835static size_t send_prepare(struct Session* session ) 891static size_t send_prepare(struct Session* session )
836{ 892{
837 fd_set rs; 893 fd_set rs;
@@ -843,7 +899,6 @@ static size_t send_prepare(struct Session* session )
843 long to; 899 long to;
844 CURLMcode mret; 900 CURLMcode mret;
845 901
846// GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"send_prepare\n");
847 max = -1; 902 max = -1;
848 FD_ZERO (&rs); 903 FD_ZERO (&rs);
849 FD_ZERO (&ws); 904 FD_ZERO (&ws);