Don't pass NULL to destroy_route
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet-new_core.c
index 25ffcb3cee88ef92b726098e65fb6e40d9a160d6..9cd6055c24bbfe5afd7673c31bfa8eca5866cee0 100644 (file)
@@ -28,6 +28,7 @@
  *
  * TODO:
  * - properly implement GLOBAL message buffer, instead of per-route buffers
+ * - do NOT use buffering if the route options say no buffer!
  * - Optimization: given BROKEN messages, destroy paths (?)
  */
 #include "platform.h"
@@ -46,6 +47,7 @@
 
 /**
  * Number of messages we are willing to buffer per route.
+ * FIXME: have global buffer pool instead!
  */
 #define ROUTE_BUFFER_SIZE 8
 
@@ -128,6 +130,11 @@ struct CadetRoute
    * Position of this route in the #route_heap.
    */
   struct GNUNET_CONTAINER_HeapNode *hn;
+
+  /**
+   * Options for the route, control buffering.
+   */
+  enum GNUNET_CADET_ChannelOption options;
 };
 
 
@@ -319,6 +326,10 @@ destroy_route (struct CadetRoute *route)
        GNUNET_sh2s (&route->cid.connection_of_tunnel));
   GNUNET_assert (route ==
                  GNUNET_CONTAINER_heap_remove_node (route->hn));
+  GNUNET_assert (GNUNET_YES ==
+                 GNUNET_CONTAINER_multishortmap_remove (routes,
+                                                        &route->cid.connection_of_tunnel,
+                                                        route));
   destroy_direction (&route->prev);
   destroy_direction (&route->next);
   GNUNET_free (route);
@@ -521,7 +532,9 @@ handle_connection_create (void *cls,
   uint16_t size = ntohs (msg->header.size) - sizeof (*msg);
   unsigned int path_length;
   unsigned int off;
+  enum GNUNET_CADET_ChannelOption options;
 
+  options = (enum GNUNET_CADET_ChannelOption) ntohl (msg->options);
   path_length = size / sizeof (struct GNUNET_PeerIdentity);
   /* Initiator is at offset 0. */
   for (off=1;off<path_length;off++)
@@ -585,6 +598,7 @@ handle_connection_create (void *cls,
         GCT_add_inbound_connection (GCP_get_tunnel (origin,
                                                     GNUNET_YES),
                                     &msg->cid,
+                                    (enum GNUNET_CADET_ChannelOption) ntohl (msg->options),
                                     path))
     {
       /* Send back BROKEN: duplicate connection on the same path,
@@ -639,6 +653,7 @@ handle_connection_create (void *cls,
        GNUNET_i2s (&pids[off + 1]),
        off + 1);
   route = GNUNET_new (struct CadetRoute);
+  route->options = options;
   route->cid = msg->cid;
   route->last_use = GNUNET_TIME_absolute_get ();
   dir_init (&route->prev,
@@ -747,11 +762,12 @@ handle_connection_broken (void *cls,
   }
 
   /* We're just an intermediary peer, route the message along its path */
-  route = get_route (&msg->cid);
   route_message (peer,
                  &msg->cid,
                  &msg->header);
-  destroy_route (route);
+  route = get_route (&msg->cid);
+  if (NULL != route)
+    destroy_route (route);
   /* FIXME: also destroy paths we MAY have up to the specified link! */
 }
 
@@ -798,11 +814,12 @@ handle_connection_destroy (void *cls,
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Received CONNECTION_DESTROY for connection %s. Destroying route.\n",
        GNUNET_sh2s (&msg->cid.connection_of_tunnel));
-  route = get_route (&msg->cid);
   route_message (peer,
                  &msg->cid,
                  &msg->header);
-  destroy_route (route);
+  route = get_route (&msg->cid);
+  if (NULL != route)
+    destroy_route (route);
 }