-fix NPE
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index 7dfd994b49df8e3601975b0860fd131aa08c8181..89a1ec4c9166bc813be86ee16b5ae4ce9eda98a6 100644 (file)
@@ -14,8 +14,8 @@
 
  You should have received a copy of the GNU General Public License
  along with GNUnet; see the file COPYING.  If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
  */
 /**
  * @file transport/gnunet-service-transport.c
 /**
  * Information we need for an asynchronous session kill.
  */
-struct SessionKiller
+struct GNUNET_ATS_SessionKiller
 {
   /**
    * Kept in a DLL.
    */
-  struct SessionKiller *next;
+  struct GNUNET_ATS_SessionKiller *next;
 
   /**
    * Kept in a DLL.
    */
-  struct SessionKiller *prev;
+  struct GNUNET_ATS_SessionKiller *prev;
 
   /**
    * Session to kill.
    */
-  struct Session *session;
+  struct GNUNET_ATS_Session *session;
 
   /**
    * Plugin for the session.
@@ -123,12 +123,12 @@ struct GNUNET_TIME_Relative hello_expiration;
 /**
  * Head of DLL of asynchronous tasks to kill sessions.
  */
-static struct SessionKiller *sk_head;
+static struct GNUNET_ATS_SessionKiller *sk_head;
 
 /**
  * Tail of DLL of asynchronous tasks to kill sessions.
  */
-static struct SessionKiller *sk_tail;
+static struct GNUNET_ATS_SessionKiller *sk_tail;
 
 /**
  * Interface scanner determines our LAN address range(s).
@@ -206,7 +206,7 @@ process_hello_update (void *cls,
  */
 static struct GNUNET_TIME_Relative
 process_payload (const struct GNUNET_HELLO_Address *address,
-                 struct Session *session,
+                 struct GNUNET_ATS_Session *session,
                  const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_TIME_Relative ret;
@@ -249,14 +249,14 @@ process_payload (const struct GNUNET_HELLO_Address *address,
 /**
  * Task to asynchronously terminate a session.
  *
- * @param cls the `struct SessionKiller` with the information for the kill
+ * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
  * @param tc scheduler context
  */
 static void
 kill_session_task (void *cls,
                    const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct SessionKiller *sk = cls;
+  struct GNUNET_ATS_SessionKiller *sk = cls;
 
   sk->task = NULL;
   GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
@@ -274,10 +274,10 @@ kill_session_task (void *cls,
  */
 static void
 kill_session (const char *plugin_name,
-              struct Session *session)
+              struct GNUNET_ATS_Session *session)
 {
   struct GNUNET_TRANSPORT_PluginFunctions *plugin;
-  struct SessionKiller *sk;
+  struct GNUNET_ATS_SessionKiller *sk;
 
   for (sk = sk_head; NULL != sk; sk = sk->next)
     if (sk->session == session)
@@ -289,7 +289,7 @@ kill_session (const char *plugin_name,
     return;
   }
   /* need to issue disconnect asynchronously */
-  sk = GNUNET_new (struct SessionKiller);
+  sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
   sk->session = session;
   sk->plugin = plugin;
   sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
@@ -313,7 +313,7 @@ static void
 connect_bl_check_cont (void *cls,
                        const struct GNUNET_PeerIdentity *peer,
                       const struct GNUNET_HELLO_Address *address,
-                      struct Session *session,
+                      struct GNUNET_ATS_Session *session,
                        int result)
 {
   struct GNUNET_MessageHeader *msg = cls;
@@ -365,7 +365,7 @@ connect_bl_check_cont (void *cls,
 struct GNUNET_TIME_Relative
 GST_receive_callback (void *cls,
                       const struct GNUNET_HELLO_Address *address,
-                      struct Session *session,
+                      struct GNUNET_ATS_Session *session,
                       const struct GNUNET_MessageHeader *message)
 {
   const char *plugin_name = cls;
@@ -462,6 +462,10 @@ GST_receive_callback (void *cls,
     GST_neighbours_handle_disconnect_message (&address->peer,
                                               message);
     break;
+  case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
+    GST_neighbours_handle_quota_message (&address->peer,
+                                         message);
+    break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
     GST_neighbours_keepalive (&address->peer,
                               message);
@@ -511,23 +515,31 @@ plugin_env_address_change_notification (void *cls,
   if (GNUNET_YES == add_remove)
   {
     addresses ++;
-    GNUNET_STATISTICS_update (cfg, "# transport addresses", 1, GNUNET_NO);
+    GNUNET_STATISTICS_update (cfg,
+                              "# transport addresses",
+                              1,
+                              GNUNET_NO);
   }
   else if (GNUNET_NO == add_remove)
   {
     if (0 == addresses)
+    {
       GNUNET_break (0);
+    }
     else
     {
       addresses --;
-      GNUNET_STATISTICS_update (cfg, "# transport addresses", -1, GNUNET_NO);
+      GNUNET_STATISTICS_update (cfg,
+                                "# transport addresses",
+                                -1,
+                                GNUNET_NO);
     }
   }
-
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Transport now has %u addresses to communicate\n",
               addresses);
-  GST_hello_modify_addresses (add_remove, address);
+  GST_hello_modify_addresses (add_remove,
+                              address);
 }
 
 
@@ -547,9 +559,9 @@ plugin_env_address_change_notification (void *cls,
 static void
 plugin_env_session_end (void *cls,
                         const struct GNUNET_HELLO_Address *address,
-                        struct Session *session)
+                        struct GNUNET_ATS_Session *session)
 {
-  struct SessionKiller *sk;
+  struct GNUNET_ATS_SessionKiller *sk;
 
   if (NULL == address)
   {
@@ -570,7 +582,8 @@ plugin_env_session_end (void *cls,
               GST_plugins_a2s (address));
 
   GST_neighbours_session_terminated (&address->peer, session);
-  GST_ats_del_session (address, session);
+  GST_ats_del_session (address,
+                       session);
   GST_blacklist_abort_matching (address, session);
 
   for (sk = sk_head; NULL != sk; sk = sk->next)
@@ -601,7 +614,7 @@ static void
 plugin_env_session_start_bl_check_cont (void *cls,
                                         const struct GNUNET_PeerIdentity *peer,
                                        const struct GNUNET_HELLO_Address *address,
-                                       struct Session *session,
+                                       struct GNUNET_ATS_Session *session,
                                         int result)
 {
   if (GNUNET_OK != result)
@@ -633,7 +646,7 @@ plugin_env_session_start_bl_check_cont (void *cls,
 static void
 plugin_env_session_start (void *cls,
                           const struct GNUNET_HELLO_Address *address,
-                          struct Session *session,
+                          struct GNUNET_ATS_Session *session,
                           enum GNUNET_ATS_Network_Type scope)
 {
   struct GNUNET_ATS_Properties prop;
@@ -662,6 +675,7 @@ plugin_env_session_start (void *cls,
        may not know the address yet; add if necessary! */
     /* FIXME: maybe change API here so we just pass scope? */
     memset (&prop, 0, sizeof (prop));
+    GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != scope);
     prop.scope = scope;
     GST_ats_add_inbound_address (address,
                                  session,
@@ -699,7 +713,7 @@ static void
 ats_request_address_change (void *cls,
                             const struct GNUNET_PeerIdentity *peer,
                             const struct GNUNET_HELLO_Address *address,
-                            struct Session *session,
+                            struct GNUNET_ATS_Session *session,
                             struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
                             struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 {