-fixing main FS build, updating man page of gnunet-pseudonym
[oweals/gnunet.git] / src / fs / gnunet-service-fs_mesh_client.c
index 5acf95ef2a16ee3d807babac8de2dd86db7095a2..d315098578551331374678b5f8fe459f4129bf24 100644 (file)
@@ -155,7 +155,7 @@ struct MeshHandle
 /**
  * Mesh tunnel for creating outbound tunnels.
  */
-static struct GNUNET_MESH_Handle *mesh_tunnel;
+static struct GNUNET_MESH_Handle *mesh_handle;
 
 /**
  * Map from peer identities to 'struct MeshHandles' with mesh
@@ -220,12 +220,13 @@ reset_mesh (struct MeshHandle *mh)
   GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map,
                                         &move_to_pending,
                                         mh);
-  mh->tunnel = GNUNET_MESH_tunnel_create (mesh_tunnel,
-                                       mh,
-                                       &mh->target,
-                                       GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
-                                       GNUNET_YES,
-                                       GNUNET_YES);
+  mh->tunnel = GNUNET_MESH_tunnel_create (mesh_handle,
+                                         mh,
+                                         &mh->target,
+                                         GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
+                                         GNUNET_NO,
+                                         GNUNET_YES);
+  transmit_pending (mh);
 }
 
 
@@ -306,7 +307,10 @@ transmit_sqm (void *cls,
   mh->wh = NULL;
   if (NULL == buf)
   {
-    reset_mesh (mh);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Mesh tunnel to %s failed during transmission attempt, rebuilding\n",
+               GNUNET_i2s (&mh->target));
+    reset_mesh_async (mh);
     return 0;
   }
   sr = mh->pending_head;
@@ -348,6 +352,8 @@ transmit_sqm (void *cls,
 static void
 transmit_pending (struct MeshHandle *mh)
 {
+  if (NULL == mh->tunnel)
+    return;
   if (NULL != mh->wh)
     return;
   mh->wh = GNUNET_MESH_notify_transmit_ready (mh->tunnel, GNUNET_YES /* allow cork */,
@@ -464,6 +470,7 @@ reply_cb (void *cls,
              "Received reply `%s' via mesh from peer %s\n",
              GNUNET_h2s (&query),
              GNUNET_i2s (&mh->target));
+  GNUNET_MESH_receive_done (tunnel);
   GNUNET_STATISTICS_update (GSF_stats,
                            gettext_noop ("# replies received via mesh"), 1,
                            GNUNET_NO);
@@ -517,12 +524,12 @@ get_mesh (const struct GNUNET_PeerIdentity *target)
                                                 mh);
   mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
   mh->target = *target;
-  mh->tunnel = GNUNET_MESH_tunnel_create (mesh_tunnel,
-                                       mh,
-                                       &mh->target,
-                                       GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
-                                       GNUNET_NO,
-                                       GNUNET_YES);
+  mh->tunnel = GNUNET_MESH_tunnel_create (mesh_handle,
+                                         mh,
+                                         &mh->target,
+                                         GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
+                                         GNUNET_NO,
+                                         GNUNET_YES);
   GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap_put (mesh_map,
                                                    &mh->target.hashPubKey,
@@ -680,18 +687,14 @@ GSF_mesh_start_client ()
     { &reply_cb, GNUNET_MESSAGE_TYPE_FS_MESH_REPLY, 0 },
     { NULL, 0, 0 }
   };
-  static const uint32_t ports[] = {
-    GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
-    0
-  };
 
   mesh_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
-  mesh_tunnel = GNUNET_MESH_connect (GSF_cfg,
-                                        NULL,
-                                        NULL,
-                                        &cleaner_cb,
-                                        handlers,
-                                        ports);
+  mesh_handle = GNUNET_MESH_connect (GSF_cfg,
+                                    NULL,
+                                    NULL,
+                                    &cleaner_cb,
+                                    handlers,
+                                    NULL);
 }
 
 
@@ -733,10 +736,10 @@ GSF_mesh_stop_client ()
                                         NULL);
   GNUNET_CONTAINER_multihashmap_destroy (mesh_map);
   mesh_map = NULL;
-  if (NULL != mesh_tunnel)
+  if (NULL != mesh_handle)
   {
-    GNUNET_MESH_disconnect (mesh_tunnel);
-    mesh_tunnel = NULL;
+    GNUNET_MESH_disconnect (mesh_handle);
+    mesh_handle = NULL;
   }
 }