2 This file is part of GNUnet.
3 (C) 2012 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 3, 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 #include <gnunet_util_lib.h>
23 #include <gnunet_gns_service.h>
24 #include <microhttpd.h>
25 #include <curl/curl.h>
27 #include "gns_proxy_proto.h"
31 #include <gnutls/gnutls.h>
32 #include <gnutls/x509.h>
33 #include <gnutls/abstract.h>
34 #include <gnutls/crypto.h>
37 #define GNUNET_GNS_PROXY_PORT 7777
38 #define MHD_MAX_CONNECTIONS 300
40 /* MHD/cURL defines */
41 #define BUF_WAIT_FOR_CURL 0
42 #define BUF_WAIT_FOR_MHD 1
43 #define HTML_HDR_CONTENT "Content-Type: text/html"
46 //#define RE_DOTPLUS "<a href=\"http://(([A-Za-z]+[.])+)([+])"
47 #define RE_A_HREF "<a href=\"https?://(([A-Za-z0-9]+[.])+)([+]|zkey)"
48 #define RE_N_MATCHES 4
50 /* The usual suspects */
52 #define HTTPS_PORT 443
56 * A structure for CA cert/key
61 gnutls_x509_crt_t cert;
64 gnutls_x509_privkey_t key;
69 * Structure for GNS certificates
71 struct ProxyGNSCertificate
73 /* The certificate as PEM */
76 /* The private key as PEM */
82 * A structure for socks requests
86 /* The client socket */
87 struct GNUNET_NETWORK_Handle *sock;
89 /* The server socket */
90 struct GNUNET_NETWORK_Handle *remote_sock;
95 /* Client socket read task */
96 GNUNET_SCHEDULER_TaskIdentifier rtask;
98 /* Server socket read task */
99 GNUNET_SCHEDULER_TaskIdentifier fwdrtask;
101 /* Client socket write task */
102 GNUNET_SCHEDULER_TaskIdentifier wtask;
104 /* Server socket write task */
105 GNUNET_SCHEDULER_TaskIdentifier fwdwtask;
113 /* Length of data in read buffer */
114 unsigned int rbuf_len;
116 /* Length of data in write buffer */
117 unsigned int wbuf_len;
119 /* This handle is scheduled for cleanup? */
122 /* Shall we close the client socket on cleanup? */
127 * DLL for Network Handles
129 struct NetworkHandleList
132 struct NetworkHandleList *next;
135 struct NetworkHandleList *prev;
138 struct GNUNET_NETWORK_Handle *h;
142 * A structure for all running Httpds
147 struct MhdHttpList *prev;
150 struct MhdHttpList *next;
152 /* is this an ssl daemon? */
155 /* the domain name to server (only important for SSL) */
158 /* The daemon handle */
159 struct MHD_Daemon *daemon;
161 /* Optional proxy certificate used */
162 struct ProxyGNSCertificate *proxy_cert;
165 GNUNET_SCHEDULER_TaskIdentifier httpd_task;
167 /* Handles associated with this daemon */
168 struct NetworkHandleList *socket_handles_head;
170 /* Handles associated with this daemon */
171 struct NetworkHandleList *socket_handles_tail;
175 * A structure for MHD<->cURL streams
180 struct ProxyCurlTask *prev;
183 struct ProxyCurlTask *next;
188 /* Optional header replacements for curl (LEHO) */
189 struct curl_slist *headers;
191 /* Optional resolver replacements for curl (LEHO) */
192 struct curl_slist *resolver;
194 /* The URL to fetch */
197 /* The cURL write buffer / MHD read buffer */
198 char buffer[CURL_MAX_WRITE_SIZE];
200 /* The pointer to the data in the buffer */
203 /* The buffer status (BUF_WAIT_FOR_CURL or BUF_WAIT_FOR_MHD) */
206 /* Number of bytes in buffer */
207 unsigned int bytes_in_buffer;
209 /* Indicates wheather the download is in progress */
210 int download_in_progress;
212 /* Indicates wheather the download was successful */
213 int download_successful;
215 /* Indicates wheather the download failed */
218 /* Indicates wheather we need to parse HTML */
221 /* Indicates wheather we are postprocessing the HTML right now */
222 int is_postprocessing;
224 /* Indicates wheather postprocessing has finished */
227 /* Task ID of the postprocessing task */
228 GNUNET_SCHEDULER_TaskIdentifier pp_task;
230 /* The postprocessing buffer TODO length? */
233 /* The authority of the corresponding host (site of origin) */
236 /* The hostname (Host header field) */
239 /* The LEgacy HOstname (can be empty) */
242 /* The associated daemon list entry */
243 struct MhdHttpList *mhd;
245 /* The associated response */
246 struct MHD_Response *response;
250 /* The port the proxy is running on (default 7777) */
251 static unsigned long port = GNUNET_GNS_PROXY_PORT;
253 /* The CA file (pem) to use for the proxy CA */
254 static char* cafile_opt;
256 /* The listen socket of the proxy */
257 static struct GNUNET_NETWORK_Handle *lsock;
259 /* The listen task ID */
260 GNUNET_SCHEDULER_TaskIdentifier ltask;
262 /* The cURL download task */
263 GNUNET_SCHEDULER_TaskIdentifier curl_download_task;
265 /* The non SSL httpd daemon handle */
266 static struct MHD_Daemon *httpd;
268 /* Number of current mhd connections */
269 static unsigned int total_mhd_connections;
271 /* The cURL multi handle */
272 static CURLM *curl_multi;
274 /* Handle to the GNS service */
275 static struct GNUNET_GNS_Handle *gns_handle;
277 /* DLL for ProxyCurlTasks */
278 static struct ProxyCurlTask *ctasks_head;
280 /* DLL for ProxyCurlTasks */
281 static struct ProxyCurlTask *ctasks_tail;
283 /* DLL for http daemons */
284 static struct MhdHttpList *mhd_httpd_head;
286 /* DLL for http daemons */
287 static struct MhdHttpList *mhd_httpd_tail;
289 /* Handle to the regex for dotplus (.+) replacement in HTML */
290 static regex_t re_dotplus;
292 /* The users local GNS zone hash */
293 static struct GNUNET_CRYPTO_ShortHashCode local_gns_zone;
295 /* The CA for SSL certificate generation */
296 static struct ProxyCA proxy_ca;
298 /* UNIX domain socket for mhd */
299 struct GNUNET_NETWORK_Handle *mhd_unix_socket;
301 /* Shorten zone private key */
302 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_zonekey;
305 * Checks if name is in tld
307 * @param name the name to check
308 * @param tld the TLD to check for
309 * @return GNUNET_YES or GNUNET_NO
312 is_tld(const char* name, const char* tld)
316 if (strlen(name) <= strlen(tld))
321 offset = strlen(name)-strlen(tld);
322 if (strcmp (name+offset, tld) != 0)
324 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
325 "%s is not in .%s TLD\n", name, tld);
334 * Read HTTP request header field 'Host'
336 * @param cls buffer to write to
337 * @param kind value kind
338 * @param key field key
339 * @param value field value
340 * @return MHD_NO when Host found
343 con_val_iter (void *cls,
344 enum MHD_ValueKind kind,
348 char* buf = (char*)cls;
350 if (0 == strcmp ("Host", key))
360 * Check HTTP response header for mime
362 * @param buffer curl buffer
363 * @param size curl blocksize
364 * @param nmemb curl blocknumber
366 * @return size of read bytes
369 curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls)
371 size_t bytes = size * nmemb;
372 struct ProxyCurlTask *ctask = cls;
373 int len = strlen (HTML_HDR_CONTENT);
376 if ( (len+1) > bytes)
379 memcpy (hdr, buffer, len);
382 if (0 == strcmp (hdr, HTML_HDR_CONTENT))
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
385 "Got HTML HTTP response header\n");
386 ctask->parse_content = GNUNET_YES;
395 * @param hd a http daemon list entry
398 run_httpd (struct MhdHttpList *hd);
410 * Task that simply runs MHD main loop
413 * @param tc task context
416 run_mhd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
419 struct MhdHttpList *hd = cls;
421 //for (hd=mhd_httpd_head; hd != NULL; hd = hd->next)
422 MHD_run (hd->daemon);
427 * Process cURL download bits
429 * @param ptr buffer with data
430 * @param size size of a record
431 * @param nmemb number of records downloaded
433 * @return number of processed bytes
436 callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
438 const char *cbuf = ptr;
440 struct ProxyCurlTask *ctask = ctx;
451 if (total > sizeof (ctask->buffer))
453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
454 "CURL gave us too much data to handle (%d)!\n",
459 if (ctask->buf_status == BUF_WAIT_FOR_MHD)
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
462 "CURL: Waiting for MHD (%s)\n", ctask->url);
463 return CURL_WRITEFUNC_PAUSE;
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "CURL: Copying to MHD (%s, %d)\n", ctask->url, total);
469 memcpy (ctask->buffer, cbuf, total);
470 ctask->bytes_in_buffer = total;
471 ctask->buffer_ptr = ctask->buffer;
473 ctask->buf_status = BUF_WAIT_FOR_MHD;
475 //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 // "cURL chunk:\n%s\n", (char*)ctask->buffer);
477 //run_mhd (NULL, NULL);
478 GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd);
483 * Ask cURL for the select sets and schedule download
486 curl_download_prepare ();
489 * Callback to free content
491 * @param cls content to free
492 * @param tc task context
495 mhd_content_free (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
497 struct ProxyCurlTask *ctask = cls;
499 if (NULL != ctask->headers)
500 curl_slist_free_all (ctask->headers);
502 if (NULL != ctask->headers)
503 curl_slist_free_all (ctask->resolver);
505 if (NULL != ctask->response)
506 MHD_destroy_response (ctask->response);
514 * Shorten result callback
516 * @param cls the proxycurltask
517 * @param short_name the shortened name (NULL on error)
520 process_shorten (void* cls, const char* short_name)
522 struct ProxyCurlTask *ctask = cls;
524 char tmp[strlen(ctask->pp_buf)]; //TODO length
526 if (NULL == short_name)
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
529 "MHD PP: Unable to shorten %s\n",
534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
535 "MHD PP: Shorten %s -> %s\n",
539 sprintf (tmp, "<a href=\"http://%s", short_name);
540 strcpy (ctask->pp_buf, tmp);
542 ctask->pp_finished = GNUNET_YES;
544 GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd);
549 * Callback for MHD response
552 * @param pos in buffer
554 * @param max space in buffer
555 * @return number of bytes written
558 mhd_content_cb (void *cls,
563 struct ProxyCurlTask *ctask = cls;
565 size_t bytes_to_copy;
568 regmatch_t m[RE_N_MATCHES];
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
571 "MHD: content cb %s\n", ctask->url);
573 if (ctask->download_successful &&
574 (ctask->buf_status == BUF_WAIT_FOR_CURL))
576 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
577 "MHD: sending response for %s\n", ctask->url);
578 ctask->download_in_progress = GNUNET_NO;
579 GNUNET_SCHEDULER_add_now (&mhd_content_free, ctask);
580 GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd);
581 total_mhd_connections--;
582 return MHD_CONTENT_READER_END_OF_STREAM;
585 if (ctask->download_error &&
586 (ctask->buf_status == BUF_WAIT_FOR_CURL))
588 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
589 "MHD: sending error response\n");
590 ctask->download_in_progress = GNUNET_NO;
591 GNUNET_SCHEDULER_add_now (&mhd_content_free, ctask);
592 GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd);
593 total_mhd_connections--;
594 return MHD_CONTENT_READER_END_WITH_ERROR;
597 if ( ctask->buf_status == BUF_WAIT_FOR_CURL )
600 bytes_to_copy = ctask->bytes_in_buffer;
602 if (ctask->parse_content == GNUNET_YES)
605 GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG,
606 "MHD: We need to parse the HTML %s\n", ctask->buffer_ptr);
608 nomatch = regexec ( &re_dotplus, ctask->buffer_ptr, RE_N_MATCHES, m, 0);
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "MHD RE: No match\n");
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 GNUNET_assert (m[1].rm_so != -1);
622 hostptr = ctask->buffer_ptr+m[1].rm_so;
626 bytes_to_copy = m[0].rm_so;
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
628 "Copying %d bytes.\n", m[0].rm_so);
634 if (ctask->is_postprocessing == GNUNET_YES)
638 if ( ctask->pp_finished == GNUNET_NO )
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
641 "MHD PP: Waiting for PP of %s\n", ctask->pp_buf);
645 ctask->is_postprocessing = GNUNET_NO;
647 ctask->bytes_in_buffer -= m[0].rm_eo;//(m[1].rm_eo-m[1].rm_so);
648 ctask->buffer_ptr += m[0].rm_eo;//(m[1].rm_eo-m[1].rm_so);
649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
650 "Skipping next %d bytes in buffer\n", m[0].rm_eo);
652 GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd);
654 if ( strlen (ctask->pp_buf) <= max )
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Copying postprocessed %s.\n", ctask->pp_buf);
658 memcpy ( buf, ctask->pp_buf, strlen (ctask->pp_buf) );
659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
661 ctask->is_postprocessing = GNUNET_NO;
662 return strlen (ctask->pp_buf);
668 memset (ctask->pp_buf, 0, sizeof(ctask->pp_buf));
670 /* If .+ extend with authority */
671 if (*(ctask->buffer_ptr+m[1].rm_eo) == '+')
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
675 memcpy (ctask->pp_buf, hostptr, (m[1].rm_eo-m[1].rm_so));
676 strcpy ( ctask->pp_buf+strlen(ctask->pp_buf),
679 /* If .zkey simply copy the name */
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
684 memcpy (ctask->pp_buf, hostptr, (m[1].rm_eo-m[1].rm_so + strlen (GNUNET_GNS_TLD_ZKEY)));
687 ctask->is_postprocessing = GNUNET_YES;
688 ctask->pp_finished = GNUNET_NO;
690 GNUNET_GNS_shorten (gns_handle,
700 if ( bytes_to_copy > max )
702 GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG,
703 "MHD: buffer in response too small! (%s)\n",
705 memcpy ( buf, ctask->buffer_ptr, max);
706 ctask->bytes_in_buffer -= max;
707 ctask->buffer_ptr += max;
712 GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG,
713 "MHD: copying %d bytes to mhd response at offset %d\n",
716 memcpy ( buf, ctask->buffer_ptr, bytes_to_copy );
717 copied = bytes_to_copy;
718 if (bytes_to_copy < ctask->bytes_in_buffer)
720 ctask->bytes_in_buffer -= bytes_to_copy;
721 ctask->buffer_ptr += bytes_to_copy;
725 ctask->bytes_in_buffer = 0;
726 ctask->buf_status = BUF_WAIT_FOR_CURL;
727 ctask->buffer_ptr = ctask->buffer;
728 if (NULL != ctask->curl)
729 curl_easy_pause (ctask->curl, CURLPAUSE_CONT);
730 GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd);
734 GNUNET_SCHEDULER_add_now (&run_mhd, ctask->mhd);
742 * Task that is run when we are ready to receive more data
746 * @param tc task context
749 curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
752 * Ask cURL for the select sets and schedule download
755 curl_download_prepare ()
762 struct GNUNET_NETWORK_FDSet *grs;
763 struct GNUNET_NETWORK_FDSet *gws;
765 struct GNUNET_TIME_Relative rtime;
771 mret = curl_multi_fdset (curl_multi, &rs, &ws, &es, &max);
773 if (mret != CURLM_OK)
775 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
776 "%s failed at %s:%d: `%s'\n",
777 "curl_multi_fdset", __FILE__, __LINE__,
778 curl_multi_strerror (mret));
783 mret = curl_multi_timeout (curl_multi, &to);
784 rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
787 "cURL multi fds: max=%d timeout=%llu\n", max, to);
789 grs = GNUNET_NETWORK_fdset_create ();
790 gws = GNUNET_NETWORK_fdset_create ();
791 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
792 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
794 "Scheduling task cURL\n");
796 if (curl_download_task != GNUNET_SCHEDULER_NO_TASK)
797 GNUNET_SCHEDULER_cancel (curl_download_task);
800 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
803 &curl_task_download, curl_multi);
804 GNUNET_NETWORK_fdset_destroy (gws);
805 GNUNET_NETWORK_fdset_destroy (grs);
811 * Task that is run when we are ready to receive more data
815 * @param tc task context
818 curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
824 struct ProxyCurlTask *ctask;
827 struct ProxyCurlTask *clean_head = NULL;
828 struct ProxyCurlTask *clean_tail = NULL;
830 curl_download_task = GNUNET_SCHEDULER_NO_TASK;
832 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
835 "Shutdown requested while trying to download\n");
839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
847 mret = curl_multi_perform (curl_multi, &running);
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
850 "Running curl tasks: %d\n", running);
853 for (; ctask != NULL; ctask = ctask->next)
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "CTask: %s\n", ctask->url);
860 if (num_ctasks != running)
862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
863 "%d ctasks, %d curl running\n", num_ctasks, running);
869 msg = curl_multi_info_read (curl_multi, &msgnum);
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
871 "Messages left: %d\n", msgnum);
878 if ((msg->data.result != CURLE_OK) &&
879 (msg->data.result != CURLE_GOT_NOTHING))
881 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
882 "Download curl failed");
884 for (; ctask != NULL; ctask = ctask->next)
886 if (NULL == ctask->curl)
889 if (memcmp (msg->easy_handle, ctask->curl, sizeof (CURL)) != 0)
892 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
893 "Download curl failed for task %s: %s.\n",
895 curl_easy_strerror (msg->data.result));
896 ctask->download_successful = GNUNET_NO;
897 ctask->download_error = GNUNET_YES;
898 //curl_multi_remove_handle (curl_multi, ctask->curl);
899 //curl_easy_cleanup (ctask->curl);
900 //ctask->curl = NULL;
901 GNUNET_CONTAINER_DLL_remove (ctasks_head, ctasks_tail,
903 GNUNET_CONTAINER_DLL_insert (clean_head, clean_tail, ctask);
906 GNUNET_assert (ctask != NULL);
910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
911 "cURL download completed.\n");
913 for (; ctask != NULL; ctask = ctask->next)
915 if (NULL == ctask->curl)
918 if (memcmp (msg->easy_handle, ctask->curl, sizeof (CURL)) != 0)
921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
922 "cURL task %s found.\n", ctask->url);
923 ctask->download_successful = GNUNET_YES;
924 //curl_multi_remove_handle (curl_multi, ctask->curl);
925 //curl_easy_cleanup (ctask->curl);
926 //ctask->curl = NULL;
927 GNUNET_CONTAINER_DLL_remove (ctasks_head, ctasks_tail,
929 GNUNET_CONTAINER_DLL_insert (clean_head, clean_tail, ctask);
933 GNUNET_assert (ctask != NULL);
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "curl end %s\n", curl_easy_strerror(msg->data.result));
942 } while (msgnum > 0);
944 for (ctask=clean_head; ctask != NULL; ctask = ctask->next)
946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
947 "Removing cURL task %s.\n", ctask->url);
948 curl_multi_remove_handle (curl_multi, ctask->curl);
949 curl_easy_cleanup (ctask->curl);
954 for (ctask=ctasks_head; ctask != NULL; ctask = ctask->next)
959 if (num_ctasks != running)
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "%d ctasks, %d curl running\n", num_ctasks, running);
965 GNUNET_assert ( num_ctasks == running );
969 } while (mret == CURLM_CALL_MULTI_PERFORM);
972 if (mret != CURLM_OK)
974 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s failed at %s:%d: `%s'\n",
975 "curl_multi_perform", __FILE__, __LINE__,
976 curl_multi_strerror (mret));
978 curl_download_prepare();
982 * Process LEHO lookup
984 * @param cls the ctask
985 * @param rd_count number of records returned
986 * @param rd record data
989 process_leho_lookup (void *cls,
991 const struct GNUNET_NAMESTORE_RecordData *rd)
993 struct ProxyCurlTask *ctask = cls;
994 char hosthdr[262]; //256 + "Host: "
998 struct hostent *phost;
1000 char resolvename[512];
1003 ctask->headers = NULL;
1005 strcpy (ctask->leho, "");
1008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1009 "No LEHO present!\n");
1011 for (i=0; i<rd_count; i++)
1013 if (rd[i].record_type != GNUNET_GNS_RECORD_LEHO)
1016 memcpy (ctask->leho, rd[i].data, rd[i].data_size);
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1019 "Found LEHO %s for %s\n", ctask->leho, ctask->url);
1022 if (0 != strcmp (ctask->leho, ""))
1024 sprintf (hosthdr, "%s%s", "Host: ", ctask->leho);
1025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1026 "New HTTP header value: %s\n", hosthdr);
1027 ctask->headers = curl_slist_append (ctask->headers, hosthdr);
1028 GNUNET_assert (NULL != ctask->headers);
1029 ret = curl_easy_setopt (ctask->curl, CURLOPT_HTTPHEADER, ctask->headers);
1030 if (CURLE_OK != ret)
1032 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s failed at %s:%d: `%s'\n",
1033 "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror(ret));
1038 if (ctask->mhd->is_ssl)
1040 phost = (struct hostent*)gethostbyname (ctask->host);
1044 ssl_ip = inet_ntoa(*((struct in_addr*)(phost->h_addr)));
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "SSL target server: %s\n", ssl_ip);
1047 sprintf (resolvename, "%s:%d:%s", ctask->leho, HTTPS_PORT, ssl_ip);
1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1049 "Curl resolve: %s\n", resolvename);
1050 ctask->resolver = curl_slist_append ( ctask->resolver, resolvename);
1051 curl_easy_setopt (ctask->curl, CURLOPT_RESOLVE, ctask->resolver);
1052 sprintf (curlurl, "https://%s%s", ctask->leho, ctask->url);
1053 curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl);
1057 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1058 "gethostbyname failed for %s!\n", ctask->host);
1059 ctask->download_successful = GNUNET_NO;
1060 ctask->download_error = GNUNET_YES;
1065 if (CURLM_OK != (mret=curl_multi_add_handle (curl_multi, ctask->curl)))
1067 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1068 "%s failed at %s:%d: `%s'\n",
1069 "curl_multi_add_handle", __FILE__, __LINE__,
1070 curl_multi_strerror (mret));
1071 ctask->download_successful = GNUNET_NO;
1072 ctask->download_error = GNUNET_YES;
1075 GNUNET_CONTAINER_DLL_insert (ctasks_head, ctasks_tail, ctask);
1077 curl_download_prepare ();
1082 * Initialize download and trigger curl
1084 * @param cls the proxycurltask
1085 * @param auth_name the name of the authority (site of origin) of ctask->host
1089 process_get_authority (void *cls,
1090 const char* auth_name)
1092 struct ProxyCurlTask *ctask = cls;
1094 if (NULL == auth_name)
1096 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1097 "Get authority failed!\n");
1098 strcpy (ctask->authority, "");
1102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1103 "Get authority yielded %s\n", auth_name);
1104 strcpy (ctask->authority, auth_name);
1107 GNUNET_GNS_lookup_zone (gns_handle,
1110 GNUNET_GNS_RECORD_LEHO,
1111 GNUNET_YES, //Only cached for performance
1113 &process_leho_lookup,
1118 * Main MHD callback for handling requests.
1121 * @param con MHD connection handle
1122 * @param url the url in the request
1123 * @param meth the HTTP method used ("GET", "PUT", etc.)
1124 * @param ver the HTTP version string (i.e. "HTTP/1.1")
1125 * @param upload_data the data being uploaded (excluding HEADERS,
1126 * for a POST that fits into memory and that is encoded
1127 * with a supported encoding, the POST data will NOT be
1128 * given in upload_data and is instead available as
1129 * part of MHD_get_connection_values; very large POST
1130 * data *will* be made available incrementally in
1132 * @param upload_data_size set initially to the size of the
1133 * upload_data provided; the method must update this
1134 * value to the number of bytes NOT processed;
1135 * @param con_cls pointer to location where we store the 'struct Request'
1136 * @return MHD_YES if the connection was handled successfully,
1137 * MHD_NO if the socket must be closed due to a serious
1138 * error while handling the request
1141 create_response (void *cls,
1142 struct MHD_Connection *con,
1146 const char *upload_data,
1147 size_t *upload_data_size,
1151 struct MhdHttpList* hd = cls;
1152 const char* page = "<html><head><title>gnoxy</title>"\
1153 "</head><body>cURL fail</body></html>";
1159 struct ProxyCurlTask *ctask;
1161 if (0 != strcmp (meth, "GET"))
1163 if (&dummy != *con_cls)
1169 if (0 != *upload_data_size)
1174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1177 MHD_get_connection_values (con,
1179 &con_val_iter, host);
1183 ctask = GNUNET_malloc (sizeof (struct ProxyCurlTask));
1186 if (curl_multi == NULL)
1187 curl_multi = curl_multi_init ();
1189 ctask->curl = curl_easy_init();
1191 if ((ctask->curl == NULL) || (curl_multi == NULL))
1193 ctask->response = MHD_create_response_from_buffer (strlen (page),
1195 MHD_RESPMEM_PERSISTENT);
1196 ret = MHD_queue_response (con,
1199 MHD_destroy_response (ctask->response);
1200 GNUNET_free (ctask);
1206 ctask->headers = NULL;
1207 ctask->resolver = NULL;
1208 ctask->buffer_ptr = NULL;
1209 ctask->download_in_progress = GNUNET_YES;
1210 ctask->download_successful = GNUNET_NO;
1211 ctask->buf_status = BUF_WAIT_FOR_CURL;
1212 ctask->bytes_in_buffer = 0;
1213 ctask->parse_content = GNUNET_NO;
1215 curl_easy_setopt (ctask->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr);
1216 curl_easy_setopt (ctask->curl, CURLOPT_HEADERDATA, ctask);
1217 curl_easy_setopt (ctask->curl, CURLOPT_WRITEFUNCTION, &callback_download);
1218 curl_easy_setopt (ctask->curl, CURLOPT_WRITEDATA, ctask);
1219 curl_easy_setopt (ctask->curl, CURLOPT_FOLLOWLOCATION, 1);
1220 curl_easy_setopt (ctask->curl, CURLOPT_MAXREDIRS, 4);
1221 /* no need to abort if the above failed */
1222 if (GNUNET_NO == ctask->mhd->is_ssl)
1224 sprintf (curlurl, "http://%s%s", host, url);
1225 curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl);
1226 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1227 "Adding new curl task for %s\n", curlurl);
1229 strcpy (ctask->host, host);
1230 strcpy (ctask->url, url);
1232 //curl_easy_setopt (ctask->curl, CURLOPT_URL, curlurl);
1233 curl_easy_setopt (ctask->curl, CURLOPT_FAILONERROR, 1);
1234 curl_easy_setopt (ctask->curl, CURLOPT_CONNECTTIMEOUT, 600L);
1235 curl_easy_setopt (ctask->curl, CURLOPT_TIMEOUT, 600L);
1237 GNUNET_GNS_get_authority (gns_handle,
1239 &process_get_authority,
1241 //download_prepare (ctask);
1242 //curl_download_prepare ();
1244 ctask->response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
1250 ret = MHD_queue_response (con, MHD_HTTP_OK, ctask->response);
1252 //MHD_destroy_response (response);
1258 * Task run whenever HTTP server operations are pending.
1261 * @param tc sched context
1264 do_httpd (void *cls,
1265 const struct GNUNET_SCHEDULER_TaskContext *tc);
1274 struct MhdHttpList *hd;
1276 for (hd=mhd_httpd_head; hd != NULL; hd = hd->next)
1284 * @param hd the daemon to run
1287 run_httpd (struct MhdHttpList *hd)
1292 struct GNUNET_NETWORK_FDSet *wrs;
1293 struct GNUNET_NETWORK_FDSet *wws;
1294 struct GNUNET_NETWORK_FDSet *wes;
1297 unsigned MHD_LONG_LONG timeout;
1298 struct GNUNET_TIME_Relative tv;
1303 wrs = GNUNET_NETWORK_fdset_create ();
1304 wes = GNUNET_NETWORK_fdset_create ();
1305 wws = GNUNET_NETWORK_fdset_create ();
1307 GNUNET_assert (MHD_YES == MHD_get_fdset (hd->daemon, &rs, &ws, &es, &max));
1310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1311 "MHD fds: max=%d\n", max);
1313 haveto = MHD_get_timeout (hd->daemon, &timeout);
1315 if (haveto == MHD_YES)
1316 tv.rel_value = (uint64_t) timeout;
1318 tv = GNUNET_TIME_UNIT_FOREVER_REL;
1319 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
1320 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
1321 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
1323 if (hd->httpd_task != GNUNET_SCHEDULER_NO_TASK)
1324 GNUNET_SCHEDULER_cancel (hd->httpd_task);
1326 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
1329 GNUNET_NETWORK_fdset_destroy (wrs);
1330 GNUNET_NETWORK_fdset_destroy (wws);
1331 GNUNET_NETWORK_fdset_destroy (wes);
1336 * Task run whenever HTTP server operations are pending.
1339 * @param tc sched context
1342 do_httpd (void *cls,
1343 const struct GNUNET_SCHEDULER_TaskContext *tc)
1345 struct MhdHttpList *hd = cls;
1347 hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
1349 MHD_run (hd->daemon);
1355 * Read data from socket
1357 * @param cls the closure
1358 * @param tc scheduler context
1361 do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1364 * Read from remote end
1366 * @param cls closure
1367 * @param tc scheduler context
1370 do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1373 * Write data to remote socket
1375 * @param cls the closure
1376 * @param tc scheduler context
1379 do_write_remote (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1381 struct Socks5Request *s5r = cls;
1384 s5r->fwdwtask = GNUNET_SCHEDULER_NO_TASK;
1386 if ((NULL != tc->read_ready) &&
1387 (GNUNET_NETWORK_fdset_isset (tc->write_ready, s5r->remote_sock)) &&
1388 ((len = GNUNET_NETWORK_socket_send (s5r->remote_sock, s5r->rbuf,
1391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1392 "Successfully sent %d bytes to remote socket\n",
1397 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write remote");
1399 if (s5r->rtask != GNUNET_SCHEDULER_NO_TASK)
1400 GNUNET_SCHEDULER_cancel (s5r->rtask);
1401 if (s5r->wtask != GNUNET_SCHEDULER_NO_TASK)
1402 GNUNET_SCHEDULER_cancel (s5r->wtask);
1403 if (s5r->fwdrtask != GNUNET_SCHEDULER_NO_TASK)
1404 GNUNET_SCHEDULER_cancel (s5r->fwdrtask);
1405 GNUNET_NETWORK_socket_close (s5r->remote_sock);
1406 GNUNET_NETWORK_socket_close (s5r->sock);
1412 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1419 * Clean up s5r handles
1421 * @param s5r the handle to destroy
1424 cleanup_s5r (struct Socks5Request *s5r)
1426 if (s5r->rtask != GNUNET_SCHEDULER_NO_TASK)
1427 GNUNET_SCHEDULER_cancel (s5r->rtask);
1428 if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK)
1429 GNUNET_SCHEDULER_cancel (s5r->fwdwtask);
1430 if (s5r->fwdrtask != GNUNET_SCHEDULER_NO_TASK)
1431 GNUNET_SCHEDULER_cancel (s5r->fwdrtask);
1433 if (NULL != s5r->remote_sock)
1434 GNUNET_NETWORK_socket_close (s5r->remote_sock);
1435 if ((NULL != s5r->sock) && (s5r->cleanup_sock == GNUNET_YES))
1436 GNUNET_NETWORK_socket_close (s5r->sock);
1442 * Write data to socket
1444 * @param cls the closure
1445 * @param tc scheduler context
1448 do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1450 struct Socks5Request *s5r = cls;
1453 s5r->wtask = GNUNET_SCHEDULER_NO_TASK;
1455 if ((NULL != tc->read_ready) &&
1456 (GNUNET_NETWORK_fdset_isset (tc->write_ready, s5r->sock)) &&
1457 ((len = GNUNET_NETWORK_socket_send (s5r->sock, s5r->wbuf,
1460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1461 "Successfully sent %d bytes to socket\n",
1467 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
1468 s5r->cleanup = GNUNET_YES;
1469 s5r->cleanup_sock = GNUNET_YES;
1475 if (GNUNET_YES == s5r->cleanup)
1481 if ((s5r->state == SOCKS5_DATA_TRANSFER) &&
1482 (s5r->fwdrtask == GNUNET_SCHEDULER_NO_TASK))
1484 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1486 &do_read_remote, s5r);
1490 * Read from remote end
1492 * @param cls closure
1493 * @param tc scheduler context
1496 do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1498 struct Socks5Request *s5r = cls;
1500 s5r->fwdrtask = GNUNET_SCHEDULER_NO_TASK;
1503 if ((NULL != tc->write_ready) &&
1504 (GNUNET_NETWORK_fdset_isset (tc->read_ready, s5r->remote_sock)) &&
1505 (s5r->wbuf_len = GNUNET_NETWORK_socket_recv (s5r->remote_sock, s5r->wbuf,
1506 sizeof (s5r->wbuf))))
1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1509 "Successfully read %d bytes from remote socket\n",
1514 if (s5r->wbuf_len == 0)
1515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1516 "0 bytes received from remote... graceful shutdown!\n");
1517 if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK)
1518 GNUNET_SCHEDULER_cancel (s5r->fwdwtask);
1519 if (s5r->rtask != GNUNET_SCHEDULER_NO_TASK)
1520 GNUNET_SCHEDULER_cancel (s5r->rtask);
1522 GNUNET_NETWORK_socket_close (s5r->remote_sock);
1523 s5r->remote_sock = NULL;
1524 GNUNET_NETWORK_socket_close (s5r->sock);
1530 s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1538 * Adds a socket to MHD
1540 * @param h the handle to the socket to add
1541 * @param daemon the daemon to add the fd to
1542 * @return whatever MHD_add_connection returns
1545 add_handle_to_mhd (struct GNUNET_NETWORK_Handle *h, struct MHD_Daemon *daemon)
1548 struct sockaddr *addr;
1551 fd = dup (GNUNET_NETWORK_get_fd (h));
1552 addr = GNUNET_NETWORK_get_addr (h);
1553 len = GNUNET_NETWORK_get_addrlen (h);
1555 return MHD_add_connection (daemon, fd, addr, len);
1559 * Calculate size of file
1561 * @param filename name of file
1562 * @return filesize or 0 on error
1565 get_file_size (const char* filename)
1569 fp = fopen (filename, "rb");
1574 if ((0 != fseek (fp, 0, SEEK_END)) || (-1 == (size = ftell (fp))))
1586 * Read file in filename
1588 * @param filename file to read
1589 * @param size pointer where filesize is stored
1593 load_file (const char* filename, unsigned int* size)
1598 *size = get_file_size (filename);
1602 fp = fopen (filename, "rb");
1606 buffer = GNUNET_malloc (*size);
1613 if (*size != fread (buffer, 1, *size, fp))
1615 GNUNET_free (buffer);
1624 * Load PEM key from file
1626 * @param key where to store the data
1627 * @param keyfile path to the PEM file
1630 load_key_from_file (gnutls_x509_privkey_t key, char* keyfile)
1632 gnutls_datum_t key_data;
1633 key_data.data = NULL;
1636 key_data.data = (unsigned char*)load_file (keyfile, &key_data.size);
1638 ret = gnutls_x509_privkey_import (key, &key_data,
1639 GNUTLS_X509_FMT_PEM);
1641 if (GNUTLS_E_SUCCESS != ret)
1643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1644 "Unable to import private key %s(ret=%d)\n", key_data.data, ret);
1648 GNUNET_free (key_data.data);
1652 * Load cert from file
1654 * @param crt struct to store data in
1655 * @param certfile path to pem file
1658 load_cert_from_file (gnutls_x509_crt_t crt, char* certfile)
1660 gnutls_datum_t cert_data;
1661 cert_data.data = NULL;
1664 cert_data.data = (unsigned char*)load_file (certfile, &cert_data.size);
1666 ret = gnutls_x509_crt_import (crt, &cert_data,
1667 GNUTLS_X509_FMT_PEM);
1668 if (GNUTLS_E_SUCCESS != ret)
1670 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1671 "Unable to import certificate %s(ret=%d)\n", certfile, ret);
1675 GNUNET_free (cert_data.data);
1681 * Generate new certificate for specific name
1683 * @param name the subject name to generate a cert for
1684 * @return a struct holding the PEM data
1686 static struct ProxyGNSCertificate *
1687 generate_gns_certificate (const char *name)
1691 unsigned int serial;
1692 size_t key_buf_size;
1693 size_t cert_buf_size;
1694 gnutls_x509_crt_t request;
1698 ret = gnutls_x509_crt_init (&request);
1700 if (GNUTLS_E_SUCCESS != ret)
1705 ret = gnutls_x509_crt_set_key (request, proxy_ca.key);
1707 if (GNUTLS_E_SUCCESS != ret)
1712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generating cert\n");
1714 struct ProxyGNSCertificate *pgc =
1715 GNUNET_malloc (sizeof (struct ProxyGNSCertificate));
1717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding DNs\n");
1719 gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COUNTRY_NAME,
1722 gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_ORGANIZATION_NAME,
1725 gnutls_x509_crt_set_dn_by_oid (request, GNUTLS_OID_X520_COMMON_NAME,
1726 0, name, strlen (name));
1728 ret = gnutls_x509_crt_set_version (request, 3);
1730 ret = gnutls_rnd (GNUTLS_RND_NONCE, &serial, sizeof (serial));
1732 etime = time (NULL);
1733 tm_data = localtime (&etime);
1736 ret = gnutls_x509_crt_set_serial (request,
1740 ret = gnutls_x509_crt_set_activation_time (request,
1743 etime = mktime (tm_data);
1750 ret = gnutls_x509_crt_set_expiration_time (request,
1752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Signing...\n");
1754 ret = gnutls_x509_crt_sign (request, proxy_ca.cert, proxy_ca.key);
1756 key_buf_size = sizeof (pgc->key);
1757 cert_buf_size = sizeof (pgc->cert);
1759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exporting certificate...\n");
1761 gnutls_x509_crt_export (request, GNUTLS_X509_FMT_PEM,
1762 pgc->cert, &cert_buf_size);
1764 gnutls_x509_privkey_export (proxy_ca.key, GNUTLS_X509_FMT_PEM,
1765 pgc->key, &key_buf_size);
1768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
1769 gnutls_x509_crt_deinit (request);
1777 * Accept policy for mhdaemons
1780 * @param addr the sockaddr
1781 * @param addrlen the sockaddr length
1782 * @return MHD_NO if sockaddr is wrong or #conns too high
1785 accept_cb (void* cls, const struct sockaddr *addr, socklen_t addrlen)
1787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1788 "In MHD accept policy cb\n");
1792 if (addr->sa_family == AF_UNIX)
1796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1797 "Connection accepted\n");
1804 * Adds a socket to an SSL MHD instance
1805 * It is important the the domain name is
1806 * correct. In most cases we need to start a new daemon
1808 * @param h the handle to add to a daemon
1809 * @praram domain the domain the ssl daemon has to serve
1810 * @return MHD_YES on success
1813 add_handle_to_ssl_mhd (struct GNUNET_NETWORK_Handle *h, char* domain)
1815 struct MhdHttpList *hd = NULL;
1816 struct ProxyGNSCertificate *pgc;
1817 struct NetworkHandleList *nh;
1819 for (hd = mhd_httpd_head; hd != NULL; hd = hd->next)
1821 if (0 == strcmp (hd->domain, domain))
1828 pgc = generate_gns_certificate (domain);
1830 hd = GNUNET_malloc (sizeof (struct MhdHttpList));
1831 hd->is_ssl = GNUNET_YES;
1832 strcpy (hd->domain, domain);
1833 hd->proxy_cert = pgc;
1836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1837 "No previous SSL instance found... starting new one for %s\n",
1840 hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL, 4444,
1842 &create_response, hd,
1843 MHD_OPTION_LISTEN_SOCKET, GNUNET_NETWORK_get_fd (mhd_unix_socket),
1844 MHD_OPTION_CONNECTION_LIMIT, MHD_MAX_CONNECTIONS,
1845 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
1846 MHD_OPTION_NOTIFY_COMPLETED,
1848 MHD_OPTION_HTTPS_MEM_KEY, pgc->key,
1849 MHD_OPTION_HTTPS_MEM_CERT, pgc->cert,
1852 GNUNET_assert (hd->daemon != NULL);
1853 hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
1855 GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, mhd_httpd_tail, hd);
1858 nh = GNUNET_malloc (sizeof (struct NetworkHandleList));
1861 GNUNET_CONTAINER_DLL_insert (hd->socket_handles_head,
1862 hd->socket_handles_tail,
1865 return add_handle_to_mhd (h, hd->daemon);
1871 * Read data from incoming connection
1873 * @param cls the closure
1874 * @param tc the scheduler context
1877 do_read (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1879 struct Socks5Request *s5r = cls;
1880 struct socks5_client_hello *c_hello;
1881 struct socks5_server_hello *s_hello;
1882 struct socks5_client_request *c_req;
1883 struct socks5_server_response *s_resp;
1889 struct hostent *phost;
1891 struct sockaddr_in remote_addr;
1892 struct in_addr *r_sin_addr;
1894 struct NetworkHandleList *nh;
1896 s5r->rtask = GNUNET_SCHEDULER_NO_TASK;
1898 if ((NULL != tc->write_ready) &&
1899 (GNUNET_NETWORK_fdset_isset (tc->read_ready, s5r->sock)) &&
1900 (s5r->rbuf_len = GNUNET_NETWORK_socket_recv (s5r->sock, s5r->rbuf,
1901 sizeof (s5r->rbuf))))
1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1904 "Successfully read %d bytes from socket\n",
1909 if (s5r->rbuf_len != 0)
1910 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "read");
1912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disco!\n");
1914 if (s5r->fwdrtask != GNUNET_SCHEDULER_NO_TASK)
1915 GNUNET_SCHEDULER_cancel (s5r->fwdrtask);
1916 if (s5r->wtask != GNUNET_SCHEDULER_NO_TASK)
1917 GNUNET_SCHEDULER_cancel (s5r->wtask);
1918 if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK)
1919 GNUNET_SCHEDULER_cancel (s5r->fwdwtask);
1920 GNUNET_NETWORK_socket_close (s5r->remote_sock);
1921 GNUNET_NETWORK_socket_close (s5r->sock);
1926 if (s5r->state == SOCKS5_INIT)
1928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1930 c_hello = (struct socks5_client_hello*)&s5r->rbuf;
1932 GNUNET_assert (c_hello->version == SOCKS_VERSION_5);
1934 s_hello = (struct socks5_server_hello*)&s5r->wbuf;
1935 s5r->wbuf_len = sizeof( struct socks5_server_hello );
1937 s_hello->version = c_hello->version;
1938 s_hello->auth_method = SOCKS_AUTH_NONE;
1940 /* Write response to client */
1941 s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1945 s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1949 s5r->state = SOCKS5_REQUEST;
1953 if (s5r->state == SOCKS5_REQUEST)
1955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1956 "Processing SOCKS5 request\n");
1957 c_req = (struct socks5_client_request*)&s5r->rbuf;
1958 s_resp = (struct socks5_server_response*)&s5r->wbuf;
1959 //Only 10byte for ipv4 response!
1960 s5r->wbuf_len = 10;//sizeof (struct socks5_server_response);
1962 GNUNET_assert (c_req->addr_type == 3);
1964 dom_len = *((uint8_t*)(&(c_req->addr_type) + 1));
1965 memset(domain, 0, sizeof(domain));
1966 strncpy(domain, (char*)(&(c_req->addr_type) + 2), dom_len);
1967 req_port = *((uint16_t*)(&(c_req->addr_type) + 2 + dom_len));
1969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1970 "Requested connection is %s:%d\n",
1974 if (is_tld (domain, GNUNET_GNS_TLD) ||
1975 is_tld (domain, GNUNET_GNS_TLD_ZKEY))
1977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1978 "Requested connection is gnunet tld\n",
1982 if (ntohs(req_port) == HTTPS_PORT)
1984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1985 "Requested connection is HTTPS\n");
1986 ret = add_handle_to_ssl_mhd ( s5r->sock, domain );
1988 else if (NULL != httpd)
1990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1991 "Requested connection is HTTP\n");
1992 nh = GNUNET_malloc (sizeof (struct NetworkHandleList));
1995 GNUNET_CONTAINER_DLL_insert (mhd_httpd_head->socket_handles_head,
1996 mhd_httpd_head->socket_handles_tail,
1999 ret = add_handle_to_mhd ( s5r->sock, httpd );
2004 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2005 _("Failed to start HTTP server\n"));
2006 s_resp->version = 0x05;
2007 s_resp->reply = 0x01;
2008 s5r->cleanup = GNUNET_YES;
2009 s5r->cleanup_sock = GNUNET_YES;
2011 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2017 /* Signal success */
2018 s_resp->version = 0x05;
2019 s_resp->reply = 0x00;
2020 s_resp->reserved = 0x00;
2021 s_resp->addr_type = 0x01;
2023 s5r->cleanup = GNUNET_YES;
2024 s5r->cleanup_sock = GNUNET_NO;
2026 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2034 phost = (struct hostent*)gethostbyname (domain);
2037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2038 "Resolve %s error!\n", domain );
2039 s_resp->version = 0x05;
2040 s_resp->reply = 0x01;
2041 s5r->cleanup = GNUNET_YES;
2042 s5r->cleanup_sock = GNUNET_YES;
2044 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2050 s5r->remote_sock = GNUNET_NETWORK_socket_create (AF_INET,
2053 r_sin_addr = (struct in_addr*)(phost->h_addr);
2054 remote_ip = r_sin_addr->s_addr;
2055 memset(&remote_addr, 0, sizeof(remote_addr));
2056 remote_addr.sin_family = AF_INET;
2057 #if HAVE_SOCKADDR_IN_SIN_LEN
2058 remote_addr.sin_len = sizeof (remote_addr);
2060 remote_addr.sin_addr.s_addr = remote_ip;
2061 remote_addr.sin_port = req_port;
2063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2064 "target server: %s:%u\n", inet_ntoa(remote_addr.sin_addr),
2068 GNUNET_NETWORK_socket_connect ( s5r->remote_sock,
2069 (const struct sockaddr*)&remote_addr,
2070 sizeof (remote_addr)))
2071 && (errno != EINPROGRESS))
2073 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect");
2074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2075 "socket request error...\n");
2076 s_resp->version = 0x05;
2077 s_resp->reply = 0x01;
2079 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2087 "new remote connection\n");
2089 s_resp->version = 0x05;
2090 s_resp->reply = 0x00;
2091 s_resp->reserved = 0x00;
2092 s_resp->addr_type = 0x01;
2094 s5r->state = SOCKS5_DATA_TRANSFER;
2097 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2101 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2109 if (s5r->state == SOCKS5_DATA_TRANSFER)
2111 if ((s5r->remote_sock == NULL) || (s5r->rbuf_len == 0))
2113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2114 "Closing connection to client\n");
2115 if (s5r->rtask != GNUNET_SCHEDULER_NO_TASK)
2116 GNUNET_SCHEDULER_cancel (s5r->rtask);
2117 if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK)
2118 GNUNET_SCHEDULER_cancel (s5r->fwdwtask);
2119 if (s5r->fwdrtask != GNUNET_SCHEDULER_NO_TASK)
2120 GNUNET_SCHEDULER_cancel (s5r->fwdrtask);
2121 if (s5r->fwdrtask != GNUNET_SCHEDULER_NO_TASK)
2122 GNUNET_SCHEDULER_cancel (s5r->fwdrtask);
2124 if (s5r->remote_sock != NULL)
2125 GNUNET_NETWORK_socket_close (s5r->remote_sock);
2126 GNUNET_NETWORK_socket_close (s5r->sock);
2131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2132 "forwarding %d bytes from client\n", s5r->rbuf_len);
2135 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2137 &do_write_remote, s5r);
2139 if (s5r->fwdrtask == GNUNET_SCHEDULER_NO_TASK)
2142 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2144 &do_read_remote, s5r);
2150 //GNUNET_CONTAINER_DLL_remove (s5conns.head, s5conns.tail, s5r);
2156 * Accept new incoming connections
2158 * @param cls the closure
2159 * @param tc the scheduler context
2162 do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2164 struct GNUNET_NETWORK_Handle *s;
2165 struct Socks5Request *s5r;
2167 ltask = GNUNET_SCHEDULER_NO_TASK;
2168 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2171 ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2175 s = GNUNET_NETWORK_socket_accept (lsock, NULL, NULL);
2179 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept");
2183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2184 "Got an inbound connection, waiting for data\n");
2186 s5r = GNUNET_malloc (sizeof (struct Socks5Request));
2188 s5r->state = SOCKS5_INIT;
2189 s5r->wtask = GNUNET_SCHEDULER_NO_TASK;
2190 s5r->fwdwtask = GNUNET_SCHEDULER_NO_TASK;
2191 s5r->fwdrtask = GNUNET_SCHEDULER_NO_TASK;
2192 s5r->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2195 //GNUNET_CONTAINER_DLL_insert (s5conns.head, s5conns.tail, s5r);
2200 * Task run on shutdown
2202 * @param cls closure
2203 * @param tc task context
2206 do_shutdown (void *cls,
2207 const struct GNUNET_SCHEDULER_TaskContext *tc)
2210 struct MhdHttpList *hd;
2211 struct MhdHttpList *tmp_hd;
2212 struct NetworkHandleList *nh;
2213 struct NetworkHandleList *tmp_nh;
2214 struct ProxyCurlTask *ctask;
2215 struct ProxyCurlTask *ctask_tmp;
2217 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2218 "Shutting down...\n");
2220 gnutls_global_deinit ();
2222 if (GNUNET_SCHEDULER_NO_TASK != curl_download_task)
2224 GNUNET_SCHEDULER_cancel (curl_download_task);
2225 curl_download_task = GNUNET_SCHEDULER_NO_TASK;
2228 for (hd = mhd_httpd_head; hd != NULL; hd = tmp_hd)
2232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2233 "Stopping daemon\n");
2235 if (GNUNET_SCHEDULER_NO_TASK != hd->httpd_task)
2237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2238 "Stopping select task %d\n",
2240 GNUNET_SCHEDULER_cancel (hd->httpd_task);
2241 hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
2244 if (NULL != hd->daemon)
2246 MHD_stop_daemon (hd->daemon);
2250 for (nh = hd->socket_handles_head; nh != NULL; nh = tmp_nh)
2254 GNUNET_NETWORK_socket_close (nh->h);
2259 if (NULL != hd->proxy_cert)
2261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2262 "Free certificate\n");
2263 GNUNET_free (hd->proxy_cert);
2269 for (ctask=ctasks_head; ctask != NULL; ctask=ctask_tmp)
2271 ctask_tmp = ctask->next;
2273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2274 "Cleaning up cURL task\n");
2276 if (ctask->curl != NULL)
2277 curl_easy_cleanup (ctask->curl);
2279 if (NULL != ctask->headers)
2280 curl_slist_free_all (ctask->headers);
2281 if (NULL != ctask->resolver)
2282 curl_slist_free_all (ctask->resolver);
2284 if (NULL != ctask->response)
2285 MHD_destroy_response (ctask->response);
2288 GNUNET_free (ctask);
2291 GNUNET_GNS_disconnect (gns_handle);
2296 * Compiles a regex for us
2298 * @param re ptr to re struct
2299 * @param rt the expression to compile
2300 * @return 0 on success
2303 compile_regex (regex_t *re, const char* rt)
2308 status = regcomp (re, rt, REG_EXTENDED|REG_NEWLINE);
2311 regerror (status, re, err, 1024);
2312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2313 "Regex error compiling '%s': %s\n", rt, err);
2321 * Loads the users local zone key
2323 * @return GNUNET_YES on success
2326 load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg)
2329 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
2330 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
2331 struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
2332 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
2334 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
2335 "ZONEKEY", &keyfile))
2337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2338 "Unable to load zone key config value!\n");
2342 if (GNUNET_NO == GNUNET_DISK_file_test (keyfile))
2344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2345 "Unable to load zone key %s!\n", keyfile);
2346 GNUNET_free(keyfile);
2350 key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
2351 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
2352 GNUNET_CRYPTO_short_hash(&pkey,
2353 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
2355 zone = &local_gns_zone;
2356 GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
2357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2358 "Using zone: %s!\n", &zonename);
2359 GNUNET_CRYPTO_rsa_key_free(key);
2360 GNUNET_free(keyfile);
2366 * Main function that will be run
2368 * @param cls closure
2369 * @param args remaining command-line arguments
2370 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
2371 * @param cfg configuration
2374 run (void *cls, char *const *args, const char *cfgfile,
2375 const struct GNUNET_CONFIGURATION_Handle *cfg)
2377 struct sockaddr_in sa;
2378 struct MhdHttpList *hd;
2379 struct sockaddr_un mhd_unix_sock_addr;
2381 char* proxy_sockfile;
2382 char* cafile_cfg = NULL;
2384 char* shorten_keyfile;
2388 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2391 cafile = cafile_opt;
2395 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
2399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2400 "Unable to load proxy CA config value!\n");
2401 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2402 "No proxy CA provided!\n");
2405 cafile = cafile_cfg;
2408 gnutls_global_init ();
2410 gnutls_x509_crt_init (&proxy_ca.cert);
2411 gnutls_x509_privkey_init (&proxy_ca.key);
2413 load_cert_from_file (proxy_ca.cert, cafile);
2414 load_key_from_file (proxy_ca.key, cafile);
2416 GNUNET_free_non_null (cafile_cfg);
2418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2419 "Loading Template\n");
2421 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
2425 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2426 "Unable to load shorten zonekey config value!\n");
2427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2428 "No shorten key provided!\n");
2433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2434 "Loading shorten zonekey %s!\n",
2436 shorten_zonekey = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile);
2437 GNUNET_free (shorten_keyfile);
2440 compile_regex (&re_dotplus, (char*) RE_A_HREF);
2442 gns_handle = GNUNET_GNS_connect (cfg);
2444 if (GNUNET_NO == load_local_zone_key (cfg))
2446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2447 "Unable to load zone!\n");
2451 if (NULL == gns_handle)
2453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2454 "Unable to connect to GNS!\n");
2458 memset (&sa, 0, sizeof (sa));
2459 sa.sin_family = AF_INET;
2460 sa.sin_port = htons (port);
2461 #if HAVE_SOCKADDR_IN_SIN_LEN
2462 sa.sin_len = sizeof (sa);
2465 lsock = GNUNET_NETWORK_socket_create (AF_INET,
2469 if ((NULL == lsock) ||
2471 GNUNET_NETWORK_socket_bind (lsock, (const struct sockaddr *) &sa,
2474 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2475 "Failed to create listen socket bound to `%s'",
2476 GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)));
2478 GNUNET_NETWORK_socket_close (lsock);
2482 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock, 5))
2484 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2485 "Failed to listen on socket bound to `%s'",
2486 GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)));
2490 ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
2491 lsock, &do_accept, NULL);
2496 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
2498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2499 "cURL global init failed!\n");
2503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2504 "Proxy listens on port %u\n",
2507 mhd_httpd_head = NULL;
2508 mhd_httpd_tail = NULL;
2509 total_mhd_connections = 0;
2511 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
2515 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2516 "Specify PROXY_UNIXPATH in gns-proxy config section!\n");
2520 mhd_unix_socket = GNUNET_NETWORK_socket_create (AF_UNIX,
2524 if (NULL == mhd_unix_socket)
2526 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2527 "Unable to create unix domain socket!\n");
2531 mhd_unix_sock_addr.sun_family = AF_UNIX;
2532 strcpy (mhd_unix_sock_addr.sun_path, proxy_sockfile);
2533 unlink (proxy_sockfile);
2534 len = strlen (proxy_sockfile) + sizeof(AF_UNIX);
2536 GNUNET_free (proxy_sockfile);
2538 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (mhd_unix_socket,
2539 (struct sockaddr*)&mhd_unix_sock_addr,
2542 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2543 "Unable to bind unix domain socket!\n");
2547 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (mhd_unix_socket,
2550 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2551 "Unable to listen on unix domain socket!\n");
2555 hd = GNUNET_malloc (sizeof (struct MhdHttpList));
2556 hd->is_ssl = GNUNET_NO;
2557 strcpy (hd->domain, "");
2558 httpd = MHD_start_daemon (MHD_USE_DEBUG, 4444, //Dummy port
2560 &create_response, hd,
2561 MHD_OPTION_LISTEN_SOCKET, GNUNET_NETWORK_get_fd (mhd_unix_socket),
2562 MHD_OPTION_CONNECTION_LIMIT, MHD_MAX_CONNECTIONS,
2563 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
2564 MHD_OPTION_NOTIFY_COMPLETED,
2568 GNUNET_assert (httpd != NULL);
2570 hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
2572 GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, mhd_httpd_tail, hd);
2576 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2577 &do_shutdown, NULL);
2583 * The main function for gnunet-gns-proxy.
2585 * @param argc number of arguments from the command line
2586 * @param argv command line arguments
2587 * @return 0 ok, 1 on error
2590 main (int argc, char *const *argv)
2592 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2594 gettext_noop ("listen on specified port"), 1,
2595 &GNUNET_GETOPT_set_string, &port},
2596 {'a', "authority", NULL,
2597 gettext_noop ("pem file to use as CA"), 1,
2598 &GNUNET_GETOPT_set_string, &cafile_opt},
2599 GNUNET_GETOPT_OPTION_END
2604 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2608 GNUNET_log_setup ("gnunet-gns-proxy", "WARNING", NULL);
2611 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns-proxy",
2612 _("GNUnet GNS proxy"),
2614 &run, NULL)) ? 0 : 1;
2615 GNUNET_free_non_null ((char*)argv);