+ struct GNUNET_PeerIdentity id;
+ struct PeerPlan *pp;
+ struct GSF_PendingRequestData *prd;
+ struct GSF_RequestPlan *rp;
+ struct GSF_RequestPlanReference *rpr;
+ struct PendingRequestList *prl;
+ struct MergeContext mpc;
+
+ GNUNET_assert (NULL != cp);
+ GSF_connected_peer_get_identity_ (cp, &id);
+ pp = GNUNET_CONTAINER_multihashmap_get (plans, &id.hashPubKey);
+ if (NULL == pp)
+ {
+ pp = GNUNET_malloc (sizeof (struct PeerPlan));
+ pp->priority_heap =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
+ pp->delay_heap =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ pp->cp = cp;
+ GNUNET_CONTAINER_multihashmap_put (plans, &id.hashPubKey, pp,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+ }
+ mpc.merged = GNUNET_NO;
+ mpc.pr = pr;
+ /* FIXME: O(n) call here, LRN reports this is a performance
+ problem. Try using hash map!? */
+ GNUNET_CONTAINER_heap_iterate (pp->priority_heap, &merge_pr, &mpc);
+ if (mpc.merged != GNUNET_NO)
+ return;
+ GNUNET_CONTAINER_heap_iterate (pp->delay_heap, &merge_pr, &mpc);
+ if (mpc.merged != GNUNET_NO)
+ return;
+ plan_count++;
+ GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# query plan entries"), 1,
+ GNUNET_NO);
+ prd = GSF_pending_request_get_data_ (pr);
+#if DEBUG_FS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Planning transmission of query `%s' to peer `%s'\n",
+ GNUNET_h2s (&prd->query), GNUNET_i2s (&id));
+#endif
+ rp = GNUNET_malloc (sizeof (struct GSF_RequestPlan));
+ rpr = GNUNET_malloc (sizeof (struct GSF_RequestPlanReference));
+ prl = GNUNET_malloc (sizeof (struct PendingRequestList));
+ rpr->rp = rp;
+ rpr->prl = prl;
+ prl->rpr = rpr;
+ prl->pr = pr;
+ GNUNET_CONTAINER_DLL_insert (prd->rpr_head, prd->rpr_tail, rpr);
+ GNUNET_CONTAINER_DLL_insert (rp->prl_head, rp->prl_tail, prl);
+ plan (pp, rp);