add function conv param string
[oweals/gnunet.git] / src / vpn / gnunet-service-vpn.c
index 62d6b3e230e23e3fd23df2828c289122f66d619b..8741aa719b3c5351b5865dc844ef79985cdbc6f5 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.
 */
 
 /**
@@ -83,11 +83,6 @@ struct DestinationChannel
    */
   struct DestinationEntry *destination;
 
-  /**
-   * Pre-allocated channel for this destination, or NULL for none.
-   */
-  struct ChannelState *ts;
-
   /**
    * Destination port this channel state is used for.
    */
@@ -246,12 +241,6 @@ struct ChannelState
    */
   struct ChannelMessageQueueEntry *tmq_tail;
 
-  /**
-   * Destination entry that has a pointer to this channel state;
-   * NULL if this channel state is in the channel map.
-   */
-  struct DestinationChannel *destination_container;
-
   /**
    * Destination to which this channel leads.  Note that
    * this struct is NOT in the destination_map (but a
@@ -552,6 +541,17 @@ free_channel_state (struct ChannelState *ts)
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Cleaning up channel state\n");
+  if (NULL != ts->th)
+  {
+    GNUNET_CADET_notify_transmit_ready_cancel (ts->th);
+    ts->th = NULL;
+  }
+  if (NULL != (channel = ts->channel))
+  {
+    ts->channel = NULL;
+    GNUNET_CADET_channel_destroy (channel);
+    return;
+  }
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# Active channels"),
                            -1, GNUNET_NO);
@@ -564,17 +564,7 @@ free_channel_state (struct ChannelState *ts)
     GNUNET_free (tnq);
   }
   GNUNET_assert (0 == ts->tmq_length);
-  if (NULL != ts->th)
-  {
-    GNUNET_CADET_notify_transmit_ready_cancel (ts->th);
-    ts->th = NULL;
-  }
   GNUNET_assert (NULL == ts->destination.heap_node);
-  if (NULL != (channel = ts->channel))
-  {
-    ts->channel = NULL;
-    GNUNET_CADET_channel_destroy (channel);
-  }
   if (NULL != ts->search)
   {
     GNUNET_REGEX_search_cancel (ts->search);
@@ -596,12 +586,6 @@ free_channel_state (struct ChannelState *ts)
                                                         &key,
                                                         ts));
   }
-  if (NULL != ts->destination_container)
-  {
-    GNUNET_assert (ts == ts->destination_container->ts);
-    ts->destination_container->ts = NULL;
-    ts->destination_container = NULL;
-  }
   GNUNET_free (ts);
 }
 
@@ -629,7 +613,7 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf)
   GNUNET_assert (size >= tnq->len);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending %u bytes via cadet channel\n",
-             tnq->len);
+             (unsigned int) tnq->len);
   GNUNET_CONTAINER_DLL_remove (ts->tmq_head,
                               ts->tmq_tail,
                               tnq);
@@ -664,7 +648,7 @@ send_to_channel (struct ChannelMessageQueueEntry *tnq,
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Queueing %u bytes for transmission via cadet channel\n",
-             tnq->len);
+             (unsigned int) tnq->len);
   GNUNET_assert (NULL != ts->channel);
   GNUNET_CONTAINER_DLL_insert_tail (ts->tmq_head,
                                    ts->tmq_tail,
@@ -796,7 +780,6 @@ create_channel_to_destination (struct DestinationChannel *dt,
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# Cadet channels created"),
                            1, GNUNET_NO);
-  GNUNET_assert (NULL == dt->ts);
   switch (client_af)
   {
   case AF_INET:
@@ -813,8 +796,6 @@ create_channel_to_destination (struct DestinationChannel *dt,
   ts->af = client_af;
   ts->destination = *dt->destination;
   ts->destination.heap_node = NULL; /* copy is NOT in destination heap */
-  dt->ts = ts;
-  ts->destination_container = dt; /* we are referenced from dt */
   if (dt->destination->is_service)
   {
     ts->channel = GNUNET_CADET_channel_create (cadet_handle,
@@ -1102,14 +1083,9 @@ route_packet (struct DestinationEntry *destination,
                 GNUNET_h2s (&key));
     /* need to either use the existing channel from the destination (if still
        available) or create a fresh one */
-    if (NULL == dt->ts)
-      ts = create_channel_to_destination (dt, af);
-    else
-      ts = dt->ts;
+    ts = create_channel_to_destination (dt, af);
     if (NULL == ts)
       return;
-    dt->ts = NULL;
-    ts->destination_container = NULL; /* no longer 'contained' */
     /* now bind existing "unbound" channel to our IP/port tuple */
     ts->protocol = protocol;
     ts->af = af;
@@ -2519,11 +2495,6 @@ free_destination_entry (struct DestinationEntry *de)
     GNUNET_CONTAINER_DLL_remove (de->dt_head,
                                 de->dt_tail,
                                 dt);
-    if (NULL != dt->ts)
-    {
-      free_channel_state (dt->ts);
-      GNUNET_assert (NULL == dt->ts);
-    }
     GNUNET_free (dt);
   }
   if (NULL != de->heap_node)
@@ -2895,11 +2866,9 @@ cleanup_channel (void *cls,
  * Function scheduled as very last function, cleans up after us
  *
  * @param cls unused
- * @param tc unused
  */
 static void
-cleanup (void *cls,
-         const struct GNUNET_SCHEDULER_TaskContext *tc)
+cleanup (void *cls)
 {
   unsigned int i;
 
@@ -3130,9 +3099,8 @@ run (void *cls,
                                       &message_token, NULL, NULL);
   nc = GNUNET_SERVER_notification_context_create (server, 1);
   GNUNET_SERVER_add_handlers (server, service_handlers);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &cleanup,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&cleanup,
+                                NULL);
 }