gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27836 - in gnunet/src: include transport


From: gnunet
Subject: [GNUnet-SVN] r27836 - in gnunet/src: include transport
Date: Tue, 9 Jul 2013 17:23:13 +0200

Author: wachs
Date: 2013-07-09 17:23:13 +0200 (Tue, 09 Jul 2013)
New Revision: 27836

Modified:
   gnunet/src/include/gnunet_transport_plugin.h
   gnunet/src/transport/gnunet-service-transport_neighbours.c
   gnunet/src/transport/plugin_transport_tcp.c
Log:
new api function to get network for session


Modified: gnunet/src/include/gnunet_transport_plugin.h
===================================================================
--- gnunet/src/include/gnunet_transport_plugin.h        2013-07-09 15:13:38 UTC 
(rev 27835)
+++ gnunet/src/include/gnunet_transport_plugin.h        2013-07-09 15:23:13 UTC 
(rev 27836)
@@ -494,6 +494,17 @@
 
 
 /**
+ * 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
+ */
+typedef int (*GNUNET_TRANSPORT_GetNetworkType) (void *cls,
+                                                void *session);
+
+
+/**
  * Each plugin is required to return a pointer to a struct of this
  * type as the return value from its entry point.
  */
@@ -556,6 +567,12 @@
    * object
    */
   GNUNET_TRANSPORT_CreateSession get_session;
+
+
+  /**
+   * Function to obtain the network type for a session
+   */
+  GNUNET_TRANSPORT_GetNetworkType get_network;
 };
 
 

Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c  2013-07-09 
15:13:38 UTC (rev 27835)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c  2013-07-09 
15:23:13 UTC (rev 27836)
@@ -1925,6 +1925,9 @@
 {
   struct BlackListCheckContext *bcc = cls;
   struct NeighbourMapEntry *n;
+  struct GNUNET_TRANSPORT_PluginFunctions *papi;
+       struct GNUNET_ATS_Information ats;
+       int net;
 
   bcc->bc = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1990,10 +1993,29 @@
     if (GNUNET_OK == result)
     {
       /* valid new address, let ATS know! */
-      GNUNET_ATS_address_add (GST_ats,
-                              bcc->na.address,
-                              bcc->na.session,
-                              NULL, 0);
+      GNUNET_assert (bcc->na.address->transport_name != NULL);
+      if (NULL == (papi = GST_plugins_find (bcc->na.address->transport_name)))
+      {
+        /* we don't have the plugin for this address */
+       GNUNET_break (0);
+      }
+      else
+      {
+       if (NULL != papi->get_network)
+       {
+               net = papi->get_network (NULL, bcc->na.session);
+               ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
+               ats.value = net;
+//                     GNUNET_break (0);
+//                     fprintf (stderr, "NET: %u\n", ntohl(net));
+               GNUNET_ATS_address_add (GST_ats,
+                                                                               
                                                bcc->na.address,
+                                                                               
                                                bcc->na.session,
+                                                                               
                                                &ats, 1);
+       }
+       else
+               GNUNET_break (0);
+      }
     }
     n->state = S_CONNECT_RECV_ATS;
     n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
@@ -2755,6 +2777,9 @@
   const struct SessionConnectMessage *scm;
   struct GNUNET_TIME_Absolute ts;
   struct NeighbourMapEntry *n;
+  struct GNUNET_TRANSPORT_PluginFunctions *papi;
+       struct GNUNET_ATS_Information ats;
+       int net;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received CONNECT_ACK message from peer `%s'\n",
@@ -2802,10 +2827,29 @@
                        n->primary_address.bandwidth_in,
                        n->primary_address.bandwidth_out);
     /* Tell ATS that the outbound session we created to send CONNECT was 
successfull */
-    GNUNET_ATS_address_add (GST_ats,
-                            n->primary_address.address,
-                            n->primary_address.session,
-                            NULL, 0);
+    GNUNET_assert (n->primary_address.address->transport_name != NULL);
+    if (NULL == (papi = GST_plugins_find 
(n->primary_address.address->transport_name)))
+    {
+      /* we don't have the plugin for this address */
+       GNUNET_break (0);
+    }
+    else
+    {
+       if (NULL != papi->get_network)
+       {
+               net = papi->get_network (NULL, n->primary_address.session);
+               ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
+               ats.value = net;
+//             GNUNET_break (0);
+//             fprintf (stderr, "NET: %u\n", ntohl(net));
+        GNUNET_ATS_address_add (GST_ats,
+                                n->primary_address.address,
+                                n->primary_address.session,
+                                &ats, 1);
+       }
+       else
+               GNUNET_break (0);
+    }
     set_address (&n->primary_address,
                 n->primary_address.address,
                 n->primary_address.session,
@@ -2850,10 +2894,31 @@
     n->state = S_CONNECTED;
     n->timeout = GNUNET_TIME_relative_to_absolute 
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
     GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
-    GNUNET_ATS_address_add(GST_ats,
-                           n->alternative_address.address,
-                           n->alternative_address.session,
-                           NULL, 0);
+
+    GNUNET_assert (n->alternative_address.address->transport_name != NULL);
+    if (NULL == (papi = GST_plugins_find 
(n->alternative_address.address->transport_name)))
+    {
+      /* we don't have the plugin for this address */
+       GNUNET_break (0);
+    }
+    else
+    {
+       if (NULL != papi->get_network)
+       {
+               net = papi->get_network (NULL, n->alternative_address.session);
+               ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
+               ats.value = net;
+//             GNUNET_break (0);
+//             fprintf (stderr, "NET: %u\n", ntohl(net));
+        GNUNET_ATS_address_add (GST_ats,
+                                n->alternative_address.address,
+                                n->alternative_address.session,
+                                &ats, 1);
+       }
+       else
+               GNUNET_break (0);
+    }
+
     set_address (&n->primary_address,
                 n->alternative_address.address,
                 n->alternative_address.session,
@@ -3060,10 +3125,32 @@
   connect_notify_cb (callback_cls, &n->id,
                      n->primary_address.bandwidth_in,
                      n->primary_address.bandwidth_out);
-  GNUNET_ATS_address_add(GST_ats,
-                         n->primary_address.address,
-                         n->primary_address.session,
-                         NULL, 0);
+
+  GNUNET_assert (n->primary_address.address->transport_name != NULL);
+  struct GNUNET_TRANSPORT_PluginFunctions *papi;
+  if (NULL == (papi = GST_plugins_find 
(n->primary_address.address->transport_name)))
+  {
+    /* we don't have the plugin for this address */
+       GNUNET_break (0);
+  }
+  else
+  {
+       if (NULL != papi->get_network)
+       {
+               int net = papi->get_network (NULL, n->primary_address.session);
+               struct GNUNET_ATS_Information ats;
+               ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
+               ats.value = net;
+//             GNUNET_break (0);
+//             fprintf (stderr, "NET: %u\n", ntohl(net));
+      GNUNET_ATS_address_add (GST_ats,
+                              n->primary_address.address,
+                              n->primary_address.session,
+                              &ats, 1);
+       }
+       else
+               GNUNET_break (0);
+  }
   set_address (&n->primary_address,
               n->primary_address.address,
               n->primary_address.session,

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2013-07-09 15:13:38 UTC (rev 
27835)
+++ gnunet/src/transport/plugin_transport_tcp.c 2013-07-09 15:23:13 UTC (rev 
27836)
@@ -1938,6 +1938,7 @@
   struct IPv6TcpAddress *t6;
   const struct sockaddr_in *s4;
   const struct sockaddr_in6 *s6;
+  struct GNUNET_ATS_Information ats;
 
   if (0 ==
       memcmp (&wm->clientIdentity, plugin->env->my_identity,
@@ -1945,11 +1946,12 @@
   {
     /* refuse connections from ourselves */
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_break (0);
     return;
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, 
-       "Received %s message from `%4s'\n", "WELCOME",
-       GNUNET_i2s (&wm->clientIdentity));
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Received %s message from `%4s' %p\n", "WELCOME",
+       GNUNET_i2s (&wm->clientIdentity), client);
   GNUNET_STATISTICS_update (plugin->env->stats,
                             gettext_noop ("# TCP WELCOME messages received"), 
1,
                             GNUNET_NO);
@@ -1958,7 +1960,7 @@
   {
     if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG, 
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
           "Found existing session %p for peer `%s'\n",
           session,
           GNUNET_a2s (vaddr, alen));
@@ -1998,34 +2000,43 @@
         session->addrlen = sizeof (struct IPv6TcpAddress);
       }
 
-      struct GNUNET_ATS_Information ats;
       ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen);
       session->ats_address_network_type = ats.value;
-
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+     "Creating new session %p for peer `%s'\n",
+     session,
+     GNUNET_a2s (vaddr, alen));
       GNUNET_free (vaddr);
+      GNUNET_CONTAINER_multihashmap_put (plugin->sessionmap,
+                                      &session->target.hashPubKey,
+                                      session,
+                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+      inc_sessions (plugin, session, __LINE__);
     }
     else
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG, 
           "Did not obtain TCP socket address for incoming connection\n");
+      GNUNET_break (0);
     }
-    GNUNET_CONTAINER_multihashmap_put (plugin->sessionmap, 
-                                      &session->target.hashPubKey, 
-                                      session, 
-                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
-    inc_sessions (plugin, session, __LINE__);
   }
 
   if (session->expecting_welcome != GNUNET_YES)
   {
     GNUNET_break_op (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_break (0);
     return;
   }
   session->last_activity = GNUNET_TIME_absolute_get ();
   session->expecting_welcome = GNUNET_NO;
 
 
+  /* Notify transport and ATS about new session */
+  plugin->env->session_start (NULL, &wm->clientIdentity,
+               PLUGIN_NAME, session->addr, session->addrlen, session, &ats, 1);
+
+
   process_pending_messages (session);
 
   GNUNET_SERVER_client_set_timeout (client,
@@ -2368,7 +2379,21 @@
   }
 }
 
+/**
+ * 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
+ */
+int tcp_get_network (void *cls,
+                     void *session)
+{
+       struct Session *s = (struct Session *) session;
+       return s->ats_address_network_type;
+}
 
+
 /**
  * Entry point for the plugin.
  *
@@ -2502,6 +2527,7 @@
   api->check_address = &tcp_plugin_check_address;
   api->address_to_string = &tcp_address_to_string;
   api->string_to_address = &tcp_string_to_address;
+  api->get_network = &tcp_get_network;
   plugin->service = service;
   if (service != NULL)
   {




reply via email to

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