aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-05-11 13:44:09 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-05-11 13:44:09 +0000
commit015b6b2e2816fd679ac3091c49952f005df39ee4 (patch)
tree2ca3282e9a248aa240db9bc7a9693dc9a7b60817 /src
parentbed8e0d389aacc368b3dd9704d355b284236fea3 (diff)
downloadgnunet-015b6b2e2816fd679ac3091c49952f005df39ee4.tar.gz
gnunet-015b6b2e2816fd679ac3091c49952f005df39ee4.zip
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_http.c63
1 files changed, 50 insertions, 13 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index d9d1e6f34..9689d452e 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -168,6 +168,7 @@ struct Plugin *plugin;
168 168
169static CURLM *multi_handle; 169static CURLM *multi_handle;
170 170
171static struct sockaddr_in * current_ip;
171 172
172/** 173/**
173 * Finds a http session in our linked list using peer identity as a key 174 * Finds a http session in our linked list using peer identity as a key
@@ -244,6 +245,33 @@ static struct Session * create_session_by_pi( const struct GNUNET_PeerIdentity *
244} 245}
245 246
246/** 247/**
248 * Creates a http session in our linked list by ip address
249 * Only ip is set here, all other fields have to be set by calling method
250 * @param peer peeridentity
251 * @return created http session
252 */
253static struct Session * create_session_by_ip ( struct sockaddr_in * addr )
254{
255 struct Session * cur;
256 struct Session * last_in_list;
257 /* Create a new session object */
258 cur = GNUNET_malloc (sizeof (struct Session));
259 // FIXME: memcpy( &(cur->ip), , sizeof( struct GNUNET_PeerIdentity ) );
260
261 cur->next = NULL;
262
263 /* Insert into linked list */
264 last_in_list = plugin->sessions;
265 while (last_in_list->next != NULL)
266 {
267 last_in_list = last_in_list->next;
268 }
269 last_in_list->next = cur;
270
271 return cur;
272}
273
274/**
247 * Callback called by MHD when a connection is terminated 275 * Callback called by MHD when a connection is terminated
248 */ 276 */
249static void requestCompletedCallback (void *cls, struct MHD_Connection * connection, void **httpSessionCache) 277static void requestCompletedCallback (void *cls, struct MHD_Connection * connection, void **httpSessionCache)
@@ -263,12 +291,14 @@ acceptPolicyCallback (void *cls,
263 /* 40 == max IPv6 Address length as string: (4 * 8) + (7 * :) + \0 */ 291 /* 40 == max IPv6 Address length as string: (4 * 8) + (7 * :) + \0 */
264 char * address = GNUNET_malloc(40); 292 char * address = GNUNET_malloc(40);
265 inet_ntop(addrin->sin_family, &addrin->sin_addr.s_addr,address,40); 293 inet_ntop(addrin->sin_family, &addrin->sin_addr.s_addr,address,40);
294 memcpy( cls, addrin, sizeof (struct sockaddr_in) );
266 if (addrin->sin_family == AF_INET) 295 if (addrin->sin_family == AF_INET)
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv4 connection from `%s'\n", address); 296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv4 connection from `%s'\n", address);
268 if (addrin->sin_family == AF_INET6) 297 if (addrin->sin_family == AF_INET6)
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv6 connection from `%s'\n",address); 298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv6 connection from `%s'\n",address);
270 GNUNET_free (address); 299 GNUNET_free (address);
271 300
301 /* Every connection is accepted, nothing more to do here */
272 return MHD_YES; 302 return MHD_YES;
273} 303}
274 304
@@ -289,22 +319,26 @@ accessHandlerCallback (void *cls,
289 const char *upload_data, 319 const char *upload_data,
290 size_t * upload_data_size, void **httpSessionCache) 320 size_t * upload_data_size, void **httpSessionCache)
291{ 321{
292 //struct Session * http_session; 322 struct Session * http_session;
293
294 struct MHD_Response *response; 323 struct MHD_Response *response;
295 unsigned int have; 324 struct sockaddr_in * addrin = (struct sockaddr_in *) cls;
325 http_session = *httpSessionCache;
326 char * address = GNUNET_malloc(40);
296 327
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' request from \n",method);
298 if (*httpSessionCache==NULL)
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New request \n",method);
300 else
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Already known request \n",method);
302 328
303 /* Find out if session exists, otherwise create one */ 329 inet_ntop(addrin->sin_family, &addrin->sin_addr.s_addr,address,40);
304 //struct sockaddr_in * test = session->addr; 330
305 //http_session = find_session_by_ip ( test ); 331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' request from `%s'\n",method, address);
332
333 /* Check if new or already known session */
334 if ( NULL == http_session )
335 {
336 /* Create a new session */
306 337
338 /* Insert session into linked list*/
307 339
340 /* Set closure */
341 }
308 /* Is it a PUT or a GET request */ 342 /* Is it a PUT or a GET request */
309 if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) ) 343 if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) )
310 { 344 {
@@ -313,7 +347,6 @@ accessHandlerCallback (void *cls,
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url); 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url);
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: `%s'\n",upload_data); 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: `%s'\n",upload_data);
315 /* FIXME: GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# PUT requests"), 1, GNUNET_NO); */ 349 /* FIXME: GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# PUT requests"), 1, GNUNET_NO); */
316 have = *upload_data_size;
317 /* No data left */ 350 /* No data left */
318 *upload_data_size = 0; 351 *upload_data_size = 0;
319 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); 352 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
@@ -326,6 +359,7 @@ accessHandlerCallback (void *cls,
326 //GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET requests"), 1, GNUNET_NO); 359 //GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET requests"), 1, GNUNET_NO);
327 } 360 }
328 361
362 GNUNET_free (address);
329 return MHD_YES; 363 return MHD_YES;
330} 364}
331 365
@@ -629,6 +663,7 @@ libgnunet_plugin_transport_http_done (void *cls)
629 663
630 curl_multi_cleanup(multi_handle); 664 curl_multi_cleanup(multi_handle);
631 665
666 GNUNET_free (current_ip);
632 GNUNET_free (plugin); 667 GNUNET_free (plugin);
633 GNUNET_free (api); 668 GNUNET_free (api);
634 return NULL; 669 return NULL;
@@ -675,12 +710,14 @@ libgnunet_plugin_transport_http_init (void *cls)
675 return NULL; 710 return NULL;
676 } 711 }
677 712
713 current_ip = GNUNET_malloc ( sizeof(struct sockaddr_in) );
714
678 if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0)) 715 if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0))
679 { 716 {
680 http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6, 717 http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6,
681 port, 718 port,
682 &acceptPolicyCallback, 719 &acceptPolicyCallback,
683 NULL, &accessHandlerCallback, NULL, 720 current_ip, &accessHandlerCallback, current_ip,
684 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16, 721 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16,
685 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, 722 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1,
686 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, 723 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,