diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/gnunet-service-fs_push.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/fs/gnunet-service-fs_push.c')
-rw-r--r-- | src/fs/gnunet-service-fs_push.c | 385 |
1 files changed, 175 insertions, 210 deletions
diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c index 099010758..108fce5fc 100644 --- a/src/fs/gnunet-service-fs_push.c +++ b/src/fs/gnunet-service-fs_push.c | |||
@@ -112,7 +112,7 @@ struct MigrationReadyPeer | |||
112 | * Handle to peer. | 112 | * Handle to peer. |
113 | */ | 113 | */ |
114 | struct GSF_ConnectedPeer *peer; | 114 | struct GSF_ConnectedPeer *peer; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Handle for current transmission request, | 117 | * Handle for current transmission request, |
118 | * or NULL for none. | 118 | * or NULL for none. |
@@ -181,11 +181,8 @@ static int enabled; | |||
181 | static void | 181 | static void |
182 | delete_migration_block (struct MigrationReadyBlock *mb) | 182 | delete_migration_block (struct MigrationReadyBlock *mb) |
183 | { | 183 | { |
184 | GNUNET_CONTAINER_DLL_remove (mig_head, | 184 | GNUNET_CONTAINER_DLL_remove (mig_head, mig_tail, mb); |
185 | mig_tail, | 185 | GNUNET_PEER_decrement_rcs (mb->target_list, MIGRATION_LIST_SIZE); |
186 | mb); | ||
187 | GNUNET_PEER_decrement_rcs (mb->target_list, | ||
188 | MIGRATION_LIST_SIZE); | ||
189 | mig_size--; | 186 | mig_size--; |
190 | GNUNET_free (mb); | 187 | GNUNET_free (mb); |
191 | } | 188 | } |
@@ -193,9 +190,8 @@ delete_migration_block (struct MigrationReadyBlock *mb) | |||
193 | 190 | ||
194 | /** | 191 | /** |
195 | * Find content for migration to this peer. | 192 | * Find content for migration to this peer. |
196 | */ | 193 | */ |
197 | static void | 194 | static void find_content (struct MigrationReadyPeer *mrp); |
198 | find_content (struct MigrationReadyPeer *mrp); | ||
199 | 195 | ||
200 | 196 | ||
201 | /** | 197 | /** |
@@ -208,9 +204,7 @@ find_content (struct MigrationReadyPeer *mrp); | |||
208 | * @return number of bytes copied to 'buf', can be 0 (without indicating an error) | 204 | * @return number of bytes copied to 'buf', can be 0 (without indicating an error) |
209 | */ | 205 | */ |
210 | static size_t | 206 | static size_t |
211 | transmit_message (void *cls, | 207 | transmit_message (void *cls, size_t buf_size, void *buf) |
212 | size_t buf_size, | ||
213 | void *buf) | ||
214 | { | 208 | { |
215 | struct MigrationReadyPeer *peer = cls; | 209 | struct MigrationReadyPeer *peer = cls; |
216 | struct PutMessage *msg; | 210 | struct PutMessage *msg; |
@@ -220,22 +214,21 @@ transmit_message (void *cls, | |||
220 | msg = peer->msg; | 214 | msg = peer->msg; |
221 | peer->msg = NULL; | 215 | peer->msg = NULL; |
222 | if (buf == NULL) | 216 | if (buf == NULL) |
223 | { | 217 | { |
224 | #if DEBUG_FS_MIGRATION | 218 | #if DEBUG_FS_MIGRATION |
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
226 | "Failed to migrate content to another peer (disconnect)\n"); | 220 | "Failed to migrate content to another peer (disconnect)\n"); |
227 | #endif | 221 | #endif |
228 | GNUNET_free (msg); | 222 | GNUNET_free (msg); |
229 | return 0; | 223 | return 0; |
230 | } | 224 | } |
231 | msize = ntohs (msg->header.size); | 225 | msize = ntohs (msg->header.size); |
232 | GNUNET_assert (msize <= buf_size); | 226 | GNUNET_assert (msize <= buf_size); |
233 | memcpy (buf, msg, msize); | 227 | memcpy (buf, msg, msize); |
234 | GNUNET_free (msg); | 228 | GNUNET_free (msg); |
235 | #if DEBUG_FS_MIGRATION | 229 | #if DEBUG_FS_MIGRATION |
236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
237 | "Pushing %u bytes to another peer\n", | 231 | "Pushing %u bytes to another peer\n", msize); |
238 | msize); | ||
239 | #endif | 232 | #endif |
240 | find_content (peer); | 233 | find_content (peer); |
241 | return msize; | 234 | return msize; |
@@ -251,11 +244,11 @@ transmit_message (void *cls, | |||
251 | */ | 244 | */ |
252 | static int | 245 | static int |
253 | transmit_content (struct MigrationReadyPeer *peer, | 246 | transmit_content (struct MigrationReadyPeer *peer, |
254 | struct MigrationReadyBlock *block) | 247 | struct MigrationReadyBlock *block) |
255 | { | 248 | { |
256 | size_t msize; | 249 | size_t msize; |
257 | struct PutMessage *msg; | 250 | struct PutMessage *msg; |
258 | unsigned int i; | 251 | unsigned int i; |
259 | struct GSF_PeerPerformanceData *ppd; | 252 | struct GSF_PeerPerformanceData *ppd; |
260 | int ret; | 253 | int ret; |
261 | 254 | ||
@@ -267,40 +260,33 @@ transmit_content (struct MigrationReadyPeer *peer, | |||
267 | msg->header.size = htons (msize); | 260 | msg->header.size = htons (msize); |
268 | msg->type = htonl (block->type); | 261 | msg->type = htonl (block->type); |
269 | msg->expiration = GNUNET_TIME_absolute_hton (block->expiration); | 262 | msg->expiration = GNUNET_TIME_absolute_hton (block->expiration); |
270 | memcpy (&msg[1], | 263 | memcpy (&msg[1], &block[1], block->size); |
271 | &block[1], | ||
272 | block->size); | ||
273 | peer->msg = msg; | 264 | peer->msg = msg; |
274 | for (i=0;i<MIGRATION_LIST_SIZE;i++) | 265 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
266 | { | ||
267 | if (block->target_list[i] == 0) | ||
275 | { | 268 | { |
276 | if (block->target_list[i] == 0) | 269 | block->target_list[i] = ppd->pid; |
277 | { | 270 | GNUNET_PEER_change_rc (block->target_list[i], 1); |
278 | block->target_list[i] = ppd->pid; | 271 | break; |
279 | GNUNET_PEER_change_rc (block->target_list[i], 1); | ||
280 | break; | ||
281 | } | ||
282 | } | 272 | } |
273 | } | ||
283 | if (MIGRATION_LIST_SIZE == i) | 274 | if (MIGRATION_LIST_SIZE == i) |
284 | { | 275 | { |
285 | delete_migration_block (block); | 276 | delete_migration_block (block); |
286 | ret = GNUNET_YES; | 277 | ret = GNUNET_YES; |
287 | } | 278 | } |
288 | else | 279 | else |
289 | { | 280 | { |
290 | ret = GNUNET_NO; | 281 | ret = GNUNET_NO; |
291 | } | 282 | } |
292 | #if DEBUG_FS_MIGRATION | 283 | #if DEBUG_FS_MIGRATION |
293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
294 | "Asking for transmission of %u bytes for migration\n", | 285 | "Asking for transmission of %u bytes for migration\n", msize); |
295 | msize); | ||
296 | #endif | 286 | #endif |
297 | peer->th = GSF_peer_transmit_ (peer->peer, | 287 | peer->th = GSF_peer_transmit_ (peer->peer, GNUNET_NO, 0 /* priority */ , |
298 | GNUNET_NO, | 288 | GNUNET_TIME_UNIT_FOREVER_REL, |
299 | 0 /* priority */, | 289 | msize, &transmit_message, peer); |
300 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
301 | msize, | ||
302 | &transmit_message, | ||
303 | peer); | ||
304 | return ret; | 290 | return ret; |
305 | } | 291 | } |
306 | 292 | ||
@@ -317,7 +303,7 @@ count_targets (struct MigrationReadyBlock *block) | |||
317 | { | 303 | { |
318 | unsigned int i; | 304 | unsigned int i; |
319 | 305 | ||
320 | for (i=0;i<MIGRATION_LIST_SIZE;i++) | 306 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
321 | if (block->target_list[i] == 0) | 307 | if (block->target_list[i] == 0) |
322 | return i; | 308 | return i; |
323 | return i; | 309 | return i; |
@@ -334,7 +320,7 @@ count_targets (struct MigrationReadyBlock *block) | |||
334 | */ | 320 | */ |
335 | static long | 321 | static long |
336 | score_content (struct MigrationReadyPeer *peer, | 322 | score_content (struct MigrationReadyPeer *peer, |
337 | struct MigrationReadyBlock *block) | 323 | struct MigrationReadyBlock *block) |
338 | { | 324 | { |
339 | unsigned int i; | 325 | unsigned int i; |
340 | struct GSF_PeerPerformanceData *ppd; | 326 | struct GSF_PeerPerformanceData *ppd; |
@@ -342,14 +328,12 @@ score_content (struct MigrationReadyPeer *peer, | |||
342 | uint32_t dist; | 328 | uint32_t dist; |
343 | 329 | ||
344 | ppd = GSF_get_peer_performance_data_ (peer->peer); | 330 | ppd = GSF_get_peer_performance_data_ (peer->peer); |
345 | for (i=0;i<MIGRATION_LIST_SIZE;i++) | 331 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
346 | if (block->target_list[i] == ppd->pid) | 332 | if (block->target_list[i] == ppd->pid) |
347 | return -1; | 333 | return -1; |
348 | GNUNET_assert (0 != ppd->pid); | 334 | GNUNET_assert (0 != ppd->pid); |
349 | GNUNET_PEER_resolve (ppd->pid, | 335 | GNUNET_PEER_resolve (ppd->pid, &id); |
350 | &id); | 336 | dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, &id.hashPubKey); |
351 | dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, | ||
352 | &id.hashPubKey); | ||
353 | /* closer distance, higher score: */ | 337 | /* closer distance, higher score: */ |
354 | return UINT32_MAX - dist; | 338 | return UINT32_MAX - dist; |
355 | } | 339 | } |
@@ -359,15 +343,14 @@ score_content (struct MigrationReadyPeer *peer, | |||
359 | * If the migration task is not currently running, consider | 343 | * If the migration task is not currently running, consider |
360 | * (re)scheduling it with the appropriate delay. | 344 | * (re)scheduling it with the appropriate delay. |
361 | */ | 345 | */ |
362 | static void | 346 | static void consider_gathering (void); |
363 | consider_gathering (void); | ||
364 | 347 | ||
365 | 348 | ||
366 | /** | 349 | /** |
367 | * Find content for migration to this peer. | 350 | * Find content for migration to this peer. |
368 | * | 351 | * |
369 | * @param mrp peer to find content for | 352 | * @param mrp peer to find content for |
370 | */ | 353 | */ |
371 | static void | 354 | static void |
372 | find_content (struct MigrationReadyPeer *mrp) | 355 | find_content (struct MigrationReadyPeer *mrp) |
373 | { | 356 | { |
@@ -381,51 +364,51 @@ find_content (struct MigrationReadyPeer *mrp) | |||
381 | best_score = -1; | 364 | best_score = -1; |
382 | pos = mig_head; | 365 | pos = mig_head; |
383 | while (NULL != pos) | 366 | while (NULL != pos) |
367 | { | ||
368 | score = score_content (mrp, pos); | ||
369 | if (score > best_score) | ||
384 | { | 370 | { |
385 | score = score_content (mrp, pos); | 371 | best_score = score; |
386 | if (score > best_score) | 372 | best = pos; |
387 | { | ||
388 | best_score = score; | ||
389 | best = pos; | ||
390 | } | ||
391 | pos = pos->next; | ||
392 | } | 373 | } |
393 | if (NULL == best) | 374 | pos = pos->next; |
375 | } | ||
376 | if (NULL == best) | ||
377 | { | ||
378 | if (mig_size < MAX_MIGRATION_QUEUE) | ||
394 | { | 379 | { |
395 | if (mig_size < MAX_MIGRATION_QUEUE) | ||
396 | { | ||
397 | #if DEBUG_FS_MIGRATION | 380 | #if DEBUG_FS_MIGRATION |
398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
399 | "No content found for pushing, waiting for queue to fill\n"); | 382 | "No content found for pushing, waiting for queue to fill\n"); |
400 | #endif | 383 | #endif |
401 | return; /* will fill up eventually... */ | 384 | return; /* will fill up eventually... */ |
402 | } | 385 | } |
403 | #if DEBUG_FS_MIGRATION | 386 | #if DEBUG_FS_MIGRATION |
404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
405 | "No suitable content found, purging content from full queue\n"); | 388 | "No suitable content found, purging content from full queue\n"); |
406 | #endif | 389 | #endif |
407 | /* failed to find migration target AND | 390 | /* failed to find migration target AND |
408 | queue is full, purge most-forwarded | 391 | * queue is full, purge most-forwarded |
409 | block from queue to make room for more */ | 392 | * block from queue to make room for more */ |
410 | pos = mig_head; | 393 | pos = mig_head; |
411 | while (NULL != pos) | 394 | while (NULL != pos) |
412 | { | 395 | { |
413 | score = count_targets (pos); | 396 | score = count_targets (pos); |
414 | if (score >= best_score) | 397 | if (score >= best_score) |
415 | { | 398 | { |
416 | best_score = score; | 399 | best_score = score; |
417 | best = pos; | 400 | best = pos; |
418 | } | 401 | } |
419 | pos = pos->next; | 402 | pos = pos->next; |
420 | } | ||
421 | GNUNET_assert (NULL != best); | ||
422 | delete_migration_block (best); | ||
423 | consider_gathering (); | ||
424 | return; | ||
425 | } | 403 | } |
404 | GNUNET_assert (NULL != best); | ||
405 | delete_migration_block (best); | ||
406 | consider_gathering (); | ||
407 | return; | ||
408 | } | ||
426 | #if DEBUG_FS_MIGRATION | 409 | #if DEBUG_FS_MIGRATION |
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
428 | "Preparing to push best content to peer\n"); | 411 | "Preparing to push best content to peer\n"); |
429 | #endif | 412 | #endif |
430 | transmit_content (mrp, best); | 413 | transmit_content (mrp, best); |
431 | } | 414 | } |
@@ -440,7 +423,7 @@ find_content (struct MigrationReadyPeer *mrp) | |||
440 | */ | 423 | */ |
441 | static void | 424 | static void |
442 | gather_migration_blocks (void *cls, | 425 | gather_migration_blocks (void *cls, |
443 | const struct GNUNET_SCHEDULER_TaskContext *tc); | 426 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
444 | 427 | ||
445 | 428 | ||
446 | /** | 429 | /** |
@@ -458,22 +441,17 @@ consider_gathering () | |||
458 | return; | 441 | return; |
459 | if (mig_task != GNUNET_SCHEDULER_NO_TASK) | 442 | if (mig_task != GNUNET_SCHEDULER_NO_TASK) |
460 | return; | 443 | return; |
461 | if (mig_size >= MAX_MIGRATION_QUEUE) | 444 | if (mig_size >= MAX_MIGRATION_QUEUE) |
462 | return; | 445 | return; |
463 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 446 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, mig_size); |
464 | mig_size); | 447 | delay = GNUNET_TIME_relative_divide (delay, MAX_MIGRATION_QUEUE); |
465 | delay = GNUNET_TIME_relative_divide (delay, | 448 | delay = GNUNET_TIME_relative_max (delay, min_migration_delay); |
466 | MAX_MIGRATION_QUEUE); | ||
467 | delay = GNUNET_TIME_relative_max (delay, | ||
468 | min_migration_delay); | ||
469 | #if DEBUG_FS_MIGRATION | 449 | #if DEBUG_FS_MIGRATION |
470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 450 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
471 | "Scheduling gathering task (queue size: %u)\n", | 451 | "Scheduling gathering task (queue size: %u)\n", mig_size); |
472 | mig_size); | ||
473 | #endif | 452 | #endif |
474 | mig_task = GNUNET_SCHEDULER_add_delayed (delay, | 453 | mig_task = GNUNET_SCHEDULER_add_delayed (delay, |
475 | &gather_migration_blocks, | 454 | &gather_migration_blocks, NULL); |
476 | NULL); | ||
477 | } | 455 | } |
478 | 456 | ||
479 | 457 | ||
@@ -493,53 +471,47 @@ consider_gathering () | |||
493 | */ | 471 | */ |
494 | static void | 472 | static void |
495 | process_migration_content (void *cls, | 473 | process_migration_content (void *cls, |
496 | const GNUNET_HashCode *key, | 474 | const GNUNET_HashCode * key, |
497 | size_t size, | 475 | size_t size, |
498 | const void *data, | 476 | const void *data, |
499 | enum GNUNET_BLOCK_Type type, | 477 | enum GNUNET_BLOCK_Type type, |
500 | uint32_t priority, | 478 | uint32_t priority, |
501 | uint32_t anonymity, | 479 | uint32_t anonymity, |
502 | struct GNUNET_TIME_Absolute | 480 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
503 | expiration, uint64_t uid) | ||
504 | { | 481 | { |
505 | struct MigrationReadyBlock *mb; | 482 | struct MigrationReadyBlock *mb; |
506 | struct MigrationReadyPeer *pos; | 483 | struct MigrationReadyPeer *pos; |
507 | 484 | ||
508 | mig_qe = NULL; | 485 | mig_qe = NULL; |
509 | if (key == NULL) | 486 | if (key == NULL) |
510 | { | 487 | { |
511 | #if DEBUG_FS_MIGRATION | 488 | #if DEBUG_FS_MIGRATION |
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No content found for migration...\n"); |
513 | "No content found for migration...\n"); | ||
514 | #endif | 490 | #endif |
515 | consider_gathering (); | 491 | consider_gathering (); |
516 | return; | 492 | return; |
517 | } | 493 | } |
518 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value < | 494 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value < |
519 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value) | 495 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value) |
520 | { | 496 | { |
521 | /* content will expire soon, don't bother */ | 497 | /* content will expire soon, don't bother */ |
522 | consider_gathering (); | 498 | consider_gathering (); |
523 | return; | 499 | return; |
524 | } | 500 | } |
525 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) | 501 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) |
526 | { | 502 | { |
527 | if (GNUNET_OK != | 503 | if (GNUNET_OK != |
528 | GNUNET_FS_handle_on_demand_block (key, size, data, | 504 | GNUNET_FS_handle_on_demand_block (key, size, data, |
529 | type, priority, anonymity, | 505 | type, priority, anonymity, |
530 | expiration, uid, | 506 | expiration, uid, |
531 | &process_migration_content, | 507 | &process_migration_content, NULL)) |
532 | NULL)) | 508 | consider_gathering (); |
533 | consider_gathering (); | 509 | return; |
534 | return; | 510 | } |
535 | } | ||
536 | #if DEBUG_FS_MIGRATION | 511 | #if DEBUG_FS_MIGRATION |
537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
538 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", | 513 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", |
539 | GNUNET_h2s (key), | 514 | GNUNET_h2s (key), type, mig_size + 1, MAX_MIGRATION_QUEUE); |
540 | type, | ||
541 | mig_size + 1, | ||
542 | MAX_MIGRATION_QUEUE); | ||
543 | #endif | 515 | #endif |
544 | mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size); | 516 | mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size); |
545 | mb->query = *key; | 517 | mb->query = *key; |
@@ -547,25 +519,22 @@ process_migration_content (void *cls, | |||
547 | mb->size = size; | 519 | mb->size = size; |
548 | mb->type = type; | 520 | mb->type = type; |
549 | memcpy (&mb[1], data, size); | 521 | memcpy (&mb[1], data, size); |
550 | GNUNET_CONTAINER_DLL_insert_after (mig_head, | 522 | GNUNET_CONTAINER_DLL_insert_after (mig_head, mig_tail, mig_tail, mb); |
551 | mig_tail, | ||
552 | mig_tail, | ||
553 | mb); | ||
554 | mig_size++; | 523 | mig_size++; |
555 | pos = peer_head; | 524 | pos = peer_head; |
556 | while (pos != NULL) | 525 | while (pos != NULL) |
526 | { | ||
527 | if (NULL == pos->th) | ||
557 | { | 528 | { |
558 | if (NULL == pos->th) | ||
559 | { | ||
560 | #if DEBUG_FS_MIGRATION | 529 | #if DEBUG_FS_MIGRATION |
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
562 | "Preparing to push best content to peer\n"); | 531 | "Preparing to push best content to peer\n"); |
563 | #endif | 532 | #endif |
564 | if (GNUNET_YES == transmit_content (pos, mb)) | 533 | if (GNUNET_YES == transmit_content (pos, mb)) |
565 | break; /* 'mb' was freed! */ | 534 | break; /* 'mb' was freed! */ |
566 | } | ||
567 | pos = pos->next; | ||
568 | } | 535 | } |
536 | pos = pos->next; | ||
537 | } | ||
569 | consider_gathering (); | 538 | consider_gathering (); |
570 | } | 539 | } |
571 | 540 | ||
@@ -579,25 +548,26 @@ process_migration_content (void *cls, | |||
579 | */ | 548 | */ |
580 | static void | 549 | static void |
581 | gather_migration_blocks (void *cls, | 550 | gather_migration_blocks (void *cls, |
582 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 551 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
583 | { | 552 | { |
584 | mig_task = GNUNET_SCHEDULER_NO_TASK; | 553 | mig_task = GNUNET_SCHEDULER_NO_TASK; |
585 | if (mig_size >= MAX_MIGRATION_QUEUE) | 554 | if (mig_size >= MAX_MIGRATION_QUEUE) |
586 | return; | 555 | return; |
587 | if (GSF_dsh != NULL) | 556 | if (GSF_dsh != NULL) |
588 | { | 557 | { |
589 | #if DEBUG_FS_MIGRATION | 558 | #if DEBUG_FS_MIGRATION |
590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
591 | "Asking datastore for content for replication (queue size: %u)\n", | 560 | "Asking datastore for content for replication (queue size: %u)\n", |
592 | mig_size); | 561 | mig_size); |
593 | #endif | 562 | #endif |
594 | mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, | 563 | mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, |
595 | 0, UINT_MAX, | 564 | 0, UINT_MAX, |
596 | GNUNET_TIME_UNIT_FOREVER_REL, | 565 | GNUNET_TIME_UNIT_FOREVER_REL, |
597 | &process_migration_content, NULL); | 566 | &process_migration_content, |
598 | if (NULL == mig_qe) | 567 | NULL); |
599 | consider_gathering (); | 568 | if (NULL == mig_qe) |
600 | } | 569 | consider_gathering (); |
570 | } | ||
601 | } | 571 | } |
602 | 572 | ||
603 | 573 | ||
@@ -617,9 +587,7 @@ GSF_push_start_ (struct GSF_ConnectedPeer *peer) | |||
617 | mrp = GNUNET_malloc (sizeof (struct MigrationReadyPeer)); | 587 | mrp = GNUNET_malloc (sizeof (struct MigrationReadyPeer)); |
618 | mrp->peer = peer; | 588 | mrp->peer = peer; |
619 | find_content (mrp); | 589 | find_content (mrp); |
620 | GNUNET_CONTAINER_DLL_insert (peer_head, | 590 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, mrp); |
621 | peer_tail, | ||
622 | mrp); | ||
623 | } | 591 | } |
624 | 592 | ||
625 | 593 | ||
@@ -636,27 +604,25 @@ GSF_push_stop_ (struct GSF_ConnectedPeer *peer) | |||
636 | 604 | ||
637 | pos = peer_head; | 605 | pos = peer_head; |
638 | while (pos != NULL) | 606 | while (pos != NULL) |
607 | { | ||
608 | if (pos->peer == peer) | ||
639 | { | 609 | { |
640 | if (pos->peer == peer) | 610 | GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos); |
641 | { | 611 | if (NULL != pos->th) |
642 | GNUNET_CONTAINER_DLL_remove (peer_head, | 612 | { |
643 | peer_tail, | 613 | GSF_peer_transmit_cancel_ (pos->th); |
644 | pos); | 614 | pos->th = NULL; |
645 | if (NULL != pos->th) | 615 | } |
646 | { | 616 | if (NULL != pos->msg) |
647 | GSF_peer_transmit_cancel_ (pos->th); | 617 | { |
648 | pos->th = NULL; | 618 | GNUNET_free (pos->msg); |
649 | } | 619 | pos->msg = NULL; |
650 | if (NULL != pos->msg) | 620 | } |
651 | { | 621 | GNUNET_free (pos); |
652 | GNUNET_free (pos->msg); | 622 | return; |
653 | pos->msg = NULL; | ||
654 | } | ||
655 | GNUNET_free (pos); | ||
656 | return; | ||
657 | } | ||
658 | pos = pos->next; | ||
659 | } | 623 | } |
624 | pos = pos->next; | ||
625 | } | ||
660 | } | 626 | } |
661 | 627 | ||
662 | 628 | ||
@@ -667,23 +633,22 @@ void | |||
667 | GSF_push_init_ () | 633 | GSF_push_init_ () |
668 | { | 634 | { |
669 | enabled = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, | 635 | enabled = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, |
670 | "FS", | 636 | "FS", "CONTENT_PUSHING"); |
671 | "CONTENT_PUSHING"); | ||
672 | if (GNUNET_YES != enabled) | 637 | if (GNUNET_YES != enabled) |
673 | return; | 638 | return; |
674 | 639 | ||
675 | if (GNUNET_OK != | 640 | if (GNUNET_OK != |
676 | GNUNET_CONFIGURATION_get_value_time (GSF_cfg, | 641 | GNUNET_CONFIGURATION_get_value_time (GSF_cfg, |
677 | "fs", | 642 | "fs", |
678 | "MIN_MIGRATION_DELAY", | 643 | "MIN_MIGRATION_DELAY", |
679 | &min_migration_delay)) | 644 | &min_migration_delay)) |
680 | { | 645 | { |
681 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 646 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
682 | _("Invalid value specified for option `%s' in section `%s', content pushing disabled\n"), | 647 | _ |
683 | "MIN_MIGRATION_DELAY", | 648 | ("Invalid value specified for option `%s' in section `%s', content pushing disabled\n"), |
684 | "fs"); | 649 | "MIN_MIGRATION_DELAY", "fs"); |
685 | return; | 650 | return; |
686 | } | 651 | } |
687 | consider_gathering (); | 652 | consider_gathering (); |
688 | } | 653 | } |
689 | 654 | ||
@@ -695,15 +660,15 @@ void | |||
695 | GSF_push_done_ () | 660 | GSF_push_done_ () |
696 | { | 661 | { |
697 | if (GNUNET_SCHEDULER_NO_TASK != mig_task) | 662 | if (GNUNET_SCHEDULER_NO_TASK != mig_task) |
698 | { | 663 | { |
699 | GNUNET_SCHEDULER_cancel (mig_task); | 664 | GNUNET_SCHEDULER_cancel (mig_task); |
700 | mig_task = GNUNET_SCHEDULER_NO_TASK; | 665 | mig_task = GNUNET_SCHEDULER_NO_TASK; |
701 | } | 666 | } |
702 | if (NULL != mig_qe) | 667 | if (NULL != mig_qe) |
703 | { | 668 | { |
704 | GNUNET_DATASTORE_cancel (mig_qe); | 669 | GNUNET_DATASTORE_cancel (mig_qe); |
705 | mig_qe = NULL; | 670 | mig_qe = NULL; |
706 | } | 671 | } |
707 | while (NULL != mig_head) | 672 | while (NULL != mig_head) |
708 | delete_migration_block (mig_head); | 673 | delete_migration_block (mig_head); |
709 | GNUNET_assert (0 == mig_size); | 674 | GNUNET_assert (0 == mig_size); |