diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/fs/gnunet-service-fs_push.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/fs/gnunet-service-fs_push.c')
-rw-r--r-- | src/fs/gnunet-service-fs_push.c | 466 |
1 files changed, 235 insertions, 231 deletions
diff --git a/src/fs/gnunet-service-fs_push.c b/src/fs/gnunet-service-fs_push.c index 162dcc0b5..02990a637 100644 --- a/src/fs/gnunet-service-fs_push.c +++ b/src/fs/gnunet-service-fs_push.c | |||
@@ -49,13 +49,15 @@ | |||
49 | * that if this value is increased, the migration testcase may need to be | 49 | * that if this value is increased, the migration testcase may need to be |
50 | * adjusted as well (especially the CONTENT_LIFETIME in fs_test_lib.c). | 50 | * adjusted as well (especially the CONTENT_LIFETIME in fs_test_lib.c). |
51 | */ | 51 | */ |
52 | #define MIN_MIGRATION_CONTENT_LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 52 | #define MIN_MIGRATION_CONTENT_LIFETIME GNUNET_TIME_relative_multiply ( \ |
53 | GNUNET_TIME_UNIT_MINUTES, 30) | ||
53 | 54 | ||
54 | 55 | ||
55 | /** | 56 | /** |
56 | * Block that is ready for migration to other peers. Actual data is at the end of the block. | 57 | * Block that is ready for migration to other peers. Actual data is at the end of the block. |
57 | */ | 58 | */ |
58 | struct MigrationReadyBlock { | 59 | struct MigrationReadyBlock |
60 | { | ||
59 | /** | 61 | /** |
60 | * This is a doubly-linked list. | 62 | * This is a doubly-linked list. |
61 | */ | 63 | */ |
@@ -102,7 +104,8 @@ struct MigrationReadyBlock { | |||
102 | /** | 104 | /** |
103 | * Information about a peer waiting for migratable data. | 105 | * Information about a peer waiting for migratable data. |
104 | */ | 106 | */ |
105 | struct MigrationReadyPeer { | 107 | struct MigrationReadyPeer |
108 | { | ||
106 | /** | 109 | /** |
107 | * This is a doubly-linked list. | 110 | * This is a doubly-linked list. |
108 | */ | 111 | */ |
@@ -183,15 +186,15 @@ static int value_found; | |||
183 | * @param mb block to delete | 186 | * @param mb block to delete |
184 | */ | 187 | */ |
185 | static void | 188 | static void |
186 | delete_migration_block(struct MigrationReadyBlock *mb) | 189 | delete_migration_block (struct MigrationReadyBlock *mb) |
187 | { | 190 | { |
188 | GNUNET_CONTAINER_DLL_remove(mig_head, | 191 | GNUNET_CONTAINER_DLL_remove (mig_head, |
189 | mig_tail, | 192 | mig_tail, |
190 | mb); | 193 | mb); |
191 | GNUNET_PEER_decrement_rcs(mb->target_list, | 194 | GNUNET_PEER_decrement_rcs (mb->target_list, |
192 | MIGRATION_LIST_SIZE); | 195 | MIGRATION_LIST_SIZE); |
193 | mig_size--; | 196 | mig_size--; |
194 | GNUNET_free(mb); | 197 | GNUNET_free (mb); |
195 | } | 198 | } |
196 | 199 | ||
197 | 200 | ||
@@ -201,7 +204,7 @@ delete_migration_block(struct MigrationReadyBlock *mb) | |||
201 | * @param cls a `struct MigrationReadyPeer *` | 204 | * @param cls a `struct MigrationReadyPeer *` |
202 | */ | 205 | */ |
203 | static void | 206 | static void |
204 | find_content(void *cls); | 207 | find_content (void *cls); |
205 | 208 | ||
206 | 209 | ||
207 | /** | 210 | /** |
@@ -212,50 +215,50 @@ find_content(void *cls); | |||
212 | * @return #GNUNET_YES if the block was deleted (!) | 215 | * @return #GNUNET_YES if the block was deleted (!) |
213 | */ | 216 | */ |
214 | static int | 217 | static int |
215 | transmit_content(struct MigrationReadyPeer *mrp, | 218 | transmit_content (struct MigrationReadyPeer *mrp, |
216 | struct MigrationReadyBlock *block) | 219 | struct MigrationReadyBlock *block) |
217 | { | 220 | { |
218 | struct PutMessage *msg; | 221 | struct PutMessage *msg; |
219 | unsigned int i; | 222 | unsigned int i; |
220 | struct GSF_PeerPerformanceData *ppd; | 223 | struct GSF_PeerPerformanceData *ppd; |
221 | int ret; | 224 | int ret; |
222 | 225 | ||
223 | ppd = GSF_get_peer_performance_data_(mrp->peer); | 226 | ppd = GSF_get_peer_performance_data_ (mrp->peer); |
224 | GNUNET_assert(NULL == mrp->env); | 227 | GNUNET_assert (NULL == mrp->env); |
225 | mrp->env = GNUNET_MQ_msg_extra(msg, | 228 | mrp->env = GNUNET_MQ_msg_extra (msg, |
226 | block->size, | 229 | block->size, |
227 | GNUNET_MESSAGE_TYPE_FS_PUT); | 230 | GNUNET_MESSAGE_TYPE_FS_PUT); |
228 | msg->type = htonl(block->type); | 231 | msg->type = htonl (block->type); |
229 | msg->expiration = GNUNET_TIME_absolute_hton(block->expiration); | 232 | msg->expiration = GNUNET_TIME_absolute_hton (block->expiration); |
230 | GNUNET_memcpy(&msg[1], | 233 | GNUNET_memcpy (&msg[1], |
231 | &block[1], | 234 | &block[1], |
232 | block->size); | 235 | block->size); |
233 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) | 236 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
237 | { | ||
238 | if (block->target_list[i] == 0) | ||
234 | { | 239 | { |
235 | if (block->target_list[i] == 0) | 240 | block->target_list[i] = ppd->pid; |
236 | { | 241 | GNUNET_PEER_change_rc (block->target_list[i], |
237 | block->target_list[i] = ppd->pid; | 242 | 1); |
238 | GNUNET_PEER_change_rc(block->target_list[i], | 243 | break; |
239 | 1); | ||
240 | break; | ||
241 | } | ||
242 | } | 244 | } |
245 | } | ||
243 | if (MIGRATION_LIST_SIZE == i) | 246 | if (MIGRATION_LIST_SIZE == i) |
244 | { | 247 | { |
245 | delete_migration_block(block); | 248 | delete_migration_block (block); |
246 | ret = GNUNET_YES; | 249 | ret = GNUNET_YES; |
247 | } | 250 | } |
248 | else | 251 | else |
249 | { | 252 | { |
250 | ret = GNUNET_NO; | 253 | ret = GNUNET_NO; |
251 | } | 254 | } |
252 | GNUNET_MQ_notify_sent(mrp->env, | 255 | GNUNET_MQ_notify_sent (mrp->env, |
253 | &find_content, | 256 | &find_content, |
254 | mrp); | 257 | mrp); |
255 | GSF_peer_transmit_(mrp->peer, | 258 | GSF_peer_transmit_ (mrp->peer, |
256 | GNUNET_NO, | 259 | GNUNET_NO, |
257 | 0 /* priority */, | 260 | 0 /* priority */, |
258 | mrp->env); | 261 | mrp->env); |
259 | return ret; | 262 | return ret; |
260 | } | 263 | } |
261 | 264 | ||
@@ -268,7 +271,7 @@ transmit_content(struct MigrationReadyPeer *mrp, | |||
268 | * @return number of times block was forwarded | 271 | * @return number of times block was forwarded |
269 | */ | 272 | */ |
270 | static unsigned int | 273 | static unsigned int |
271 | count_targets(struct MigrationReadyBlock *block) | 274 | count_targets (struct MigrationReadyBlock *block) |
272 | { | 275 | { |
273 | unsigned int i; | 276 | unsigned int i; |
274 | 277 | ||
@@ -288,8 +291,8 @@ count_targets(struct MigrationReadyBlock *block) | |||
288 | * @return score (>= 0: feasible, negative: infeasible) | 291 | * @return score (>= 0: feasible, negative: infeasible) |
289 | */ | 292 | */ |
290 | static long | 293 | static long |
291 | score_content(struct MigrationReadyPeer *mrp, | 294 | score_content (struct MigrationReadyPeer *mrp, |
292 | struct MigrationReadyBlock *block) | 295 | struct MigrationReadyBlock *block) |
293 | { | 296 | { |
294 | unsigned int i; | 297 | unsigned int i; |
295 | struct GSF_PeerPerformanceData *ppd; | 298 | struct GSF_PeerPerformanceData *ppd; |
@@ -297,18 +300,18 @@ score_content(struct MigrationReadyPeer *mrp, | |||
297 | struct GNUNET_HashCode hc; | 300 | struct GNUNET_HashCode hc; |
298 | uint32_t dist; | 301 | uint32_t dist; |
299 | 302 | ||
300 | ppd = GSF_get_peer_performance_data_(mrp->peer); | 303 | ppd = GSF_get_peer_performance_data_ (mrp->peer); |
301 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) | 304 | for (i = 0; i < MIGRATION_LIST_SIZE; i++) |
302 | if (block->target_list[i] == ppd->pid) | 305 | if (block->target_list[i] == ppd->pid) |
303 | return -1; | 306 | return -1; |
304 | GNUNET_assert(0 != ppd->pid); | 307 | GNUNET_assert (0 != ppd->pid); |
305 | GNUNET_PEER_resolve(ppd->pid, | 308 | GNUNET_PEER_resolve (ppd->pid, |
306 | &id); | 309 | &id); |
307 | GNUNET_CRYPTO_hash(&id, | 310 | GNUNET_CRYPTO_hash (&id, |
308 | sizeof(struct GNUNET_PeerIdentity), | 311 | sizeof(struct GNUNET_PeerIdentity), |
309 | &hc); | 312 | &hc); |
310 | dist = GNUNET_CRYPTO_hash_distance_u32(&block->query, | 313 | dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query, |
311 | &hc); | 314 | &hc); |
312 | /* closer distance, higher score: */ | 315 | /* closer distance, higher score: */ |
313 | return UINT32_MAX - dist; | 316 | return UINT32_MAX - dist; |
314 | } | 317 | } |
@@ -319,7 +322,7 @@ score_content(struct MigrationReadyPeer *mrp, | |||
319 | * (re)scheduling it with the appropriate delay. | 322 | * (re)scheduling it with the appropriate delay. |
320 | */ | 323 | */ |
321 | static void | 324 | static void |
322 | consider_gathering(void); | 325 | consider_gathering (void); |
323 | 326 | ||
324 | 327 | ||
325 | /** | 328 | /** |
@@ -328,7 +331,7 @@ consider_gathering(void); | |||
328 | * @param cls peer to find content for | 331 | * @param cls peer to find content for |
329 | */ | 332 | */ |
330 | static void | 333 | static void |
331 | find_content(void *cls) | 334 | find_content (void *cls) |
332 | { | 335 | { |
333 | struct MigrationReadyPeer *mrp = cls; | 336 | struct MigrationReadyPeer *mrp = cls; |
334 | struct MigrationReadyBlock *pos; | 337 | struct MigrationReadyBlock *pos; |
@@ -341,48 +344,48 @@ find_content(void *cls) | |||
341 | best_score = -1; | 344 | best_score = -1; |
342 | pos = mig_head; | 345 | pos = mig_head; |
343 | while (NULL != pos) | 346 | while (NULL != pos) |
347 | { | ||
348 | score = score_content (mrp, pos); | ||
349 | if (score > best_score) | ||
344 | { | 350 | { |
345 | score = score_content(mrp, pos); | 351 | best_score = score; |
346 | if (score > best_score) | 352 | best = pos; |
347 | { | ||
348 | best_score = score; | ||
349 | best = pos; | ||
350 | } | ||
351 | pos = pos->next; | ||
352 | } | 353 | } |
354 | pos = pos->next; | ||
355 | } | ||
353 | if (NULL == best) | 356 | if (NULL == best) |
357 | { | ||
358 | if (mig_size < MAX_MIGRATION_QUEUE) | ||
354 | { | 359 | { |
355 | if (mig_size < MAX_MIGRATION_QUEUE) | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
356 | { | 361 | "No content found for pushing, waiting for queue to fill\n"); |
357 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 362 | return; /* will fill up eventually... */ |
358 | "No content found for pushing, waiting for queue to fill\n"); | ||
359 | return; /* will fill up eventually... */ | ||
360 | } | ||
361 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
362 | "No suitable content found, purging content from full queue\n"); | ||
363 | /* failed to find migration target AND | ||
364 | * queue is full, purge most-forwarded | ||
365 | * block from queue to make room for more */ | ||
366 | pos = mig_head; | ||
367 | while (NULL != pos) | ||
368 | { | ||
369 | score = count_targets(pos); | ||
370 | if (score >= best_score) | ||
371 | { | ||
372 | best_score = score; | ||
373 | best = pos; | ||
374 | } | ||
375 | pos = pos->next; | ||
376 | } | ||
377 | GNUNET_assert(NULL != best); | ||
378 | delete_migration_block(best); | ||
379 | consider_gathering(); | ||
380 | return; | ||
381 | } | 363 | } |
382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
383 | "Preparing to push best content to peer\n"); | 365 | "No suitable content found, purging content from full queue\n"); |
384 | transmit_content(mrp, | 366 | /* failed to find migration target AND |
385 | best); | 367 | * queue is full, purge most-forwarded |
368 | * block from queue to make room for more */ | ||
369 | pos = mig_head; | ||
370 | while (NULL != pos) | ||
371 | { | ||
372 | score = count_targets (pos); | ||
373 | if (score >= best_score) | ||
374 | { | ||
375 | best_score = score; | ||
376 | best = pos; | ||
377 | } | ||
378 | pos = pos->next; | ||
379 | } | ||
380 | GNUNET_assert (NULL != best); | ||
381 | delete_migration_block (best); | ||
382 | consider_gathering (); | ||
383 | return; | ||
384 | } | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
386 | "Preparing to push best content to peer\n"); | ||
387 | transmit_content (mrp, | ||
388 | best); | ||
386 | } | 389 | } |
387 | 390 | ||
388 | 391 | ||
@@ -393,7 +396,7 @@ find_content(void *cls) | |||
393 | * @param cls unused | 396 | * @param cls unused |
394 | */ | 397 | */ |
395 | static void | 398 | static void |
396 | gather_migration_blocks(void *cls); | 399 | gather_migration_blocks (void *cls); |
397 | 400 | ||
398 | 401 | ||
399 | /** | 402 | /** |
@@ -401,7 +404,7 @@ gather_migration_blocks(void *cls); | |||
401 | * (re)scheduling it with the appropriate delay. | 404 | * (re)scheduling it with the appropriate delay. |
402 | */ | 405 | */ |
403 | static void | 406 | static void |
404 | consider_gathering() | 407 | consider_gathering () |
405 | { | 408 | { |
406 | struct GNUNET_TIME_Relative delay; | 409 | struct GNUNET_TIME_Relative delay; |
407 | 410 | ||
@@ -413,25 +416,26 @@ consider_gathering() | |||
413 | return; | 416 | return; |
414 | if (mig_size >= MAX_MIGRATION_QUEUE) | 417 | if (mig_size >= MAX_MIGRATION_QUEUE) |
415 | return; | 418 | return; |
416 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 419 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
417 | mig_size); | 420 | mig_size); |
418 | delay = GNUNET_TIME_relative_divide(delay, | 421 | delay = GNUNET_TIME_relative_divide (delay, |
419 | MAX_MIGRATION_QUEUE); | 422 | MAX_MIGRATION_QUEUE); |
420 | delay = GNUNET_TIME_relative_max(delay, | 423 | delay = GNUNET_TIME_relative_max (delay, |
421 | min_migration_delay); | 424 | min_migration_delay); |
422 | if (GNUNET_NO == value_found) | 425 | if (GNUNET_NO == value_found) |
423 | { | 426 | { |
424 | /* wait at least 5s if the datastore is empty */ | 427 | /* wait at least 5s if the datastore is empty */ |
425 | delay = GNUNET_TIME_relative_max(delay, | 428 | delay = GNUNET_TIME_relative_max (delay, |
426 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 429 | GNUNET_TIME_relative_multiply ( |
427 | 5)); | 430 | GNUNET_TIME_UNIT_SECONDS, |
428 | } | 431 | 5)); |
429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 432 | } |
430 | "Scheduling gathering task (queue size: %u)\n", | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
431 | mig_size); | 434 | "Scheduling gathering task (queue size: %u)\n", |
432 | mig_task = GNUNET_SCHEDULER_add_delayed(delay, | 435 | mig_size); |
433 | &gather_migration_blocks, | 436 | mig_task = GNUNET_SCHEDULER_add_delayed (delay, |
434 | NULL); | 437 | &gather_migration_blocks, |
438 | NULL); | ||
435 | } | 439 | } |
436 | 440 | ||
437 | 441 | ||
@@ -451,82 +455,82 @@ consider_gathering() | |||
451 | * maybe 0 if no unique identifier is available | 455 | * maybe 0 if no unique identifier is available |
452 | */ | 456 | */ |
453 | static void | 457 | static void |
454 | process_migration_content(void *cls, | 458 | process_migration_content (void *cls, |
455 | const struct GNUNET_HashCode *key, | 459 | const struct GNUNET_HashCode *key, |
456 | size_t size, | 460 | size_t size, |
457 | const void *data, | 461 | const void *data, |
458 | enum GNUNET_BLOCK_Type type, | 462 | enum GNUNET_BLOCK_Type type, |
459 | uint32_t priority, | 463 | uint32_t priority, |
460 | uint32_t anonymity, | 464 | uint32_t anonymity, |
461 | uint32_t replication, | 465 | uint32_t replication, |
462 | struct GNUNET_TIME_Absolute expiration, | 466 | struct GNUNET_TIME_Absolute expiration, |
463 | uint64_t uid) | 467 | uint64_t uid) |
464 | { | 468 | { |
465 | struct MigrationReadyBlock *mb; | 469 | struct MigrationReadyBlock *mb; |
466 | struct MigrationReadyPeer *pos; | 470 | struct MigrationReadyPeer *pos; |
467 | 471 | ||
468 | mig_qe = NULL; | 472 | mig_qe = NULL; |
469 | if (NULL == key) | 473 | if (NULL == key) |
470 | { | 474 | { |
471 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
472 | "No content found for migration...\n"); | 476 | "No content found for migration...\n"); |
473 | consider_gathering(); | 477 | consider_gathering (); |
474 | return; | 478 | return; |
475 | } | 479 | } |
476 | value_found = GNUNET_YES; | 480 | value_found = GNUNET_YES; |
477 | if (GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us < | 481 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us < |
478 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us) | 482 | MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us) |
479 | { | 483 | { |
480 | /* content will expire soon, don't bother */ | 484 | /* content will expire soon, don't bother */ |
481 | consider_gathering(); | 485 | consider_gathering (); |
482 | return; | 486 | return; |
483 | } | 487 | } |
484 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) | 488 | if (type == GNUNET_BLOCK_TYPE_FS_ONDEMAND) |
485 | { | 489 | { |
486 | if (GNUNET_OK != | 490 | if (GNUNET_OK != |
487 | GNUNET_FS_handle_on_demand_block(key, | 491 | GNUNET_FS_handle_on_demand_block (key, |
488 | size, | 492 | size, |
489 | data, | 493 | data, |
490 | type, | 494 | type, |
491 | priority, | 495 | priority, |
492 | anonymity, | 496 | anonymity, |
493 | replication, | 497 | replication, |
494 | expiration, | 498 | expiration, |
495 | uid, | 499 | uid, |
496 | &process_migration_content, | 500 | &process_migration_content, |
497 | NULL)) | 501 | NULL)) |
498 | consider_gathering(); | 502 | consider_gathering (); |
499 | return; | 503 | return; |
500 | } | 504 | } |
501 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 505 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
502 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", | 506 | "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n", |
503 | GNUNET_h2s(key), | 507 | GNUNET_h2s (key), |
504 | type, mig_size + 1, | 508 | type, mig_size + 1, |
505 | MAX_MIGRATION_QUEUE); | 509 | MAX_MIGRATION_QUEUE); |
506 | mb = GNUNET_malloc(sizeof(struct MigrationReadyBlock) + size); | 510 | mb = GNUNET_malloc (sizeof(struct MigrationReadyBlock) + size); |
507 | mb->query = *key; | 511 | mb->query = *key; |
508 | mb->expiration = expiration; | 512 | mb->expiration = expiration; |
509 | mb->size = size; | 513 | mb->size = size; |
510 | mb->type = type; | 514 | mb->type = type; |
511 | GNUNET_memcpy(&mb[1], data, size); | 515 | GNUNET_memcpy (&mb[1], data, size); |
512 | GNUNET_CONTAINER_DLL_insert_after(mig_head, | 516 | GNUNET_CONTAINER_DLL_insert_after (mig_head, |
513 | mig_tail, | 517 | mig_tail, |
514 | mig_tail, | 518 | mig_tail, |
515 | mb); | 519 | mb); |
516 | mig_size++; | 520 | mig_size++; |
517 | for (pos = peer_head; NULL != pos; pos = pos->next) | 521 | for (pos = peer_head; NULL != pos; pos = pos->next) |
522 | { | ||
523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
524 | "Preparing to push best content to peer %s\n", | ||
525 | GNUNET_i2s (GSF_connected_peer_get_identity2_ (pos->peer))); | ||
526 | if ((NULL == pos->env) && | ||
527 | (GNUNET_YES == transmit_content (pos, | ||
528 | mb))) | ||
518 | { | 529 | { |
519 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 530 | break; /* 'mb' was freed! */ |
520 | "Preparing to push best content to peer %s\n", | ||
521 | GNUNET_i2s(GSF_connected_peer_get_identity2_(pos->peer))); | ||
522 | if ((NULL == pos->env) && | ||
523 | (GNUNET_YES == transmit_content(pos, | ||
524 | mb))) | ||
525 | { | ||
526 | break; /* 'mb' was freed! */ | ||
527 | } | ||
528 | } | 531 | } |
529 | consider_gathering(); | 532 | } |
533 | consider_gathering (); | ||
530 | } | 534 | } |
531 | 535 | ||
532 | 536 | ||
@@ -537,24 +541,24 @@ process_migration_content(void *cls, | |||
537 | * @param cls unused | 541 | * @param cls unused |
538 | */ | 542 | */ |
539 | static void | 543 | static void |
540 | gather_migration_blocks(void *cls) | 544 | gather_migration_blocks (void *cls) |
541 | { | 545 | { |
542 | mig_task = NULL; | 546 | mig_task = NULL; |
543 | if (mig_size >= MAX_MIGRATION_QUEUE) | 547 | if (mig_size >= MAX_MIGRATION_QUEUE) |
544 | return; | 548 | return; |
545 | if (NULL == GSF_dsh) | 549 | if (NULL == GSF_dsh) |
546 | return; | 550 | return; |
547 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
548 | "Asking datastore for content for replication (queue size: %u)\n", | 552 | "Asking datastore for content for replication (queue size: %u)\n", |
549 | mig_size); | 553 | mig_size); |
550 | value_found = GNUNET_NO; | 554 | value_found = GNUNET_NO; |
551 | mig_qe = GNUNET_DATASTORE_get_for_replication(GSF_dsh, | 555 | mig_qe = GNUNET_DATASTORE_get_for_replication (GSF_dsh, |
552 | 0, | 556 | 0, |
553 | UINT_MAX, | 557 | UINT_MAX, |
554 | &process_migration_content, | 558 | &process_migration_content, |
555 | NULL); | 559 | NULL); |
556 | if (NULL == mig_qe) | 560 | if (NULL == mig_qe) |
557 | consider_gathering(); | 561 | consider_gathering (); |
558 | } | 562 | } |
559 | 563 | ||
560 | 564 | ||
@@ -565,7 +569,7 @@ gather_migration_blocks(void *cls) | |||
565 | * @param peer handle for the peer that connected | 569 | * @param peer handle for the peer that connected |
566 | */ | 570 | */ |
567 | void | 571 | void |
568 | GSF_push_start_(struct GSF_ConnectedPeer *peer) | 572 | GSF_push_start_ (struct GSF_ConnectedPeer *peer) |
569 | { | 573 | { |
570 | struct MigrationReadyPeer *mrp; | 574 | struct MigrationReadyPeer *mrp; |
571 | 575 | ||
@@ -575,22 +579,22 @@ GSF_push_start_(struct GSF_ConnectedPeer *peer) | |||
575 | if (mrp->peer == peer) | 579 | if (mrp->peer == peer) |
576 | break; | 580 | break; |
577 | if (NULL != mrp) | 581 | if (NULL != mrp) |
578 | { | 582 | { |
579 | /* same peer added twice, must not happen */ | 583 | /* same peer added twice, must not happen */ |
580 | GNUNET_break(0); | 584 | GNUNET_break (0); |
581 | return; | 585 | return; |
582 | } | 586 | } |
583 | 587 | ||
584 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Adding peer %s to list for pushing\n", | 589 | "Adding peer %s to list for pushing\n", |
586 | GNUNET_i2s(GSF_connected_peer_get_identity2_(peer))); | 590 | GNUNET_i2s (GSF_connected_peer_get_identity2_ (peer))); |
587 | 591 | ||
588 | mrp = GNUNET_new(struct MigrationReadyPeer); | 592 | mrp = GNUNET_new (struct MigrationReadyPeer); |
589 | mrp->peer = peer; | 593 | mrp->peer = peer; |
590 | find_content(mrp); | 594 | find_content (mrp); |
591 | GNUNET_CONTAINER_DLL_insert(peer_head, | 595 | GNUNET_CONTAINER_DLL_insert (peer_head, |
592 | peer_tail, | 596 | peer_tail, |
593 | mrp); | 597 | mrp); |
594 | } | 598 | } |
595 | 599 | ||
596 | 600 | ||
@@ -601,7 +605,7 @@ GSF_push_start_(struct GSF_ConnectedPeer *peer) | |||
601 | * @param peer handle for the peer that disconnected | 605 | * @param peer handle for the peer that disconnected |
602 | */ | 606 | */ |
603 | void | 607 | void |
604 | GSF_push_stop_(struct GSF_ConnectedPeer *peer) | 608 | GSF_push_stop_ (struct GSF_ConnectedPeer *peer) |
605 | { | 609 | { |
606 | struct MigrationReadyPeer *pos; | 610 | struct MigrationReadyPeer *pos; |
607 | 611 | ||
@@ -611,11 +615,11 @@ GSF_push_stop_(struct GSF_ConnectedPeer *peer) | |||
611 | if (NULL == pos) | 615 | if (NULL == pos) |
612 | return; | 616 | return; |
613 | if (NULL != pos->env) | 617 | if (NULL != pos->env) |
614 | GNUNET_MQ_send_cancel(pos->env); | 618 | GNUNET_MQ_send_cancel (pos->env); |
615 | GNUNET_CONTAINER_DLL_remove(peer_head, | 619 | GNUNET_CONTAINER_DLL_remove (peer_head, |
616 | peer_tail, | 620 | peer_tail, |
617 | pos); | 621 | pos); |
618 | GNUNET_free(pos); | 622 | GNUNET_free (pos); |
619 | } | 623 | } |
620 | 624 | ||
621 | 625 | ||
@@ -623,28 +627,28 @@ GSF_push_stop_(struct GSF_ConnectedPeer *peer) | |||
623 | * Setup the module. | 627 | * Setup the module. |
624 | */ | 628 | */ |
625 | void | 629 | void |
626 | GSF_push_init_() | 630 | GSF_push_init_ () |
627 | { | 631 | { |
628 | enabled = | 632 | enabled = |
629 | GNUNET_CONFIGURATION_get_value_yesno(GSF_cfg, | 633 | GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, |
630 | "FS", | 634 | "FS", |
631 | "CONTENT_PUSHING"); | 635 | "CONTENT_PUSHING"); |
632 | if (GNUNET_YES != enabled) | 636 | if (GNUNET_YES != enabled) |
633 | return; | 637 | return; |
634 | 638 | ||
635 | if (GNUNET_OK != | 639 | if (GNUNET_OK != |
636 | GNUNET_CONFIGURATION_get_value_time(GSF_cfg, | 640 | GNUNET_CONFIGURATION_get_value_time (GSF_cfg, |
637 | "fs", | 641 | "fs", |
638 | "MIN_MIGRATION_DELAY", | 642 | "MIN_MIGRATION_DELAY", |
639 | &min_migration_delay)) | 643 | &min_migration_delay)) |
640 | { | 644 | { |
641 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, | 645 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, |
642 | "fs", | 646 | "fs", |
643 | "MIN_MIGRATION_DELAY", | 647 | "MIN_MIGRATION_DELAY", |
644 | _("time required, content pushing disabled")); | 648 | _ ("time required, content pushing disabled")); |
645 | return; | 649 | return; |
646 | } | 650 | } |
647 | consider_gathering(); | 651 | consider_gathering (); |
648 | } | 652 | } |
649 | 653 | ||
650 | 654 | ||
@@ -652,21 +656,21 @@ GSF_push_init_() | |||
652 | * Shutdown the module. | 656 | * Shutdown the module. |
653 | */ | 657 | */ |
654 | void | 658 | void |
655 | GSF_push_done_() | 659 | GSF_push_done_ () |
656 | { | 660 | { |
657 | if (NULL != mig_task) | 661 | if (NULL != mig_task) |
658 | { | 662 | { |
659 | GNUNET_SCHEDULER_cancel(mig_task); | 663 | GNUNET_SCHEDULER_cancel (mig_task); |
660 | mig_task = NULL; | 664 | mig_task = NULL; |
661 | } | 665 | } |
662 | if (NULL != mig_qe) | 666 | if (NULL != mig_qe) |
663 | { | 667 | { |
664 | GNUNET_DATASTORE_cancel(mig_qe); | 668 | GNUNET_DATASTORE_cancel (mig_qe); |
665 | mig_qe = NULL; | 669 | mig_qe = NULL; |
666 | } | 670 | } |
667 | while (NULL != mig_head) | 671 | while (NULL != mig_head) |
668 | delete_migration_block(mig_head); | 672 | delete_migration_block (mig_head); |
669 | GNUNET_assert(0 == mig_size); | 673 | GNUNET_assert (0 == mig_size); |
670 | } | 674 | } |
671 | 675 | ||
672 | /* end of gnunet-service-fs_push.c */ | 676 | /* end of gnunet-service-fs_push.c */ |