remove output
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
index e2aaaa9e1387cf4cb3eb4cc37088421285659ae7..75daeab71da289a63787799ff21aeee9c4e846db 100644 (file)
  */
 
 #if BUILD_HTTPS
+#define PLUGIN_NAME "https_client"
 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_client_init
 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_client_done
 #else
+#define PLUGIN_NAME "http_client"
 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_client_init
 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done
 #endif
@@ -920,7 +922,6 @@ client_receive_mst_cb (void *cls, void *client,
   atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE);
   atsi.value = s->ats_address_network_type;
   GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
-
   delay = s->plugin->env->receive (plugin->env->cls, &s->target, message,
                                    s, (const char *) s->addr, s->addrlen);
 
@@ -1249,8 +1250,8 @@ client_connect_get (struct Session *s)
        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);
+         curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L);
+         curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L);
        }
        else
        {
@@ -1326,8 +1327,8 @@ client_connect_put (struct Session *s)
        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);
+         curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L);
+         curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L);
        }
        else
        {
@@ -1438,6 +1439,22 @@ client_connect (struct Session *s)
 }
 
 
+/**
+ * Function obtain the network type for a session
+ *
+ * @param cls closure ('struct Plugin*')
+ * @param session the session
+ * @return the network type in HBO or GNUNET_SYSERR
+ */
+static enum GNUNET_ATS_Network_Type
+http_client_get_network (void *cls,
+                        struct Session *session)
+{
+  GNUNET_assert (NULL != session);
+  return ntohl (session->ats_address_network_type);
+}
+
+
 /**
  * Creates a new outbound session the transport service will use to send data to the
  * peer
@@ -1499,9 +1516,11 @@ http_client_plugin_get_session (void *cls,
       //fprintf (stderr, "Address %s is in %s\n", GNUNET_a2s (sa,salen), GNUNET_ATS_print_network_type(ntohl(ats.value)));
       GNUNET_free (sa);
   }
+
   else if (GNUNET_NO == res)
   {
-      ats.value = htonl (GNUNET_ATS_COST_WAN);
+               /* Cannot convert to sockaddr -> is external hostname */
+      ats.value = htonl (GNUNET_ATS_NET_WAN);
   }
 
   if (GNUNET_ATS_NET_UNSPECIFIED == ntohl(ats.value))
@@ -1522,6 +1541,12 @@ http_client_plugin_get_session (void *cls,
   s->put_tmp_disconnected = GNUNET_NO;
   client_start_session_timeout (s);
 
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                   "Created new session %p for `%s' address `%s''\n",
+                   s,
+                   http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen),
+                   GNUNET_i2s (&s->target));
+
   /* add new session */
   GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
 
@@ -1530,7 +1555,7 @@ http_client_plugin_get_session (void *cls,
   {
     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
                      "Cannot connect to peer `%s' address `%s''\n",
-                     http_common_plugin_address_to_string (NULL, plugin->name, s->addr, s->addrlen),
+                     http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen),
                      GNUNET_i2s (&s->target));
     client_delete_session (s);
     return NULL;
@@ -1747,7 +1772,7 @@ 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);
+       return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen);
 }
 
 /**
@@ -1784,7 +1809,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
   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;
-
+  api->get_network = &http_client_get_network;
 
 #if BUILD_HTTPS
   plugin->name = "transport-https_client";