gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r11216 - gnunet/src/transport
Date: Thu, 6 May 2010 13:52:54 +0200

Author: wachs
Date: 2010-05-06 13:52:54 +0200 (Thu, 06 May 2010)
New Revision: 11216

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-06 09:59:08 UTC 
(rev 11215)
+++ gnunet/src/transport/plugin_transport_http.c        2010-05-06 11:52:54 UTC 
(rev 11216)
@@ -47,6 +47,8 @@
 
 #define HTTP_TIMEOUT 600
 
+#define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt(c, a, b); if 
(ret != CURLE_OK) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: 
`%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror(ret)); } 
while (0);
+
 /**
  * Text of the response sent back after the last bytes of a PUT
  * request have been received (just to formally obey the HTTP
@@ -161,12 +163,25 @@
  */
 static GNUNET_SCHEDULER_TaskIdentifier http_task_v6;
 
+static char * hd_src ;
 
+
 /**
  * Curl multi for managing client operations.
  */
 static CURLM *curl_multi;
 
+static char * get_url( const struct GNUNET_PeerIdentity * target)
+{
+  return strdup("http://localhost:12389";);
+}
+
+static size_t curl_read_function( void *ptr, size_t size, size_t nmemb, void 
*stream)
+{
+  // strcpy ("Testmessa")
+  return 0;
+}
+
 /**
  * Function that can be used by the transport service to transmit
  * a message using the plugin.
@@ -195,21 +210,68 @@
  */
 static ssize_t
 http_plugin_send (void *cls,
-                      const struct GNUNET_PeerIdentity *
-                      target,
-                      const char *msgbuf,
-                      size_t msgbuf_size,
-                      unsigned int priority,
-                      struct GNUNET_TIME_Relative timeout,
-                     struct Session *session,
-                      const void *addr,
-                      size_t addrlen,
-                      int force_address,
-                      GNUNET_TRANSPORT_TransmitContinuation
-                      cont, void *cont_cls)
+                  const struct GNUNET_PeerIdentity * target,
+                  const char *msgbuf,
+                  size_t msgbuf_size,
+                  unsigned int priority,
+                  struct GNUNET_TIME_Relative timeout,
+                  struct Session *session,
+                  const void *addr,
+                  size_t addrlen,
+                  int force_address,
+                  GNUNET_TRANSPORT_TransmitContinuation cont,
+                  void *cont_cls)
 {
+  char * peer_url = get_url( target );
+  CURL *curl;
+  CURLcode ret;
+
   int bytes_sent = 0;
   /*  struct Plugin *plugin = cls; */
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending %u bytes (`%s') to 
`%s'\n",msgbuf_size, msgbuf,GNUNET_i2s(target));
+  /* Insert code to send using cURL */
+  curl = curl_easy_init ();
+
+  CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1);
+  CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4);
+
+   /* setting put options */
+  CURL_EASY_SETOPT (curl, CURLOPT_UPLOAD, 1L);
+  CURL_EASY_SETOPT (curl, CURLOPT_PUT, 1L);
+  CURL_EASY_SETOPT (curl, CURLOPT_READDATA, msgbuf);
+
+
+  /* no need to abort if the above failed */
+  CURL_EASY_SETOPT (curl,
+                    CURLOPT_URL,
+                    peer_url);
+  if (ret != CURLE_OK)
+    {
+      /* clean_up (); */
+      return 0;
+    }
+  CURL_EASY_SETOPT (curl,
+                    CURLOPT_FAILONERROR,
+                    1);
+#if 0
+  CURL_EASY_SETOPT (curl,
+                    CURLOPT_VERBOSE,
+                    1);
+#endif
+  CURL_EASY_SETOPT (curl,
+                    CURLOPT_BUFFERSIZE,
+                    GNUNET_SERVER_MAX_MESSAGE_SIZE);
+  if (0 == strncmp (peer_url, "http", 4))
+    CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet");
+  CURL_EASY_SETOPT (curl,
+                    CURLOPT_CONNECTTIMEOUT,
+                    60L);
+  CURL_EASY_SETOPT (curl,
+                    CURLOPT_TIMEOUT,
+                    60L);
+
+  GNUNET_free(peer_url);
   return bytes_sent;
 }
 
@@ -510,34 +572,26 @@
     }
   if ((http_daemon_v4 == NULL) && (http_daemon_v6 == NULL) && (port != 0))
     {
+      http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6,
+                                         port,
+                                         &acceptPolicyCallback,
+                                         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,
+                                         MHD_OPTION_CONNECTION_MEMORY_LIMIT, 
(size_t) (16 * 1024),
+                                         MHD_OPTION_END);
       http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG,
-                                     port,
-                                     &acceptPolicyCallback,
-                                     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,
-                                     MHD_OPTION_CONNECTION_MEMORY_LIMIT, 
(size_t) (16 * 1024),
-                                     MHD_OPTION_END);
-      http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6,
-                                     port,
-                                     &acceptPolicyCallback,
-                                     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,
-                                     MHD_OPTION_CONNECTION_MEMORY_LIMIT, 
(size_t) (16 * 1024),
-                                     MHD_OPTION_END);
+                                         port,
+                                         &acceptPolicyCallback,
+                                         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,
+                                         MHD_OPTION_CONNECTION_MEMORY_LIMIT, 
(size_t) (16 * 1024),
+                                         MHD_OPTION_END);
     }
 
-
-  if ((http_daemon_v4 != NULL) && (http_daemon_v6 != NULL))
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv4 and 
IPv6 enabled\n",port);
-  if ((http_daemon_v4 != NULL) && (http_daemon_v6 == NULL))
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv4 
enabled\n",port);
-  if ((http_daemon_v4 == NULL) && (http_daemon_v6 != NULL))
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with IPv6 
enabled\n",port);
-
   curl_multi = curl_multi_init ();
 
   if (http_daemon_v4 != NULL)
@@ -545,6 +599,10 @@
   if (http_daemon_v6 != NULL)
     http_task_v6 = prepare_daemon (http_daemon_v6);
 
+  if ((http_daemon_v4 == NULL) || (http_daemon_v6 != NULL))
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u\n",port);
+
+
   if (NULL == plugin->env->stats)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,

Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-05-06 09:59:08 UTC 
(rev 11215)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-05-06 11:52:54 UTC 
(rev 11216)
@@ -46,6 +46,7 @@
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
+
 /**
  * Our public key.
  */
@@ -139,7 +140,7 @@
                                        api));
   if (my_private_key != NULL)
     GNUNET_CRYPTO_rsa_key_free (my_private_key);
-
+  GNUNET_SCHEDULER_shutdown(sched);
   return;
 }
 
@@ -225,7 +226,6 @@
   stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
   env.stats = stats;
 
-  /*
   max_connect_per_transport = (uint32_t) tneigh;
   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
   GNUNET_free (keyfile);
@@ -240,7 +240,7 @@
     }
   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);*/
+                      sizeof (my_public_key), &my_identity.hashPubKey);
 
   /* load plugins... */
   setup_plugin_environment ();
@@ -263,6 +263,12 @@
 
     }
   fail = GNUNET_NO;
+
+  char * test_message  = "Hello World!";
+  size_t size = strlen(test_message) +1;
+
+  /* Testing to send */
+  api->send(NULL, &my_identity,test_message,size,0, TIMEOUT, NULL, NULL, 0, 
GNUNET_NO, NULL, NULL);
   shutdown_clean ();
   return;
 }





reply via email to

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