(no commit message)
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 20 May 2010 11:12:26 +0000 (11:12 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 20 May 2010 11:12:26 +0000 (11:12 +0000)
src/transport/plugin_transport_http.c
src/transport/test_plugin_transport_data_http.conf
src/transport/test_plugin_transport_http.c

index af2a19cdea42336bcd709a2be9224515f61c5d15..22f06caca15a51fdf37dd214545e624d10a2aaa0 100644 (file)
@@ -45,7 +45,6 @@
  */
 #define HTTP_PUT_RESPONSE "Thank you!"
 
-
 /**
  * After how long do we expire an address that we
  * learned from another peer if it is not reconfirmed
  */
 #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
 
+/**
+ * Page returned if request invalid
+ */
+#define HTTP_ERROR_RESPONSE "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested URL was not found on this server.<P><HR><ADDRESS></ADDRESS></BODY></HTML>"
+
 
 /**
  * Encapsulation of all of the state of the plugin.
@@ -183,7 +187,7 @@ static GNUNET_SCHEDULER_TaskIdentifier http_task_v6;
 
 
 /**
- * Pl
+ * Information about this plugin
  */
 static struct Plugin *plugin;
 
@@ -197,6 +201,12 @@ static CURLM *multi_handle;
  */
 static char * hostname;
 
+/**
+ * Our ASCII encoded, hashed peer identity
+ * This string is used to distinguish between connections and is added to the urls
+ */
+static struct GNUNET_CRYPTO_HashAsciiEncoded my_ascii_hash_ident;
+
 
 /**
  * Finds a http session in our linked list using peer identity as a key
@@ -309,10 +319,14 @@ static void requestCompletedCallback (void *cls, struct MHD_Connection * connect
   struct Session * cs;
 
   cs = *httpSessionCache;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection `%s' was terminated\n",cs->ip);
-  /* session set to inactive */
-  cs->is_active = GNUNET_NO;
-
+  if (cs != NULL)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection from peer `%s' was terminated\n",GNUNET_i2s(&cs->sender));
+    /* session set to inactive */
+    cs->is_active = GNUNET_NO;
+  }
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Not accepted connection was terminated\n");
   return;
 }
 
@@ -351,10 +365,22 @@ accessHandlerCallback (void *cls,
   struct sockaddr_in  *addrin;
   struct sockaddr_in6 *addrin6;
   char * address = NULL;
+  struct GNUNET_PeerIdentity pi_in;
   int res = GNUNET_NO;
 
   if ( NULL == *httpSessionCache)
   {
+    /* check url for peer identity */
+    res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey));
+    if ( GNUNET_SYSERR == res )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Peer has no valid ident\n");
+      response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
+      res = MHD_queue_response (session, MHD_HTTP_NOT_FOUND, response);
+      MHD_destroy_response (response);
+      return MHD_YES;
+    }
+
     conn_info = MHD_get_connection_info(session, MHD_CONNECTION_INFO_CLIENT_ADDRESS );
     /* Incoming IPv4 connection */
     if ( AF_INET == conn_info->client_addr->sin_family)
@@ -371,8 +397,7 @@ accessHandlerCallback (void *cls,
       inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN);
     }
 
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' request from `[%s]:%u'\n",method, address,conn_info->client_addr->sin_port);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' request from peer `%s' from `[%s]:%u'\n",method, GNUNET_h2s(&pi_in.hashPubKey),address,conn_info->client_addr->sin_port);
 
     /* find session for address */
     cs = NULL;
@@ -382,16 +407,15 @@ accessHandlerCallback (void *cls,
       while ( NULL != cs)
       {
 
-        /* FIXME: When are two connections equal? ip1 == ip2  or ip1:port1 == ip2:port2 ?
-         * Think about NAT, reuse connections...
-         */
-
         /* Comparison based on ip address */
-        res = (0 == memcmp(&(conn_info->client_addr->sin_addr),&(cs->addr->sin_addr), sizeof (struct in_addr))) ? GNUNET_YES : GNUNET_NO;
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"res is %u \n",res);
+        // res = (0 == memcmp(&(conn_info->client_addr->sin_addr),&(cs->addr->sin_addr), sizeof (struct in_addr))) ? GNUNET_YES : GNUNET_NO;
+
         /* Comparison based on ip address, port number and address family */
-        /* res = (0 == memcmp((conn_info->client_addr),(cs->addr), sizeof (struct sockaddr_in))) ? GNUNET_YES : GNUNET_NO;
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"port1 is %u port2 is %u, res is %u \n",conn_info->client_addr->sin_port,cs->addr->sin_port,res); */
+        // res = (0 == memcmp((conn_info->client_addr),(cs->addr), sizeof (struct sockaddr_in))) ? GNUNET_YES : GNUNET_NO;
+
+        /* Comparison based on PeerIdentity */
+        res = (0 == memcmp(&pi_in,&(cs->sender), sizeof (struct GNUNET_PeerIdentity))) ? GNUNET_YES : GNUNET_NO;
+
         if ( GNUNET_YES  == res)
         {
           /* existing session for this address found */
@@ -408,9 +432,9 @@ accessHandlerCallback (void *cls,
       cs = GNUNET_malloc ( sizeof( struct Session) );
       cs->addr = GNUNET_malloc ( sizeof (struct sockaddr_in) );
 
-
       cs->ip = address;
       memcpy(cs->addr, conn_info->client_addr, sizeof (struct sockaddr_in));
+      memcpy(&cs->sender, &pi_in, sizeof (struct GNUNET_PeerIdentity));
       cs->next = NULL;
       cs->is_active = GNUNET_YES;
 
@@ -455,6 +479,11 @@ accessHandlerCallback (void *cls,
   if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url);
+
+    response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
+    MHD_queue_response (session, MHD_HTTP_OK, response);
+    MHD_destroy_response (response);
   }
 
   return MHD_YES;
@@ -807,6 +836,9 @@ libgnunet_plugin_transport_http_init (void *cls)
 
   hostname = GNUNET_RESOLVER_local_fqdn_get ();
 
+  /* Hashing our identity to use it in URLs */
+  GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &my_ascii_hash_ident);
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
   /* Reading port number from config file */
   if ((GNUNET_OK !=
index 13cc00388a4a301b382240f430368bb38a032623..8e4bbe0334bc05385e252c22ef7183874402fbab 100644 (file)
@@ -1,6 +1,6 @@
 [PATHS]
 DEFAULTCONFIG = test_plugin_transport_data_http.conf
-SERVICEHOME = /tmp/test-gnunetd-transport-peer-1/
+SERVICEHOME = /tmp/test_plugin_transport_http/
 
 [transport-http]
 PORT = 12389
index 9e11026f8f76a229a5d932cc4ee49c8dec51fb0a..c2a2901d38c5364dd14f48eb72a14b1a9d8b276b 100644 (file)
  */
 /* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
 
+/**
+ * Our public key.
+ */
+static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
+
 /**
  * Our identity.
  */
 static struct GNUNET_PeerIdentity my_identity;
 
-#if 0
 /**
  * Our private key.
  */
 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
-#endif
+
 
 /**
  * Our scheduler.
@@ -283,6 +287,8 @@ run (void *cls,
   char * libname;
   sched = s;
   cfg = c;
+  char *keyfile;
+  unsigned long long tneigh;
 
   /* settings up statistics */
 /*  stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
@@ -295,6 +301,38 @@ run (void *cls,
     return ;
   }*/
 
+  /* parse configuration */
+  if ((GNUNET_OK !=
+       GNUNET_CONFIGURATION_get_value_number (c,
+                                              "TRANSPORT",
+                                              "NEIGHBOUR_LIMIT",
+                                              &tneigh)) ||
+      (GNUNET_OK !=
+       GNUNET_CONFIGURATION_get_value_filename (c,
+                                                "GNUNETD",
+                                                "HOSTKEY", &keyfile)))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _
+                  ("Transport service is lacking key configuration settings.  Exiting.\n"));
+      GNUNET_SCHEDULER_shutdown (s);
+      return;
+    }
+  max_connect_per_transport = (uint32_t) tneigh;
+  my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+  GNUNET_free (keyfile);
+  if (my_private_key == NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _
+                  ("Transport service could not access hostkey.  Exiting.\n"));
+      GNUNET_SCHEDULER_shutdown (s);
+      return;
+    }
+  GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
+  GNUNET_CRYPTO_hash (&my_public_key,
+                      sizeof (my_public_key), &my_identity.hashPubKey);
+
   /* load plugins... */
   setup_plugin_environment ();
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin `%s'\n"),"libgnunet_plugin_transport_http");
@@ -368,7 +406,9 @@ main (int argc, char *const *argv)
                              argv_prog,
                              "test_plugin_transport_http",
                              "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES;
-  GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
+  /* FIXME: Please do not generate a key every time
+   * GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
+   */
 
 /*  if (0 != PLIBC_KILL (pid, SIGTERM))
   {