[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11313 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11313 - gnunet/src/transport |
Date: |
Tue, 11 May 2010 15:44:09 +0200 |
Author: wachs
Date: 2010-05-11 15:44:09 +0200 (Tue, 11 May 2010)
New Revision: 11313
Modified:
gnunet/src/transport/plugin_transport_http.c
Log:
Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c 2010-05-11 13:43:44 UTC
(rev 11312)
+++ gnunet/src/transport/plugin_transport_http.c 2010-05-11 13:44:09 UTC
(rev 11313)
@@ -168,6 +168,7 @@
static CURLM *multi_handle;
+static struct sockaddr_in * current_ip;
/**
* Finds a http session in our linked list using peer identity as a key
@@ -244,6 +245,33 @@
}
/**
+ * Creates a http session in our linked list by ip address
+ * Only ip is set here, all other fields have to be set by calling method
+ * @param peer peeridentity
+ * @return created http session
+ */
+static struct Session * create_session_by_ip ( struct sockaddr_in * addr )
+{
+ struct Session * cur;
+ struct Session * last_in_list;
+ /* Create a new session object */
+ cur = GNUNET_malloc (sizeof (struct Session));
+ // FIXME: memcpy( &(cur->ip), , sizeof( struct GNUNET_PeerIdentity ) );
+
+ cur->next = NULL;
+
+ /* Insert into linked list */
+ last_in_list = plugin->sessions;
+ while (last_in_list->next != NULL)
+ {
+ last_in_list = last_in_list->next;
+ }
+ last_in_list->next = cur;
+
+ return cur;
+}
+
+/**
* Callback called by MHD when a connection is terminated
*/
static void requestCompletedCallback (void *cls, struct MHD_Connection *
connection, void **httpSessionCache)
@@ -263,12 +291,14 @@
/* 40 == max IPv6 Address length as string: (4 * 8) + (7 * :) + \0 */
char * address = GNUNET_malloc(40);
inet_ntop(addrin->sin_family, &addrin->sin_addr.s_addr,address,40);
+ memcpy( cls, addrin, sizeof (struct sockaddr_in) );
if (addrin->sin_family == AF_INET)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv4 connection from
`%s'\n", address);
if (addrin->sin_family == AF_INET6)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv6 connection from
`%s'\n",address);
GNUNET_free (address);
+ /* Every connection is accepted, nothing more to do here */
return MHD_YES;
}
@@ -289,22 +319,26 @@
const char *upload_data,
size_t * upload_data_size, void **httpSessionCache)
{
- //struct Session * http_session;
-
+ struct Session * http_session;
struct MHD_Response *response;
- unsigned int have;
+ struct sockaddr_in * addrin = (struct sockaddr_in *) cls;
+ http_session = *httpSessionCache;
+ char * address = GNUNET_malloc(40);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s'
request from \n",method);
- if (*httpSessionCache==NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New request \n",method);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Already known request \n",method);
- /* Find out if session exists, otherwise create one */
- //struct sockaddr_in * test = session->addr;
- //http_session = find_session_by_ip ( test );
+ inet_ntop(addrin->sin_family, &addrin->sin_addr.s_addr,address,40);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s'
request from `%s'\n",method, address);
+ /* Check if new or already known session */
+ if ( NULL == http_session )
+ {
+ /* Create a new session */
+
+ /* Insert session into linked list*/
+
+ /* Set closure */
+ }
/* Is it a PUT or a GET request */
if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) )
{
@@ -313,7 +347,6 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: `%s'\n",upload_data);
/* FIXME: GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("#
PUT requests"), 1, GNUNET_NO); */
- have = *upload_data_size;
/* No data left */
*upload_data_size = 0;
response = MHD_create_response_from_data (strlen
(HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
@@ -326,6 +359,7 @@
//GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET
requests"), 1, GNUNET_NO);
}
+ GNUNET_free (address);
return MHD_YES;
}
@@ -629,6 +663,7 @@
curl_multi_cleanup(multi_handle);
+ GNUNET_free (current_ip);
GNUNET_free (plugin);
GNUNET_free (api);
return NULL;
@@ -675,12 +710,14 @@
return NULL;
}
+ current_ip = GNUNET_malloc ( sizeof(struct sockaddr_in) );
+
if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0))
{
http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6,
port,
&acceptPolicyCallback,
- NULL, &accessHandlerCallback, NULL,
+ current_ip, &accessHandlerCallback,
current_ip,
MHD_OPTION_CONNECTION_LIMIT, (unsigned
int) 16,
MHD_OPTION_PER_IP_CONNECTION_LIMIT,
(unsigned int) 1,
MHD_OPTION_CONNECTION_TIMEOUT,
(unsigned int) 16,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11313 - gnunet/src/transport,
gnunet <=