[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11444 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11444 - gnunet/src/transport |
Date: |
Thu, 20 May 2010 13:12:26 +0200 |
Author: wachs
Date: 2010-05-20 13:12:26 +0200 (Thu, 20 May 2010)
New Revision: 11444
Modified:
gnunet/src/transport/plugin_transport_http.c
gnunet/src/transport/test_plugin_transport_data_http.conf
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-20 11:08:16 UTC
(rev 11443)
+++ gnunet/src/transport/plugin_transport_http.c 2010-05-20 11:12:26 UTC
(rev 11444)
@@ -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
@@ -53,7 +52,12 @@
*/
#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 @@
/**
- * Pl
+ * Information about this plugin
*/
static struct Plugin *plugin;
@@ -197,7 +201,13 @@
*/
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
* @param peer peeridentity
@@ -309,10 +319,14 @@
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 @@
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,9 +397,8 @@
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 peer `%s' from `[%s]:%u'\n",method,
GNUNET_h2s(&pi_in.hashPubKey),address,conn_info->client_addr->sin_port);
- 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);
-
/* find session for address */
cs = NULL;
if (plugin->session_count > 0)
@@ -382,16 +407,15 @@
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;
- /* 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);
/* 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 @@
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 @@
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 @@
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 !=
Modified: gnunet/src/transport/test_plugin_transport_data_http.conf
===================================================================
--- gnunet/src/transport/test_plugin_transport_data_http.conf 2010-05-20
11:08:16 UTC (rev 11443)
+++ gnunet/src/transport/test_plugin_transport_data_http.conf 2010-05-20
11:12:26 UTC (rev 11444)
@@ -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
Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c 2010-05-20 11:08:16 UTC
(rev 11443)
+++ gnunet/src/transport/test_plugin_transport_http.c 2010-05-20 11:12:26 UTC
(rev 11444)
@@ -60,17 +60,21 @@
/* 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 @@
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 @@
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 @@
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))
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11444 - gnunet/src/transport,
gnunet <=