2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/plugin_transport_template.c
23 * @brief template for a new transport service
24 * @author Christian Grothoff
28 #include "gnunet_constants.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_connection_lib.h"
31 #include "gnunet_server_lib.h"
32 #include "gnunet_service_lib.h"
33 #include "gnunet_statistics_service.h"
34 #include "gnunet_transport_service.h"
35 #include "gnunet_resolver_service.h"
36 #include "plugin_transport.h"
37 #include "gnunet_os_lib.h"
38 #include "microhttpd.h"
39 #include <curl/curl.h>
42 #define DEBUG_CURL GNUNET_CURL
43 #define DEBUG_HTTP GNUNET_NO
46 * Text of the response sent back after the last bytes of a PUT
47 * request have been received (just to formally obey the HTTP
50 #define HTTP_PUT_RESPONSE "Thank you!"
53 * After how long do we expire an address that we
54 * learned from another peer if it is not reconfirmed
57 #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
60 * Page returned if request invalid
62 #define HTTP_ERROR_RESPONSE "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested URL was not found on this server.<P><HR><ADDRESS></ADDRESS></BODY></HTML>"
65 * Timeout for a http connect
67 #define HTTP_CONNECT_TIMEOUT 30
70 * Timeout for a http connect
72 #define HTTP_MESSAGE_INITIAL_BUFFERSIZE GNUNET_SERVER_MAX_MESSAGE_SIZE
76 * Encapsulation of all of the state of the plugin.
81 * Network format for IPv4 addresses.
83 struct IPv4HttpAddress
86 * IPv4 address, in network byte order.
91 * Port number, in network byte order.
99 * Network format for IPv6 addresses.
101 struct IPv6HttpAddress
106 struct in6_addr ipv6_addr;
109 * Port number, in network byte order.
118 * Message to send using http
123 * Next field for linked list
125 struct HTTP_Message * next;
128 * buffer containing data to send
133 * amount of data already sent
138 * amount of data to sent
147 * Session handle for connections.
153 * Stored in a linked list.
155 struct Session *next;
158 * Pointer to the global plugin struct.
160 struct Plugin *plugin;
163 * Continuation function to call once the transmission buffer
164 * has again space available. NULL if there is no
165 * continuation to call.
167 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
170 * Closure for transmit_cont.
172 void *transmit_cont_cls;
175 * To whom are we talking to (set to our identity
176 * if we are still waiting for the welcome message)
178 struct GNUNET_PeerIdentity sender;
186 * Sender's ip address to distinguish between incoming connections
191 * Sender's ip address to distinguish between incoming connections
193 struct sockaddr_in * addr_inbound;
196 * Sender's ip address recieved by transport
198 struct sockaddr_in * addr_outbound;
201 * Did we initiate the connection (GNUNET_YES) or the other peer (GNUNET_NO)?
203 unsigned int is_client;
206 * Is the connection active (GNUNET_YES) or terminated (GNUNET_NO)?
208 unsigned int is_active;
211 * At what time did we reset last_received last?
213 struct GNUNET_TIME_Absolute last_quota_update;
216 * How many bytes have we received since the "last_quota_update"
219 uint64_t last_received;
222 * Number of bytes per ms that this peer is allowed
228 * Is there a HTTP/PUT in progress?
230 unsigned int is_put_in_progress;
233 * Is there a HTTP/PUT in progress?
235 unsigned int is_bad_request;
240 struct GNUNET_CRYPTO_HashAsciiEncoded hash;
242 struct HTTP_Message * pending_outbound_msg;;
244 struct HTTP_Message * pending_inbound_msg;
250 * Encapsulation of all of the state of the plugin.
257 struct GNUNET_TRANSPORT_PluginEnvironment *env;
260 * Handle to the network service.
262 struct GNUNET_SERVICE_Context *service;
264 unsigned int port_inbound;
267 * List of open sessions.
269 struct Session *sessions;
272 * Number of active sessions
275 unsigned int session_count;
279 * Daemon for listening for new IPv4 connections.
281 static struct MHD_Daemon *http_daemon_v4;
284 * Daemon for listening for new IPv6connections.
286 static struct MHD_Daemon *http_daemon_v6;
289 * Our primary task for http daemon handling IPv4 connections
291 static GNUNET_SCHEDULER_TaskIdentifier http_task_v4;
294 * Our primary task for http daemon handling IPv6 connections
296 static GNUNET_SCHEDULER_TaskIdentifier http_task_v6;
300 * The task sending data
302 static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
306 * Information about this plugin
308 static struct Plugin *plugin;
313 static CURLM *multi_handle;
318 static char * hostname;
321 * Our ASCII encoded, hashed peer identity
322 * This string is used to distinguish between connections and is added to the urls
324 static struct GNUNET_CRYPTO_HashAsciiEncoded my_ascii_hash_ident;
326 struct GNUNET_TIME_Relative timeout;
329 * Finds a http session in our linked list using peer identity as a key
330 * @param peer peeridentity
331 * @return http session corresponding to peer identity
333 static struct Session * find_session_by_pi( const struct GNUNET_PeerIdentity *peer )
335 struct Session * cur;
336 GNUNET_HashCode hc_peer;
337 GNUNET_HashCode hc_current;
339 cur = plugin->sessions;
340 hc_peer = peer->hashPubKey;
343 hc_current = cur->sender.hashPubKey;
344 if ( 0 == GNUNET_CRYPTO_hash_cmp( &hc_peer, &hc_current))
346 cur = plugin->sessions->next;
352 * Finds a http session in our linked list using libcurl handle as a key
353 * Needed when sending data with libcurl to differentiate between sessions
354 * @param handle peeridentity
355 * @return http session corresponding to peer identity
357 static struct Session * find_session_by_curlhandle( CURL* handle )
359 struct Session * cur;
361 cur = plugin->sessions;
364 if ( handle == cur->curl_handle )
366 cur = plugin->sessions->next;
372 * Create a new session
374 * @param address address the peer is using inbound
375 * @param address address the peer is using outbound
376 * @param peer identity
377 * @return created session object
379 static struct Session * create_session (struct sockaddr_in *addr_in, struct sockaddr_in *addr_out, const struct GNUNET_PeerIdentity *peer)
381 struct sockaddr_in *addrin;
382 struct sockaddr_in6 *addrin6;
383 struct Session * ses = GNUNET_malloc ( sizeof( struct Session) );
385 ses->addr_outbound = GNUNET_malloc ( sizeof (struct sockaddr_in) );
389 ses->plugin = plugin;
392 ses->addr_inbound = GNUNET_malloc ( sizeof (struct sockaddr_in) );
393 memcpy(ses->addr_inbound, addr_in, sizeof (struct sockaddr_in));
394 if ( AF_INET == addr_in->sin_family)
396 ses->ip = GNUNET_malloc (INET_ADDRSTRLEN);
398 inet_ntop(addrin->sin_family,&(addrin->sin_addr),ses->ip,INET_ADDRSTRLEN);
400 if ( AF_INET6 == addr_in->sin_family)
402 ses->ip = GNUNET_malloc (INET6_ADDRSTRLEN);
403 addrin6 = (struct sockaddr_in6 *) addr_in;
404 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr) ,ses->ip,INET6_ADDRSTRLEN);
408 ses->addr_inbound = NULL;
410 if (NULL != addr_out)
412 ses->addr_outbound = GNUNET_malloc ( sizeof (struct sockaddr_in) );
413 memcpy(ses->addr_outbound, addr_out, sizeof (struct sockaddr_in));
416 ses->addr_outbound = NULL;
418 memcpy(&ses->sender, peer, sizeof (struct GNUNET_PeerIdentity));
419 GNUNET_CRYPTO_hash_to_enc(&ses->sender.hashPubKey,&(ses->hash));
420 ses->is_active = GNUNET_NO;
421 ses->pending_inbound_msg = GNUNET_malloc( sizeof (struct HTTP_Message));
422 ses->pending_inbound_msg->buf = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE);
423 ses->pending_inbound_msg->len = GNUNET_SERVER_MAX_MESSAGE_SIZE;
424 ses->pending_inbound_msg->pos = 0;
431 * Callback called by MHD when a connection is terminated
433 static void requestCompletedCallback (void *cls, struct MHD_Connection * connection, void **httpSessionCache)
437 cs = *httpSessionCache;
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection from peer `%s' was terminated\n",GNUNET_i2s(&cs->sender));
441 /* session set to inactive */
442 cs->is_active = GNUNET_NO;
443 cs->is_put_in_progress = GNUNET_NO;
449 * Check if we are allowed to connect to the given IP.
452 acceptPolicyCallback (void *cls,
453 const struct sockaddr *addr, socklen_t addr_len)
455 /* Every connection is accepted, nothing more to do here */
463 * Process GET or PUT request received via MHD. For
464 * GET, queue response that will send back our pending
465 * messages. For PUT, process incoming data and send
466 * to GNUnet core. In either case, check if a session
467 * already exists and create a new one if not.
470 accessHandlerCallback (void *cls,
471 struct MHD_Connection *session,
475 const char *upload_data,
476 size_t * upload_data_size, void **httpSessionCache)
478 struct MHD_Response *response;
480 struct Session * cs_temp;
481 const union MHD_ConnectionInfo * conn_info;
482 struct sockaddr_in *addrin;
483 struct sockaddr_in6 *addrin6;
484 char * address = NULL;
485 struct GNUNET_PeerIdentity pi_in;
487 struct GNUNET_MessageHeader *gn_msg;
488 int send_error_to_client;
491 send_error_to_client = GNUNET_NO;
493 if ( NULL == *httpSessionCache)
495 /* check url for peer identity */
496 res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey));
497 if ( GNUNET_SYSERR == res )
499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident\n");
500 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
501 res = MHD_queue_response (session, MHD_HTTP_NOT_FOUND, response);
502 MHD_destroy_response (response);
506 conn_info = MHD_get_connection_info(session, MHD_CONNECTION_INFO_CLIENT_ADDRESS );
507 /* Incoming IPv4 connection */
508 if ( AF_INET == conn_info->client_addr->sin_family)
510 address = GNUNET_malloc (INET_ADDRSTRLEN);
511 addrin = conn_info->client_addr;
512 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
514 /* Incoming IPv6 connection */
515 if ( AF_INET6 == conn_info->client_addr->sin_family)
517 address = GNUNET_malloc (INET6_ADDRSTRLEN);
518 addrin6 = (struct sockaddr_in6 *) conn_info->client_addr;
519 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
521 /* find existing session for address */
523 if (plugin->session_count > 0)
525 cs = plugin->sessions;
529 /* Comparison based on ip address */
530 // res = (0 == memcmp(&(conn_info->client_addr->sin_addr),&(cs->addr->sin_addr), sizeof (struct in_addr))) ? GNUNET_YES : GNUNET_NO;
532 /* Comparison based on ip address, port number and address family */
533 // res = (0 == memcmp((conn_info->client_addr),(cs->addr), sizeof (struct sockaddr_in))) ? GNUNET_YES : GNUNET_NO;
535 /* Comparison based on PeerIdentity */
536 res = (0 == memcmp(&pi_in,&(cs->sender), sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_YES : GNUNET_NO;
538 if ( GNUNET_YES == res)
540 /* existing session for this address found */
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Session `%s' found\n",address);
547 /* no existing session, create a new one*/
550 /* create new session object */
551 cs = create_session(conn_info->client_addr, NULL, &pi_in);
553 /* Insert session into linked list */
554 if ( plugin->sessions == NULL)
556 plugin->sessions = cs;
557 plugin->session_count = 1;
559 cs_temp = plugin->sessions;
560 while ( cs_temp->next != NULL )
562 cs_temp = cs_temp->next;
567 plugin->session_count++;
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session `%s' inserted, count %u \n", address, plugin->session_count);
572 if (*httpSessionCache == NULL)
574 *httpSessionCache = cs;
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`[%s]:%u')\n",method, GNUNET_i2s(&cs->sender),cs->ip,cs->addr_inbound->sin_port);
580 cs = *httpSessionCache;
582 /* Is it a PUT or a GET request */
583 if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) )
586 if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_NO))
588 if (cs->pending_inbound_msg->pos !=0 )
590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
591 _("Incoming message from peer `%s', while existing message with %u bytes was not forwarded to transport'\n"),
592 GNUNET_i2s(&cs->sender), cs->pending_inbound_msg->pos);
593 cs->pending_inbound_msg->pos = 0;
596 cs->is_put_in_progress = GNUNET_YES;
597 cs->is_bad_request = GNUNET_NO;
598 cs->is_active = GNUNET_YES;
602 if ((*upload_data_size > 0) && (cs->is_bad_request != GNUNET_YES))
604 if ((*upload_data_size + cs->pending_inbound_msg->pos < cs->pending_inbound_msg->len) && (*upload_data_size + cs->pending_inbound_msg->pos <= GNUNET_SERVER_MAX_MESSAGE_SIZE))
606 /* copy uploaded data to buffer */
607 memcpy(&cs->pending_inbound_msg->buf[cs->pending_inbound_msg->pos],upload_data,*upload_data_size);
608 cs->pending_inbound_msg->pos += *upload_data_size;
609 *upload_data_size = 0;
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"%u bytes not added to message of %u bytes, message to big\n",*upload_data_size, cs->pending_inbound_msg->pos);
615 cs->is_bad_request = GNUNET_YES;
616 /* (*upload_data_size) bytes not processed */
621 if ((cs->is_put_in_progress == GNUNET_YES) && (cs->is_bad_request == GNUNET_YES))
623 *upload_data_size = 0;
624 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
625 res = MHD_queue_response (session, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, response);
628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 ENTITY TOO LARGE as PUT Response\n");
629 cs->is_bad_request = GNUNET_NO;
630 cs->is_put_in_progress =GNUNET_NO;
632 MHD_destroy_response (response);
636 if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES) && (cs->is_bad_request == GNUNET_NO))
638 send_error_to_client = GNUNET_YES;
639 struct GNUNET_MessageHeader * gn_msg = NULL;
640 /*check message and forward here */
642 if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader))
644 gn_msg = GNUNET_malloc (cs->pending_inbound_msg->pos);
645 memcpy (gn_msg,cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos);
647 if ((ntohs(gn_msg->size) == cs->pending_inbound_msg->pos))
649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved GNUnet message type %u size %u and payload %u \n",ntohs (gn_msg->type), ntohs (gn_msg->size), ntohs (gn_msg->size)-sizeof(struct GNUNET_MessageHeader));
650 /* forwarding message to transport */
651 plugin->env->receive(plugin->env, &(cs->sender), gn_msg, 1, cs , cs->ip, strlen(cs->ip) );
652 send_error_to_client = GNUNET_NO;
656 if (send_error_to_client == GNUNET_NO)
658 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
659 res = MHD_queue_response (session, MHD_HTTP_OK, response);
660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 200 OK as PUT Response\n",HTTP_PUT_RESPONSE, strlen (HTTP_PUT_RESPONSE), res );
661 MHD_destroy_response (response);
665 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved malformed message with %u bytes\n", cs->pending_inbound_msg->pos);
666 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
667 res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response);
668 MHD_destroy_response (response);
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n");
672 GNUNET_free_non_null (gn_msg);
673 cs->is_put_in_progress = GNUNET_NO;
674 cs->is_bad_request = GNUNET_NO;
675 cs->pending_inbound_msg->pos = 0;
679 if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) )
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n");
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url);
683 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
684 res = MHD_queue_response (session, MHD_HTTP_OK, response);
685 MHD_destroy_response (response);
693 * Call MHD to process pending requests and then go back
694 * and schedule the next run.
696 static void http_daemon_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
699 * Function that queries MHD's select sets and
700 * starts the task waiting for them.
702 static GNUNET_SCHEDULER_TaskIdentifier
703 http_daemon_prepare (struct MHD_Daemon *daemon_handle)
705 GNUNET_SCHEDULER_TaskIdentifier ret;
709 struct GNUNET_NETWORK_FDSet *wrs;
710 struct GNUNET_NETWORK_FDSet *wws;
711 struct GNUNET_NETWORK_FDSet *wes;
713 unsigned long long timeout;
715 struct GNUNET_TIME_Relative tv;
720 wrs = GNUNET_NETWORK_fdset_create ();
721 wes = GNUNET_NETWORK_fdset_create ();
722 wws = GNUNET_NETWORK_fdset_create ();
724 GNUNET_assert (MHD_YES ==
725 MHD_get_fdset (daemon_handle,
730 haveto = MHD_get_timeout (daemon_handle, &timeout);
731 if (haveto == MHD_YES)
732 tv.value = (uint64_t) timeout;
734 tv = GNUNET_TIME_UNIT_FOREVER_REL;
735 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max);
736 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max);
737 GNUNET_NETWORK_fdset_copy_native (wes, &es, max);
738 ret = GNUNET_SCHEDULER_add_select (plugin->env->sched,
739 GNUNET_SCHEDULER_PRIORITY_HIGH,
740 GNUNET_SCHEDULER_NO_TASK,
746 GNUNET_NETWORK_fdset_destroy (wrs);
747 GNUNET_NETWORK_fdset_destroy (wws);
748 GNUNET_NETWORK_fdset_destroy (wes);
753 * Call MHD to process pending requests and then go back
754 * and schedule the next run.
756 static void http_daemon_run (void *cls,
757 const struct GNUNET_SCHEDULER_TaskContext *tc)
759 struct MHD_Daemon *daemon_handle = cls;
761 if (daemon_handle == http_daemon_v4)
762 http_task_v4 = GNUNET_SCHEDULER_NO_TASK;
764 if (daemon_handle == http_daemon_v6)
765 http_task_v6 = GNUNET_SCHEDULER_NO_TASK;
767 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
770 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
771 if (daemon_handle == http_daemon_v4)
772 http_task_v4 = http_daemon_prepare (daemon_handle);
773 if (daemon_handle == http_daemon_v6)
774 http_task_v6 = http_daemon_prepare (daemon_handle);
779 * Removes a message from the linked list of messages
780 * @param ses session to remove message from
781 * @param msg message to remove
782 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
785 static int remove_http_message(struct Session * ses, struct HTTP_Message * msg)
787 struct HTTP_Message * cur;
788 struct HTTP_Message * next;
790 cur = ses->pending_outbound_msg;
794 return GNUNET_SYSERR;
798 ses->pending_outbound_msg = cur->next;
799 GNUNET_free (cur->buf);
805 while (cur->next!=msg)
807 if (cur->next != NULL)
810 return GNUNET_SYSERR;
813 cur->next = cur->next->next;
814 GNUNET_free (cur->next->buf);
815 GNUNET_free (cur->next);
821 static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream)
824 unsigned int len = size * nmemb;
826 tmp = GNUNET_malloc ( len+1 );
828 if (tmp[len-2] == 13)
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp);
834 if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
836 res->http_result_code=100;
838 if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
840 res->http_result_code=200;
842 if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
844 res->http_result_code=400;
846 if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
848 res->http_result_code=404;
850 if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
852 res->http_result_code=413;
860 * Callback method used with libcurl
861 * Method is called when libcurl needs to read data during sending
862 * @param stream pointer where to write data
863 * @param size size of an individual element
864 * @param nmemb count of elements that can be written to the buffer
865 * @param ptr source pointer, passed to the libcurl handle
866 * @return bytes written to stream
868 static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void *ptr)
870 struct Session * ses = ptr;
871 struct HTTP_Message * msg = ses->pending_outbound_msg;
872 unsigned int bytes_sent;
875 if (msg->len > (size * nmemb))
876 return CURL_READFUNC_ABORT;
878 if (( msg->pos < msg->len) && (msg->len < (size * nmemb)))
880 memcpy(stream, msg->buf, msg->len);
882 bytes_sent = msg->len;
889 * Callback method used with libcurl
890 * Method is called when libcurl needs to write data during sending
891 * @param stream pointer where to write data
892 * @param size size of an individual element
893 * @param nmemb count of elements that can be written to the buffer
894 * @param ptr destination pointer, passed to the libcurl handle
895 * @return bytes read from stream
897 static size_t send_write_callback( void *stream, size_t size, size_t nmemb, void *ptr)
899 char * data = malloc(size*nmemb +1);
901 memcpy( data, stream, size*nmemb);
902 data[size*nmemb] = '\0';
903 /* Just a dummy print for the response recieved for the PUT message */
904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * nmemb, data);
906 return (size * nmemb);
911 * Function setting up file descriptors and scheduling task to run
912 * @param session session to send data to
913 * @return bytes sent to peer
915 static size_t send_prepare(struct Session* session );
918 * Function setting up curl handle and selecting message to send
919 * @param ses session to send data to
920 * @return bytes sent to peer
922 static ssize_t send_select_init (struct Session* ses )
927 struct HTTP_Message * msg;
929 if ( NULL == ses->curl_handle)
930 ses->curl_handle = curl_easy_init();
931 if( NULL == ses->curl_handle)
933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Getting cURL handle failed\n");
936 msg = ses->pending_outbound_msg;
938 url = GNUNET_malloc( 7 + strlen(ses->ip) + 7 + strlen ((char *) &(ses->hash)) + 1);
939 /* FIXME: use correct port number */
940 GNUNET_asprintf(&url,"http://%s:%u/%s",ses->ip,12389, (char *) &(ses->hash));
944 curl_easy_setopt(ses->curl_handle, CURLOPT_VERBOSE, 1L);
946 curl_easy_setopt(ses->curl_handle, CURLOPT_URL, url);
947 curl_easy_setopt(ses->curl_handle, CURLOPT_PUT, 1L);
948 curl_easy_setopt(ses->curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
949 curl_easy_setopt(ses->curl_handle, CURLOPT_READFUNCTION, send_read_callback);
950 curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses);
951 curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEFUNCTION, send_write_callback);
952 curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses);
953 curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len);
954 curl_easy_setopt(ses->curl_handle, CURLOPT_TIMEOUT, (long) (timeout.value / 1000 ));
955 curl_easy_setopt(ses->curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT);
957 mret = curl_multi_add_handle(multi_handle, ses->curl_handle);
958 if (mret != CURLM_OK)
960 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
961 _("%s failed at %s:%d: `%s'\n"),
962 "curl_multi_add_handle", __FILE__, __LINE__,
963 curl_multi_strerror (mret));
966 bytes_sent = send_prepare (ses );
971 static void send_execute (void *cls,
972 const struct GNUNET_SCHEDULER_TaskContext *tc)
977 struct Session * cs = NULL;
979 http_task_send = GNUNET_SCHEDULER_NO_TASK;
980 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
986 mret = curl_multi_perform (multi_handle, &running);
992 msg = curl_multi_info_read (multi_handle, &running);
993 GNUNET_break (msg != NULL);
996 /* get session for affected curl handle */
997 GNUNET_assert ( msg->easy_handle != NULL );
998 cs = find_session_by_curlhandle (msg->easy_handle);
999 GNUNET_assert ( cs != NULL );
1004 if ( (msg->data.result != CURLE_OK) &&
1005 (msg->data.result != CURLE_GOT_NOTHING) )
1008 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1009 _("%s failed for `%s' at %s:%d: `%s'\n"),
1010 "curl_multi_perform",
1014 curl_easy_strerror (msg->data.result));
1015 /* sending msg failed*/
1016 if ( NULL != cs->transmit_cont)
1017 cs->transmit_cont (cs->transmit_cont_cls,&cs->sender,GNUNET_SYSERR);
1021 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1022 "Send to %s completed.\n", cs->ip);
1023 if (GNUNET_OK != remove_http_message(cs, cs->pending_outbound_msg))
1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'", GNUNET_i2s(&cs->sender));
1026 curl_easy_cleanup(cs->curl_handle);
1027 cs->curl_handle=NULL;
1029 /* Calling transmit continuation */
1030 if ( NULL != cs->transmit_cont)
1031 cs->transmit_cont (NULL,&cs->sender,GNUNET_OK);
1034 /* send pending messages */
1035 if (cs->pending_outbound_msg != NULL)
1037 send_select_init (cs);
1046 while ( (running > 0) );
1049 while (mret == CURLM_CALL_MULTI_PERFORM);
1055 * Function setting up file descriptors and scheduling task to run
1056 * @param ses session to send data to
1057 * @return bytes sent to peer
1059 static size_t send_prepare(struct Session* session )
1065 struct GNUNET_NETWORK_FDSet *grs;
1066 struct GNUNET_NETWORK_FDSet *gws;
1074 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
1075 if (mret != CURLM_OK)
1077 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1078 _("%s failed at %s:%d: `%s'\n"),
1079 "curl_multi_fdset", __FILE__, __LINE__,
1080 curl_multi_strerror (mret));
1083 mret = curl_multi_timeout (multi_handle, &to);
1084 if (mret != CURLM_OK)
1086 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1087 _("%s failed at %s:%d: `%s'\n"),
1088 "curl_multi_timeout", __FILE__, __LINE__,
1089 curl_multi_strerror (mret));
1093 grs = GNUNET_NETWORK_fdset_create ();
1094 gws = GNUNET_NETWORK_fdset_create ();
1095 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
1096 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
1097 http_task_send = GNUNET_SCHEDULER_add_select (plugin->env->sched,
1098 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1099 GNUNET_SCHEDULER_NO_TASK,
1100 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0),
1105 GNUNET_NETWORK_fdset_destroy (gws);
1106 GNUNET_NETWORK_fdset_destroy (grs);
1108 /* FIXME: return bytes REALLY sent */
1113 * Function that can be used by the transport service to transmit
1114 * a message using the plugin.
1116 * @param cls closure
1117 * @param target who should receive this message
1118 * @param priority how important is the message
1119 * @param msgbuf the message to transmit
1120 * @param msgbuf_size number of bytes in 'msgbuf'
1121 * @param to when should we time out
1122 * @param session which session must be used (or NULL for "any")
1123 * @param addr the address to use (can be NULL if the plugin
1124 * is "on its own" (i.e. re-use existing TCP connection))
1125 * @param addrlen length of the address in bytes
1126 * @param force_address GNUNET_YES if the plugin MUST use the given address,
1127 * otherwise the plugin may use other addresses or
1128 * existing connections (if available)
1129 * @param cont continuation to call once the message has
1130 * been transmitted (or if the transport is ready
1131 * for the next transmission call; or if the
1132 * peer disconnected...)
1133 * @param cont_cls closure for cont
1134 * @return number of bytes used (on the physical network, with overheads);
1135 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1136 * and does NOT mean that the message was not transmitted (DV)
1139 http_plugin_send (void *cls,
1140 const struct GNUNET_PeerIdentity *target,
1143 unsigned int priority,
1144 struct GNUNET_TIME_Relative to,
1145 struct Session *session,
1149 GNUNET_TRANSPORT_TransmitContinuation cont,
1152 char address[INET6_ADDRSTRLEN];
1153 struct Session* ses;
1154 struct Session* ses_temp;
1155 struct HTTP_Message * msg;
1156 struct HTTP_Message * tmp;
1159 /* find session for peer */
1160 ses = find_session_by_pi (target);
1162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Existing session for peer `%s' found\n", GNUNET_i2s(target));
1165 /* create new session object */
1167 /*FIXME: what is const void * really? Assuming struct sockaddr_in * ! */
1168 ses = create_session(NULL, (struct sockaddr_in *) addr, target);
1169 ses->is_active = GNUNET_YES;
1170 ses->transmit_cont = cont;
1172 /* Insert session into linked list */
1173 if ( plugin->sessions == NULL)
1175 plugin->sessions = ses;
1176 plugin->session_count = 1;
1178 ses_temp = plugin->sessions;
1179 while ( ses_temp->next != NULL )
1181 ses_temp = ses_temp->next;
1183 if (ses_temp != ses )
1185 ses_temp->next = ses;
1186 plugin->session_count++;
1188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session `%s' inserted, count %u \n", GNUNET_i2s(target), plugin->session_count);
1191 GNUNET_assert (addr!=NULL);
1193 if (addrlen == (sizeof (struct IPv4HttpAddress)))
1195 inet_ntop(AF_INET,&((struct IPv4HttpAddress *) addr)->ipv4_addr,address,INET_ADDRSTRLEN);
1196 port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
1198 else if (addrlen == (sizeof (struct IPv6HttpAddress)))
1200 inet_ntop(AF_INET6, &((struct IPv6HttpAddress *) addr)->ipv6_addr,address,INET6_ADDRSTRLEN);
1201 port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
1209 ses->transmit_cont = cont;
1210 ses->transmit_cont_cls = cont_cls;
1212 /* setting up message */
1213 msg = GNUNET_malloc (sizeof (struct HTTP_Message));
1215 msg->len = msgbuf_size;
1217 msg->buf = GNUNET_malloc (msgbuf_size);
1218 memcpy (msg->buf,msgbuf, msgbuf_size);
1220 /* insert created message in list of pending messages */
1221 if (ses->pending_outbound_msg == NULL)
1223 ses->pending_outbound_msg = msg;
1225 tmp = ses->pending_outbound_msg;
1226 while ( NULL != tmp->next)
1235 if (msg == ses->pending_outbound_msg)
1237 bytes_sent = send_select_init (ses);
1246 * Function that can be used to force the plugin to disconnect
1247 * from the given peer and cancel all previous transmissions
1248 * (and their continuationc).
1250 * @param cls closure
1251 * @param target peer from which to disconnect
1254 http_plugin_disconnect (void *cls,
1255 const struct GNUNET_PeerIdentity *target)
1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_disconnect\n");
1258 // struct Plugin *plugin = cls;
1264 * Convert the transports address to a nice, human-readable
1267 * @param cls closure
1268 * @param type name of the transport that generated the address
1269 * @param addr one of the addresses of the host, NULL for the last address
1270 * the specific address format depends on the transport
1271 * @param addrlen length of the address
1272 * @param numeric should (IP) addresses be displayed in numeric form?
1273 * @param timeout after how long should we give up?
1274 * @param asc function to call on each string
1275 * @param asc_cls closure for asc
1278 http_plugin_address_pretty_printer (void *cls,
1283 struct GNUNET_TIME_Relative timeout,
1284 GNUNET_TRANSPORT_AddressStringCallback
1287 const struct IPv4HttpAddress *t4;
1288 const struct IPv6HttpAddress *t6;
1289 struct sockaddr_in a4;
1290 struct sockaddr_in6 a6;
1295 if (addrlen == sizeof (struct IPv6HttpAddress))
1297 address = GNUNET_malloc (INET6_ADDRSTRLEN);
1299 a6.sin6_addr = t6->ipv6_addr;
1300 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
1301 port = ntohs(t6->u6_port);
1303 else if (addrlen == sizeof (struct IPv4HttpAddress))
1305 address = GNUNET_malloc (INET_ADDRSTRLEN);
1307 a4.sin_addr.s_addr = t4->ipv4_addr;
1308 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
1309 port = ntohs(t4->u_port);
1313 /* invalid address */
1314 GNUNET_break_op (0);
1315 asc (asc_cls, NULL);
1319 ret = GNUNET_malloc(strlen(address) +14);
1320 GNUNET_asprintf(&ret,"http://%s:%u/",address,port);
1321 GNUNET_free (address);
1328 * Another peer has suggested an address for this
1329 * peer and transport plugin. Check that this could be a valid
1330 * address. If so, consider adding it to the list
1333 * @param cls closure
1334 * @param addr pointer to the address
1335 * @param addrlen length of addr
1336 * @return GNUNET_OK if this is a plausible address for this peer
1340 http_plugin_address_suggested (void *cls,
1341 void *addr, size_t addrlen)
1343 struct IPv4HttpAddress *v4;
1344 struct IPv6HttpAddress *v6;
1347 if ((addrlen != sizeof (struct IPv4HttpAddress)) &&
1348 (addrlen != sizeof (struct IPv6HttpAddress)))
1350 GNUNET_break_op (0);
1351 return GNUNET_SYSERR;
1353 if (addrlen == sizeof (struct IPv4HttpAddress))
1355 v4 = (struct IPv4HttpAddress *) addr;
1357 port = ntohs (v4->u_port);
1358 if (port != plugin->port_inbound)
1360 GNUNET_break_op (0);
1361 return GNUNET_SYSERR;
1366 v6 = (struct IPv6HttpAddress *) addr;
1367 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1369 GNUNET_break_op (0);
1370 return GNUNET_SYSERR;
1372 port = ntohs (v6->u6_port);
1373 if (port != plugin->port_inbound)
1375 GNUNET_break_op (0);
1376 return GNUNET_SYSERR;
1385 * Function called for a quick conversion of the binary address to
1386 * a numeric address. Note that the caller must not free the
1387 * address and that the next call to this function is allowed
1388 * to override the address again.
1390 * @param cls closure
1391 * @param addr binary address
1392 * @param addrlen length of the address
1393 * @return string representing the same address
1396 http_plugin_address_to_string (void *cls,
1400 const struct IPv4HttpAddress *t4;
1401 const struct IPv6HttpAddress *t6;
1402 struct sockaddr_in a4;
1403 struct sockaddr_in6 a6;
1408 if (addrlen == sizeof (struct IPv6HttpAddress))
1410 address = GNUNET_malloc (INET6_ADDRSTRLEN);
1412 a6.sin6_addr = t6->ipv6_addr;
1413 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
1414 port = ntohs(t6->u6_port);
1416 else if (addrlen == sizeof (struct IPv4HttpAddress))
1418 address = GNUNET_malloc (INET_ADDRSTRLEN);
1420 a4.sin_addr.s_addr = t4->ipv4_addr;
1421 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
1422 port = ntohs(t4->u_port);
1426 /* invalid address */
1430 ret = GNUNET_malloc(strlen(address) +6);
1431 GNUNET_asprintf(&ret,"%s:%u",address,port);
1432 GNUNET_free (address);
1437 * Add the IP of our network interface to the list of
1438 * our external IP addresses.
1440 * @param cls the 'struct Plugin*'
1441 * @param name name of the interface
1442 * @param isDefault do we think this may be our default interface
1443 * @param addr address of the interface
1444 * @param addrlen number of bytes in addr
1445 * @return GNUNET_OK to continue iterating
1448 process_interfaces (void *cls,
1451 const struct sockaddr *addr, socklen_t addrlen)
1453 struct IPv4HttpAddress t4;
1454 struct IPv6HttpAddress t6;
1461 af = addr->sa_family;
1464 if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr))
1466 /* skip loopback addresses */
1469 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1470 t4.u_port = htons (plugin->port_inbound);
1474 else if (af == AF_INET6)
1476 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
1478 /* skip link local addresses */
1481 if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr))
1483 /* skip loopback addresses */
1486 memcpy (&t6.ipv6_addr,
1487 &((struct sockaddr_in6 *) addr)->sin6_addr,
1488 sizeof (struct in6_addr));
1489 t6.u6_port = htons (plugin->port_inbound);
1498 plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
1504 * Exit point from the plugin.
1507 libgnunet_plugin_transport_http_done (void *cls)
1509 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1510 struct Plugin *plugin = api->cls;
1511 struct Session * cs;
1512 struct Session * cs_next;
1515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unloading http plugin...\n");
1517 if ( http_task_v4 != GNUNET_SCHEDULER_NO_TASK)
1519 GNUNET_SCHEDULER_cancel(plugin->env->sched, http_task_v4);
1520 http_task_v4 = GNUNET_SCHEDULER_NO_TASK;
1523 if ( http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1525 GNUNET_SCHEDULER_cancel(plugin->env->sched, http_task_v6);
1526 http_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1529 if ( http_task_send != GNUNET_SCHEDULER_NO_TASK)
1531 GNUNET_SCHEDULER_cancel(plugin->env->sched, http_task_send);
1532 http_task_send = GNUNET_SCHEDULER_NO_TASK;
1535 if (http_daemon_v4 != NULL)
1537 MHD_stop_daemon (http_daemon_v4);
1538 http_daemon_v4 = NULL;
1540 if (http_daemon_v6 != NULL)
1542 MHD_stop_daemon (http_daemon_v6);
1543 http_daemon_v6 = NULL;
1546 mret = curl_multi_cleanup(multi_handle);
1547 if ( CURLM_OK != mret)
1548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"curl multihandle clean up failed");
1550 /* free all sessions */
1551 cs = plugin->sessions;
1555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing session to `%s'\n",cs->ip);
1558 /* freeing messages */
1559 struct HTTP_Message *cur;
1560 struct HTTP_Message *tmp;
1561 cur = cs->pending_outbound_msg;
1566 if (NULL != cur->buf)
1567 GNUNET_free (cur->buf);
1571 GNUNET_free (cs->pending_inbound_msg->buf);
1572 GNUNET_free (cs->pending_inbound_msg);
1573 GNUNET_free (cs->ip);
1574 GNUNET_free (cs->addr_inbound);
1575 GNUNET_free_non_null (cs->addr_outbound);
1577 plugin->session_count--;
1582 /* GNUNET_SERVICE_stop (plugin->service); */
1583 GNUNET_free (hostname);
1584 GNUNET_free (plugin);
1591 * Entry point for the plugin.
1594 libgnunet_plugin_transport_http_init (void *cls)
1596 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1597 struct GNUNET_TRANSPORT_PluginFunctions *api;
1598 struct GNUNET_SERVICE_Context *service;
1599 unsigned int timeout;
1600 struct GNUNET_TIME_Relative gn_timeout;
1601 long long unsigned int port;
1603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
1607 service = GNUNET_SERVICE_start ("transport-http", env->sched, env->cfg);
1608 if (service == NULL)
1610 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "", _
1611 ("Failed to start service for `%s' transport plugin.\n"),
1617 plugin = GNUNET_malloc (sizeof (struct Plugin));
1619 plugin->sessions = NULL;
1620 plugin->service = service;
1621 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1623 api->send = &http_plugin_send;
1624 api->disconnect = &http_plugin_disconnect;
1625 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1626 api->check_address = &http_plugin_address_suggested;
1627 api->address_to_string = &http_plugin_address_to_string;
1629 hostname = GNUNET_RESOLVER_local_fqdn_get ();
1631 /* Hashing our identity to use it in URLs */
1632 GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &my_ascii_hash_ident);
1634 /* Reading port number from config file */
1636 GNUNET_CONFIGURATION_get_value_number (env->cfg,
1642 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1645 ("Require valid port number for transport plugin `%s' in configuration!\n"),
1647 libgnunet_plugin_transport_http_done (api);
1650 plugin->port_inbound = port;
1651 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
1652 timeout = ( gn_timeout.value / 1000);
1653 if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0))
1655 http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6,
1657 &acceptPolicyCallback,
1658 NULL , &accessHandlerCallback, NULL,
1659 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16,
1660 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
1661 MHD_OPTION_CONNECTION_TIMEOUT, timeout,
1662 /* FIXME: set correct limit */
1663 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024),
1664 MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL,
1666 http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG,
1668 &acceptPolicyCallback,
1669 NULL , &accessHandlerCallback, NULL,
1670 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16,
1671 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
1672 MHD_OPTION_CONNECTION_TIMEOUT, timeout,
1673 /* FIXME: set correct limit */
1674 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024),
1675 MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL,
1678 if (http_daemon_v4 != NULL)
1679 http_task_v4 = http_daemon_prepare (http_daemon_v4);
1680 if (http_daemon_v6 != NULL)
1681 http_task_v6 = http_daemon_prepare (http_daemon_v6);
1683 if (http_task_v4 != GNUNET_SCHEDULER_NO_TASK)
1684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port);
1685 if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port);
1689 /* Initializing cURL */
1690 multi_handle = curl_multi_init();
1691 if ( NULL == multi_handle )
1693 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1695 _("Could not initialize curl multi handle, failed to start http plugin!\n"),
1697 libgnunet_plugin_transport_http_done (api);
1701 GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
1706 /* end of plugin_transport_template.c */