gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r11431 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r11431 - gnunet/src/transport
Date: Wed, 19 May 2010 09:27:02 +0200

Author: wachs
Date: 2010-05-19 09:27:02 +0200 (Wed, 19 May 2010)
New Revision: 11431

Modified:
   gnunet/src/transport/plugin_transport_http.c
   gnunet/src/transport/test_plugin_transport_http.c
Log:


Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-05-18 15:13:26 UTC 
(rev 11430)
+++ gnunet/src/transport/plugin_transport_http.c        2010-05-19 07:27:02 UTC 
(rev 11431)
@@ -176,9 +176,9 @@
 static CURLM *multi_handle;
 
 /**
- * IP of current incoming connection
+ * session of current incoming connection
  */
-static struct sockaddr  * current_ip;
+static struct Session  * current_session;
 
 static unsigned int locked;
 
@@ -312,27 +312,42 @@
       return MHD_NO;
   }
 
+  /* something went wrong since last attempt to connect, lost session to free 
*/
+  if ( NULL != current_session )
+  {
+    GNUNET_free ( current_session->ip );
+    GNUNET_free ( current_session );
+  }
+
   locked = GNUNET_YES;
 
   if (addr->sa_family == AF_INET6)
   {
-    address = GNUNET_malloc(INET6_ADDRSTRLEN);
+    address = GNUNET_malloc (INET6_ADDRSTRLEN);
     addrin6 = (struct sockaddr_in6 *) addr;
     inet_ntop(addrin6->sin6_family, 
&(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv6 connection from 
`%s'\n",address);
-    memcpy(current_ip,addr, sizeof (struct sockaddr));
-    GNUNET_free (address);
   }
-  if (addr->sa_family == AF_INET)
+  else if (addr->sa_family == AF_INET)
   {
     address = GNUNET_malloc(INET_ADDRSTRLEN);
     addrin = (struct sockaddr_in *) addr;
     inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv4 connection from 
`%s'\n",address);
-    memcpy(current_ip,addr, sizeof (struct sockaddr));
-    GNUNET_free (address);
   }
+  /* are there any socket types besides ipv4 and ipv6 we want to support? */
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unsupported connection type for 
incoming connection \n");
+    current_session = NULL;
+    locked = GNUNET_NO;
+    return MHD_NO;
+  }
 
+  /* create current session object */
+  current_session = GNUNET_malloc ( sizeof( struct Session) );
+  current_session->ip = address;
+
   /* Every connection is accepted, nothing more to do here */
   return MHD_YES;
 }
@@ -358,27 +373,8 @@
   struct MHD_Response *response;
   http_session = *httpSessionCache;
 
-  struct sockaddr_in  *addrin;
-  struct sockaddr_in6 *addrin6;
-  char * address = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' 
request from `%s'\n",method, current_session->ip);
 
-  if ( current_ip->sa_family == AF_INET)
-  {
-    address = GNUNET_malloc(INET_ADDRSTRLEN);
-    addrin = (struct sockaddr_in *) current_ip;
-    inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN);
-  }
-  else if (current_ip->sa_family == AF_INET6)
-  {
-    address = GNUNET_malloc(INET6_ADDRSTRLEN);
-    addrin6 = (struct sockaddr_in6 *) current_ip;
-    inet_ntop(addrin6->sin6_family, 
&(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
-  }
-  else
-
-  if ( NULL != address )
-    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 )
   {
@@ -391,6 +387,7 @@
 
   /* Since connection is established, we can unlock */
   locked = GNUNET_NO;
+  current_session = NULL;
 
   /* Is it a PUT or a GET request */
   if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) )
@@ -412,7 +409,6 @@
     //GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET 
requests"), 1, GNUNET_NO);
   }
 
-  GNUNET_free (address);
   return MHD_YES;
 }
 
@@ -718,7 +714,6 @@
 
   curl_multi_cleanup(multi_handle);
 
-  GNUNET_free (current_ip);
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;
@@ -765,13 +760,12 @@
       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,
-                                       current_ip, &accessHandlerCallback, 
current_ip,
+                                       NULL , &accessHandlerCallback, NULL,
                                        MHD_OPTION_CONNECTION_LIMIT, (unsigned 
int) 16,
                                        MHD_OPTION_PER_IP_CONNECTION_LIMIT, 
(unsigned int) 1,
                                        MHD_OPTION_CONNECTION_TIMEOUT, 
(unsigned int) 16,
@@ -781,7 +775,7 @@
     http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG,
                                        port,
                                        &acceptPolicyCallback,
-                                       current_ip, &accessHandlerCallback, 
current_ip,
+                                       NULL , &accessHandlerCallback, NULL,
                                        MHD_OPTION_CONNECTION_LIMIT, (unsigned 
int) 16,
                                        MHD_OPTION_PER_IP_CONNECTION_LIMIT, 
(unsigned int) 1,
                                        MHD_OPTION_CONNECTION_TIMEOUT, 
(unsigned int) 16,

Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-05-18 15:13:26 UTC 
(rev 11430)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-05-19 07:27:02 UTC 
(rev 11431)
@@ -103,9 +103,9 @@
 static struct GNUNET_TRANSPORT_PluginFunctions *api;
 
 /**
- * ID of the task controlling the locking between two hostlist tests
+ * ID of the task controlling the testcase timeout
  */
-static GNUNET_SCHEDULER_TaskIdentifier ti_check_stat;
+static GNUNET_SCHEDULER_TaskIdentifier ti_timeout;
 
 static unsigned int timeout_count;
 
@@ -158,9 +158,9 @@
   }*/
 
   /* if ( NULL!=stats )GNUNET_STATISTICS_destroy (stats, GNUNET_YES); */
-  if (ti_check_stat != GNUNET_SCHEDULER_NO_TASK)
-    GNUNET_SCHEDULER_cancel(sched,ti_check_stat);
-  ti_check_stat = GNUNET_SCHEDULER_NO_TASK;
+  if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
+    GNUNET_SCHEDULER_cancel(sched,ti_timeout);
+  ti_timeout = GNUNET_SCHEDULER_NO_TASK;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
   GNUNET_assert (NULL == GNUNET_PLUGIN_unload 
("libgnunet_plugin_transport_http", api));
@@ -223,10 +223,10 @@
  * this task again for a later time.
  */
 static void
-task_check_stat (void *cls,
+task_timeout (void *cls,
             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  ti_check_stat = GNUNET_SCHEDULER_NO_TASK;
+  ti_timeout = GNUNET_SCHEDULER_NO_TASK;
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
 
@@ -247,7 +247,7 @@
                                            &process_stat,
                                            NULL);*/
 
-  ti_check_stat = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL, 
&task_check_stat, NULL);
+  ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, STAT_INTERVALL, 
&task_timeout, NULL);
   return;
 }
 
@@ -309,7 +309,7 @@
     return;
   }
 
-  ti_check_stat = GNUNET_SCHEDULER_add_now (sched, &task_check_stat, NULL);
+  ti_timeout = GNUNET_SCHEDULER_add_now (sched, &task_timeout, NULL);
   return;
 
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]