Added transition code for new MESH API
[oweals/gnunet.git] / src / mesh / mesh_api_new.c
index 7c45cd7b8b13b1f7334e7f18a44bc8a6cbf5d542..1d25868255317b70bd62aaed6b53888d980b380a 100644 (file)
@@ -45,7 +45,7 @@ extern "C"
 #include "mesh.h"
 #include "mesh_protocol.h"
 
-#define DEBUG GNUNET_YES
+#define MESH_API_DEBUG GNUNET_YES
 
 #define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__)
 
@@ -618,7 +618,7 @@ send_connect (struct GNUNET_MESH_Handle *h)
       types[ntypes] = htons (h->message_handlers[ntypes].type);
     msg->applications = htons (napps);
     msg->types = htons (ntypes);
-#if DEBUG
+#if MESH_API_DEBUG
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "mesh: Sending %lu bytes long message %d types and %d apps\n",
          ntohs (msg->header.size), ntypes, napps);
@@ -642,7 +642,7 @@ reconnect (struct GNUNET_MESH_Handle *h)
   struct GNUNET_MESH_Tunnel *t;
   unsigned int i;
 
-#if DEBUG
+#if MESH_API_DEBUG
   LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
   LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *******   RECONNECT   *******\n");
   LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
@@ -683,6 +683,14 @@ reconnect (struct GNUNET_MESH_Handle *h)
     struct GNUNET_MESH_TunnelMessage tmsg;
     struct GNUNET_MESH_PeerControl pmsg;
 
+    if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
+    {
+      /* Tunnel was created by service (incoming tunnel) */
+      /* TODO: Notify service of missing tunnel, to request
+       * creator to recreate path (find a path to him via DHT?)
+       */
+      continue;
+    }
     tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
     tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
     tmsg.tunnel_id = htonl (t->tid);
@@ -753,7 +761,7 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h,
   MESH_TunnelNumber tid;
 
   tid = ntohl (msg->tunnel_id);
-  if (tid <= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI)
+  if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
   {
     GNUNET_break (0);
     return;
@@ -938,7 +946,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
         GNUNET_MESH_disconnect (h);
         return;
       }
-#if DEBUG
+#if MESH_API_DEBUG
       else
       {
         LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1470,7 +1478,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
   uint32_t least_priority;
   size_t overhead;
 
-#if DEBUG
+#if MESH_API_DEBUG
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "mesh: mesh notify transmit ready called\n");
   if (NULL != target)
@@ -1567,6 +1575,25 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th)
 }
 
 
+/**
+ * Transition API for tunnel ctx management
+ */
+void
+GNUNET_MESH_tunnel_set_data (struct GNUNET_MESH_Tunnel *tunnel, void *data)
+{
+  tunnel->ctx = data;
+}
+
+/**
+ * Transition API for tunnel ctx management
+ */
+void *
+GNUNET_MESH_tunnel_get_data (struct GNUNET_MESH_Tunnel *tunnel)
+{
+  return tunnel->ctx;
+}
+
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif