-doxygen
[oweals/gnunet.git] / src / fs / gnunet-service-fs_mesh_client.c
index 3da3a937f70d966a87db9c0ced5cd3be18355594..95e3702741527b2215cc97efd31c4026a861a096 100644 (file)
@@ -92,8 +92,8 @@ struct GSF_MeshRequest
   enum GNUNET_BLOCK_Type type;
 
   /**
-   * Did we transmit this request already? YES if we are
-   * in the 'waiting_map', NO if we are in the 'pending' DLL.
+   * Did we transmit this request already? #GNUNET_YES if we are
+   * in the 'waiting_map', #GNUNET_NO if we are in the 'pending' DLL.
    */
   int was_transmitted;
 };
@@ -115,7 +115,7 @@ struct MeshHandle
   struct GSF_MeshRequest *pending_tail;
 
   /**
-   * Map from query to 'struct GSF_MeshRequest's waiting for
+   * Map from query to `struct GSF_MeshRequest`s waiting for
    * a reply.
    */
   struct GNUNET_CONTAINER_MultiHashMap *waiting_map;
@@ -180,10 +180,10 @@ transmit_pending (struct MeshHandle *mh);
  * Iterator called on each entry in a waiting map to
  * move it back to the pending list.
  *
- * @param cls the 'struct MeshHandle'
+ * @param cls the `struct MeshHandle`
  * @param key the key of the entry in the map (the query)
- * @param value the 'struct GSF_MeshRequest' to move to pending
- * @return GNUNET_YES (continue to iterate)
+ * @param value the `struct GSF_MeshRequest` to move to pending
+ * @return #GNUNET_YES (continue to iterate)
  */
 static int
 move_to_pending (void *cls,
@@ -228,8 +228,7 @@ reset_mesh (struct MeshHandle *mh)
                                          mh,
                                          &mh->target,
                                          GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
-                                         GNUNET_NO,
-                                         GNUNET_YES);
+                                         GNUNET_MESH_OPTION_RELIABLE);
   transmit_pending (mh);
 }
 
@@ -237,7 +236,7 @@ reset_mesh (struct MeshHandle *mh)
 /**
  * Task called when it is time to destroy an inactive mesh channel.
  *
- * @param cls the 'struct MeshHandle' to tear down
+ * @param cls the `struct MeshHandle` to tear down
  * @param tc scheduler context, unused
  */
 static void
@@ -260,7 +259,7 @@ mesh_timeout (void *cls,
 /**
  * Task called when it is time to reset an mesh.
  *
- * @param cls the 'struct MeshHandle' to tear down
+ * @param cls the `struct MeshHandle` to tear down
  * @param tc scheduler context, unused
  */
 static void
@@ -368,7 +367,7 @@ transmit_pending (struct MeshHandle *mh)
 
 
 /**
- * Closure for 'handle_reply'.
+ * Closure for handle_reply().
  */
 struct HandleReplyClosure
 {
@@ -404,9 +403,9 @@ struct HandleReplyClosure
  * Iterator called on each entry in a waiting map to
  * process a result.
  *
- * @param cls the 'struct HandleReplyClosure'
+ * @param cls the `struct HandleReplyClosure`
  * @param key the key of the entry in the map (the query)
- * @param value the 'struct GSF_MeshRequest' to handle result for
+ * @param value the `struct GSF_MeshRequest` to handle result for
  * @return #GNUNET_YES (continue to iterate)
  */
 static int
@@ -433,7 +432,7 @@ handle_reply (void *cls,
  * Functions with this signature are called whenever a complete reply
  * is received.
  *
- * @param cls closure with the 'struct MeshHandle'
+ * @param cls closure with the `struct MeshHandle`
  * @param channel channel handle
  * @param channel_ctx channel context
  * @param message the actual message
@@ -468,6 +467,11 @@ reply_cb (void *cls,
                            &srm[1], msize, &query))
   {
     GNUNET_break_op (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Received bogus reply of type %u with %u bytes via mesh from peer %s\n",
+                type,
+                msize,
+                GNUNET_i2s (&mh->target));
     reset_mesh_async (mh);
     return GNUNET_SYSERR;
   }
@@ -538,8 +542,7 @@ get_mesh (const struct GNUNET_PeerIdentity *target)
                                             mh,
                                             &mh->target,
                                             GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER,
-                                            GNUNET_NO,
-                                            GNUNET_YES);
+                                            GNUNET_MESH_OPTION_RELIABLE);
   GNUNET_assert (mh ==
                  GNUNET_CONTAINER_multipeermap_get (mesh_map,
                                                     target));
@@ -672,6 +675,14 @@ cleaner_cb (void *cls,
   mh->channel = NULL;
   while (NULL != (sr = mh->pending_head))
     GSF_mesh_query_cancel (sr);
+  /* first remove `mh` from the `mesh_map`, so that if the
+     callback from `free_waiting_entry()` happens to re-issue
+     the request, we don't immediately have it back in the
+     `waiting_map`. */
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_CONTAINER_multipeermap_remove (mesh_map,
+                                                      &mh->target,
+                                                      mh));
   GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map,
                                         &free_waiting_entry,
                                         mh);
@@ -681,10 +692,8 @@ cleaner_cb (void *cls,
     GNUNET_SCHEDULER_cancel (mh->timeout_task);
   if (GNUNET_SCHEDULER_NO_TASK != mh->reset_task)
     GNUNET_SCHEDULER_cancel (mh->reset_task);
-  GNUNET_assert (GNUNET_OK ==
-                GNUNET_CONTAINER_multipeermap_remove (mesh_map,
-                                                      &mh->target,
-                                                      mh));
+  GNUNET_assert (0 ==
+                 GNUNET_CONTAINER_multihashmap_size (mh->waiting_map));
   GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map);
   GNUNET_free (mh);
 }