aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_pe.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-04-21 15:14:14 +0000
committerChristian Grothoff <christian@grothoff.org>2011-04-21 15:14:14 +0000
commit41700b6cb0345080513d82bdbe2dbe33c8654491 (patch)
treefeab3a7f27cdadd01897239c86cbdd137da55b8f /src/fs/gnunet-service-fs_pe.c
parentbbf3c4e04289295df264539e1017f3778f45f97f (diff)
downloadgnunet-41700b6cb0345080513d82bdbe2dbe33c8654491.tar.gz
gnunet-41700b6cb0345080513d82bdbe2dbe33c8654491.zip
wip
Diffstat (limited to 'src/fs/gnunet-service-fs_pe.c')
-rw-r--r--src/fs/gnunet-service-fs_pe.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c
index b3f46cf45..28036150f 100644
--- a/src/fs/gnunet-service-fs_pe.c
+++ b/src/fs/gnunet-service-fs_pe.c
@@ -121,6 +121,17 @@ static struct GNUNET_CONTAINER_MultiHashMap *plans;
121 121
122 122
123/** 123/**
124 * Figure out when and how to transmit to the given peer.
125 *
126 * @param cls the 'struct GSF_ConnectedPeer' for transmission
127 * @param tc scheduler context
128 */
129static void
130schedule_peer_transmission (void *cls,
131 const struct GNUNET_SCHEDULER_TaskContext *tc);
132
133
134/**
124 * Insert the given request plan into the heap with the appropriate weight. 135 * Insert the given request plan into the heap with the appropriate weight.
125 * 136 *
126 * @param pp associated peer's plan 137 * @param pp associated peer's plan
@@ -156,21 +167,13 @@ plan (struct PeerPlan *pp,
156 rp->hn = GNUNET_CONTAINER_heap_insert (pp->delay_heap, 167 rp->hn = GNUNET_CONTAINER_heap_insert (pp->delay_heap,
157 rp, 168 rp,
158 rp->earliest_transmission.abs_value); 169 rp->earliest_transmission.abs_value);
170 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
171 GNUNET_SCHEDULER_cancel (pp->task);
172 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
159} 173}
160 174
161 175
162/** 176/**
163 * Figure out when and how to transmit to the given peer.
164 *
165 * @param cls the 'struct GSF_ConnectedPeer' for transmission
166 * @param tc scheduler context
167 */
168static void
169schedule_peer_transmission (void *cls,
170 const struct GNUNET_SCHEDULER_TaskContext *tc);
171
172
173/**
174 * Function called to get a message for transmission. 177 * Function called to get a message for transmission.
175 * 178 *
176 * @param cls closure 179 * @param cls closure
@@ -238,7 +241,11 @@ schedule_peer_transmission (void *cls,
238 size_t msize; 241 size_t msize;
239 242
240 pp->task = GNUNET_SCHEDULER_NO_TASK; 243 pp->task = GNUNET_SCHEDULER_NO_TASK;
241 GNUNET_assert (NULL == pp->pth); 244 if (pp->pth != NULL)
245 {
246 GSF_peer_transmit_cancel_ (pp->pth);
247 pp->pth = NULL;
248 }
242 /* move ready requests to priority queue */ 249 /* move ready requests to priority queue */
243 while ( (NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) && 250 while ( (NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) &&
244 (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value == 0) ) 251 (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value == 0) )
@@ -253,7 +260,20 @@ schedule_peer_transmission (void *cls,
253 /* priority heap (still) empty, check for delay... */ 260 /* priority heap (still) empty, check for delay... */
254 rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap); 261 rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap);
255 if (NULL == rp) 262 if (NULL == rp)
256 return; /* both queues empty */ 263 {
264#if DEBUG_FS
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
266 "No active requests for plan %p.\n",
267 pp);
268#endif
269 return; /* both queues empty */
270 }
271#if DEBUG_FS
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Sleeping for %llu ms before retrying requests on plan %p.\n",
274 (unsigned long long) GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission).rel_value,
275 pp);
276#endif
257 pp->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission), 277 pp->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission),
258 &schedule_peer_transmission, 278 &schedule_peer_transmission,
259 pp); 279 pp);
@@ -267,7 +287,7 @@ schedule_peer_transmission (void *cls,
267 rp); 287 rp);
268#endif 288#endif
269 GNUNET_assert (NULL != rp); 289 GNUNET_assert (NULL != rp);
270 msize = GSF_pending_request_get_message_ (rp->pr, 0, NULL); 290 msize = GSF_pending_request_get_message_ (rp->pr, 0, NULL);
271 pp->pth = GSF_peer_transmit_ (pp->cp, 291 pp->pth = GSF_peer_transmit_ (pp->cp,
272 GNUNET_YES, 292 GNUNET_YES,
273 rp->priority, 293 rp->priority,
@@ -322,31 +342,6 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp,
322 prd->rp_tail, 342 prd->rp_tail,
323 rp); 343 rp);
324 plan (pp, rp); 344 plan (pp, rp);
325 if (0 == GNUNET_CONTAINER_heap_get_size (pp->priority_heap))
326 {
327 /* no request that should be done immediately, figure out delay */
328 if (rp != GNUNET_CONTAINER_heap_peek (pp->delay_heap))
329 return; /* did not change delay heap top, no need to do anything */
330 GNUNET_assert (NULL == pp->pth);
331 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
332 GNUNET_SCHEDULER_cancel (pp->task);
333 pp->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission),
334 &schedule_peer_transmission,
335 pp);
336 return;
337 }
338
339 if (pp->pth != NULL)
340 {
341 if (rp != GNUNET_CONTAINER_heap_peek (pp->priority_heap))
342 return; /* did not change priority heap top, no need to do anyhing */
343 GSF_peer_transmit_cancel_ (pp->pth);
344 pp->pth = NULL;
345 }
346 if (GNUNET_SCHEDULER_NO_TASK != pp->task)
347 GNUNET_SCHEDULER_cancel (pp->task);
348 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission,
349 pp);
350} 345}
351 346
352 347