fix div by zero
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index e7b221344d160503699d5b5becab33f843d45d71..8c4f33fd0db0202bda93873f9101408a54852533 100644 (file)
@@ -2,20 +2,18 @@
  This file is part of GNUnet.
  Copyright (C) 2010-2016 GNUnet e.V.
 
- GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
 
  GNUnet is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- General Public License for more details.
Affero General Public License for more details.
 
- 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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /**
  * @file transport/gnunet-service-transport.c
@@ -150,11 +148,11 @@ struct TransportClient
 
   /**
    * What type of client is this?
-   */ 
+   */
   enum ClientType type;
 
   union {
-  
+
     /**
      * Peer identity to monitor the addresses of.
      * Zero to monitor all neighbours.  Valid if
@@ -172,21 +170,21 @@ struct TransportClient
        * if we're performing one that has been cancelled).
        */
       struct GST_BlacklistCheck *bc;
-      
+
       /**
        * Set to #GNUNET_YES if we're currently waiting for a reply.
        */
       int waiting_for_reply;
-      
+
       /**
        * #GNUNET_YES if we have to call receive_done for this client
        */
       int call_receive_done;
-            
+
     } blacklist;
-    
+
   } details;
-  
+
 };
 
 
@@ -272,7 +270,7 @@ struct AddressToStringContext
  */
 struct SendTransmitContinuationContext
 {
-  
+
   /**
    * Client that made the request.
    */
@@ -541,6 +539,13 @@ client_disconnect_cb (void *cls,
   GNUNET_CONTAINER_multipeermap_iterate (active_stccs,
                                         &mark_match_down,
                                         tc);
+  for (struct AddressToStringContext *cur = a2s_head;
+       NULL != cur;
+       cur = cur->next)
+  {
+    if (cur->tc == tc)
+      cur->tc = NULL;
+  }
   GNUNET_CONTAINER_DLL_remove (clients_head,
                                clients_tail,
                                tc);
@@ -563,7 +568,7 @@ client_disconnect_cb (void *cls,
                                             bc);
     }
     break;
-  }               
+  }
   GNUNET_free (tc);
 }
 
@@ -607,7 +612,7 @@ notify_client_about_neighbour (void *cls,
 
 /**
  * Initialize a normal client.  We got a start message from this
- * client, add him to the list of clients for broadcasting of inbound
+ * client, add it to the list of clients for broadcasting of inbound
  * messages.
  *
  * @param cls the client
@@ -681,6 +686,8 @@ handle_client_hello (void *cls,
 {
   struct TransportClient *tc = cls;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             "Received HELLO message\n");
   GST_validation_handle_hello (message);
   GNUNET_SERVICE_client_continue (tc->client);
 }
@@ -793,7 +800,7 @@ handle_client_send (void *cls,
                    const struct OutboundMessage *obm)
 {
   static unsigned long long uuid_gen;
-  struct TransportClient *tc = cls;  
+  struct TransportClient *tc = cls;
   const struct GNUNET_MessageHeader *obmm;
   struct SendTransmitContinuationContext *stcc;
 
@@ -864,6 +871,8 @@ transmit_address_to_client (void *cls,
 
   GNUNET_assert ( (GNUNET_OK == res) ||
                   (GNUNET_SYSERR == res) );
+  if (NULL == actx->tc)
+    return;
   if (NULL == buf)
   {
     env = GNUNET_MQ_msg (atsm,
@@ -878,6 +887,7 @@ transmit_address_to_client (void *cls,
       GNUNET_CONTAINER_DLL_remove (a2s_head,
                                    a2s_tail,
                                    actx);
+      GNUNET_free (actx);
       return;
     }
     if (GNUNET_SYSERR == res)
@@ -937,7 +947,7 @@ check_client_address_to_string (void *cls,
     return GNUNET_SYSERR;
   }
   return GNUNET_OK;
-}    
+}
 
 
 /**
@@ -950,7 +960,7 @@ static void
 handle_client_address_to_string (void *cls,
                                 const struct AddressLookupMessage *alum)
 {
-  struct TransportClient *tc = cls;  
+  struct TransportClient *tc = cls;
   struct GNUNET_TRANSPORT_PluginFunctions *papi;
   const char *plugin_name;
   const char *address;
@@ -1308,7 +1318,7 @@ handle_client_monitor_plugins (void *cls,
                               const struct GNUNET_MessageHeader *message)
 {
   struct TransportClient *tc = cls;
-  
+
   GNUNET_SERVICE_client_mark_monitor (tc->client);
   GNUNET_SERVICE_client_disable_continue_warning (tc->client);
   GNUNET_notification_context_add (plugin_nc,
@@ -1690,9 +1700,10 @@ GST_receive_callback (void *cls,
     goto end;
   type = ntohs (message->type);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received message with type %u from peer `%s'\n",
+              "Received message with type %u from peer `%s' at %s\n",
               type,
-              GNUNET_i2s (&address->peer));
+              GNUNET_i2s (&address->peer),
+              GST_plugins_a2s (address));
 
   GNUNET_STATISTICS_update (GST_stats,
                             gettext_noop ("# bytes total received"),
@@ -2162,7 +2173,7 @@ test_connection_ok (void *cls,
 
 /**
  * Initialize a blacklisting client.  We got a blacklist-init
- * message from this client, add him to the list of clients
+ * message from this client, add it to the list of clients
  * to query for blacklisting.
  *
  * @param cls the client
@@ -2226,7 +2237,7 @@ handle_client_set_metric (void *cls,
                          const struct TrafficMetricMessage *tm)
 {
   struct TransportClient *tc = cls;
-  
+
   GST_manipulation_set_metric (tm);
   GNUNET_SERVICE_client_continue (tc->client);
 }
@@ -2375,7 +2386,7 @@ handle_client_blacklist_reply (void *cls,
   bc = tc->details.blacklist.bc;
   tc->details.blacklist.bc = NULL;
   tc->details.blacklist.waiting_for_reply = GNUNET_NO;
-  tc->details.blacklist.call_receive_done = GNUNET_YES; 
+  tc->details.blacklist.call_receive_done = GNUNET_YES;
   if (NULL != bc)
   {
     /* only run this if the blacklist check has not been
@@ -2791,7 +2802,7 @@ run (void *cls,
   GNUNET_assert (NULL != GST_my_private_key);
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-             "My identity is `%4s'\n",
+             "My identity is `%s'\n",
              GNUNET_i2s_full (&GST_my_identity));
 
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
@@ -2808,7 +2819,7 @@ run (void *cls,
 #if HAVE_GETRLIMIT
   {
     struct rlimit r_file;
-  
+
     if (0 == getrlimit (RLIMIT_NOFILE,
                        &r_file))
     {
@@ -2893,7 +2904,7 @@ GNUNET_SERVICE_MAIN
                        GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
                        struct OutboundMessage,
                        NULL),
- GNUNET_MQ_hd_var_size (client_address_to_string,                      
+ GNUNET_MQ_hd_var_size (client_address_to_string,
                        GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
                        struct AddressLookupMessage,
                        NULL),
@@ -2913,7 +2924,7 @@ GNUNET_SERVICE_MAIN
                          GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
                          struct TrafficMetricMessage,
                          NULL),
- GNUNET_MQ_hd_fixed_size (client_monitor_plugins, 
+ GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
                          GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
                          struct GNUNET_MessageHeader,
                          NULL),