gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r27659 - gnunet/src/transport
Date: Thu, 27 Jun 2013 17:02:11 +0200

Author: wachs
Date: 2013-06-27 17:02:11 +0200 (Thu, 27 Jun 2013)
New Revision: 27659

Modified:
   gnunet/src/transport/plugin_transport_http_client.c
   gnunet/src/transport/plugin_transport_http_common.c
   gnunet/src/transport/plugin_transport_http_common.h
   gnunet/src/transport/plugin_transport_http_server.c
Log:
Implementing bug 0002910
- extended plugin to contain option field in addresses
Implementing bug 0002677
- adding ssl verification for external hostname having 
  - the server send the HTTP_OPTIONS_VERIFY_CERTIFICATE option
  - client use this option to enable ssl verification



Modified: gnunet/src/transport/plugin_transport_http_client.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_client.c 2013-06-27 14:57:58 UTC 
(rev 27658)
+++ gnunet/src/transport/plugin_transport_http_client.c 2013-06-27 15:02:11 UTC 
(rev 27659)
@@ -152,7 +152,7 @@
   /**
    * Address
    */
-  void *addr;
+  struct HttpAddress *addr;
 
   /**
    * Address length
@@ -277,6 +277,11 @@
   char *protocol;
 
   /**
+   * My options to be included in the address
+   */
+  uint32_t options;
+
+  /**
    * Maximum number of sockets the plugin can use
    * Each http inbound /outbound connections are two connections
    */
@@ -917,7 +922,7 @@
   GNUNET_break (s->ats_address_network_type != ntohl 
(GNUNET_ATS_NET_UNSPECIFIED));
 
   delay = s->plugin->env->receive (plugin->env->cls, &s->target, message,
-                                   s, s->addr, s->addrlen);
+                                   s, (const char *) s->addr, s->addrlen);
 
   plugin->env->update_address_metrics (plugin->env->cls,
                                       &s->target,
@@ -939,7 +944,8 @@
 
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Client: peer `%s' address `%s' next read delayed for 
%llu ms\n",
-                     GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen),
+                     GNUNET_i2s (&s->target),
+                     http_common_plugin_address_to_string (NULL, 
s->plugin->protocol, s->addr, s->addrlen),
                      delay);
   }
   client_reschedule_session_timeout (s);
@@ -1227,6 +1233,7 @@
 static int
 client_connect_get (struct Session *s)
 {
+
   CURLMcode mret;
   /* create get connection */
   s->client_get = curl_easy_init ();
@@ -1239,8 +1246,17 @@
 #endif
 #if BUILD_HTTPS
   curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
-  curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0);
-  curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0);
+       if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
+                       (ntohl (s->addr->options) & 
HTTP_OPTIONS_VERIFY_CERTIFICATE))
+       {
+         curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1);
+         curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 1);
+       }
+       else
+       {
+               curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0);
+               curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0);
+       }
   curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
   curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
 #else
@@ -1249,8 +1265,6 @@
 #endif
 
   curl_easy_setopt (s->client_get, CURLOPT_URL, s->url);
-  curl_easy_setopt (s->client_get, CURLOPT_URL, s->url);
-  curl_easy_setopt (s->client_get, CURLOPT_URL, s->url);
   //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, 
&curl_get_header_cb);
   //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps);
   curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, client_send_cb);
@@ -1309,8 +1323,17 @@
 #endif
 #if BUILD_HTTPS
   curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
-  curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0);
-  curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0);
+       if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
+                       (ntohl (s->addr->options) & 
HTTP_OPTIONS_VERIFY_CERTIFICATE))
+       {
+         curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1);
+         curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 1);
+       }
+       else
+       {
+               curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0);
+               curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0);
+       }
   curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
   curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
 #else
@@ -1366,9 +1389,8 @@
   struct HTTP_Client_Plugin *plugin = s->plugin;
   int res = GNUNET_OK;
 
-
   /* create url */
-  if (NULL == http_common_plugin_address_to_string (NULL, s->addr, s->addrlen))
+  if (NULL == http_common_plugin_address_to_string (NULL, plugin->protocol, 
s->addr, s->addrlen))
   {
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Invalid address peer `%s'\n",
@@ -1377,9 +1399,9 @@
   }
 
   GNUNET_asprintf (&s->url, "%s/%s;%u",
-      http_common_plugin_address_to_string (plugin, s->addr, s->addrlen),
-                   GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),
-                   plugin->last_tag);
+      http_common_plugin_address_to_url (NULL, s->addr, s->addrlen),
+                       GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),
+                       plugin->last_tag);
 
   plugin->last_tag++;
 
@@ -1454,10 +1476,10 @@
     return NULL;
   }
 
+  /* Determine network location */
   ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
   ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED);
   sa = http_common_socket_from_address (address->address, 
address->address_length, &res);
-
   if (GNUNET_SYSERR == res)
   {
       return NULL;
@@ -1508,7 +1530,7 @@
   {
     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
                      "Cannot connect to peer `%s' address `%s''\n",
-                     http_common_plugin_address_to_string (NULL, s->addr, 
s->addrlen),
+                     http_common_plugin_address_to_string (NULL, plugin->name, 
s->addr, s->addrlen),
                      GNUNET_i2s (&s->target));
     client_delete_session (s);
     return NULL;
@@ -1721,6 +1743,13 @@
   return GNUNET_OK;
 }
 
+const char *http_plugin_address_to_string (void *cls,
+                                           const void *addr,
+                                           size_t addrlen)
+{
+       return http_common_plugin_address_to_string (cls, p->name, addr, 
addrlen);
+}
+
 /**
  * Entry point for the plugin.
  */
@@ -1737,7 +1766,7 @@
        initialze the plugin or the API */
     api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
     api->cls = NULL;
-    api->address_to_string = &http_common_plugin_address_to_string;
+    api->address_to_string = &http_plugin_address_to_string;
     api->string_to_address = &http_common_plugin_string_to_address;
     api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
     return api;
@@ -1752,7 +1781,7 @@
   api->disconnect = &http_client_plugin_disconnect;
   api->check_address = &http_client_plugin_address_suggested;
   api->get_session = &http_client_plugin_get_session;
-  api->address_to_string = &http_common_plugin_address_to_string;
+  api->address_to_string = &http_plugin_address_to_string;
   api->string_to_address = &http_common_plugin_string_to_address;
   api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
 
@@ -1765,6 +1794,7 @@
   plugin->protocol = "http";
 #endif
   plugin->last_tag = 1;
+  plugin->options = 0; /* Setup options */
 
   if (GNUNET_SYSERR == client_configure_plugin (plugin))
   {

Modified: gnunet/src/transport/plugin_transport_http_common.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_common.c 2013-06-27 14:57:58 UTC 
(rev 27658)
+++ gnunet/src/transport/plugin_transport_http_common.c 2013-06-27 15:02:11 UTC 
(rev 27659)
@@ -202,20 +202,50 @@
                                         GNUNET_TRANSPORT_AddressStringCallback
                                         asc, void *asc_cls)
 {
-  const char *saddr = (const char *) addr;
+       const struct HttpAddress *address = addr;
 
-  if ( (NULL == saddr) ||
-       (0 >= addrlen) ||
-       ('\0' != saddr[addrlen-1]) )
+  if (NULL == http_common_plugin_address_to_string (NULL, (char *) type, 
address, addrlen))
   {
       asc (asc_cls, NULL);
       return;
   }
-  asc (asc_cls, saddr);
+  asc (asc_cls, http_common_plugin_address_to_string (NULL, (char *) type, 
address, addrlen));
   asc (asc_cls, NULL);
 }
 
+const char *
+http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen)
+{
+  static char rbuf[1024];
+       const struct HttpAddress *address = addr;
+  const char * addr_str;
 
+
+
+  if (NULL == addr)
+  {
+       GNUNET_break (0);
+    return NULL;
+  }
+  if (0 >= addrlen)
+  {
+       GNUNET_break (0);
+    return NULL;
+  }
+  if (addrlen != http_common_address_get_size (address))
+  {
+       GNUNET_break (0);
+    return NULL;
+  }
+  addr_str = (char *) &address[1];
+
+  if (addr_str[ntohl(address->urlen) -1] != '\0')
+    return NULL;
+
+  memcpy (rbuf, &address[1], ntohl(address->urlen));
+  return rbuf;
+}
+
 /**
  * Function called for a quick conversion of the binary address to
  * a numeric address.  Note that the caller must not free the
@@ -228,16 +258,35 @@
  * @return string representing the same address
  */
 const char *
-http_common_plugin_address_to_string (void *cls, const void *addr, size_t 
addrlen)
+http_common_plugin_address_to_string (void *cls, char *plugin, const void 
*addr, size_t addrlen)
 {
-  const char *saddr = (const char *) addr;
-  if (NULL == saddr)
+  static char rbuf[1024];
+       const struct HttpAddress *address = addr;
+  const char * addr_str;
+  char *res;
+
+
+  if (NULL == addr)
       return NULL;
   if (0 >= addrlen)
     return NULL;
-  if (saddr[addrlen-1] != '\0')
+  if (addrlen != http_common_address_get_size (address))
+       return NULL;
+  addr_str = (char *) &address[1];
+
+  if (addr_str[ntohl(address->urlen) -1] != '\0')
     return NULL;
-  return saddr;
+
+  GNUNET_asprintf (&res, "%s.%u.%s", plugin, address->options, &address[1]);
+  if (strlen(res) + 1 < 500)
+  {
+       memcpy (rbuf, res, strlen(res) + 1);
+       GNUNET_free (res);
+       return rbuf;
+  }
+  GNUNET_break (0);
+       GNUNET_free (res);
+       return NULL;
 }
 
 /**
@@ -259,15 +308,63 @@
                         void **buf,
                         size_t *added)
 {
-  if (NULL == addr)
-      return GNUNET_SYSERR;
-  if (0 >= addrlen)
+       struct HttpAddress *a;
+  char *address;
+  char *plugin;
+  char *optionstr;
+  size_t urlen;
+  uint32_t options;
+
+  /* Format protocol.options.address:port */
+  address = NULL;
+  plugin = NULL;
+  optionstr = NULL;
+  options = 0;
+  if ((NULL == addr) || (addrlen == 0))
+  {
+    GNUNET_break (0);
     return GNUNET_SYSERR;
-  if (addr[addrlen-1] != '\0')
+  }
+  if ('\0' != addr[addrlen - 1])
+  {
+    GNUNET_break (0);
     return GNUNET_SYSERR;
+  }
+  if (strlen (addr) != addrlen - 1)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  plugin = GNUNET_strdup (addr);
+  optionstr = strchr (plugin, '.');
+  if (NULL == optionstr)
+  {
+    GNUNET_break (0);
+    GNUNET_free (plugin);
+    return GNUNET_SYSERR;
+  }
+  optionstr[0] = '\0';
+  optionstr ++;
+  options = atol (optionstr);
+  address = strchr (optionstr, '.');
+  if (NULL == address)
+  {
+    GNUNET_break (0);
+    GNUNET_free (plugin);
+    return GNUNET_SYSERR;
+  }
+  address[0] = '\0';
+  address ++;
+  urlen = strlen (address) + 1;
 
-  (*buf) = strdup (addr);
-  (*added) = strlen (addr) + 1;
+  a = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
+  a->options = htonl(options);
+  a->urlen = htonl(urlen);
+  memcpy (&a[1], address, urlen);
+
+  (*buf) = a;
+  (*added) = sizeof (struct HttpAddress) + urlen;
+  GNUNET_free (plugin);
   return GNUNET_OK;
 }
 
@@ -277,14 +374,25 @@
  * @param protocol protocol
  * @param addr sockaddr * address
  * @param addrlen length of the address
- * @return the string
+ * @return the HttpAddress
  */
-char *
+struct HttpAddress *
 http_common_address_from_socket (const char *protocol, const struct sockaddr 
*addr, socklen_t addrlen)
 {
+  struct HttpAddress *address = NULL;
   char *res;
+  size_t len;
+
   GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen));
-  return res;
+  len = strlen (res)+1;
+
+  address = GNUNET_malloc (sizeof (struct HttpAddress) + len);
+  address->options = htonl (HTTP_OPTIONS_NONE);
+  address->urlen = htonl (len);
+  memcpy (&address[1], res, len);
+  GNUNET_free (res);
+
+  return address;
 }
 
 /**
@@ -301,28 +409,39 @@
 struct sockaddr *
 http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
 {
+       const struct HttpAddress *ha;
        struct SplittedHTTPAddress * spa;
   struct sockaddr_storage *s;
   (*res) = GNUNET_SYSERR;
   char * to_conv;
 
+  ha = (const struct HttpAddress *) addr;
   if (NULL == addr)
-    {
-      GNUNET_break (0);
-      return NULL;
-    }
+       {
+               GNUNET_break (0);
+               return NULL;
+       }
   if (0 >= addrlen)
-    {
-      GNUNET_break (0);
-      return NULL;
-    }
+       {
+               GNUNET_break (0);
+               return NULL;
+       }
+  if (addrlen < sizeof (struct HttpAddress))
+       {
+               GNUNET_break (0);
+               return NULL;
+       }
+  if (addrlen < sizeof (struct HttpAddress) + ntohl (ha->urlen))
+       {
+               /* This is a legacy addresses */
+               return NULL;
+       }
   if (((char *) addr)[addrlen-1] != '\0')
-    {
-      GNUNET_break (0);
-      return NULL;
-    }
-
-  spa = http_split_address (addr);
+       {
+               GNUNET_break (0);
+               return NULL;
+       }
+  spa = http_split_address ((const char *) &ha[1]);
   if (NULL == spa)
   {
       (*res) = GNUNET_SYSERR;
@@ -361,9 +480,9 @@
  * @return the size
  */
 size_t
-http_common_address_get_size (const void *addr)
+http_common_address_get_size (const struct HttpAddress * addr)
 {
- return strlen (addr) + 1;
+ return sizeof (struct HttpAddress) + ntohl(addr->urlen);
 }
 
 /**
@@ -378,8 +497,12 @@
 size_t
 http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void 
*addr2, size_t addrlen2)
 {
+       const struct HttpAddress *ha1;
+       const struct HttpAddress *ha2;
   const char *a1 = (const char *) addr1;
   const char *a2 = (const char *) addr2;
+  ha1 = (const struct HttpAddress *) a1;
+  ha2 = (const struct HttpAddress *) a2;
 
   if (NULL == a1)
       return GNUNET_SYSERR;
@@ -397,8 +520,10 @@
 
   if (addrlen1 != addrlen2)
     return GNUNET_NO;
+  if (ha1->urlen != ha2->urlen)
+    return GNUNET_NO;
 
-  if (0 == strcmp (addr1, addr2))
+  if (0 == strcmp ((const char *) &ha1[1],(const char *) &ha2[1]))
     return GNUNET_YES;
   return GNUNET_NO;
 }

Modified: gnunet/src/transport/plugin_transport_http_common.h
===================================================================
--- gnunet/src/transport/plugin_transport_http_common.h 2013-06-27 14:57:58 UTC 
(rev 27658)
+++ gnunet/src/transport/plugin_transport_http_common.h 2013-06-27 15:02:11 UTC 
(rev 27659)
@@ -27,6 +27,7 @@
 #include "platform.h"
 #include "gnunet_common.h"
 #include "gnunet_transport_plugin.h"
+
 /**
  * Timeout values for testing
  */
@@ -53,7 +54,34 @@
 #define HTTP_DEFAULT_PORT 80
 #define HTTPS_DEFAULT_PORT 443
 
+enum HTTP_OPTIONS
+{
+                       HTTP_OPTIONS_NONE = 0,
+        HTTP_OPTIONS_VERIFY_CERTIFICATE = 1
+};
 
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * HttpAddress
+ */
+struct HttpAddress
+{
+       /**
+        * Address options
+        */
+       uint32_t options;
+
+       /**
+        * Length of URL located after struct
+        *
+        */
+       uint32_t urlen;
+};
+
+GNUNET_NETWORK_STRUCT_END
+
 struct SplittedHTTPAddress;
 
 struct SplittedHTTPAddress *
@@ -94,6 +122,7 @@
  */
 const char *
 http_common_plugin_address_to_string (void *cls,
+                                                                               
                                                                        char 
*plugin,
                                       const void *addr,
                                       size_t addrlen);
 
@@ -125,10 +154,10 @@
  * @param addrlen length of the address
  * @return the string
  */
-char *
+struct HttpAddress *
 http_common_address_from_socket (const char *protocol,
-                                 const struct sockaddr *addr,
-                                 socklen_t addrlen);
+                                                                               
                                                 const struct sockaddr *addr,
+                                                                               
                                                 socklen_t addrlen);
 
 /**
  * Create a socketaddr from a HTTP address
@@ -144,6 +173,9 @@
 struct sockaddr *
 http_common_socket_from_address (const void *addr, size_t addrlen, int *res);
 
+const char *
+http_common_plugin_address_to_url (void *cls, const void *addr, size_t 
addrlen);
+
 /**
  * Get the length of an address
  *
@@ -151,7 +183,7 @@
  * @return the size
  */
 size_t
-http_common_address_get_size (const void *addr);
+http_common_address_get_size (const struct HttpAddress * addr);
 
 
 /**

Modified: gnunet/src/transport/plugin_transport_http_server.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_server.c 2013-06-27 14:57:58 UTC 
(rev 27658)
+++ gnunet/src/transport/plugin_transport_http_server.c 2013-06-27 15:02:11 UTC 
(rev 27659)
@@ -55,7 +55,6 @@
  */
 struct Plugin;
 
-
 /**
  * Session handle for connections.
  */
@@ -209,6 +208,11 @@
   char *protocol;
 
   /**
+   * My options to be included in the address
+   */
+  uint32_t options;
+
+  /**
    * External address
    */
   char *external_hostname;
@@ -245,7 +249,7 @@
    * External hostname the plugin can be connected to, can be different to
    * the host's FQDN, used e.g. for reverse proxying
    */
-  char *ext_addr;
+  struct HttpAddress *ext_addr;
 
   /**
    * Notify transport only about external address
@@ -377,7 +381,7 @@
    */
   struct HttpAddressWrapper *prev;
 
-  void *addr;
+  struct HttpAddress *address;
 
   size_t addrlen;
 };
@@ -662,7 +666,7 @@
     next = pos->next;
     if (GNUNET_YES == (http_common_cmp_addresses(addr,
                                                  addrlen,
-                                                 pos->addr,
+                                                 pos->address,
                                                  pos->addrlen)))
       return GNUNET_OK;
 
@@ -1021,7 +1025,7 @@
   const union MHD_ConnectionInfo *conn_info;
   struct GNUNET_ATS_Information ats;
 
-  char *addr;
+  struct HttpAddress *addr;
   size_t addr_len;
 
   struct GNUNET_PeerIdentity target;
@@ -1111,7 +1115,7 @@
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Creating new session for peer `%s' connecting from 
`%s'\n",
                      GNUNET_i2s (&target),
-                     http_common_plugin_address_to_string (NULL, addr, 
addr_len));
+                     http_common_plugin_address_to_string (NULL,  p->protocol, 
addr, addr_len));
 
     s = GNUNET_malloc (sizeof (struct Session));
     memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity));
@@ -1313,7 +1317,7 @@
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Peer `%s' address `%s' next read delayed for %llu ms\n",
                      GNUNET_i2s (&s->target),
-                     http_common_plugin_address_to_string (NULL, s->addr, 
s->addrlen),
+                     http_common_plugin_address_to_string (NULL,  p->protocol, 
s->addr, s->addrlen),
                      delay);
   }
   server_reschedule_session_timeout (s);
@@ -1420,6 +1424,7 @@
                        s, sc,
                        GNUNET_i2s (&s->target),
                        http_common_plugin_address_to_string (NULL,
+                                                                               
                                                                                
    p->protocol,
                                                              s->addr,
                                                              s->addrlen));
       sc->connected = GNUNET_YES;
@@ -1433,6 +1438,7 @@
                        s, sc,
                        GNUNET_i2s (&s->target),
                        http_common_plugin_address_to_string (NULL,
+                                                                               
                                                                                
          p->protocol,
                                                              s->addr,
                                                              s->addrlen));
       sc->connected = GNUNET_NO;
@@ -1452,6 +1458,7 @@
                        s, sc,
                        GNUNET_i2s (&s->target),
                        http_common_plugin_address_to_string (NULL,
+                                                                               
                                                                                
    p->protocol,
                                                              s->addr,
                                                              s->addrlen),
                        *upload_data_size);
@@ -1532,7 +1539,7 @@
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Peer `%s' connection  %p, GET on address `%s' 
disconnected\n",
                      GNUNET_i2s (&s->target), s->server_send,
-                     http_common_plugin_address_to_string (NULL, s->addr, 
s->addrlen));
+                     http_common_plugin_address_to_string (NULL,  p->protocol, 
s->addr, s->addrlen));
     s->server_send = NULL;
     if (NULL != (s->server_recv))
     {
@@ -1550,7 +1557,7 @@
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Peer `%s' connection %p PUT on address `%s' 
disconnected\n",
                      GNUNET_i2s (&s->target), s->server_recv,
-                     http_common_plugin_address_to_string (NULL, s->addr, 
s->addrlen));
+                     http_common_plugin_address_to_string (NULL,  p->protocol, 
s->addr, s->addrlen));
     s->server_recv = NULL;
     /* Do not terminate session when PUT disconnects
     if (NULL != (s->server_send))
@@ -1578,7 +1585,7 @@
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Peer `%s' on address `%s' disconnected\n",
                      GNUNET_i2s (&s->target),
-                     http_common_plugin_address_to_string (NULL, s->addr, 
s->addrlen));
+                     http_common_plugin_address_to_string (NULL,  p->protocol, 
s->addr, s->addrlen));
 
     if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended))
     {
@@ -2152,22 +2159,22 @@
   struct HttpAddressWrapper *w = NULL;
 
   w = GNUNET_malloc (sizeof (struct HttpAddressWrapper));
-  w->addr = http_common_address_from_socket (plugin->protocol, addr, addrlen);
-  if (NULL == w->addr)
+  w->address = http_common_address_from_socket (plugin->protocol, addr, 
addrlen);
+  if (NULL == w->address)
   {
     GNUNET_free (w);
     return;
   }
-  w->addrlen = http_common_address_get_size (w->addr);
+  w->addrlen = http_common_address_get_size (w->address);
 
   GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w);
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "Notifying transport to add address `%s'\n",
-                   http_common_plugin_address_to_string(NULL, w->addr, 
w->addrlen));
+                   http_common_plugin_address_to_string (NULL,  p->protocol, 
w->address, w->addrlen));
 #if BUILD_HTTPS
-  plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, 
w->addrlen, "https_client");
+  plugin->env->notify_address (plugin->env->cls, add_remove, w->address, 
w->addrlen, "https_client");
 #else
-  plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, 
w->addrlen, "http_client");
+  plugin->env->notify_address (plugin->env->cls, add_remove, w->address, 
w->addrlen, "http_client");
 #endif
 }
 
@@ -2194,7 +2201,7 @@
 
   while (NULL != w)
   {
-      if (GNUNET_YES == http_common_cmp_addresses(w->addr, w->addrlen, saddr, 
saddr_len))
+      if (GNUNET_YES == http_common_cmp_addresses(w->address, w->addrlen, 
saddr, saddr_len))
         break;
       w = w->next;
   }
@@ -2205,14 +2212,14 @@
 
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "Notifying transport to remove address `%s'\n",
-                   http_common_plugin_address_to_string (NULL, w->addr, 
w->addrlen));
+                   http_common_plugin_address_to_string (NULL,  p->protocol, 
w->address, w->addrlen));
   GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
 #if BUILD_HTTPS
-  plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, 
w->addrlen, "https_client");
+  plugin->env->notify_address (plugin->env->cls, add_remove, w->address, 
w->addrlen, "https_client");
 #else
-  plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, 
w->addrlen, "http_client");
+  plugin->env->notify_address (plugin->env->cls, add_remove, w->address, 
w->addrlen, "http_client");
 #endif
-  GNUNET_free (w->addr);
+  GNUNET_free (w->address);
   GNUNET_free (w);
 }
 
@@ -2533,7 +2540,7 @@
   {
     w = plugin->addr_head;
     GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
-    GNUNET_free (w->addr);
+    GNUNET_free (w->address);
     GNUNET_free (w);
   }
 }
@@ -2588,30 +2595,29 @@
 server_notify_external_hostname (void *cls, const struct 
GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct HTTP_Server_Plugin *plugin = cls;
+  unsigned int urlen;
+  char *url;
 
   plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
-
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
 
+  GNUNET_asprintf(&url, "%s://%s", plugin->protocol, 
plugin->external_hostname);
 
-#if BUILD_HTTPS
-  GNUNET_asprintf(&plugin->ext_addr, "%s%s://%s", plugin->protocol,
-               (GNUNET_YES == plugin->verify_external_hostname) ? "+" : "",
-               plugin->external_hostname);
-#else
-  GNUNET_asprintf(&plugin->ext_addr, "%s://%s", plugin->protocol,
-               plugin->external_hostname);
-#endif
-
-  plugin->ext_addr_len = strlen (plugin->ext_addr) + 1;
+  urlen = strlen (url) + 1;
+  plugin->ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
+  plugin->ext_addr->options = htonl(plugin->options);
+  plugin->ext_addr->urlen = htonl (urlen);
+  plugin->ext_addr_len = sizeof (struct HttpAddress) + urlen;
+  memcpy (&plugin->ext_addr[1], url, urlen);
+  GNUNET_free (url);
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "Notifying transport about external hostname address 
`%s'\n", plugin->ext_addr);
 
 #if BUILD_HTTPS
   if (GNUNET_YES == plugin->verify_external_hostname)
     GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name,
-                     "Enabling SSL verification for external hostname address 
`%s'\n", plugin->ext_addr);
+                     "Enabling SSL verification for external hostname address 
`%s'\n", plugin->external_hostname);
   plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
                                plugin->ext_addr, plugin->ext_addr_len,
                                "https_client");
@@ -2756,6 +2762,8 @@
                                                                                
                                                                                
"VERIFY_EXTERNAL_HOSTNAME");
   if (GNUNET_SYSERR == plugin->verify_external_hostname)
        plugin->verify_external_hostname = GNUNET_NO;
+  if (GNUNET_YES == plugin->verify_external_hostname)
+       plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE;
 #endif
 
   if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 
plugin->name,
@@ -2908,6 +2916,7 @@
       GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                        "Notifying transport to remove address `%s'\n",
                        http_common_plugin_address_to_string (NULL,
+                                 p->protocol,
                            plugin->ext_addr,
                            plugin->ext_addr_len));
 #if BUILD_HTTPS
@@ -2961,7 +2970,14 @@
   return NULL;
 }
 
+const char *http_plugin_address_to_string (void *cls,
+                                           const void *addr,
+                                           size_t addrlen)
+{
+       return http_common_plugin_address_to_string (cls, p->protocol, addr, 
addrlen);
+}
 
+
 /**
  * Entry point for the plugin.
  *
@@ -2985,7 +3001,7 @@
        initialze the plugin or the API */
     api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
     api->cls = NULL;
-    api->address_to_string = &http_common_plugin_address_to_string;
+    api->address_to_string = &http_plugin_address_to_string;
     api->string_to_address = &http_common_plugin_string_to_address;
     api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
     return api;
@@ -2998,7 +3014,7 @@
   api->check_address = &http_server_plugin_address_suggested;
   api->get_session = &http_server_plugin_get_session;
 
-  api->address_to_string = &http_common_plugin_address_to_string;
+  api->address_to_string = &http_plugin_address_to_string;
   api->string_to_address = &http_common_plugin_string_to_address;
   api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
 




reply via email to

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