- more new code
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 26 Jan 2012 12:21:37 +0000 (12:21 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 26 Jan 2012 12:21:37 +0000 (12:21 +0000)
src/transport/gnunet-service-transport_neighbours.c
src/transport/plugin_transport_http.c
src/transport/plugin_transport_tcp.c

index a61d9d3715c692823004b9a4851eea051394a97a..e46eb8ea3d1759bfe95c8deeccd350116903473c 100644 (file)
@@ -1363,7 +1363,8 @@ send_connect_ack_continuation (void *cls,
 int
 GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
                                        const struct GNUNET_HELLO_Address
-                                       *address, struct Session *session,
+                                       *address,
+                                       struct Session *session,
                                        const struct GNUNET_ATS_Information *ats,
                                        uint32_t ats_count,
                                        struct GNUNET_BANDWIDTH_Value32NBO
@@ -1442,13 +1443,58 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
     GNUNET_HELLO_address_free (n->address);
   n->address = GNUNET_HELLO_address_copy (address);
   n->address_state = FRESH;
-  n->session = session;
   n->bandwidth_in = bandwidth_in;
   n->bandwidth_out = bandwidth_out;
   GNUNET_SCHEDULER_cancel (n->timeout_task);
   n->timeout_task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
                                     &neighbour_timeout_task, n);
+
+#if TEST_NEW_CODE
+  /* Obtain an session for this address from plugin */
+  papi = GST_plugins_find (address->transport_name);
+  GNUNET_assert (papi != NULL);
+  if (session == NULL)
+  {
+    struct GNUNET_TRANSPORT_PluginFunctions *papi;
+    n->session = papi->get_session (papi->cls, address);
+    /* Session could not be initiated */
+    if (n->session == NULL)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to obtain new session %p for peer `%s' and  address '%s'\n",
+                  n->session, GNUNET_i2s (&n->id), GST_plugins_a2s (n->address));
+
+      GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL);
+
+      if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
+        GNUNET_SCHEDULER_cancel (n->ats_suggest);
+      n->ats_suggest =  GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT,
+                                        ats_suggest_cancel,
+                                        n);
+      GNUNET_ATS_suggest_address (GST_ats, &n->id);
+      GNUNET_HELLO_address_free (n->address);
+      n->address = NULL;
+      return GNUNET_NO;
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Obtained new session %p for peer `%s' and  address '%s'\n",
+                  n->session, GNUNET_i2s (&n->id), GST_plugins_a2s (n->address));
+    }
+  }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Using existing session %p for peer `%s' and  address '%s'\n",
+                n->session, GNUNET_i2s (&n->id), GST_plugins_a2s (n->address));
+    n->session = session;
+  }
+#else
+  n->session = session;
+#endif
+
   switch (n->state)
   {
   case S_NOT_CONNECTED:
index ecf32c943f0fc4b98b455dbff51f29af85ba45bf..f4729811ccac725804eb884a7a8a03fd2c340b68 100644 (file)
@@ -540,7 +540,7 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @return the session or NULL of max connections exceeded
  */
 
-static const struct Session *
+static struct Session *
 http_get_session (void *cls,
                   const struct GNUNET_HELLO_Address *address)
 {
index 19bf8d304ad8a420f4609ef48cd5aa36a8cc8ff7..625747585c628dbde4a7f7216343fa2a9b16dcad 100644 (file)
@@ -1305,7 +1305,8 @@ int session_it (void *cls,
  * @param addrlen length of addr
  * @return the session if the address is valid, NULL otherwise
  */
-const const struct Session * tcp_plugin_create_session (void *cls,
+static struct Session *
+tcp_plugin_create_session (void *cls,
                       const struct GNUNET_HELLO_Address *address)
 {
   struct Plugin * plugin = cls;