+/**
+ * Closure for merge_pr().
+ */
+struct MergeContext
+{
+
+ struct GSF_PendingRequest *pr;
+
+ int merged;
+
+};
+
+
+/**
+ * Iterator that checks if an equivalent request is already
+ * present for this peer.
+ *
+ * @param cls closure
+ * @param query the query
+ * @param element request plan stored at the node
+ * @return #GNUNET_YES if we should continue to iterate,
+ * #GNUNET_NO if not (merge success)
+ */
+static int
+merge_pr (void *cls, const struct GNUNET_HashCode * query, void *element)
+{
+ struct MergeContext *mpr = cls;
+ struct GSF_RequestPlan *rp = element;
+ struct GSF_PendingRequestData *prd;
+ struct GSF_PendingRequestPlanBijection *bi;
+ struct GSF_PendingRequest *latest;
+
+ if (GNUNET_OK !=
+ GSF_pending_request_is_compatible_ (mpr->pr, rp->pe_head->pr))
+ return GNUNET_YES;
+ /* merge new request with existing request plan */
+ bi = GNUNET_new (struct GSF_PendingRequestPlanBijection);
+ bi->rp = rp;
+ bi->pr = mpr->pr;
+ prd = GSF_pending_request_get_data_ (mpr->pr);
+ GNUNET_CONTAINER_MDLL_insert (PR, prd->pr_head, prd->pr_tail, bi);
+ GNUNET_CONTAINER_MDLL_insert (PE, rp->pe_head, rp->pe_tail, bi);
+ mpr->merged = GNUNET_YES;
+#if INSANE_STATISTICS
+ GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# requests merged"), 1,
+ GNUNET_NO);
+#endif
+ latest = get_latest (rp);
+ if (GSF_pending_request_get_data_ (latest)->ttl.abs_value_us <
+ prd->ttl.abs_value_us)
+ {
+#if INSANE_STATISTICS
+ GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# requests refreshed"),
+ 1, GNUNET_NO);
+#endif
+ rp->transmission_counter = 0; /* reset */
+ }
+ return GNUNET_NO;
+}
+
+