[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r21705 - gnunet/src/gns
From: |
gnunet |
Subject: |
[GNUnet-SVN] r21705 - gnunet/src/gns |
Date: |
Fri, 1 Jun 2012 18:10:17 +0200 |
Author: schanzen
Date: 2012-06-01 18:10:17 +0200 (Fri, 01 Jun 2012)
New Revision: 21705
Modified:
gnunet/src/gns/Makefile.am
gnunet/src/gns/gns_proxy_proto.h
gnunet/src/gns/gnunet-gns-fcfsd.c
gnunet/src/gns/gnunet-gns-proxy.c
Log:
-fix, mhd start
Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am 2012-06-01 15:36:14 UTC (rev 21704)
+++ gnunet/src/gns/Makefile.am 2012-06-01 16:10:17 UTC (rev 21705)
@@ -206,7 +206,7 @@
gnunet_gns_proxy_SOURCES = \
gnunet-gns-proxy.c
-gnunet_gns_proxy_LDADD = \
+gnunet_gns_proxy_LDADD = -lmicrohttpd \
$(top_builddir)/src/gns/libgnunetgns.la \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
Modified: gnunet/src/gns/gns_proxy_proto.h
===================================================================
--- gnunet/src/gns/gns_proxy_proto.h 2012-06-01 15:36:14 UTC (rev 21704)
+++ gnunet/src/gns/gns_proxy_proto.h 2012-06-01 16:10:17 UTC (rev 21705)
@@ -38,46 +38,6 @@
uint8_t auth_method;
};
-#define BUF_WAIT_FOR_CURL 0
-#define BUF_WAIT_FOR_MHD 1
-
-/* Struct used to store connection
- * information
- */
-struct socks5_bridge
-{
- int fd;
- struct socks5_bridge* remote_end;
- struct sockaddr addr;
- socklen_t addr_len;
- char host[256];
- int status;
-
- /* This is an ssl bridge? */
- int use_ssl;
-
- /* if use_ssl=1 we have a daemon associated */
- struct MHD_Daemon *ssl_daemon;
-
- /* http url + host */
- char* full_url;
-
- /* handle to curl */
- //CURL* curl;
-
- /* is response html? */
- int res_is_html;
-
- /* buffer structures */
- pthread_t thread;
- pthread_mutex_t m_done;
- int is_done;
- pthread_mutex_t m_buf;
- //char MHD_CURL_BUF[CURL_MAX_WRITE_SIZE];
- size_t MHD_CURL_BUF_SIZE;
- int MHD_CURL_BUF_STATUS;
-};
-
/* Server response to client requests */
struct socks5_server_response
{
Modified: gnunet/src/gns/gnunet-gns-fcfsd.c
===================================================================
--- gnunet/src/gns/gnunet-gns-fcfsd.c 2012-06-01 15:36:14 UTC (rev 21704)
+++ gnunet/src/gns/gnunet-gns-fcfsd.c 2012-06-01 16:10:17 UTC (rev 21705)
@@ -470,8 +470,8 @@
* upload_data provided; the method must update this
* value to the number of bytes NOT processed;
* @param ptr pointer to location where we store the 'struct Request'
- * @return MHS_YES if the connection was handled successfully,
- * MHS_NO if the socket must be closed due to a serios
+ * @return MHD_YES if the connection was handled successfully,
+ * MHD_NO if the socket must be closed due to a serious
* error while handling the request
*/
static int
Modified: gnunet/src/gns/gnunet-gns-proxy.c
===================================================================
--- gnunet/src/gns/gnunet-gns-proxy.c 2012-06-01 15:36:14 UTC (rev 21704)
+++ gnunet/src/gns/gnunet-gns-proxy.c 2012-06-01 16:10:17 UTC (rev 21705)
@@ -20,6 +20,7 @@
#include "platform.h"
#include <gnunet_util_lib.h>
+#include <microhttpd.h>
#include "gns_proxy_proto.h"
#include "gns.h"
@@ -56,9 +57,6 @@
struct Socks5Request
{
- struct Socks5Request *prev;
- struct Socks5Request *next;
-
struct GNUNET_NETWORK_Handle *sock;
struct GNUNET_NETWORK_Handle *remote_sock;
@@ -75,19 +73,145 @@
unsigned int wbuf_len;
};
-struct Socks5Connections
-{
- struct Socks5Request *head;
- struct Socks5Request *tail;
-};
-
-
unsigned long port = GNUNET_GNS_PROXY_PORT;
static struct GNUNET_NETWORK_Handle *lsock;
GNUNET_SCHEDULER_TaskIdentifier ltask;
-static struct Socks5Connections s5conns;
+static struct MHD_Daemon *httpd;
+static GNUNET_SCHEDULER_TaskIdentifier httpd_task;
/**
+ * Main MHD callback for handling requests.
+ *
+ * @param cls unused
+ * @param connection MHD connection handle
+ * @param method the HTTP method used ("GET", "PUT", etc.)
+ * @param version the HTTP version string (i.e. "HTTP/1.1")
+ * @param upload_data the data being uploaded (excluding HEADERS,
+ * for a POST that fits into memory and that is encoded
+ * with a supported encoding, the POST data will NOT be
+ * given in upload_data and is instead available as
+ * part of MHD_get_connection_values; very large POST
+ * data *will* be made available incrementally in
+ * upload_data)
+ * @param upload_data_size set initially to the size of the
+ * upload_data provided; the method must update this
+ * value to the number of bytes NOT processed;
+ * @param ptr pointer to location where we store the 'struct Request'
+ * @return MHD_YES if the connection was handled successfully,
+ * MHD_NO if the socket must be closed due to a serious
+ * error while handling the request
+ */
+static int
+create_response (void *cls,
+ struct MHD_Connection *con,
+ const char *url,
+ const char *meth,
+ const char *ver,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ static int dummy;
+ const char* page = "<html><head><title>gnoxy</title>"\
+ "</head><body>gnoxy demo</body></html>";
+ struct MHD_Response *response;
+ int ret;
+
+ if (0 != strcmp (meth, "GET"))
+ return MHD_NO;
+ if (&dummy != *con_cls)
+ {
+ *con_cls = &dummy;
+ return MHD_YES;
+ }
+
+ if (0 != *upload_data_size)
+ return MHD_NO;
+
+ *con_cls = NULL;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "url %s\n", url);
+
+ response = MHD_create_response_from_buffer (strlen (page),
+ (void*)page,
+ MHD_RESPMEM_PERSISTENT);
+ ret = MHD_queue_response (con,
+ MHD_HTTP_OK,
+ response);
+ MHD_destroy_response (response);
+ return ret;
+}
+
+/**
+ * Task run whenever HTTP server operations are pending.
+ *
+ * @param cls unused
+ * @param tc sched context
+ */
+static void
+do_httpd (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+/**
+ * Schedule MHD
+ */
+static void
+run_httpd ()
+{
+ fd_set rs;
+ fd_set ws;
+ fd_set es;
+ struct GNUNET_NETWORK_FDSet *wrs;
+ struct GNUNET_NETWORK_FDSet *wws;
+ struct GNUNET_NETWORK_FDSet *wes;
+ int max;
+ int haveto;
+ unsigned MHD_LONG_LONG timeout;
+ struct GNUNET_TIME_Relative tv;
+
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
+ wrs = GNUNET_NETWORK_fdset_create ();
+ wes = GNUNET_NETWORK_fdset_create ();
+ wws = GNUNET_NETWORK_fdset_create ();
+ max = -1;
+ GNUNET_assert (MHD_YES == MHD_get_fdset (httpd, &rs, &ws, &es, &max));
+ haveto = MHD_get_timeout (httpd, &timeout);
+
+ if (haveto == MHD_YES)
+ tv.rel_value = (uint64_t) timeout;
+ else
+ tv = GNUNET_TIME_UNIT_FOREVER_REL;
+ GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
+ GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
+ GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
+ httpd_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ tv, wrs, wws,
+ &do_httpd, NULL);
+ GNUNET_NETWORK_fdset_destroy (wrs);
+ GNUNET_NETWORK_fdset_destroy (wws);
+ GNUNET_NETWORK_fdset_destroy (wes);
+}
+
+/**
+ * Task run whenever HTTP server operations are pending.
+ *
+ * @param cls unused
+ * @param tc sched context
+ */
+static void
+do_httpd (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ httpd_task = GNUNET_SCHEDULER_NO_TASK;
+ MHD_run (httpd);
+ run_httpd ();
+}
+
+/**
* Read data from socket
*
* @param cls the closure
@@ -355,6 +479,28 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requested connection is gnunet tld\n",
domain);
+
+ if (httpd == NULL)
+ {
+
+
+ if (NULL == httpd)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to start HTTP server\n"));
+ s_resp->version = 0x05;
+ s_resp->reply = 0x01;
+ s5r->wtask =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ s5r->sock,
+ &do_write, s5r);
+ //ERROR!
+ //TODO! close socket after the write! schedule task
+ //GNUNET_NETWORK_socket_close (s5r->sock);
+ //GNUNET_free(s5r);
+ return;
+ }
+ }
}
else
{
@@ -575,6 +721,16 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Proxy listens on port %u\n",
port);
+
+ httpd = MHD_start_daemon (MHD_USE_DEBUG, 4444,
+ NULL, NULL,
+ &create_response, NULL,
+ MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128,
+ MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)
16,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ NULL, NULL,
+ MHD_OPTION_END);
+ run_httpd ();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r21705 - gnunet/src/gns,
gnunet <=