diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-01 16:10:17 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-01 16:10:17 +0000 |
commit | 7f0b04482f00c6902ef972fb50d40756d31e3fdc (patch) | |
tree | 3e2dd611cd8e8bc515bb09d8238f1823a33579d7 /src | |
parent | c835d0bd4b765026a7b1884d236e1975a929f77a (diff) | |
download | gnunet-7f0b04482f00c6902ef972fb50d40756d31e3fdc.tar.gz gnunet-7f0b04482f00c6902ef972fb50d40756d31e3fdc.zip |
-fix, mhd start
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/Makefile.am | 2 | ||||
-rw-r--r-- | src/gns/gns_proxy_proto.h | 40 | ||||
-rw-r--r-- | src/gns/gnunet-gns-fcfsd.c | 4 | ||||
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 178 |
4 files changed, 170 insertions, 54 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 33b10c2bb..5614ebe36 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -206,7 +206,7 @@ gnunet_gns_DEPENDENCIES = \ | |||
206 | 206 | ||
207 | gnunet_gns_proxy_SOURCES = \ | 207 | gnunet_gns_proxy_SOURCES = \ |
208 | gnunet-gns-proxy.c | 208 | gnunet-gns-proxy.c |
209 | gnunet_gns_proxy_LDADD = \ | 209 | gnunet_gns_proxy_LDADD = -lmicrohttpd \ |
210 | $(top_builddir)/src/gns/libgnunetgns.la \ | 210 | $(top_builddir)/src/gns/libgnunetgns.la \ |
211 | $(top_builddir)/src/util/libgnunetutil.la \ | 211 | $(top_builddir)/src/util/libgnunetutil.la \ |
212 | $(GN_LIBINTL) | 212 | $(GN_LIBINTL) |
diff --git a/src/gns/gns_proxy_proto.h b/src/gns/gns_proxy_proto.h index 39f7e881c..ef30d5c03 100644 --- a/src/gns/gns_proxy_proto.h +++ b/src/gns/gns_proxy_proto.h | |||
@@ -38,46 +38,6 @@ struct socks5_server_hello | |||
38 | uint8_t auth_method; | 38 | uint8_t auth_method; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | #define BUF_WAIT_FOR_CURL 0 | ||
42 | #define BUF_WAIT_FOR_MHD 1 | ||
43 | |||
44 | /* Struct used to store connection | ||
45 | * information | ||
46 | */ | ||
47 | struct socks5_bridge | ||
48 | { | ||
49 | int fd; | ||
50 | struct socks5_bridge* remote_end; | ||
51 | struct sockaddr addr; | ||
52 | socklen_t addr_len; | ||
53 | char host[256]; | ||
54 | int status; | ||
55 | |||
56 | /* This is an ssl bridge? */ | ||
57 | int use_ssl; | ||
58 | |||
59 | /* if use_ssl=1 we have a daemon associated */ | ||
60 | struct MHD_Daemon *ssl_daemon; | ||
61 | |||
62 | /* http url + host */ | ||
63 | char* full_url; | ||
64 | |||
65 | /* handle to curl */ | ||
66 | //CURL* curl; | ||
67 | |||
68 | /* is response html? */ | ||
69 | int res_is_html; | ||
70 | |||
71 | /* buffer structures */ | ||
72 | pthread_t thread; | ||
73 | pthread_mutex_t m_done; | ||
74 | int is_done; | ||
75 | pthread_mutex_t m_buf; | ||
76 | //char MHD_CURL_BUF[CURL_MAX_WRITE_SIZE]; | ||
77 | size_t MHD_CURL_BUF_SIZE; | ||
78 | int MHD_CURL_BUF_STATUS; | ||
79 | }; | ||
80 | |||
81 | /* Server response to client requests */ | 41 | /* Server response to client requests */ |
82 | struct socks5_server_response | 42 | struct socks5_server_response |
83 | { | 43 | { |
diff --git a/src/gns/gnunet-gns-fcfsd.c b/src/gns/gnunet-gns-fcfsd.c index 7e099df62..cd4e8e72d 100644 --- a/src/gns/gnunet-gns-fcfsd.c +++ b/src/gns/gnunet-gns-fcfsd.c | |||
@@ -470,8 +470,8 @@ lookup_result_processor (void *cls, | |||
470 | * upload_data provided; the method must update this | 470 | * upload_data provided; the method must update this |
471 | * value to the number of bytes NOT processed; | 471 | * value to the number of bytes NOT processed; |
472 | * @param ptr pointer to location where we store the 'struct Request' | 472 | * @param ptr pointer to location where we store the 'struct Request' |
473 | * @return MHS_YES if the connection was handled successfully, | 473 | * @return MHD_YES if the connection was handled successfully, |
474 | * MHS_NO if the socket must be closed due to a serios | 474 | * MHD_NO if the socket must be closed due to a serious |
475 | * error while handling the request | 475 | * error while handling the request |
476 | */ | 476 | */ |
477 | static int | 477 | static int |
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index dd75c2efa..7a157e87d 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include "platform.h" | 21 | #include "platform.h" |
22 | #include <gnunet_util_lib.h> | 22 | #include <gnunet_util_lib.h> |
23 | #include <microhttpd.h> | ||
23 | #include "gns_proxy_proto.h" | 24 | #include "gns_proxy_proto.h" |
24 | #include "gns.h" | 25 | #include "gns.h" |
25 | 26 | ||
@@ -56,9 +57,6 @@ is_tld(const char* name, const char* tld) | |||
56 | 57 | ||
57 | struct Socks5Request | 58 | struct Socks5Request |
58 | { | 59 | { |
59 | struct Socks5Request *prev; | ||
60 | struct Socks5Request *next; | ||
61 | |||
62 | struct GNUNET_NETWORK_Handle *sock; | 60 | struct GNUNET_NETWORK_Handle *sock; |
63 | struct GNUNET_NETWORK_Handle *remote_sock; | 61 | struct GNUNET_NETWORK_Handle *remote_sock; |
64 | 62 | ||
@@ -75,17 +73,143 @@ struct Socks5Request | |||
75 | unsigned int wbuf_len; | 73 | unsigned int wbuf_len; |
76 | }; | 74 | }; |
77 | 75 | ||
78 | struct Socks5Connections | ||
79 | { | ||
80 | struct Socks5Request *head; | ||
81 | struct Socks5Request *tail; | ||
82 | }; | ||
83 | |||
84 | |||
85 | unsigned long port = GNUNET_GNS_PROXY_PORT; | 76 | unsigned long port = GNUNET_GNS_PROXY_PORT; |
86 | static struct GNUNET_NETWORK_Handle *lsock; | 77 | static struct GNUNET_NETWORK_Handle *lsock; |
87 | GNUNET_SCHEDULER_TaskIdentifier ltask; | 78 | GNUNET_SCHEDULER_TaskIdentifier ltask; |
88 | static struct Socks5Connections s5conns; | 79 | static struct MHD_Daemon *httpd; |
80 | static GNUNET_SCHEDULER_TaskIdentifier httpd_task; | ||
81 | |||
82 | /** | ||
83 | * Main MHD callback for handling requests. | ||
84 | * | ||
85 | * @param cls unused | ||
86 | * @param connection MHD connection handle | ||
87 | * @param method the HTTP method used ("GET", "PUT", etc.) | ||
88 | * @param version the HTTP version string (i.e. "HTTP/1.1") | ||
89 | * @param upload_data the data being uploaded (excluding HEADERS, | ||
90 | * for a POST that fits into memory and that is encoded | ||
91 | * with a supported encoding, the POST data will NOT be | ||
92 | * given in upload_data and is instead available as | ||
93 | * part of MHD_get_connection_values; very large POST | ||
94 | * data *will* be made available incrementally in | ||
95 | * upload_data) | ||
96 | * @param upload_data_size set initially to the size of the | ||
97 | * upload_data provided; the method must update this | ||
98 | * value to the number of bytes NOT processed; | ||
99 | * @param ptr pointer to location where we store the 'struct Request' | ||
100 | * @return MHD_YES if the connection was handled successfully, | ||
101 | * MHD_NO if the socket must be closed due to a serious | ||
102 | * error while handling the request | ||
103 | */ | ||
104 | static int | ||
105 | create_response (void *cls, | ||
106 | struct MHD_Connection *con, | ||
107 | const char *url, | ||
108 | const char *meth, | ||
109 | const char *ver, | ||
110 | const char *upload_data, | ||
111 | size_t *upload_data_size, | ||
112 | void **con_cls) | ||
113 | { | ||
114 | static int dummy; | ||
115 | const char* page = "<html><head><title>gnoxy</title>"\ | ||
116 | "</head><body>gnoxy demo</body></html>"; | ||
117 | struct MHD_Response *response; | ||
118 | int ret; | ||
119 | |||
120 | if (0 != strcmp (meth, "GET")) | ||
121 | return MHD_NO; | ||
122 | if (&dummy != *con_cls) | ||
123 | { | ||
124 | *con_cls = &dummy; | ||
125 | return MHD_YES; | ||
126 | } | ||
127 | |||
128 | if (0 != *upload_data_size) | ||
129 | return MHD_NO; | ||
130 | |||
131 | *con_cls = NULL; | ||
132 | |||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
134 | "url %s\n", url); | ||
135 | |||
136 | response = MHD_create_response_from_buffer (strlen (page), | ||
137 | (void*)page, | ||
138 | MHD_RESPMEM_PERSISTENT); | ||
139 | ret = MHD_queue_response (con, | ||
140 | MHD_HTTP_OK, | ||
141 | response); | ||
142 | MHD_destroy_response (response); | ||
143 | return ret; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * Task run whenever HTTP server operations are pending. | ||
148 | * | ||
149 | * @param cls unused | ||
150 | * @param tc sched context | ||
151 | */ | ||
152 | static void | ||
153 | do_httpd (void *cls, | ||
154 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
155 | |||
156 | /** | ||
157 | * Schedule MHD | ||
158 | */ | ||
159 | static void | ||
160 | run_httpd () | ||
161 | { | ||
162 | fd_set rs; | ||
163 | fd_set ws; | ||
164 | fd_set es; | ||
165 | struct GNUNET_NETWORK_FDSet *wrs; | ||
166 | struct GNUNET_NETWORK_FDSet *wws; | ||
167 | struct GNUNET_NETWORK_FDSet *wes; | ||
168 | int max; | ||
169 | int haveto; | ||
170 | unsigned MHD_LONG_LONG timeout; | ||
171 | struct GNUNET_TIME_Relative tv; | ||
172 | |||
173 | FD_ZERO (&rs); | ||
174 | FD_ZERO (&ws); | ||
175 | FD_ZERO (&es); | ||
176 | wrs = GNUNET_NETWORK_fdset_create (); | ||
177 | wes = GNUNET_NETWORK_fdset_create (); | ||
178 | wws = GNUNET_NETWORK_fdset_create (); | ||
179 | max = -1; | ||
180 | GNUNET_assert (MHD_YES == MHD_get_fdset (httpd, &rs, &ws, &es, &max)); | ||
181 | haveto = MHD_get_timeout (httpd, &timeout); | ||
182 | |||
183 | if (haveto == MHD_YES) | ||
184 | tv.rel_value = (uint64_t) timeout; | ||
185 | else | ||
186 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | ||
187 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | ||
188 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | ||
189 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); | ||
190 | httpd_task = | ||
191 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | ||
192 | tv, wrs, wws, | ||
193 | &do_httpd, NULL); | ||
194 | GNUNET_NETWORK_fdset_destroy (wrs); | ||
195 | GNUNET_NETWORK_fdset_destroy (wws); | ||
196 | GNUNET_NETWORK_fdset_destroy (wes); | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * Task run whenever HTTP server operations are pending. | ||
201 | * | ||
202 | * @param cls unused | ||
203 | * @param tc sched context | ||
204 | */ | ||
205 | static void | ||
206 | do_httpd (void *cls, | ||
207 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
208 | { | ||
209 | httpd_task = GNUNET_SCHEDULER_NO_TASK; | ||
210 | MHD_run (httpd); | ||
211 | run_httpd (); | ||
212 | } | ||
89 | 213 | ||
90 | /** | 214 | /** |
91 | * Read data from socket | 215 | * Read data from socket |
@@ -355,6 +479,28 @@ do_read (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
356 | "Requested connection is gnunet tld\n", | 480 | "Requested connection is gnunet tld\n", |
357 | domain); | 481 | domain); |
482 | |||
483 | if (httpd == NULL) | ||
484 | { | ||
485 | |||
486 | |||
487 | if (NULL == httpd) | ||
488 | { | ||
489 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
490 | _("Failed to start HTTP server\n")); | ||
491 | s_resp->version = 0x05; | ||
492 | s_resp->reply = 0x01; | ||
493 | s5r->wtask = | ||
494 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
495 | s5r->sock, | ||
496 | &do_write, s5r); | ||
497 | //ERROR! | ||
498 | //TODO! close socket after the write! schedule task | ||
499 | //GNUNET_NETWORK_socket_close (s5r->sock); | ||
500 | //GNUNET_free(s5r); | ||
501 | return; | ||
502 | } | ||
503 | } | ||
358 | } | 504 | } |
359 | else | 505 | else |
360 | { | 506 | { |
@@ -575,6 +721,16 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
576 | "Proxy listens on port %u\n", | 722 | "Proxy listens on port %u\n", |
577 | port); | 723 | port); |
724 | |||
725 | httpd = MHD_start_daemon (MHD_USE_DEBUG, 4444, | ||
726 | NULL, NULL, | ||
727 | &create_response, NULL, | ||
728 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, | ||
729 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | ||
730 | MHD_OPTION_NOTIFY_COMPLETED, | ||
731 | NULL, NULL, | ||
732 | MHD_OPTION_END); | ||
733 | run_httpd (); | ||
578 | 734 | ||
579 | } | 735 | } |
580 | 736 | ||