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 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Port %u \n", addrin->sin_port);
399 inet_ntop(addrin->sin_family,&(addrin->sin_addr),ses->ip,INET_ADDRSTRLEN);
401 if ( AF_INET6 == addr_in->sin_family)
403 ses->ip = GNUNET_malloc (INET6_ADDRSTRLEN);
404 addrin6 = (struct sockaddr_in6 *) addr_in;
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Port %u \n", addrin6->sin6_port);
406 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr) ,ses->ip,INET6_ADDRSTRLEN);
410 ses->addr_inbound = NULL;
412 if (NULL != addr_out)
414 ses->addr_outbound = GNUNET_malloc ( sizeof (struct sockaddr_in) );
415 memcpy(ses->addr_outbound, addr_out, sizeof (struct sockaddr_in));
418 ses->addr_outbound = NULL;
420 memcpy(&ses->sender, peer, sizeof (struct GNUNET_PeerIdentity));
421 GNUNET_CRYPTO_hash_to_enc(&ses->sender.hashPubKey,&(ses->hash));
422 ses->is_active = GNUNET_NO;
423 ses->pending_inbound_msg = GNUNET_malloc( sizeof (struct HTTP_Message));
424 ses->pending_inbound_msg->buf = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE);
425 ses->pending_inbound_msg->len = GNUNET_SERVER_MAX_MESSAGE_SIZE;
426 ses->pending_inbound_msg->pos = 0;
433 * Callback called by MHD when a connection is terminated
435 static void requestCompletedCallback (void *cls, struct MHD_Connection * connection, void **httpSessionCache)
439 cs = *httpSessionCache;
442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection from peer `%s' was terminated\n",GNUNET_i2s(&cs->sender));
443 /* session set to inactive */
444 cs->is_active = GNUNET_NO;
445 cs->is_put_in_progress = GNUNET_NO;
451 * Check if we are allowed to connect to the given IP.
454 acceptPolicyCallback (void *cls,
455 const struct sockaddr *addr, socklen_t addr_len)
457 /* Every connection is accepted, nothing more to do here */
465 * Process GET or PUT request received via MHD. For
466 * GET, queue response that will send back our pending
467 * messages. For PUT, process incoming data and send
468 * to GNUnet core. In either case, check if a session
469 * already exists and create a new one if not.
472 accessHandlerCallback (void *cls,
473 struct MHD_Connection *session,
477 const char *upload_data,
478 size_t * upload_data_size, void **httpSessionCache)
480 struct MHD_Response *response;
482 struct Session * cs_temp;
483 const union MHD_ConnectionInfo * conn_info;
484 struct sockaddr_in *addrin;
485 struct sockaddr_in6 *addrin6;
486 char * address = NULL;
487 struct GNUNET_PeerIdentity pi_in;
489 struct GNUNET_MessageHeader *gn_msg;
490 int send_error_to_client;
493 send_error_to_client = GNUNET_NO;
495 if ( NULL == *httpSessionCache)
497 /* check url for peer identity */
498 res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey));
499 if ( GNUNET_SYSERR == res )
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident\n");
502 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
503 res = MHD_queue_response (session, MHD_HTTP_NOT_FOUND, response);
504 MHD_destroy_response (response);
508 conn_info = MHD_get_connection_info(session, MHD_CONNECTION_INFO_CLIENT_ADDRESS );
509 /* Incoming IPv4 connection */
510 if ( AF_INET == conn_info->client_addr->sin_family)
512 address = GNUNET_malloc (INET_ADDRSTRLEN);
513 addrin = conn_info->client_addr;
514 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
516 /* Incoming IPv6 connection */
517 if ( AF_INET6 == conn_info->client_addr->sin_family)
519 address = GNUNET_malloc (INET6_ADDRSTRLEN);
520 addrin6 = (struct sockaddr_in6 *) conn_info->client_addr;
521 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
523 /* find existing session for address */
525 if (plugin->session_count > 0)
527 cs = plugin->sessions;
531 /* Comparison based on ip address */
532 // res = (0 == memcmp(&(conn_info->client_addr->sin_addr),&(cs->addr->sin_addr), sizeof (struct in_addr))) ? GNUNET_YES : GNUNET_NO;
534 /* Comparison based on ip address, port number and address family */
535 // res = (0 == memcmp((conn_info->client_addr),(cs->addr), sizeof (struct sockaddr_in))) ? GNUNET_YES : GNUNET_NO;
537 /* Comparison based on PeerIdentity */
538 res = (0 == memcmp(&pi_in,&(cs->sender), sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_YES : GNUNET_NO;
540 if ( GNUNET_YES == res)
542 /* existing session for this address found */
543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Session `%s' found\n",address);
549 /* no existing session, create a new one*/
552 /* create new session object */
553 cs = create_session(conn_info->client_addr, NULL, &pi_in);
555 /* Insert session into linked list */
556 if ( plugin->sessions == NULL)
558 plugin->sessions = cs;
559 plugin->session_count = 1;
561 cs_temp = plugin->sessions;
562 while ( cs_temp->next != NULL )
564 cs_temp = cs_temp->next;
569 plugin->session_count++;
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session `%s' inserted, count %u \n", address, plugin->session_count);
574 if (*httpSessionCache == NULL)
576 *httpSessionCache = cs;
578 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);
582 cs = *httpSessionCache;
584 /* Is it a PUT or a GET request */
585 if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) )
588 if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_NO))
590 if (cs->pending_inbound_msg->pos !=0 )
592 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
593 _("Incoming message from peer `%s', while existing message with %u bytes was not forwarded to transport'\n"),
594 GNUNET_i2s(&cs->sender), cs->pending_inbound_msg->pos);
595 cs->pending_inbound_msg->pos = 0;
598 cs->is_put_in_progress = GNUNET_YES;
599 cs->is_bad_request = GNUNET_NO;
600 cs->is_active = GNUNET_YES;
604 if ((*upload_data_size > 0) && (cs->is_bad_request != GNUNET_YES))
606 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))
608 /* copy uploaded data to buffer */
609 memcpy(&cs->pending_inbound_msg->buf[cs->pending_inbound_msg->pos],upload_data,*upload_data_size);
610 cs->pending_inbound_msg->pos += *upload_data_size;
611 *upload_data_size = 0;
616 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);
617 cs->is_bad_request = GNUNET_YES;
618 /* (*upload_data_size) bytes not processed */
623 if ((cs->is_put_in_progress == GNUNET_YES) && (cs->is_bad_request == GNUNET_YES))
625 *upload_data_size = 0;
626 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
627 res = MHD_queue_response (session, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, response);
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 ENTITY TOO LARGE as PUT Response\n");
631 cs->is_bad_request = GNUNET_NO;
632 cs->is_put_in_progress =GNUNET_NO;
634 MHD_destroy_response (response);
638 if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES) && (cs->is_bad_request == GNUNET_NO))
640 send_error_to_client = GNUNET_YES;
641 struct GNUNET_MessageHeader * gn_msg = NULL;
642 /*check message and forward here */
644 if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader))
646 gn_msg = GNUNET_malloc (cs->pending_inbound_msg->pos);
647 memcpy (gn_msg,cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos);
649 if ((ntohs(gn_msg->size) == cs->pending_inbound_msg->pos))
651 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));
652 /* forwarding message to transport */
653 plugin->env->receive(plugin->env, &(cs->sender), gn_msg, 1, cs , cs->ip, strlen(cs->ip) );
654 send_error_to_client = GNUNET_NO;
658 if (send_error_to_client == GNUNET_NO)
660 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
661 res = MHD_queue_response (session, MHD_HTTP_OK, response);
662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 200 OK as PUT Response\n",HTTP_PUT_RESPONSE, strlen (HTTP_PUT_RESPONSE), res );
663 MHD_destroy_response (response);
667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved malformed message with %u bytes\n", cs->pending_inbound_msg->pos);
668 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
669 res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response);
670 MHD_destroy_response (response);
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n");
674 GNUNET_free_non_null (gn_msg);
675 cs->is_put_in_progress = GNUNET_NO;
676 cs->is_bad_request = GNUNET_NO;
677 cs->pending_inbound_msg->pos = 0;
681 if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) )
683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n");
684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url);
685 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
686 res = MHD_queue_response (session, MHD_HTTP_OK, response);
687 MHD_destroy_response (response);
695 * Call MHD to process pending requests and then go back
696 * and schedule the next run.
698 static void http_daemon_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
701 * Function that queries MHD's select sets and
702 * starts the task waiting for them.
704 static GNUNET_SCHEDULER_TaskIdentifier
705 http_daemon_prepare (struct MHD_Daemon *daemon_handle)
707 GNUNET_SCHEDULER_TaskIdentifier ret;
711 struct GNUNET_NETWORK_FDSet *wrs;
712 struct GNUNET_NETWORK_FDSet *wws;
713 struct GNUNET_NETWORK_FDSet *wes;
715 unsigned long long timeout;
717 struct GNUNET_TIME_Relative tv;
722 wrs = GNUNET_NETWORK_fdset_create ();
723 wes = GNUNET_NETWORK_fdset_create ();
724 wws = GNUNET_NETWORK_fdset_create ();
726 GNUNET_assert (MHD_YES ==
727 MHD_get_fdset (daemon_handle,
732 haveto = MHD_get_timeout (daemon_handle, &timeout);
733 if (haveto == MHD_YES)
734 tv.value = (uint64_t) timeout;
736 tv = GNUNET_TIME_UNIT_FOREVER_REL;
737 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max);
738 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max);
739 GNUNET_NETWORK_fdset_copy_native (wes, &es, max);
740 ret = GNUNET_SCHEDULER_add_select (plugin->env->sched,
741 GNUNET_SCHEDULER_PRIORITY_HIGH,
742 GNUNET_SCHEDULER_NO_TASK,
748 GNUNET_NETWORK_fdset_destroy (wrs);
749 GNUNET_NETWORK_fdset_destroy (wws);
750 GNUNET_NETWORK_fdset_destroy (wes);
755 * Call MHD to process pending requests and then go back
756 * and schedule the next run.
758 static void http_daemon_run (void *cls,
759 const struct GNUNET_SCHEDULER_TaskContext *tc)
761 struct MHD_Daemon *daemon_handle = cls;
763 if (daemon_handle == http_daemon_v4)
764 http_task_v4 = GNUNET_SCHEDULER_NO_TASK;
766 if (daemon_handle == http_daemon_v6)
767 http_task_v6 = GNUNET_SCHEDULER_NO_TASK;
769 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
772 GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
773 if (daemon_handle == http_daemon_v4)
774 http_task_v4 = http_daemon_prepare (daemon_handle);
775 if (daemon_handle == http_daemon_v6)
776 http_task_v6 = http_daemon_prepare (daemon_handle);
781 * Removes a message from the linked list of messages
782 * @param ses session to remove message from
783 * @param msg message to remove
784 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
787 static int remove_http_message(struct Session * ses, struct HTTP_Message * msg)
789 struct HTTP_Message * cur;
790 struct HTTP_Message * next;
792 cur = ses->pending_outbound_msg;
796 return GNUNET_SYSERR;
800 ses->pending_outbound_msg = cur->next;
801 GNUNET_free (cur->buf);
807 while (cur->next!=msg)
809 if (cur->next != NULL)
812 return GNUNET_SYSERR;
815 cur->next = cur->next->next;
816 GNUNET_free (cur->next->buf);
817 GNUNET_free (cur->next);
823 static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream)
826 unsigned int len = size * nmemb;
828 tmp = GNUNET_malloc ( len+1 );
830 if (tmp[len-2] == 13)
833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp);
836 if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
838 res->http_result_code=100;
840 if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
842 res->http_result_code=200;
844 if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
846 res->http_result_code=400;
848 if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
850 res->http_result_code=404;
852 if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
854 res->http_result_code=413;
862 * Callback method used with libcurl
863 * Method is called when libcurl needs to read data during sending
864 * @param stream pointer where to write data
865 * @param size size of an individual element
866 * @param nmemb count of elements that can be written to the buffer
867 * @param ptr source pointer, passed to the libcurl handle
868 * @return bytes written to stream
870 static size_t send_read_callback(void *stream, size_t size, size_t nmemb, void *ptr)
872 struct Session * ses = ptr;
873 struct HTTP_Message * msg = ses->pending_outbound_msg;
874 unsigned int bytes_sent;
877 if (msg->len > (size * nmemb))
878 return CURL_READFUNC_ABORT;
880 if (( msg->pos < msg->len) && (msg->len < (size * nmemb)))
882 memcpy(stream, msg->buf, msg->len);
884 bytes_sent = msg->len;
891 * Callback method used with libcurl
892 * Method is called when libcurl needs to write data during sending
893 * @param stream pointer where to write data
894 * @param size size of an individual element
895 * @param nmemb count of elements that can be written to the buffer
896 * @param ptr destination pointer, passed to the libcurl handle
897 * @return bytes read from stream
899 static size_t send_write_callback( void *stream, size_t size, size_t nmemb, void *ptr)
901 char * data = malloc(size*nmemb +1);
903 memcpy( data, stream, size*nmemb);
904 data[size*nmemb] = '\0';
905 /* Just a dummy print for the response recieved for the PUT message */
906 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * nmemb, data);
908 return (size * nmemb);
913 * Function setting up file descriptors and scheduling task to run
914 * @param session session to send data to
915 * @return bytes sent to peer
917 static size_t send_prepare(struct Session* session );
920 * Function setting up curl handle and selecting message to send
921 * @param ses session to send data to
922 * @return bytes sent to peer
924 static ssize_t send_select_init (struct Session* ses )
929 struct HTTP_Message * msg;
931 if ( NULL == ses->curl_handle)
932 ses->curl_handle = curl_easy_init();
933 if( NULL == ses->curl_handle)
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Getting cURL handle failed\n");
938 msg = ses->pending_outbound_msg;
940 url = GNUNET_malloc( 7 + strlen(ses->ip) + 7 + strlen ((char *) &(ses->hash)) + 1);
941 /* FIXME: use correct port number */
942 GNUNET_asprintf(&url,"http://%s:%u/%s",ses->ip,12389, (char *) &(ses->hash));
946 curl_easy_setopt(ses->curl_handle, CURLOPT_VERBOSE, 1L);
948 curl_easy_setopt(ses->curl_handle, CURLOPT_URL, url);
949 curl_easy_setopt(ses->curl_handle, CURLOPT_PUT, 1L);
950 curl_easy_setopt(ses->curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
951 curl_easy_setopt(ses->curl_handle, CURLOPT_READFUNCTION, send_read_callback);
952 curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses);
953 curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEFUNCTION, send_write_callback);
954 curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses);
955 curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len);
956 curl_easy_setopt(ses->curl_handle, CURLOPT_TIMEOUT, (long) (timeout.value / 1000 ));
957 curl_easy_setopt(ses->curl_handle, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT);
959 mret = curl_multi_add_handle(multi_handle, ses->curl_handle);
960 if (mret != CURLM_OK)
962 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
963 _("%s failed at %s:%d: `%s'\n"),
964 "curl_multi_add_handle", __FILE__, __LINE__,
965 curl_multi_strerror (mret));
968 bytes_sent = send_prepare (ses );
973 static void send_execute (void *cls,
974 const struct GNUNET_SCHEDULER_TaskContext *tc)
979 struct Session * cs = NULL;
981 http_task_send = GNUNET_SCHEDULER_NO_TASK;
982 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
988 mret = curl_multi_perform (multi_handle, &running);
994 msg = curl_multi_info_read (multi_handle, &running);
995 GNUNET_break (msg != NULL);
998 /* get session for affected curl handle */
999 GNUNET_assert ( msg->easy_handle != NULL );
1000 cs = find_session_by_curlhandle (msg->easy_handle);
1001 GNUNET_assert ( cs != NULL );
1006 if ( (msg->data.result != CURLE_OK) &&
1007 (msg->data.result != CURLE_GOT_NOTHING) )
1010 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1011 _("%s failed for `%s' at %s:%d: `%s'\n"),
1012 "curl_multi_perform",
1016 curl_easy_strerror (msg->data.result));
1017 /* sending msg failed*/
1018 if ( NULL != cs->transmit_cont)
1019 cs->transmit_cont (cs->transmit_cont_cls,&cs->sender,GNUNET_SYSERR);
1023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1024 "Send to %s completed.\n", cs->ip);
1025 if (GNUNET_OK != remove_http_message(cs, cs->pending_outbound_msg))
1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'", GNUNET_i2s(&cs->sender));
1028 curl_easy_cleanup(cs->curl_handle);
1029 cs->curl_handle=NULL;
1031 /* Calling transmit continuation */
1032 if ( NULL != cs->transmit_cont)
1033 cs->transmit_cont (NULL,&cs->sender,GNUNET_OK);
1036 /* send pending messages */
1037 if (cs->pending_outbound_msg != NULL)
1039 send_select_init (cs);
1048 while ( (running > 0) );
1051 while (mret == CURLM_CALL_MULTI_PERFORM);
1057 * Function setting up file descriptors and scheduling task to run
1058 * @param ses session to send data to
1059 * @return bytes sent to peer
1061 static size_t send_prepare(struct Session* session )
1067 struct GNUNET_NETWORK_FDSet *grs;
1068 struct GNUNET_NETWORK_FDSet *gws;
1076 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
1077 if (mret != CURLM_OK)
1079 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1080 _("%s failed at %s:%d: `%s'\n"),
1081 "curl_multi_fdset", __FILE__, __LINE__,
1082 curl_multi_strerror (mret));
1085 mret = curl_multi_timeout (multi_handle, &to);
1086 if (mret != CURLM_OK)
1088 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1089 _("%s failed at %s:%d: `%s'\n"),
1090 "curl_multi_timeout", __FILE__, __LINE__,
1091 curl_multi_strerror (mret));
1095 grs = GNUNET_NETWORK_fdset_create ();
1096 gws = GNUNET_NETWORK_fdset_create ();
1097 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
1098 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
1099 http_task_send = GNUNET_SCHEDULER_add_select (plugin->env->sched,
1100 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1101 GNUNET_SCHEDULER_NO_TASK,
1102 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0),
1107 GNUNET_NETWORK_fdset_destroy (gws);
1108 GNUNET_NETWORK_fdset_destroy (grs);
1110 /* FIXME: return bytes REALLY sent */
1115 * Function that can be used by the transport service to transmit
1116 * a message using the plugin.
1118 * @param cls closure
1119 * @param target who should receive this message
1120 * @param priority how important is the message
1121 * @param msgbuf the message to transmit
1122 * @param msgbuf_size number of bytes in 'msgbuf'
1123 * @param to when should we time out
1124 * @param session which session must be used (or NULL for "any")
1125 * @param addr the address to use (can be NULL if the plugin
1126 * is "on its own" (i.e. re-use existing TCP connection))
1127 * @param addrlen length of the address in bytes
1128 * @param force_address GNUNET_YES if the plugin MUST use the given address,
1129 * otherwise the plugin may use other addresses or
1130 * existing connections (if available)
1131 * @param cont continuation to call once the message has
1132 * been transmitted (or if the transport is ready
1133 * for the next transmission call; or if the
1134 * peer disconnected...)
1135 * @param cont_cls closure for cont
1136 * @return number of bytes used (on the physical network, with overheads);
1137 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1138 * and does NOT mean that the message was not transmitted (DV)
1141 http_plugin_send (void *cls,
1142 const struct GNUNET_PeerIdentity *target,
1145 unsigned int priority,
1146 struct GNUNET_TIME_Relative to,
1147 struct Session *session,
1151 GNUNET_TRANSPORT_TransmitContinuation cont,
1154 char address[INET6_ADDRSTRLEN];
1155 struct Session* ses;
1156 struct Session* ses_temp;
1157 struct HTTP_Message * msg;
1158 struct HTTP_Message * tmp;
1161 /* find session for peer */
1162 ses = find_session_by_pi (target);
1164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Existing session for peer `%s' found\n", GNUNET_i2s(target));
1167 /* create new session object */
1169 /*FIXME: what is const void * really? Assuming struct sockaddr_in * ! */
1170 ses = create_session(NULL, (struct sockaddr_in *) addr, target);
1171 ses->is_active = GNUNET_YES;
1172 ses->transmit_cont = cont;
1174 /* Insert session into linked list */
1175 if ( plugin->sessions == NULL)
1177 plugin->sessions = ses;
1178 plugin->session_count = 1;
1180 ses_temp = plugin->sessions;
1181 while ( ses_temp->next != NULL )
1183 ses_temp = ses_temp->next;
1185 if (ses_temp != ses )
1187 ses_temp->next = ses;
1188 plugin->session_count++;
1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session `%s' inserted, count %u \n", GNUNET_i2s(target), plugin->session_count);
1193 GNUNET_assert (addr!=NULL);
1195 if (addrlen == (sizeof (struct IPv4HttpAddress)))
1197 inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
1198 port = ((struct IPv4HttpAddress *) addr)->u_port;
1199 //port = ntohs(((struct in_addr *) addr)->);
1201 else if (addrlen == (sizeof (struct IPv6HttpAddress)))
1203 inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
1204 port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"ADDR `%s':%u \n",address,port);
1213 ses->transmit_cont = cont;
1214 ses->transmit_cont_cls = cont_cls;
1216 /* setting up message */
1217 msg = GNUNET_malloc (sizeof (struct HTTP_Message));
1219 msg->len = msgbuf_size;
1221 msg->buf = GNUNET_malloc (msgbuf_size);
1222 memcpy (msg->buf,msgbuf, msgbuf_size);
1224 /* insert created message in list of pending messages */
1225 if (ses->pending_outbound_msg == NULL)
1227 ses->pending_outbound_msg = msg;
1229 tmp = ses->pending_outbound_msg;
1230 while ( NULL != tmp->next)
1239 if (msg == ses->pending_outbound_msg)
1241 bytes_sent = send_select_init (ses);
1250 * Function that can be used to force the plugin to disconnect
1251 * from the given peer and cancel all previous transmissions
1252 * (and their continuationc).
1254 * @param cls closure
1255 * @param target peer from which to disconnect
1258 http_plugin_disconnect (void *cls,
1259 const struct GNUNET_PeerIdentity *target)
1261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: http_plugin_disconnect\n");
1262 // struct Plugin *plugin = cls;
1268 * Convert the transports address to a nice, human-readable
1271 * @param cls closure
1272 * @param type name of the transport that generated the address
1273 * @param addr one of the addresses of the host, NULL for the last address
1274 * the specific address format depends on the transport
1275 * @param addrlen length of the address
1276 * @param numeric should (IP) addresses be displayed in numeric form?
1277 * @param timeout after how long should we give up?
1278 * @param asc function to call on each string
1279 * @param asc_cls closure for asc
1282 http_plugin_address_pretty_printer (void *cls,
1287 struct GNUNET_TIME_Relative timeout,
1288 GNUNET_TRANSPORT_AddressStringCallback
1291 const struct IPv4HttpAddress *t4;
1292 const struct IPv6HttpAddress *t6;
1293 struct sockaddr_in a4;
1294 struct sockaddr_in6 a6;
1299 if (addrlen == sizeof (struct IPv6HttpAddress))
1301 address = GNUNET_malloc (INET6_ADDRSTRLEN);
1303 a6.sin6_addr = t6->ipv6_addr;
1304 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
1305 port = ntohs(t6->u6_port);
1307 else if (addrlen == sizeof (struct IPv4HttpAddress))
1309 address = GNUNET_malloc (INET_ADDRSTRLEN);
1311 a4.sin_addr.s_addr = t4->ipv4_addr;
1312 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
1313 port = ntohs(t4->u_port);
1317 /* invalid address */
1318 GNUNET_break_op (0);
1319 asc (asc_cls, NULL);
1323 ret = GNUNET_malloc(strlen(address) +14);
1324 GNUNET_asprintf(&ret,"http://%s:%u/",address,port);
1325 GNUNET_free (address);
1332 * Another peer has suggested an address for this
1333 * peer and transport plugin. Check that this could be a valid
1334 * address. If so, consider adding it to the list
1337 * @param cls closure
1338 * @param addr pointer to the address
1339 * @param addrlen length of addr
1340 * @return GNUNET_OK if this is a plausible address for this peer
1344 http_plugin_address_suggested (void *cls,
1345 void *addr, size_t addrlen)
1347 struct IPv4HttpAddress *v4;
1348 struct IPv6HttpAddress *v6;
1350 if ((addrlen != sizeof (struct IPv4HttpAddress)) &&
1351 (addrlen != sizeof (struct IPv6HttpAddress)))
1353 GNUNET_break_op (0);
1354 return GNUNET_SYSERR;
1356 if (addrlen == sizeof (struct IPv4HttpAddress))
1358 v4 = (struct IPv4HttpAddress *) addr;
1360 v4->u_port = ntohs (v4->u_port);
1361 if (v4->u_port != plugin->port_inbound)
1363 GNUNET_break_op (0);
1364 return GNUNET_SYSERR;
1369 v6 = (struct IPv6HttpAddress *) addr;
1370 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1372 GNUNET_break_op (0);
1373 return GNUNET_SYSERR;
1375 v6->u6_port = ntohs (v6->u6_port);
1376 if (v6->u6_port != plugin->port_inbound)
1378 GNUNET_break_op (0);
1379 return GNUNET_SYSERR;
1388 * Function called for a quick conversion of the binary address to
1389 * a numeric address. Note that the caller must not free the
1390 * address and that the next call to this function is allowed
1391 * to override the address again.
1393 * @param cls closure
1394 * @param addr binary address
1395 * @param addrlen length of the address
1396 * @return string representing the same address
1399 http_plugin_address_to_string (void *cls,
1403 const struct IPv4HttpAddress *t4;
1404 const struct IPv6HttpAddress *t6;
1405 struct sockaddr_in a4;
1406 struct sockaddr_in6 a6;
1411 if (addrlen == sizeof (struct IPv6HttpAddress))
1413 address = GNUNET_malloc (INET6_ADDRSTRLEN);
1415 a6.sin6_addr = t6->ipv6_addr;
1416 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
1417 port = ntohs(t6->u6_port);
1419 else if (addrlen == sizeof (struct IPv4HttpAddress))
1421 address = GNUNET_malloc (INET_ADDRSTRLEN);
1423 a4.sin_addr.s_addr = t4->ipv4_addr;
1424 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
1425 port = ntohs(t4->u_port);
1429 /* invalid address */
1433 ret = GNUNET_malloc(strlen(address) +6);
1434 GNUNET_asprintf(&ret,"%s:%u",address,port);
1435 GNUNET_free (address);
1440 * Add the IP of our network interface to the list of
1441 * our external IP addresses.
1443 * @param cls the 'struct Plugin*'
1444 * @param name name of the interface
1445 * @param isDefault do we think this may be our default interface
1446 * @param addr address of the interface
1447 * @param addrlen number of bytes in addr
1448 * @return GNUNET_OK to continue iterating
1451 process_interfaces (void *cls,
1454 const struct sockaddr *addr, socklen_t addrlen)
1456 struct IPv4HttpAddress t4;
1457 struct IPv6HttpAddress t6;
1464 af = addr->sa_family;
1467 if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr))
1469 /* skip loopback addresses */
1472 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1473 t4.u_port = htons (plugin->port_inbound);
1477 else if (af == AF_INET6)
1479 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
1481 /* skip link local addresses */
1484 if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr))
1486 /* skip loopback addresses */
1489 memcpy (&t6.ipv6_addr,
1490 &((struct sockaddr_in6 *) addr)->sin6_addr,
1491 sizeof (struct in6_addr));
1492 t6.u6_port = htons (plugin->port_inbound);
1501 plugin->env->notify_address(plugin->env->cls,"http",arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
1507 * Exit point from the plugin.
1510 libgnunet_plugin_transport_http_done (void *cls)
1512 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1513 struct Plugin *plugin = api->cls;
1514 struct Session * cs;
1515 struct Session * cs_next;
1518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unloading http plugin...\n");
1520 if ( http_task_v4 != GNUNET_SCHEDULER_NO_TASK)
1522 GNUNET_SCHEDULER_cancel(plugin->env->sched, http_task_v4);
1523 http_task_v4 = GNUNET_SCHEDULER_NO_TASK;
1526 if ( http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1528 GNUNET_SCHEDULER_cancel(plugin->env->sched, http_task_v6);
1529 http_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1532 if ( http_task_send != GNUNET_SCHEDULER_NO_TASK)
1534 GNUNET_SCHEDULER_cancel(plugin->env->sched, http_task_send);
1535 http_task_send = GNUNET_SCHEDULER_NO_TASK;
1538 if (http_daemon_v4 != NULL)
1540 MHD_stop_daemon (http_daemon_v4);
1541 http_daemon_v4 = NULL;
1543 if (http_daemon_v6 != NULL)
1545 MHD_stop_daemon (http_daemon_v6);
1546 http_daemon_v6 = NULL;
1549 mret = curl_multi_cleanup(multi_handle);
1550 if ( CURLM_OK != mret)
1551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"curl multihandle clean up failed");
1553 /* free all sessions */
1554 cs = plugin->sessions;
1558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing session to `%s'\n",cs->ip);
1561 /* freeing messages */
1562 struct HTTP_Message *cur;
1563 struct HTTP_Message *tmp;
1564 cur = cs->pending_outbound_msg;
1569 if (NULL != cur->buf)
1570 GNUNET_free (cur->buf);
1574 GNUNET_free (cs->pending_inbound_msg->buf);
1575 GNUNET_free (cs->pending_inbound_msg);
1576 GNUNET_free (cs->ip);
1577 GNUNET_free (cs->addr_inbound);
1578 GNUNET_free_non_null (cs->addr_outbound);
1580 plugin->session_count--;
1585 /* GNUNET_SERVICE_stop (plugin->service); */
1586 GNUNET_free (hostname);
1587 GNUNET_free (plugin);
1594 * Entry point for the plugin.
1597 libgnunet_plugin_transport_http_init (void *cls)
1599 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1600 struct GNUNET_TRANSPORT_PluginFunctions *api;
1601 struct GNUNET_SERVICE_Context *service;
1602 unsigned int timeout;
1603 struct GNUNET_TIME_Relative gn_timeout;
1604 long long unsigned int port;
1606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
1610 service = GNUNET_SERVICE_start ("transport-http", env->sched, env->cfg);
1611 if (service == NULL)
1613 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "", _
1614 ("Failed to start service for `%s' transport plugin.\n"),
1620 plugin = GNUNET_malloc (sizeof (struct Plugin));
1622 plugin->sessions = NULL;
1623 plugin->service = service;
1624 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1626 api->send = &http_plugin_send;
1627 api->disconnect = &http_plugin_disconnect;
1628 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1629 api->check_address = &http_plugin_address_suggested;
1630 api->address_to_string = &http_plugin_address_to_string;
1632 hostname = GNUNET_RESOLVER_local_fqdn_get ();
1634 /* Hashing our identity to use it in URLs */
1635 GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &my_ascii_hash_ident);
1637 /* Reading port number from config file */
1639 GNUNET_CONFIGURATION_get_value_number (env->cfg,
1645 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1648 ("Require valid port number for transport plugin `%s' in configuration!\n"),
1650 libgnunet_plugin_transport_http_done (api);
1653 plugin->port_inbound = port;
1654 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
1655 timeout = ( gn_timeout.value / 1000);
1656 if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0))
1658 http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6,
1660 &acceptPolicyCallback,
1661 NULL , &accessHandlerCallback, NULL,
1662 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16,
1663 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
1664 MHD_OPTION_CONNECTION_TIMEOUT, timeout,
1665 /* FIXME: set correct limit */
1666 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024),
1667 MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL,
1669 http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG,
1671 &acceptPolicyCallback,
1672 NULL , &accessHandlerCallback, NULL,
1673 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16,
1674 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
1675 MHD_OPTION_CONNECTION_TIMEOUT, timeout,
1676 /* FIXME: set correct limit */
1677 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024),
1678 MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL,
1681 if (http_daemon_v4 != NULL)
1682 http_task_v4 = http_daemon_prepare (http_daemon_v4);
1683 if (http_daemon_v6 != NULL)
1684 http_task_v6 = http_daemon_prepare (http_daemon_v6);
1686 if (http_task_v4 != GNUNET_SCHEDULER_NO_TASK)
1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port);
1688 if (http_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 and IPv6 on port %u\n",port);
1692 /* Initializing cURL */
1693 multi_handle = curl_multi_init();
1694 if ( NULL == multi_handle )
1696 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1698 _("Could not initialize curl multi handle, failed to start http plugin!\n"),
1700 libgnunet_plugin_transport_http_done (api);
1704 GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
1709 /* end of plugin_transport_template.c */