aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_cp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r--src/fs/gnunet-service-fs_cp.c1373
1 files changed, 630 insertions, 743 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index ea8a84dfe..4e57455b2 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -134,7 +134,7 @@ struct GSF_DelayedHandle
134 /** 134 /**
135 * Kept in a doubly-linked list. 135 * Kept in a doubly-linked list.
136 */ 136 */
137 struct GSF_DelayedHandle *next; 137 struct GSF_DelayedHandle *next;
138 138
139 /** 139 /**
140 * Kept in a doubly-linked list. 140 * Kept in a doubly-linked list.
@@ -160,7 +160,7 @@ struct GSF_DelayedHandle
160 * Size of the message. 160 * Size of the message.
161 */ 161 */
162 size_t msize; 162 size_t msize;
163 163
164}; 164};
165 165
166 166
@@ -174,7 +174,7 @@ struct PeerRequest
174 * Handle to generic request. 174 * Handle to generic request.
175 */ 175 */
176 struct GSF_PendingRequest *pr; 176 struct GSF_PendingRequest *pr;
177 177
178 /** 178 /**
179 * Handle to specific peer. 179 * Handle to specific peer.
180 */ 180 */
@@ -191,7 +191,7 @@ struct PeerRequest
191/** 191/**
192 * A connected peer. 192 * A connected peer.
193 */ 193 */
194struct GSF_ConnectedPeer 194struct GSF_ConnectedPeer
195{ 195{
196 196
197 /** 197 /**
@@ -330,17 +330,17 @@ get_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
330{ 330{
331 if (atsi == NULL) 331 if (atsi == NULL)
332 return GNUNET_TIME_UNIT_SECONDS; 332 return GNUNET_TIME_UNIT_SECONDS;
333 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && 333 while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
334 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) ) 334 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY))
335 atsi++; 335 atsi++;
336 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) 336 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
337 { 337 {
338 GNUNET_break (0); 338 GNUNET_break (0);
339 /* how can we not have latency data? */ 339 /* how can we not have latency data? */
340 return GNUNET_TIME_UNIT_SECONDS; 340 return GNUNET_TIME_UNIT_SECONDS;
341 } 341 }
342 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 342 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
343 ntohl (atsi->value)); 343 ntohl (atsi->value));
344} 344}
345 345
346 346
@@ -352,13 +352,12 @@ get_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
352 */ 352 */
353static void 353static void
354update_atsi (struct GSF_ConnectedPeer *cp, 354update_atsi (struct GSF_ConnectedPeer *cp,
355 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 355 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
356{ 356{
357 struct GNUNET_TIME_Relative latency; 357 struct GNUNET_TIME_Relative latency;
358 358
359 latency = get_latency (atsi); 359 latency = get_latency (atsi);
360 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, 360 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency);
361 latency);
362 /* LATER: merge atsi into cp's performance data (if we ever care...) */ 361 /* LATER: merge atsi into cp's performance data (if we ever care...) */
363} 362}
364 363
@@ -384,10 +383,7 @@ GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp)
384 * @param buf where to copy the message 383 * @param buf where to copy the message
385 * @return number of bytes copied to buf 384 * @return number of bytes copied to buf
386 */ 385 */
387static size_t 386static size_t peer_transmit_ready_cb (void *cls, size_t size, void *buf);
388peer_transmit_ready_cb (void *cls,
389 size_t size,
390 void *buf);
391 387
392 388
393 389
@@ -406,11 +402,11 @@ peer_transmit_ready_cb (void *cls,
406 */ 402 */
407static void 403static void
408core_reserve_callback (void *cls, 404core_reserve_callback (void *cls,
409 const struct GNUNET_PeerIdentity *peer, 405 const struct GNUNET_PeerIdentity *peer,
410 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 406 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
411 int32_t amount, 407 int32_t amount,
412 struct GNUNET_TIME_Relative res_delay, 408 struct GNUNET_TIME_Relative res_delay,
413 uint64_t preference); 409 uint64_t preference);
414 410
415 411
416/** 412/**
@@ -426,43 +422,38 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
426 struct GNUNET_PeerIdentity target; 422 struct GNUNET_PeerIdentity target;
427 uint64_t ip; 423 uint64_t ip;
428 424
429 if ( (NULL != pth->cth) || 425 if ((NULL != pth->cth) || (0 != pth->cth_in_progress))
430 (0 != pth->cth_in_progress) ) 426 return; /* already done */
431 return; /* already done */
432 cp = pth->cp; 427 cp = pth->cp;
433 GNUNET_assert (0 != cp->ppd.pid); 428 GNUNET_assert (0 != cp->ppd.pid);
434 GNUNET_PEER_resolve (cp->ppd.pid, 429 GNUNET_PEER_resolve (cp->ppd.pid, &target);
435 &target); 430 if ((GNUNET_YES == pth->is_query) && (GNUNET_YES != pth->was_reserved))
436 if ( (GNUNET_YES == pth->is_query) && 431 {
437 (GNUNET_YES != pth->was_reserved) ) 432 /* query, need reservation */
438 { 433 if (GNUNET_YES != cp->did_reserve)
439 /* query, need reservation */ 434 return; /* not ready */
440 if (GNUNET_YES != cp->did_reserve) 435 cp->did_reserve = GNUNET_NO;
441 return; /* not ready */ 436 /* reservation already done! */
442 cp->did_reserve = GNUNET_NO; 437 pth->was_reserved = GNUNET_YES;
443 /* reservation already done! */ 438 ip = cp->inc_preference;
444 pth->was_reserved = GNUNET_YES; 439 cp->inc_preference = 0;
445 ip = cp->inc_preference; 440 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
446 cp->inc_preference = 0; 441 &target,
447 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 442 GNUNET_TIME_UNIT_FOREVER_REL,
448 &target, 443 GNUNET_BANDWIDTH_VALUE_MAX,
449 GNUNET_TIME_UNIT_FOREVER_REL, 444 DBLOCK_SIZE,
450 GNUNET_BANDWIDTH_VALUE_MAX, 445 ip,
451 DBLOCK_SIZE, 446 &core_reserve_callback, cp);
452 ip, 447 }
453 &core_reserve_callback,
454 cp);
455 }
456 GNUNET_assert (pth->cth == NULL); 448 GNUNET_assert (pth->cth == NULL);
457 pth->cth_in_progress++; 449 pth->cth_in_progress++;
458 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core, 450 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
459 GNUNET_YES, 451 GNUNET_YES,
460 pth->priority, 452 pth->priority,
461 GNUNET_TIME_absolute_get_remaining (pth->timeout), 453 GNUNET_TIME_absolute_get_remaining
462 &target, 454 (pth->timeout), &target,
463 pth->size, 455 pth->size,
464 &peer_transmit_ready_cb, 456 &peer_transmit_ready_cb, pth);
465 pth);
466 GNUNET_assert (0 < pth->cth_in_progress--); 457 GNUNET_assert (0 < pth->cth_in_progress--);
467} 458}
468 459
@@ -476,46 +467,43 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
476 * @return number of bytes copied to buf 467 * @return number of bytes copied to buf
477 */ 468 */
478static size_t 469static size_t
479peer_transmit_ready_cb (void *cls, 470peer_transmit_ready_cb (void *cls, size_t size, void *buf)
480 size_t size,
481 void *buf)
482{ 471{
483 struct GSF_PeerTransmitHandle *pth = cls; 472 struct GSF_PeerTransmitHandle *pth = cls;
484 struct GSF_PeerTransmitHandle *pos; 473 struct GSF_PeerTransmitHandle *pos;
485 struct GSF_ConnectedPeer *cp; 474 struct GSF_ConnectedPeer *cp;
486 size_t ret; 475 size_t ret;
487 476
488 GNUNET_assert ( (NULL == buf) || 477 GNUNET_assert ((NULL == buf) || (pth->size <= size));
489 (pth->size <= size) );
490 pth->cth = NULL; 478 pth->cth = NULL;
491 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) 479 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
492 { 480 {
493 GNUNET_SCHEDULER_cancel (pth->timeout_task); 481 GNUNET_SCHEDULER_cancel (pth->timeout_task);
494 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; 482 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
495 } 483 }
496 cp = pth->cp; 484 cp = pth->cp;
497 GNUNET_CONTAINER_DLL_remove (cp->pth_head, 485 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
498 cp->pth_tail,
499 pth);
500 if (GNUNET_YES == pth->is_query) 486 if (GNUNET_YES == pth->is_query)
501 { 487 {
502 cp->ppd.last_request_times[(cp->last_request_times_off++) % MAX_QUEUE_PER_PEER] = GNUNET_TIME_absolute_get (); 488 cp->ppd.last_request_times[(cp->last_request_times_off++) %
503 GNUNET_assert (0 < cp->ppd.pending_queries--); 489 MAX_QUEUE_PER_PEER] =
504 } 490 GNUNET_TIME_absolute_get ();
491 GNUNET_assert (0 < cp->ppd.pending_queries--);
492 }
505 else if (GNUNET_NO == pth->is_query) 493 else if (GNUNET_NO == pth->is_query)
506 { 494 {
507 GNUNET_assert (0 < cp->ppd.pending_replies--); 495 GNUNET_assert (0 < cp->ppd.pending_replies--);
508 } 496 }
509 GNUNET_LOAD_update (cp->ppd.transmission_delay, 497 GNUNET_LOAD_update (cp->ppd.transmission_delay,
510 GNUNET_TIME_absolute_get_duration (pth->transmission_request_start_time).rel_value); 498 GNUNET_TIME_absolute_get_duration
511 ret = pth->gmc (pth->gmc_cls, 499 (pth->transmission_request_start_time).rel_value);
512 size, buf); 500 ret = pth->gmc (pth->gmc_cls, size, buf);
513 GNUNET_assert (NULL == pth->cth); 501 GNUNET_assert (NULL == pth->cth);
514 for (pos = cp->pth_head; pos != NULL; pos = pos->next) 502 for (pos = cp->pth_head; pos != NULL; pos = pos->next)
515 { 503 {
516 GNUNET_assert (pos != pth); 504 GNUNET_assert (pos != pth);
517 schedule_transmission (pos); 505 schedule_transmission (pos);
518 } 506 }
519 GNUNET_assert (pth->cth == NULL); 507 GNUNET_assert (pth->cth == NULL);
520 GNUNET_assert (pth->cth_in_progress == 0); 508 GNUNET_assert (pth->cth_in_progress == 0);
521 GNUNET_free (pth); 509 GNUNET_free (pth);
@@ -530,26 +518,22 @@ peer_transmit_ready_cb (void *cls,
530 * @param tc scheduler context 518 * @param tc scheduler context
531 */ 519 */
532static void 520static void
533retry_reservation (void *cls, 521retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
534 const struct GNUNET_SCHEDULER_TaskContext *tc)
535{ 522{
536 struct GSF_ConnectedPeer *cp = cls; 523 struct GSF_ConnectedPeer *cp = cls;
537 uint64_t ip; 524 uint64_t ip;
538 struct GNUNET_PeerIdentity target; 525 struct GNUNET_PeerIdentity target;
539 526
540 GNUNET_PEER_resolve (cp->ppd.pid, 527 GNUNET_PEER_resolve (cp->ppd.pid, &target);
541 &target);
542 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK; 528 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
543 ip = cp->inc_preference; 529 ip = cp->inc_preference;
544 cp->inc_preference = 0; 530 cp->inc_preference = 0;
545 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 531 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
546 &target, 532 &target,
547 GNUNET_TIME_UNIT_FOREVER_REL, 533 GNUNET_TIME_UNIT_FOREVER_REL,
548 GNUNET_BANDWIDTH_VALUE_MAX, 534 GNUNET_BANDWIDTH_VALUE_MAX,
549 DBLOCK_SIZE, 535 DBLOCK_SIZE,
550 ip, 536 ip, &core_reserve_callback, cp);
551 &core_reserve_callback,
552 cp);
553} 537}
554 538
555 539
@@ -567,40 +551,37 @@ retry_reservation (void *cls,
567 */ 551 */
568static void 552static void
569core_reserve_callback (void *cls, 553core_reserve_callback (void *cls,
570 const struct GNUNET_PeerIdentity *peer, 554 const struct GNUNET_PeerIdentity *peer,
571 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 555 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
572 int32_t amount, 556 int32_t amount,
573 struct GNUNET_TIME_Relative res_delay, 557 struct GNUNET_TIME_Relative res_delay,
574 uint64_t preference) 558 uint64_t preference)
575{ 559{
576 struct GSF_ConnectedPeer *cp = cls; 560 struct GSF_ConnectedPeer *cp = cls;
577 struct GSF_PeerTransmitHandle *pth; 561 struct GSF_PeerTransmitHandle *pth;
578 562
579 cp->irc = NULL; 563 cp->irc = NULL;
580 if (0 == amount) 564 if (0 == amount)
581 { 565 {
582 cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay, 566 cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay,
583 &retry_reservation, 567 &retry_reservation, cp);
584 cp); 568 return;
585 return; 569 }
586 }
587 cp->did_reserve = GNUNET_YES; 570 cp->did_reserve = GNUNET_YES;
588 pth = cp->pth_head; 571 pth = cp->pth_head;
589 if ( (NULL != pth) && 572 if ((NULL != pth) && (NULL == pth->cth))
590 (NULL == pth->cth) ) 573 {
591 { 574 /* reservation success, try transmission now! */
592 /* reservation success, try transmission now! */ 575 pth->cth_in_progress++;
593 pth->cth_in_progress++; 576 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
594 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core, 577 GNUNET_YES,
595 GNUNET_YES, 578 pth->priority,
596 pth->priority, 579 GNUNET_TIME_absolute_get_remaining
597 GNUNET_TIME_absolute_get_remaining (pth->timeout), 580 (pth->timeout), peer,
598 peer, 581 pth->size,
599 pth->size, 582 &peer_transmit_ready_cb, pth);
600 &peer_transmit_ready_cb, 583 GNUNET_assert (0 < pth->cth_in_progress--);
601 pth); 584 }
602 GNUNET_assert (0 < pth->cth_in_progress--);
603 }
604} 585}
605 586
606 587
@@ -614,7 +595,7 @@ core_reserve_callback (void *cls,
614 */ 595 */
615struct GSF_ConnectedPeer * 596struct GSF_ConnectedPeer *
616GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 597GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
617 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 598 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
618{ 599{
619 struct GSF_ConnectedPeer *cp; 600 struct GSF_ConnectedPeer *cp;
620 char *fn; 601 char *fn;
@@ -624,13 +605,11 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
624 cp->ppd.pid = GNUNET_PEER_intern (peer); 605 cp->ppd.pid = GNUNET_PEER_intern (peer);
625 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); 606 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
626 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core, 607 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
627 peer, 608 peer,
628 GNUNET_TIME_UNIT_FOREVER_REL, 609 GNUNET_TIME_UNIT_FOREVER_REL,
629 GNUNET_BANDWIDTH_VALUE_MAX, 610 GNUNET_BANDWIDTH_VALUE_MAX,
630 DBLOCK_SIZE, 611 DBLOCK_SIZE,
631 0, 612 0, &core_reserve_callback, cp);
632 &core_reserve_callback,
633 cp);
634 fn = get_trust_filename (peer); 613 fn = get_trust_filename (peer);
635 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && 614 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
636 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) 615 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
@@ -638,10 +617,10 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
638 GNUNET_free (fn); 617 GNUNET_free (fn);
639 cp->request_map = GNUNET_CONTAINER_multihashmap_create (128); 618 cp->request_map = GNUNET_CONTAINER_multihashmap_create (128);
640 GNUNET_break (GNUNET_OK == 619 GNUNET_break (GNUNET_OK ==
641 GNUNET_CONTAINER_multihashmap_put (cp_map, 620 GNUNET_CONTAINER_multihashmap_put (cp_map,
642 &peer->hashPubKey, 621 &peer->hashPubKey,
643 cp, 622 cp,
644 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 623 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
645 update_atsi (cp, atsi); 624 update_atsi (cp, atsi);
646 GSF_push_start_ (cp); 625 GSF_push_start_ (cp);
647 return cp; 626 return cp;
@@ -656,23 +635,20 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
656 * @param tc scheduler context 635 * @param tc scheduler context
657 */ 636 */
658static void 637static void
659revive_migration (void *cls, 638revive_migration (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
660 const struct GNUNET_SCHEDULER_TaskContext *tc)
661{ 639{
662 struct GSF_ConnectedPeer *cp = cls; 640 struct GSF_ConnectedPeer *cp = cls;
663 struct GNUNET_TIME_Relative bt; 641 struct GNUNET_TIME_Relative bt;
664 642
665 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK; 643 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
666 bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until); 644 bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until);
667 if (0 != bt.rel_value) 645 if (0 != bt.rel_value)
668 { 646 {
669 /* still time left... */ 647 /* still time left... */
670 cp->mig_revive_task 648 cp->mig_revive_task
671 = GNUNET_SCHEDULER_add_delayed (bt, 649 = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
672 &revive_migration, 650 return;
673 cp); 651 }
674 return;
675 }
676 GSF_push_start_ (cp); 652 GSF_push_start_ (cp);
677} 653}
678 654
@@ -686,9 +662,9 @@ revive_migration (void *cls,
686struct GSF_ConnectedPeer * 662struct GSF_ConnectedPeer *
687GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) 663GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
688{ 664{
689 if (NULL == cp_map) return NULL; 665 if (NULL == cp_map)
690 return GNUNET_CONTAINER_multihashmap_get (cp_map, 666 return NULL;
691 &peer->hashPubKey); 667 return GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
692} 668}
693 669
694 670
@@ -705,36 +681,33 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
705 */ 681 */
706int 682int
707GSF_handle_p2p_migration_stop_ (void *cls, 683GSF_handle_p2p_migration_stop_ (void *cls,
708 const struct GNUNET_PeerIdentity *other, 684 const struct GNUNET_PeerIdentity *other,
709 const struct GNUNET_MessageHeader *message, 685 const struct GNUNET_MessageHeader *message,
710 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 686 const struct GNUNET_TRANSPORT_ATS_Information
687 *atsi)
711{ 688{
712 struct GSF_ConnectedPeer *cp; 689 struct GSF_ConnectedPeer *cp;
713 const struct MigrationStopMessage *msm; 690 const struct MigrationStopMessage *msm;
714 struct GNUNET_TIME_Relative bt; 691 struct GNUNET_TIME_Relative bt;
715 692
716 msm = (const struct MigrationStopMessage*) message; 693 msm = (const struct MigrationStopMessage *) message;
717 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 694 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &other->hashPubKey);
718 &other->hashPubKey);
719 if (cp == NULL) 695 if (cp == NULL)
720 { 696 {
721 GNUNET_break (0); 697 GNUNET_break (0);
722 return GNUNET_OK; 698 return GNUNET_OK;
723 } 699 }
724 bt = GNUNET_TIME_relative_ntoh (msm->duration); 700 bt = GNUNET_TIME_relative_ntoh (msm->duration);
725 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 701 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
726 _("Migration of content to peer `%s' blocked for %llu ms\n"), 702 _("Migration of content to peer `%s' blocked for %llu ms\n"),
727 GNUNET_i2s (other), 703 GNUNET_i2s (other), (unsigned long long) bt.rel_value);
728 (unsigned long long) bt.rel_value);
729 cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt); 704 cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt);
730 if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK) 705 if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK)
731 { 706 {
732 GSF_push_stop_ (cp); 707 GSF_push_stop_ (cp);
733 cp->mig_revive_task 708 cp->mig_revive_task
734 = GNUNET_SCHEDULER_add_delayed (bt, 709 = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
735 &revive_migration, 710 }
736 cp);
737 }
738 update_atsi (cp, atsi); 711 update_atsi (cp, atsi);
739 return GNUNET_OK; 712 return GNUNET_OK;
740} 713}
@@ -748,32 +721,28 @@ GSF_handle_p2p_migration_stop_ (void *cls,
748 * @param buf where to copy the message, NULL on error (peer disconnect) 721 * @param buf where to copy the message, NULL on error (peer disconnect)
749 * @return number of bytes copied to 'buf', can be 0 (without indicating an error) 722 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
750 */ 723 */
751static size_t 724static size_t
752copy_reply (void *cls, 725copy_reply (void *cls, size_t buf_size, void *buf)
753 size_t buf_size,
754 void *buf)
755{ 726{
756 struct PutMessage *pm = cls; 727 struct PutMessage *pm = cls;
757 size_t size; 728 size_t size;
758 729
759 if (buf != NULL) 730 if (buf != NULL)
760 { 731 {
761 GNUNET_assert (buf_size >= ntohs (pm->header.size)); 732 GNUNET_assert (buf_size >= ntohs (pm->header.size));
762 size = ntohs (pm->header.size); 733 size = ntohs (pm->header.size);
763 memcpy (buf, pm, size); 734 memcpy (buf, pm, size);
764 GNUNET_STATISTICS_update (GSF_stats, 735 GNUNET_STATISTICS_update (GSF_stats,
765 gettext_noop ("# replies transmitted to other peers"), 736 gettext_noop
766 1, 737 ("# replies transmitted to other peers"), 1,
767 GNUNET_NO); 738 GNUNET_NO);
768 } 739 }
769 else 740 else
770 { 741 {
771 size = 0; 742 size = 0;
772 GNUNET_STATISTICS_update (GSF_stats, 743 GNUNET_STATISTICS_update (GSF_stats,
773 gettext_noop ("# replies dropped"), 744 gettext_noop ("# replies dropped"), 1, GNUNET_NO);
774 1, 745 }
775 GNUNET_NO);
776 }
777 GNUNET_free (pm); 746 GNUNET_free (pm);
778 return size; 747 return size;
779} 748}
@@ -788,9 +757,7 @@ copy_reply (void *cls,
788 * @return GNUNET_YES (continue to iterate) 757 * @return GNUNET_YES (continue to iterate)
789 */ 758 */
790static int 759static int
791cancel_pending_request (void *cls, 760cancel_pending_request (void *cls, const GNUNET_HashCode * query, void *value)
792 const GNUNET_HashCode *query,
793 void *value)
794{ 761{
795 struct PeerRequest *peerreq = value; 762 struct PeerRequest *peerreq = value;
796 struct GSF_PendingRequest *pr = peerreq->pr; 763 struct GSF_PendingRequest *pr = peerreq->pr;
@@ -798,19 +765,17 @@ cancel_pending_request (void *cls,
798 struct GSF_PendingRequestData *prd; 765 struct GSF_PendingRequestData *prd;
799 766
800 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK) 767 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
801 { 768 {
802 GNUNET_SCHEDULER_cancel (peerreq->kill_task); 769 GNUNET_SCHEDULER_cancel (peerreq->kill_task);
803 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK; 770 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
804 } 771 }
805 GNUNET_STATISTICS_update (GSF_stats, 772 GNUNET_STATISTICS_update (GSF_stats,
806 gettext_noop ("# P2P searches active"), 773 gettext_noop ("# P2P searches active"),
807 -1, 774 -1, GNUNET_NO);
808 GNUNET_NO);
809 prd = GSF_pending_request_get_data_ (pr); 775 prd = GSF_pending_request_get_data_ (pr);
810 GNUNET_break (GNUNET_YES == 776 GNUNET_break (GNUNET_YES ==
811 GNUNET_CONTAINER_multihashmap_remove (cp->request_map, 777 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
812 &prd->query, 778 &prd->query, peerreq));
813 peerreq));
814 GSF_pending_request_cancel_ (pr, GNUNET_NO); 779 GSF_pending_request_cancel_ (pr, GNUNET_NO);
815 GNUNET_free (peerreq); 780 GNUNET_free (peerreq);
816 return GNUNET_OK; 781 return GNUNET_OK;
@@ -822,10 +787,9 @@ cancel_pending_request (void *cls,
822 * 787 *
823 * @param cls the request to free 788 * @param cls the request to free
824 * @param tc task context 789 * @param tc task context
825 */ 790 */
826static void 791static void
827peer_request_destroy (void *cls, 792peer_request_destroy (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
828 const struct GNUNET_SCHEDULER_TaskContext *tc)
829{ 793{
830 struct PeerRequest *peerreq = cls; 794 struct PeerRequest *peerreq = cls;
831 struct GSF_PendingRequest *pr = peerreq->pr; 795 struct GSF_PendingRequest *pr = peerreq->pr;
@@ -833,9 +797,7 @@ peer_request_destroy (void *cls,
833 797
834 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK; 798 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
835 prd = GSF_pending_request_get_data_ (pr); 799 prd = GSF_pending_request_get_data_ (pr);
836 cancel_pending_request (NULL, 800 cancel_pending_request (NULL, &prd->query, peerreq);
837 &prd->query,
838 peerreq);
839} 801}
840 802
841 803
@@ -846,27 +808,21 @@ peer_request_destroy (void *cls,
846 * @param tc scheduler context 808 * @param tc scheduler context
847 */ 809 */
848static void 810static void
849transmit_delayed_now (void *cls, 811transmit_delayed_now (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
850 const struct GNUNET_SCHEDULER_TaskContext *tc)
851{ 812{
852 struct GSF_DelayedHandle *dh = cls; 813 struct GSF_DelayedHandle *dh = cls;
853 struct GSF_ConnectedPeer *cp = dh->cp; 814 struct GSF_ConnectedPeer *cp = dh->cp;
854 815
855 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, 816 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, cp->delayed_tail, dh);
856 cp->delayed_tail,
857 dh);
858 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 817 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
859 { 818 {
860 GNUNET_free (dh->pm); 819 GNUNET_free (dh->pm);
861 GNUNET_free (dh); 820 GNUNET_free (dh);
862 return; 821 return;
863 } 822 }
864 (void) GSF_peer_transmit_ (cp, GNUNET_NO, 823 (void) GSF_peer_transmit_ (cp, GNUNET_NO,
865 UINT32_MAX, 824 UINT32_MAX,
866 REPLY_TIMEOUT, 825 REPLY_TIMEOUT, dh->msize, &copy_reply, dh->pm);
867 dh->msize,
868 &copy_reply,
869 dh->pm);
870 GNUNET_free (dh); 826 GNUNET_free (dh);
871} 827}
872 828
@@ -883,12 +839,12 @@ get_randomized_delay ()
883 839
884 /* FIXME: replace 5000 with something relating to current observed P2P message latency */ 840 /* FIXME: replace 5000 with something relating to current observed P2P message latency */
885 ret = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 841 ret = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
886 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 842 GNUNET_CRYPTO_random_u32
887 5000)); 843 (GNUNET_CRYPTO_QUALITY_WEAK, 5000));
888 GNUNET_STATISTICS_update (GSF_stats, 844 GNUNET_STATISTICS_update (GSF_stats,
889 gettext_noop ("# artificial delays introduced (ms)"), 845 gettext_noop
890 ret.rel_value, 846 ("# artificial delays introduced (ms)"),
891 GNUNET_NO); 847 ret.rel_value, GNUNET_NO);
892 848
893 return ret; 849 return ret;
894} 850}
@@ -913,13 +869,12 @@ get_randomized_delay ()
913 */ 869 */
914static void 870static void
915handle_p2p_reply (void *cls, 871handle_p2p_reply (void *cls,
916 enum GNUNET_BLOCK_EvaluationResult eval, 872 enum GNUNET_BLOCK_EvaluationResult eval,
917 struct GSF_PendingRequest *pr, 873 struct GSF_PendingRequest *pr,
918 uint32_t reply_anonymity_level, 874 uint32_t reply_anonymity_level,
919 struct GNUNET_TIME_Absolute expiration, 875 struct GNUNET_TIME_Absolute expiration,
920 enum GNUNET_BLOCK_Type type, 876 enum GNUNET_BLOCK_Type type,
921 const void *data, 877 const void *data, size_t data_len)
922 size_t data_len)
923{ 878{
924 struct PeerRequest *peerreq = cls; 879 struct PeerRequest *peerreq = cls;
925 struct GSF_ConnectedPeer *cp = peerreq->cp; 880 struct GSF_ConnectedPeer *cp = peerreq->cp;
@@ -927,101 +882,91 @@ handle_p2p_reply (void *cls,
927 struct PutMessage *pm; 882 struct PutMessage *pm;
928 size_t msize; 883 size_t msize;
929 884
930 GNUNET_assert (data_len + sizeof (struct PutMessage) < GNUNET_SERVER_MAX_MESSAGE_SIZE); 885 GNUNET_assert (data_len + sizeof (struct PutMessage) <
886 GNUNET_SERVER_MAX_MESSAGE_SIZE);
931 GNUNET_assert (peerreq->pr == pr); 887 GNUNET_assert (peerreq->pr == pr);
932 prd = GSF_pending_request_get_data_ (pr); 888 prd = GSF_pending_request_get_data_ (pr);
933 if (NULL == data) 889 if (NULL == data)
934 { 890 {
935 GNUNET_STATISTICS_update (GSF_stats, 891 GNUNET_STATISTICS_update (GSF_stats,
936 gettext_noop ("# P2P searches active"), 892 gettext_noop ("# P2P searches active"),
937 -1, 893 -1, GNUNET_NO);
938 GNUNET_NO); 894 GNUNET_break (GNUNET_YES ==
939 GNUNET_break (GNUNET_YES == 895 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
940 GNUNET_CONTAINER_multihashmap_remove (cp->request_map, 896 &prd->query, peerreq));
941 &prd->query, 897 GNUNET_free (peerreq);
942 peerreq)); 898 return;
943 GNUNET_free (peerreq); 899 }
944 return;
945 }
946 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY); 900 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY);
947 if ( (prd->type != type) && 901 if ((prd->type != type) && (prd->type != GNUNET_BLOCK_TYPE_ANY))
948 (prd->type != GNUNET_BLOCK_TYPE_ANY) ) 902 {
949 { 903 GNUNET_break (0);
950 GNUNET_break (0); 904 return;
951 return; 905 }
952 }
953#if DEBUG_FS 906#if DEBUG_FS
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
955 "Transmitting result for query `%s' to peer\n", 908 "Transmitting result for query `%s' to peer\n",
956 GNUNET_h2s (&prd->query)); 909 GNUNET_h2s (&prd->query));
957#endif 910#endif
958 GNUNET_STATISTICS_update (GSF_stats, 911 GNUNET_STATISTICS_update (GSF_stats,
959 gettext_noop ("# replies received for other peers"), 912 gettext_noop ("# replies received for other peers"),
960 1, 913 1, GNUNET_NO);
961 GNUNET_NO);
962 msize = sizeof (struct PutMessage) + data_len; 914 msize = sizeof (struct PutMessage) + data_len;
963 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 915 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
916 {
917 GNUNET_break (0);
918 return;
919 }
920 if ((reply_anonymity_level != UINT32_MAX) && (reply_anonymity_level > 1))
921 {
922 if (reply_anonymity_level - 1 > GSF_cover_content_count)
964 { 923 {
965 GNUNET_break (0); 924 GNUNET_STATISTICS_update (GSF_stats,
925 gettext_noop
926 ("# replies dropped due to insufficient cover traffic"),
927 1, GNUNET_NO);
966 return; 928 return;
967 } 929 }
968 if ( (reply_anonymity_level != UINT32_MAX) && 930 GSF_cover_content_count -= (reply_anonymity_level - 1);
969 (reply_anonymity_level > 1) ) 931 }
970 { 932
971 if (reply_anonymity_level - 1 > GSF_cover_content_count)
972 {
973 GNUNET_STATISTICS_update (GSF_stats,
974 gettext_noop ("# replies dropped due to insufficient cover traffic"),
975 1,
976 GNUNET_NO);
977 return;
978 }
979 GSF_cover_content_count -= (reply_anonymity_level - 1);
980 }
981
982 pm = GNUNET_malloc (msize); 933 pm = GNUNET_malloc (msize);
983 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT); 934 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
984 pm->header.size = htons (msize); 935 pm->header.size = htons (msize);
985 pm->type = htonl (type); 936 pm->type = htonl (type);
986 pm->expiration = GNUNET_TIME_absolute_hton (expiration); 937 pm->expiration = GNUNET_TIME_absolute_hton (expiration);
987 memcpy (&pm[1], data, data_len); 938 memcpy (&pm[1], data, data_len);
988 if ( (reply_anonymity_level != UINT32_MAX) && 939 if ((reply_anonymity_level != UINT32_MAX) &&
989 (reply_anonymity_level != 0) && 940 (reply_anonymity_level != 0) &&
990 (GSF_enable_randomized_delays == GNUNET_YES) ) 941 (GSF_enable_randomized_delays == GNUNET_YES))
991 { 942 {
992 struct GSF_DelayedHandle *dh; 943 struct GSF_DelayedHandle *dh;
993 944
994 dh = GNUNET_malloc (sizeof (struct GSF_DelayedHandle)); 945 dh = GNUNET_malloc (sizeof (struct GSF_DelayedHandle));
995 dh->cp = cp; 946 dh->cp = cp;
996 dh->pm = pm; 947 dh->pm = pm;
997 dh->msize = msize; 948 dh->msize = msize;
998 GNUNET_CONTAINER_DLL_insert (cp->delayed_head, 949 GNUNET_CONTAINER_DLL_insert (cp->delayed_head, cp->delayed_tail, dh);
999 cp->delayed_tail, 950 dh->delay_task = GNUNET_SCHEDULER_add_delayed (get_randomized_delay (),
1000 dh); 951 &transmit_delayed_now, dh);
1001 dh->delay_task = GNUNET_SCHEDULER_add_delayed (get_randomized_delay (), 952 }
1002 &transmit_delayed_now,
1003 dh);
1004 }
1005 else 953 else
1006 { 954 {
1007 (void) GSF_peer_transmit_ (cp, GNUNET_NO, 955 (void) GSF_peer_transmit_ (cp, GNUNET_NO,
1008 UINT32_MAX, 956 UINT32_MAX,
1009 REPLY_TIMEOUT, 957 REPLY_TIMEOUT, msize, &copy_reply, pm);
1010 msize, 958 }
1011 &copy_reply,
1012 pm);
1013 }
1014 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST) 959 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
1015 return; 960 return;
1016 if (GNUNET_SCHEDULER_NO_TASK == peerreq->kill_task) 961 if (GNUNET_SCHEDULER_NO_TASK == peerreq->kill_task)
1017 { 962 {
1018 GNUNET_STATISTICS_update (GSF_stats, 963 GNUNET_STATISTICS_update (GSF_stats,
1019 gettext_noop ("# P2P searches destroyed due to ultimate reply"), 964 gettext_noop
1020 1, 965 ("# P2P searches destroyed due to ultimate reply"),
1021 GNUNET_NO); 966 1, GNUNET_NO);
1022 peerreq->kill_task = GNUNET_SCHEDULER_add_now (&peer_request_destroy, 967 peerreq->kill_task =
1023 peerreq); 968 GNUNET_SCHEDULER_add_now (&peer_request_destroy, peerreq);
1024 } 969 }
1025} 970}
1026 971
1027 972
@@ -1040,25 +985,25 @@ change_host_trust (struct GSF_ConnectedPeer *cp, int value)
1040 return 0; 985 return 0;
1041 GNUNET_assert (cp != NULL); 986 GNUNET_assert (cp != NULL);
1042 if (value > 0) 987 if (value > 0)
988 {
989 if (cp->ppd.trust + value < cp->ppd.trust)
1043 { 990 {
1044 if (cp->ppd.trust + value < cp->ppd.trust) 991 value = UINT32_MAX - cp->ppd.trust;
1045 { 992 cp->ppd.trust = UINT32_MAX;
1046 value = UINT32_MAX - cp->ppd.trust;
1047 cp->ppd.trust = UINT32_MAX;
1048 }
1049 else
1050 cp->ppd.trust += value;
1051 } 993 }
994 else
995 cp->ppd.trust += value;
996 }
1052 else 997 else
998 {
999 if (cp->ppd.trust < -value)
1053 { 1000 {
1054 if (cp->ppd.trust < -value) 1001 value = -cp->ppd.trust;
1055 { 1002 cp->ppd.trust = 0;
1056 value = -cp->ppd.trust;
1057 cp->ppd.trust = 0;
1058 }
1059 else
1060 cp->ppd.trust += value;
1061 } 1003 }
1004 else
1005 cp->ppd.trust += value;
1006 }
1062 return value; 1007 return value;
1063} 1008}
1064 1009
@@ -1072,8 +1017,7 @@ change_host_trust (struct GSF_ConnectedPeer *cp, int value)
1072 * @return effective priority 1017 * @return effective priority
1073 */ 1018 */
1074static int32_t 1019static int32_t
1075bound_priority (uint32_t prio_in, 1020bound_priority (uint32_t prio_in, struct GSF_ConnectedPeer *cp)
1076 struct GSF_ConnectedPeer *cp)
1077{ 1021{
1078#define N ((double)128.0) 1022#define N ((double)128.0)
1079 uint32_t ret; 1023 uint32_t ret;
@@ -1082,47 +1026,46 @@ bound_priority (uint32_t prio_in,
1082 1026
1083 ld = GSF_test_get_load_too_high_ (0); 1027 ld = GSF_test_get_load_too_high_ (0);
1084 if (ld == GNUNET_SYSERR) 1028 if (ld == GNUNET_SYSERR)
1085 { 1029 {
1086 GNUNET_STATISTICS_update (GSF_stats, 1030 GNUNET_STATISTICS_update (GSF_stats,
1087 gettext_noop ("# requests done for free (low load)"), 1031 gettext_noop
1088 1, 1032 ("# requests done for free (low load)"), 1,
1089 GNUNET_NO); 1033 GNUNET_NO);
1090 return 0; /* excess resources */ 1034 return 0; /* excess resources */
1091 } 1035 }
1092 if (prio_in > INT32_MAX) 1036 if (prio_in > INT32_MAX)
1093 prio_in = INT32_MAX; 1037 prio_in = INT32_MAX;
1094 ret = - change_host_trust (cp, - (int) prio_in); 1038 ret = -change_host_trust (cp, -(int) prio_in);
1095 if (ret > 0) 1039 if (ret > 0)
1096 { 1040 {
1097 if (ret > GSF_current_priorities + N) 1041 if (ret > GSF_current_priorities + N)
1098 rret = GSF_current_priorities + N; 1042 rret = GSF_current_priorities + N;
1099 else 1043 else
1100 rret = ret; 1044 rret = ret;
1101 GSF_current_priorities 1045 GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N;
1102 = (GSF_current_priorities * (N-1) + rret)/N; 1046 }
1103 } 1047 if ((ld == GNUNET_YES) && (ret > 0))
1104 if ( (ld == GNUNET_YES) && (ret > 0) ) 1048 {
1105 { 1049 /* try with charging */
1106 /* try with charging */ 1050 ld = GSF_test_get_load_too_high_ (ret);
1107 ld = GSF_test_get_load_too_high_ (ret); 1051 }
1108 }
1109 if (ld == GNUNET_YES) 1052 if (ld == GNUNET_YES)
1110 { 1053 {
1111 GNUNET_STATISTICS_update (GSF_stats, 1054 GNUNET_STATISTICS_update (GSF_stats,
1112 gettext_noop ("# request dropped, priority insufficient"), 1055 gettext_noop
1113 1, 1056 ("# request dropped, priority insufficient"), 1,
1114 GNUNET_NO); 1057 GNUNET_NO);
1115 /* undo charge */ 1058 /* undo charge */
1116 change_host_trust (cp, (int) ret); 1059 change_host_trust (cp, (int) ret);
1117 return -1; /* not enough resources */ 1060 return -1; /* not enough resources */
1118 } 1061 }
1119 else 1062 else
1120 { 1063 {
1121 GNUNET_STATISTICS_update (GSF_stats, 1064 GNUNET_STATISTICS_update (GSF_stats,
1122 gettext_noop ("# requests done for a price (normal load)"), 1065 gettext_noop
1123 1, 1066 ("# requests done for a price (normal load)"), 1,
1124 GNUNET_NO); 1067 GNUNET_NO);
1125 } 1068 }
1126#undef N 1069#undef N
1127 return ret; 1070 return ret;
1128} 1071}
@@ -1144,13 +1087,13 @@ bound_ttl (int32_t ttl_in, uint32_t prio)
1144 1087
1145 if (ttl_in <= 0) 1088 if (ttl_in <= 0)
1146 return ttl_in; 1089 return ttl_in;
1147 allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000; 1090 allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
1148 if (ttl_in > allowed) 1091 if (ttl_in > allowed)
1149 { 1092 {
1150 if (allowed >= (1 << 30)) 1093 if (allowed >= (1 << 30))
1151 return 1 << 30; 1094 return 1 << 30;
1152 return allowed; 1095 return allowed;
1153 } 1096 }
1154 return ttl_in; 1097 return ttl_in;
1155} 1098}
1156 1099
@@ -1168,7 +1111,7 @@ bound_ttl (int32_t ttl_in, uint32_t prio)
1168 */ 1111 */
1169struct GSF_PendingRequest * 1112struct GSF_PendingRequest *
1170GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other, 1113GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1171 const struct GNUNET_MessageHeader *message) 1114 const struct GNUNET_MessageHeader *message)
1172{ 1115{
1173 struct PeerRequest *peerreq; 1116 struct PeerRequest *peerreq;
1174 struct GSF_PendingRequest *pr; 1117 struct GSF_PendingRequest *pr;
@@ -1177,7 +1120,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1177 struct GSF_ConnectedPeer *cps; 1120 struct GSF_ConnectedPeer *cps;
1178 const GNUNET_HashCode *namespace; 1121 const GNUNET_HashCode *namespace;
1179 const struct GNUNET_PeerIdentity *target; 1122 const struct GNUNET_PeerIdentity *target;
1180 enum GSF_PendingRequestOptions options; 1123 enum GSF_PendingRequestOptions options;
1181 uint16_t msize; 1124 uint16_t msize;
1182 const struct GetMessage *gm; 1125 const struct GetMessage *gm;
1183 unsigned int bits; 1126 unsigned int bits;
@@ -1191,229 +1134,214 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1191 GNUNET_PEER_Id spid; 1134 GNUNET_PEER_Id spid;
1192 1135
1193 GNUNET_assert (other != NULL); 1136 GNUNET_assert (other != NULL);
1194 msize = ntohs(message->size); 1137 msize = ntohs (message->size);
1195 if (msize < sizeof (struct GetMessage)) 1138 if (msize < sizeof (struct GetMessage))
1196 { 1139 {
1197 GNUNET_break_op (0); 1140 GNUNET_break_op (0);
1198 return NULL; 1141 return NULL;
1199 } 1142 }
1200 GNUNET_STATISTICS_update (GSF_stats, 1143 GNUNET_STATISTICS_update (GSF_stats,
1201 gettext_noop ("# GET requests received (from other peers)"), 1144 gettext_noop
1202 1, 1145 ("# GET requests received (from other peers)"), 1,
1203 GNUNET_NO); 1146 GNUNET_NO);
1204 gm = (const struct GetMessage*) message; 1147 gm = (const struct GetMessage *) message;
1205 type = ntohl (gm->type); 1148 type = ntohl (gm->type);
1206 bm = ntohl (gm->hash_bitmap); 1149 bm = ntohl (gm->hash_bitmap);
1207 bits = 0; 1150 bits = 0;
1208 while (bm > 0) 1151 while (bm > 0)
1209 { 1152 {
1210 if (1 == (bm & 1)) 1153 if (1 == (bm & 1))
1211 bits++; 1154 bits++;
1212 bm >>= 1; 1155 bm >>= 1;
1213 } 1156 }
1214 if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode)) 1157 if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode))
1215 { 1158 {
1216 GNUNET_break_op (0); 1159 GNUNET_break_op (0);
1217 return NULL; 1160 return NULL;
1218 } 1161 }
1219 opt = (const GNUNET_HashCode*) &gm[1]; 1162 opt = (const GNUNET_HashCode *) &gm[1];
1220 bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (GNUNET_HashCode); 1163 bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (GNUNET_HashCode);
1221 /* bfsize must be power of 2, check! */ 1164 /* bfsize must be power of 2, check! */
1222 if (0 != ( (bfsize - 1) & bfsize)) 1165 if (0 != ((bfsize - 1) & bfsize))
1223 { 1166 {
1224 GNUNET_break_op (0); 1167 GNUNET_break_op (0);
1225 return NULL; 1168 return NULL;
1226 } 1169 }
1227 GSF_cover_query_count++; 1170 GSF_cover_query_count++;
1228 bm = ntohl (gm->hash_bitmap); 1171 bm = ntohl (gm->hash_bitmap);
1229 bits = 0; 1172 bits = 0;
1230 cps = GNUNET_CONTAINER_multihashmap_get (cp_map, 1173 cps = GNUNET_CONTAINER_multihashmap_get (cp_map, &other->hashPubKey);
1231 &other->hashPubKey);
1232 if (NULL == cps) 1174 if (NULL == cps)
1233 { 1175 {
1234 /* peer must have just disconnected */ 1176 /* peer must have just disconnected */
1235 GNUNET_STATISTICS_update (GSF_stats, 1177 GNUNET_STATISTICS_update (GSF_stats,
1236 gettext_noop ("# requests dropped due to initiator not being connected"), 1178 gettext_noop
1237 1, 1179 ("# requests dropped due to initiator not being connected"),
1238 GNUNET_NO); 1180 1, GNUNET_NO);
1239 return NULL; 1181 return NULL;
1240 } 1182 }
1241 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) 1183 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1242 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 1184 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &opt[bits++]);
1243 &opt[bits++]);
1244 else 1185 else
1245 cp = cps; 1186 cp = cps;
1246 if (cp == NULL) 1187 if (cp == NULL)
1247 { 1188 {
1248#if DEBUG_FS 1189#if DEBUG_FS
1249 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) 1190 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1251 "Failed to find RETURN-TO peer `%4s' in connection set. Dropping query.\n", 1192 "Failed to find RETURN-TO peer `%4s' in connection set. Dropping query.\n",
1252 GNUNET_i2s ((const struct GNUNET_PeerIdentity*) &opt[bits-1])); 1193 GNUNET_i2s ((const struct GNUNET_PeerIdentity *)
1253 1194 &opt[bits - 1]));
1254 else 1195
1255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1196 else
1256 "Failed to find peer `%4s' in connection set. Dropping query.\n", 1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1257 GNUNET_i2s (other)); 1198 "Failed to find peer `%4s' in connection set. Dropping query.\n",
1199 GNUNET_i2s (other));
1258#endif 1200#endif
1259 GNUNET_STATISTICS_update (GSF_stats, 1201 GNUNET_STATISTICS_update (GSF_stats,
1260 gettext_noop ("# requests dropped due to missing reverse route"), 1202 gettext_noop
1261 1, 1203 ("# requests dropped due to missing reverse route"),
1262 GNUNET_NO); 1204 1, GNUNET_NO);
1263 return NULL; 1205 return NULL;
1264 } 1206 }
1265 /* note that we can really only check load here since otherwise 1207 /* note that we can really only check load here since otherwise
1266 peers could find out that we are overloaded by not being 1208 * peers could find out that we are overloaded by not being
1267 disconnected after sending us a malformed query... */ 1209 * disconnected after sending us a malformed query... */
1268 priority = bound_priority (ntohl (gm->priority), cps); 1210 priority = bound_priority (ntohl (gm->priority), cps);
1269 if (priority < 0) 1211 if (priority < 0)
1270 { 1212 {
1271#if DEBUG_FS 1213#if DEBUG_FS
1272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1273 "Dropping query from `%s', this peer is too busy.\n", 1215 "Dropping query from `%s', this peer is too busy.\n",
1274 GNUNET_i2s (other)); 1216 GNUNET_i2s (other));
1275#endif 1217#endif
1276 return NULL; 1218 return NULL;
1277 } 1219 }
1278#if DEBUG_FS 1220#if DEBUG_FS
1279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1280 "Received request for `%s' of type %u from peer `%4s' with flags %u\n", 1222 "Received request for `%s' of type %u from peer `%4s' with flags %u\n",
1281 GNUNET_h2s (&gm->query), 1223 GNUNET_h2s (&gm->query),
1282 (unsigned int) type, 1224 (unsigned int) type, GNUNET_i2s (other), (unsigned int) bm);
1283 GNUNET_i2s (other),
1284 (unsigned int) bm);
1285#endif 1225#endif
1286 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL; 1226 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL;
1287 if ( (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && 1227 if ((type == GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace == NULL))
1288 (namespace == NULL) ) 1228 {
1289 { 1229 GNUNET_break_op (0);
1290 GNUNET_break_op (0); 1230 return NULL;
1291 return NULL; 1231 }
1292 } 1232 if ((type != GNUNET_BLOCK_TYPE_FS_SBLOCK) && (namespace != NULL))
1293 if ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) && 1233 {
1294 (namespace != NULL) ) 1234 GNUNET_break_op (0);
1295 { 1235 return NULL;
1296 GNUNET_break_op (0); 1236 }
1297 return NULL; 1237 target =
1298 } 1238 (0 !=
1299 target = (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity*) &opt[bits++]) : NULL; 1239 (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity
1240 *) &opt[bits++]) : NULL;
1300 options = 0; 1241 options = 0;
1301 spid = 0; 1242 spid = 0;
1302 if ( (GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority)) || 1243 if ((GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority))
1303 (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) > 1244 || (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) >
1304 GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 + GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)) ) 1245 GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 +
1305 { 1246 GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)))
1306 /* don't have BW to send to peer, or would likely take longer than we have for it, 1247 {
1307 so at best indirect the query */ 1248 /* don't have BW to send to peer, or would likely take longer than we have for it,
1308 priority = 0; 1249 * so at best indirect the query */
1309 options |= GSF_PRO_FORWARD_ONLY; 1250 priority = 0;
1310 spid = GNUNET_PEER_intern (other); 1251 options |= GSF_PRO_FORWARD_ONLY;
1311 GNUNET_assert (0 != spid); 1252 spid = GNUNET_PEER_intern (other);
1312 } 1253 GNUNET_assert (0 != spid);
1254 }
1313 ttl = bound_ttl (ntohl (gm->ttl), priority); 1255 ttl = bound_ttl (ntohl (gm->ttl), priority);
1314 /* decrement ttl (always) */ 1256 /* decrement ttl (always) */
1315 ttl_decrement = 2 * TTL_DECREMENT + 1257 ttl_decrement = 2 * TTL_DECREMENT +
1316 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1258 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TTL_DECREMENT);
1317 TTL_DECREMENT); 1259 if ((ttl < 0) && (((int32_t) (ttl - ttl_decrement)) > 0))
1318 if ( (ttl < 0) && 1260 {
1319 (((int32_t)(ttl - ttl_decrement)) > 0) )
1320 {
1321#if DEBUG_FS 1261#if DEBUG_FS
1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1323 "Dropping query from `%s' due to TTL underflow (%d - %u).\n", 1263 "Dropping query from `%s' due to TTL underflow (%d - %u).\n",
1324 GNUNET_i2s (other), 1264 GNUNET_i2s (other), ttl, ttl_decrement);
1325 ttl,
1326 ttl_decrement);
1327#endif 1265#endif
1328 GNUNET_STATISTICS_update (GSF_stats, 1266 GNUNET_STATISTICS_update (GSF_stats,
1329 gettext_noop ("# requests dropped due TTL underflow"), 1267 gettext_noop
1330 1, 1268 ("# requests dropped due TTL underflow"), 1,
1331 GNUNET_NO); 1269 GNUNET_NO);
1332 /* integer underflow => drop (should be very rare)! */ 1270 /* integer underflow => drop (should be very rare)! */
1333 return NULL; 1271 return NULL;
1334 } 1272 }
1335 ttl -= ttl_decrement; 1273 ttl -= ttl_decrement;
1336 1274
1337 /* test if the request already exists */ 1275 /* test if the request already exists */
1338 peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map, 1276 peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map, &gm->query);
1339 &gm->query); 1277 if (peerreq != NULL)
1340 if (peerreq != NULL) 1278 {
1341 { 1279 pr = peerreq->pr;
1342 pr = peerreq->pr; 1280 prd = GSF_pending_request_get_data_ (pr);
1343 prd = GSF_pending_request_get_data_ (pr); 1281 if ((prd->type == type) &&
1344 if ( (prd->type == type) && 1282 ((type != GNUNET_BLOCK_TYPE_FS_SBLOCK) ||
1345 ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) || 1283 (0 == memcmp (&prd->namespace, namespace, sizeof (GNUNET_HashCode)))))
1346 (0 == memcmp (&prd->namespace, 1284 {
1347 namespace, 1285 if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get ().abs_value + ttl)
1348 sizeof (GNUNET_HashCode))) ) ) 1286 {
1349 { 1287 /* existing request has higher TTL, drop new one! */
1350 if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get().abs_value + ttl) 1288 prd->priority += priority;
1351 {
1352 /* existing request has higher TTL, drop new one! */
1353 prd->priority += priority;
1354#if DEBUG_FS 1289#if DEBUG_FS
1355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1356 "Have existing request with higher TTL, dropping new request.\n", 1291 "Have existing request with higher TTL, dropping new request.\n",
1357 GNUNET_i2s (other)); 1292 GNUNET_i2s (other));
1358#endif 1293#endif
1359 GNUNET_STATISTICS_update (GSF_stats, 1294 GNUNET_STATISTICS_update (GSF_stats,
1360 gettext_noop ("# requests dropped due to higher-TTL request"), 1295 gettext_noop
1361 1, 1296 ("# requests dropped due to higher-TTL request"),
1362 GNUNET_NO); 1297 1, GNUNET_NO);
1363 return NULL; 1298 return NULL;
1364 } 1299 }
1365 /* existing request has lower TTL, drop old one! */ 1300 /* existing request has lower TTL, drop old one! */
1366 GNUNET_STATISTICS_update (GSF_stats, 1301 GNUNET_STATISTICS_update (GSF_stats,
1367 gettext_noop ("# P2P searches active"), 1302 gettext_noop ("# P2P searches active"),
1368 -1, 1303 -1, GNUNET_NO);
1369 GNUNET_NO); 1304 priority += prd->priority;
1370 priority += prd->priority; 1305 GSF_pending_request_cancel_ (pr, GNUNET_YES);
1371 GSF_pending_request_cancel_ (pr, GNUNET_YES); 1306 GNUNET_assert (GNUNET_YES ==
1372 GNUNET_assert (GNUNET_YES == 1307 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
1373 GNUNET_CONTAINER_multihashmap_remove (cp->request_map, 1308 &gm->query,
1374 &gm->query, 1309 peerreq));
1375 peerreq)); 1310 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
1376 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK) 1311 {
1377 { 1312 GNUNET_SCHEDULER_cancel (peerreq->kill_task);
1378 GNUNET_SCHEDULER_cancel (peerreq->kill_task); 1313 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
1379 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK; 1314 }
1380 } 1315 GNUNET_free (peerreq);
1381 GNUNET_free (peerreq);
1382 }
1383 } 1316 }
1384 1317 }
1318
1385 peerreq = GNUNET_malloc (sizeof (struct PeerRequest)); 1319 peerreq = GNUNET_malloc (sizeof (struct PeerRequest));
1386 peerreq->cp = cp; 1320 peerreq->cp = cp;
1387 pr = GSF_pending_request_create_ (options, 1321 pr = GSF_pending_request_create_ (options,
1388 type, 1322 type,
1389 &gm->query, 1323 &gm->query,
1390 namespace, 1324 namespace,
1391 target, 1325 target,
1392 (bfsize > 0) ? (const char*)&opt[bits] : NULL, 1326 (bfsize >
1393 bfsize, 1327 0) ? (const char *) &opt[bits] : NULL,
1394 ntohl (gm->filter_mutator), 1328 bfsize, ntohl (gm->filter_mutator),
1395 1 /* anonymity */, 1329 1 /* anonymity */ ,
1396 (uint32_t) priority, 1330 (uint32_t) priority, ttl, spid, NULL, 0, /* replies_seen */
1397 ttl, 1331 &handle_p2p_reply, peerreq);
1398 spid,
1399 NULL, 0, /* replies_seen */
1400 &handle_p2p_reply,
1401 peerreq);
1402 GNUNET_assert (NULL != pr); 1332 GNUNET_assert (NULL != pr);
1403 peerreq->pr = pr; 1333 peerreq->pr = pr;
1404 GNUNET_break (GNUNET_OK == 1334 GNUNET_break (GNUNET_OK ==
1405 GNUNET_CONTAINER_multihashmap_put (cp->request_map, 1335 GNUNET_CONTAINER_multihashmap_put (cp->request_map,
1406 &gm->query, 1336 &gm->query,
1407 peerreq, 1337 peerreq,
1408 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 1338 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1409 GNUNET_STATISTICS_update (GSF_stats,
1410 gettext_noop ("# P2P query messages received and processed"),
1411 1,
1412 GNUNET_NO);
1413 GNUNET_STATISTICS_update (GSF_stats, 1339 GNUNET_STATISTICS_update (GSF_stats,
1414 gettext_noop ("# P2P searches active"), 1340 gettext_noop
1415 1, 1341 ("# P2P query messages received and processed"), 1,
1416 GNUNET_NO); 1342 GNUNET_NO);
1343 GNUNET_STATISTICS_update (GSF_stats, gettext_noop ("# P2P searches active"),
1344 1, GNUNET_NO);
1417 return pr; 1345 return pr;
1418} 1346}
1419 1347
@@ -1426,34 +1354,29 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1426 * @param tc scheduler context 1354 * @param tc scheduler context
1427 */ 1355 */
1428static void 1356static void
1429peer_transmit_timeout (void *cls, 1357peer_transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1430 const struct GNUNET_SCHEDULER_TaskContext *tc)
1431{ 1358{
1432 struct GSF_PeerTransmitHandle *pth = cls; 1359 struct GSF_PeerTransmitHandle *pth = cls;
1433 struct GSF_ConnectedPeer *cp; 1360 struct GSF_ConnectedPeer *cp;
1434 1361
1435#if DEBUG_FS 1362#if DEBUG_FS
1436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1437 "Timeout trying to transmit to other peer\n"); 1364 "Timeout trying to transmit to other peer\n");
1438#endif 1365#endif
1439 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1366 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1440 cp = pth->cp; 1367 cp = pth->cp;
1441 GNUNET_CONTAINER_DLL_remove (cp->pth_head, 1368 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
1442 cp->pth_tail,
1443 pth);
1444 if (GNUNET_YES == pth->is_query) 1369 if (GNUNET_YES == pth->is_query)
1445 GNUNET_assert (0 < cp->ppd.pending_queries--); 1370 GNUNET_assert (0 < cp->ppd.pending_queries--);
1446 else if (GNUNET_NO == pth->is_query) 1371 else if (GNUNET_NO == pth->is_query)
1447 GNUNET_assert (0 < cp->ppd.pending_replies--); 1372 GNUNET_assert (0 < cp->ppd.pending_replies--);
1448 GNUNET_LOAD_update (cp->ppd.transmission_delay, 1373 GNUNET_LOAD_update (cp->ppd.transmission_delay, UINT64_MAX);
1449 UINT64_MAX);
1450 if (NULL != pth->cth) 1374 if (NULL != pth->cth)
1451 { 1375 {
1452 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth); 1376 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1453 pth->cth = NULL; 1377 pth->cth = NULL;
1454 } 1378 }
1455 pth->gmc (pth->gmc_cls, 1379 pth->gmc (pth->gmc_cls, 0, NULL);
1456 0, NULL);
1457 GNUNET_assert (0 == pth->cth_in_progress); 1380 GNUNET_assert (0 == pth->cth_in_progress);
1458 GNUNET_free (pth); 1381 GNUNET_free (pth);
1459} 1382}
@@ -1475,12 +1398,10 @@ peer_transmit_timeout (void *cls,
1475 */ 1398 */
1476struct GSF_PeerTransmitHandle * 1399struct GSF_PeerTransmitHandle *
1477GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, 1400GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
1478 int is_query, 1401 int is_query,
1479 uint32_t priority, 1402 uint32_t priority,
1480 struct GNUNET_TIME_Relative timeout, 1403 struct GNUNET_TIME_Relative timeout,
1481 size_t size, 1404 size_t size, GSF_GetMessageCallback gmc, void *gmc_cls)
1482 GSF_GetMessageCallback gmc,
1483 void *gmc_cls)
1484{ 1405{
1485 struct GSF_PeerTransmitHandle *pth; 1406 struct GSF_PeerTransmitHandle *pth;
1486 struct GSF_PeerTransmitHandle *pos; 1407 struct GSF_PeerTransmitHandle *pos;
@@ -1498,28 +1419,22 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
1498 /* insertion sort (by priority, descending) */ 1419 /* insertion sort (by priority, descending) */
1499 prev = NULL; 1420 prev = NULL;
1500 pos = cp->pth_head; 1421 pos = cp->pth_head;
1501 while ( (pos != NULL) && 1422 while ((pos != NULL) && (pos->priority > priority))
1502 (pos->priority > priority) ) 1423 {
1503 { 1424 prev = pos;
1504 prev = pos; 1425 pos = pos->next;
1505 pos = pos->next; 1426 }
1506 }
1507 if (prev == NULL) 1427 if (prev == NULL)
1508 GNUNET_CONTAINER_DLL_insert (cp->pth_head, 1428 GNUNET_CONTAINER_DLL_insert (cp->pth_head, cp->pth_tail, pth);
1509 cp->pth_tail,
1510 pth);
1511 else 1429 else
1512 GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, 1430 GNUNET_CONTAINER_DLL_insert_after (cp->pth_head, cp->pth_tail, prev, pth);
1513 cp->pth_tail,
1514 prev,
1515 pth);
1516 if (GNUNET_YES == is_query) 1431 if (GNUNET_YES == is_query)
1517 cp->ppd.pending_queries++; 1432 cp->ppd.pending_queries++;
1518 else if (GNUNET_NO == is_query) 1433 else if (GNUNET_NO == is_query)
1519 cp->ppd.pending_replies++; 1434 cp->ppd.pending_replies++;
1520 pth->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, 1435 pth->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
1521 &peer_transmit_timeout, 1436 &peer_transmit_timeout,
1522 pth); 1437 pth);
1523 schedule_transmission (pth); 1438 schedule_transmission (pth);
1524 return pth; 1439 return pth;
1525} 1440}
@@ -1536,21 +1451,19 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
1536 struct GSF_ConnectedPeer *cp; 1451 struct GSF_ConnectedPeer *cp;
1537 1452
1538 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1453 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1539 { 1454 {
1540 GNUNET_SCHEDULER_cancel (pth->timeout_task); 1455 GNUNET_SCHEDULER_cancel (pth->timeout_task);
1541 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1456 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1542 } 1457 }
1543 if (NULL != pth->cth) 1458 if (NULL != pth->cth)
1544 { 1459 {
1545 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth); 1460 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1546 pth->cth = NULL; 1461 pth->cth = NULL;
1547 } 1462 }
1548 cp = pth->cp; 1463 cp = pth->cp;
1549 GNUNET_CONTAINER_DLL_remove (cp->pth_head, 1464 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
1550 cp->pth_tail,
1551 pth);
1552 if (GNUNET_YES == pth->is_query) 1465 if (GNUNET_YES == pth->is_query)
1553 GNUNET_assert (0 < cp->ppd.pending_queries--); 1466 GNUNET_assert (0 < cp->ppd.pending_queries--);
1554 else if (GNUNET_NO == pth->is_query) 1467 else if (GNUNET_NO == pth->is_query)
1555 GNUNET_assert (0 < cp->ppd.pending_replies--); 1468 GNUNET_assert (0 < cp->ppd.pending_replies--);
1556 GNUNET_assert (0 == pth->cth_in_progress); 1469 GNUNET_assert (0 == pth->cth_in_progress);
@@ -1567,14 +1480,18 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
1567 */ 1480 */
1568void 1481void
1569GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, 1482GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
1570 struct GNUNET_TIME_Absolute request_time, 1483 struct GNUNET_TIME_Absolute request_time,
1571 uint32_t request_priority) 1484 uint32_t request_priority)
1572{ 1485{
1573 struct GNUNET_TIME_Relative delay; 1486 struct GNUNET_TIME_Relative delay;
1574 1487
1575 delay = GNUNET_TIME_absolute_get_duration (request_time); 1488 delay = GNUNET_TIME_absolute_get_duration (request_time);
1576 cp->ppd.avg_reply_delay.rel_value = (cp->ppd.avg_reply_delay.rel_value * (RUNAVG_DELAY_N-1) + delay.rel_value) / RUNAVG_DELAY_N; 1489 cp->ppd.avg_reply_delay.rel_value =
1577 cp->ppd.avg_priority = (cp->ppd.avg_priority * (RUNAVG_DELAY_N-1) + request_priority) / RUNAVG_DELAY_N; 1490 (cp->ppd.avg_reply_delay.rel_value * (RUNAVG_DELAY_N - 1) +
1491 delay.rel_value) / RUNAVG_DELAY_N;
1492 cp->ppd.avg_priority =
1493 (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) +
1494 request_priority) / RUNAVG_DELAY_N;
1578} 1495}
1579 1496
1580 1497
@@ -1587,9 +1504,10 @@ GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
1587 */ 1504 */
1588void 1505void
1589GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, 1506GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
1590 struct GSF_LocalClient *initiator_client) 1507 struct GSF_LocalClient *initiator_client)
1591{ 1508{
1592 cp->ppd.last_client_replies[cp->last_client_replies_woff++ % CS2P_SUCCESS_LIST_SIZE] = initiator_client; 1509 cp->ppd.last_client_replies[cp->last_client_replies_woff++ %
1510 CS2P_SUCCESS_LIST_SIZE] = initiator_client;
1593} 1511}
1594 1512
1595 1513
@@ -1602,7 +1520,7 @@ GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
1602 */ 1520 */
1603void 1521void
1604GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, 1522GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
1605 const struct GSF_ConnectedPeer *initiator_peer) 1523 const struct GSF_ConnectedPeer *initiator_peer)
1606{ 1524{
1607 unsigned int woff; 1525 unsigned int woff;
1608 1526
@@ -1627,16 +1545,15 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
1627 */ 1545 */
1628void 1546void
1629GSF_peer_status_handler_ (void *cls, 1547GSF_peer_status_handler_ (void *cls,
1630 const struct GNUNET_PeerIdentity *peer, 1548 const struct GNUNET_PeerIdentity *peer,
1631 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1549 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1632 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 1550 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1633 struct GNUNET_TIME_Absolute timeout, 1551 struct GNUNET_TIME_Absolute timeout,
1634 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1552 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1635{ 1553{
1636 struct GSF_ConnectedPeer *cp; 1554 struct GSF_ConnectedPeer *cp;
1637 1555
1638 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 1556 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
1639 &peer->hashPubKey);
1640 GNUNET_assert (NULL != cp); 1557 GNUNET_assert (NULL != cp);
1641 update_atsi (cp, atsi); 1558 update_atsi (cp, atsi);
1642} 1559}
@@ -1650,40 +1567,36 @@ GSF_peer_status_handler_ (void *cls,
1650 * @param peer identity of peer that connected 1567 * @param peer identity of peer that connected
1651 */ 1568 */
1652void 1569void
1653GSF_peer_disconnect_handler_ (void *cls, 1570GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer)
1654 const struct GNUNET_PeerIdentity *peer)
1655{ 1571{
1656 struct GSF_ConnectedPeer *cp; 1572 struct GSF_ConnectedPeer *cp;
1657 struct GSF_PeerTransmitHandle *pth; 1573 struct GSF_PeerTransmitHandle *pth;
1658 struct GSF_DelayedHandle *dh; 1574 struct GSF_DelayedHandle *dh;
1659 1575
1660 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, 1576 cp = GNUNET_CONTAINER_multihashmap_get (cp_map, &peer->hashPubKey);
1661 &peer->hashPubKey);
1662 if (NULL == cp) 1577 if (NULL == cp)
1663 return; /* must have been disconnect from core with 1578 return; /* must have been disconnect from core with
1664 'peer' == my_id, ignore */ 1579 * 'peer' == my_id, ignore */
1665 GNUNET_assert (GNUNET_YES == 1580 GNUNET_assert (GNUNET_YES ==
1666 GNUNET_CONTAINER_multihashmap_remove (cp_map, 1581 GNUNET_CONTAINER_multihashmap_remove (cp_map,
1667 &peer->hashPubKey, 1582 &peer->hashPubKey, cp));
1668 cp));
1669 if (NULL != cp->migration_pth) 1583 if (NULL != cp->migration_pth)
1670 { 1584 {
1671 GSF_peer_transmit_cancel_ (cp->migration_pth); 1585 GSF_peer_transmit_cancel_ (cp->migration_pth);
1672 cp->migration_pth = NULL; 1586 cp->migration_pth = NULL;
1673 } 1587 }
1674 if (NULL != cp->irc) 1588 if (NULL != cp->irc)
1675 { 1589 {
1676 GNUNET_CORE_peer_change_preference_cancel (cp->irc); 1590 GNUNET_CORE_peer_change_preference_cancel (cp->irc);
1677 cp->irc = NULL; 1591 cp->irc = NULL;
1678 } 1592 }
1679 if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task) 1593 if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task)
1680 { 1594 {
1681 GNUNET_SCHEDULER_cancel (cp->irc_delay_task); 1595 GNUNET_SCHEDULER_cancel (cp->irc_delay_task);
1682 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK; 1596 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
1683 } 1597 }
1684 GNUNET_CONTAINER_multihashmap_iterate (cp->request_map, 1598 GNUNET_CONTAINER_multihashmap_iterate (cp->request_map,
1685 &cancel_pending_request, 1599 &cancel_pending_request, cp);
1686 cp);
1687 GNUNET_CONTAINER_multihashmap_destroy (cp->request_map); 1600 GNUNET_CONTAINER_multihashmap_destroy (cp->request_map);
1688 cp->request_map = NULL; 1601 cp->request_map = NULL;
1689 GSF_plan_notify_peer_disconnect_ (cp); 1602 GSF_plan_notify_peer_disconnect_ (cp);
@@ -1692,40 +1605,35 @@ GSF_peer_disconnect_handler_ (void *cls,
1692 memset (cp->ppd.last_p2p_replies, 0, sizeof (cp->ppd.last_p2p_replies)); 1605 memset (cp->ppd.last_p2p_replies, 0, sizeof (cp->ppd.last_p2p_replies));
1693 GSF_push_stop_ (cp); 1606 GSF_push_stop_ (cp);
1694 while (NULL != (pth = cp->pth_head)) 1607 while (NULL != (pth = cp->pth_head))
1608 {
1609 if (NULL != pth->cth)
1695 { 1610 {
1696 if (NULL != pth->cth) 1611 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1697 { 1612 pth->cth = NULL;
1698 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1699 pth->cth = NULL;
1700 }
1701 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1702 {
1703 GNUNET_SCHEDULER_cancel (pth->timeout_task);
1704 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1705 }
1706 GNUNET_CONTAINER_DLL_remove (cp->pth_head,
1707 cp->pth_tail,
1708 pth);
1709 GNUNET_assert (0 == pth->cth_in_progress);
1710 pth->gmc (pth->gmc_cls,
1711 0, NULL);
1712 GNUNET_free (pth);
1713 } 1613 }
1714 while (NULL != (dh = cp->delayed_head)) 1614 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1715 { 1615 {
1716 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, 1616 GNUNET_SCHEDULER_cancel (pth->timeout_task);
1717 cp->delayed_tail, 1617 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1718 dh);
1719 GNUNET_SCHEDULER_cancel (dh->delay_task);
1720 GNUNET_free (dh->pm);
1721 GNUNET_free (dh);
1722 } 1618 }
1619 GNUNET_CONTAINER_DLL_remove (cp->pth_head, cp->pth_tail, pth);
1620 GNUNET_assert (0 == pth->cth_in_progress);
1621 pth->gmc (pth->gmc_cls, 0, NULL);
1622 GNUNET_free (pth);
1623 }
1624 while (NULL != (dh = cp->delayed_head))
1625 {
1626 GNUNET_CONTAINER_DLL_remove (cp->delayed_head, cp->delayed_tail, dh);
1627 GNUNET_SCHEDULER_cancel (dh->delay_task);
1628 GNUNET_free (dh->pm);
1629 GNUNET_free (dh);
1630 }
1723 GNUNET_PEER_change_rc (cp->ppd.pid, -1); 1631 GNUNET_PEER_change_rc (cp->ppd.pid, -1);
1724 if (GNUNET_SCHEDULER_NO_TASK != cp->mig_revive_task) 1632 if (GNUNET_SCHEDULER_NO_TASK != cp->mig_revive_task)
1725 { 1633 {
1726 GNUNET_SCHEDULER_cancel (cp->mig_revive_task); 1634 GNUNET_SCHEDULER_cancel (cp->mig_revive_task);
1727 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK; 1635 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
1728 } 1636 }
1729 GNUNET_free (cp); 1637 GNUNET_free (cp);
1730} 1638}
1731 1639
@@ -1756,17 +1664,12 @@ struct IterationContext
1756 * @return GNUNET_YES to continue iteration 1664 * @return GNUNET_YES to continue iteration
1757 */ 1665 */
1758static int 1666static int
1759call_iterator (void *cls, 1667call_iterator (void *cls, const GNUNET_HashCode * key, void *value)
1760 const GNUNET_HashCode *key,
1761 void *value)
1762{ 1668{
1763 struct IterationContext *ic = cls; 1669 struct IterationContext *ic = cls;
1764 struct GSF_ConnectedPeer *cp = value; 1670 struct GSF_ConnectedPeer *cp = value;
1765 1671
1766 ic->it (ic->it_cls, 1672 ic->it (ic->it_cls, (const struct GNUNET_PeerIdentity *) key, cp, &cp->ppd);
1767 (const struct GNUNET_PeerIdentity*) key,
1768 cp,
1769 &cp->ppd);
1770 return GNUNET_YES; 1673 return GNUNET_YES;
1771} 1674}
1772 1675
@@ -1778,16 +1681,13 @@ call_iterator (void *cls,
1778 * @param it_cls closure for it 1681 * @param it_cls closure for it
1779 */ 1682 */
1780void 1683void
1781GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, 1684GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls)
1782 void *it_cls)
1783{ 1685{
1784 struct IterationContext ic; 1686 struct IterationContext ic;
1785 1687
1786 ic.it = it; 1688 ic.it = it;
1787 ic.it_cls = it_cls; 1689 ic.it_cls = it_cls;
1788 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1690 GNUNET_CONTAINER_multihashmap_iterate (cp_map, &call_iterator, &ic);
1789 &call_iterator,
1790 &ic);
1791} 1691}
1792 1692
1793 1693
@@ -1799,11 +1699,10 @@ GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
1799 */ 1699 */
1800void 1700void
1801GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, 1701GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
1802 struct GNUNET_PeerIdentity *id) 1702 struct GNUNET_PeerIdentity *id)
1803{ 1703{
1804 GNUNET_assert (0 != cp->ppd.pid); 1704 GNUNET_assert (0 != cp->ppd.pid);
1805 GNUNET_PEER_resolve (cp->ppd.pid, 1705 GNUNET_PEER_resolve (cp->ppd.pid, id);
1806 id);
1807} 1706}
1808 1707
1809 1708
@@ -1816,9 +1715,7 @@ GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
1816 * @return number of bytes copied to buf 1715 * @return number of bytes copied to buf
1817 */ 1716 */
1818static size_t 1717static size_t
1819create_migration_stop_message (void *cls, 1718create_migration_stop_message (void *cls, size_t size, void *buf)
1820 size_t size,
1821 void *buf)
1822{ 1719{
1823 struct GSF_ConnectedPeer *cp = cls; 1720 struct GSF_ConnectedPeer *cp = cls;
1824 struct MigrationStopMessage msm; 1721 struct MigrationStopMessage msm;
@@ -1830,7 +1727,9 @@ create_migration_stop_message (void *cls,
1830 msm.header.size = htons (sizeof (struct MigrationStopMessage)); 1727 msm.header.size = htons (sizeof (struct MigrationStopMessage));
1831 msm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP); 1728 msm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP);
1832 msm.reserved = htonl (0); 1729 msm.reserved = htonl (0);
1833 msm.duration = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block)); 1730 msm.duration =
1731 GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
1732 (cp->last_migration_block));
1834 memcpy (buf, &msm, sizeof (struct MigrationStopMessage)); 1733 memcpy (buf, &msm, sizeof (struct MigrationStopMessage));
1835 return sizeof (struct MigrationStopMessage); 1734 return sizeof (struct MigrationStopMessage);
1836} 1735}
@@ -1845,33 +1744,35 @@ create_migration_stop_message (void *cls,
1845 */ 1744 */
1846void 1745void
1847GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp, 1746GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
1848 struct GNUNET_TIME_Relative block_time) 1747 struct GNUNET_TIME_Relative block_time)
1849{ 1748{
1850 if (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value > block_time.rel_value) 1749 if (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value >
1851 { 1750 block_time.rel_value)
1751 {
1852#if DEBUG_FS && 0 1752#if DEBUG_FS && 0
1853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1854 "Migration already blocked for another %llu ms\n", 1754 "Migration already blocked for another %llu ms\n",
1855 (unsigned long long) GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value); 1755 (unsigned long long)
1756 GNUNET_TIME_absolute_get_remaining
1757 (cp->last_migration_block).rel_value);
1856#endif 1758#endif
1857 return; /* already blocked */ 1759 return; /* already blocked */
1858 } 1760 }
1859#if DEBUG_FS && 0 1761#if DEBUG_FS && 0
1860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1861 "Asking to stop migration for %llu ms\n", 1763 "Asking to stop migration for %llu ms\n",
1862 (unsigned long long) block_time.rel_value); 1764 (unsigned long long) block_time.rel_value);
1863#endif 1765#endif
1864 cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time); 1766 cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time);
1865 if (cp->migration_pth != NULL) 1767 if (cp->migration_pth != NULL)
1866 GSF_peer_transmit_cancel_ (cp->migration_pth); 1768 GSF_peer_transmit_cancel_ (cp->migration_pth);
1867 cp->migration_pth 1769 cp->migration_pth
1868 = GSF_peer_transmit_ (cp, 1770 = GSF_peer_transmit_ (cp,
1869 GNUNET_SYSERR, 1771 GNUNET_SYSERR,
1870 UINT32_MAX, 1772 UINT32_MAX,
1871 GNUNET_TIME_UNIT_FOREVER_REL, 1773 GNUNET_TIME_UNIT_FOREVER_REL,
1872 sizeof (struct MigrationStopMessage), 1774 sizeof (struct MigrationStopMessage),
1873 &create_migration_stop_message, 1775 &create_migration_stop_message, cp);
1874 cp);
1875} 1776}
1876 1777
1877 1778
@@ -1884,9 +1785,7 @@ GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
1884 * @return GNUNET_OK to continue iteration 1785 * @return GNUNET_OK to continue iteration
1885 */ 1786 */
1886static int 1787static int
1887flush_trust (void *cls, 1788flush_trust (void *cls, const GNUNET_HashCode * key, void *value)
1888 const GNUNET_HashCode *key,
1889 void *value)
1890{ 1789{
1891 struct GSF_ConnectedPeer *cp = value; 1790 struct GSF_ConnectedPeer *cp = value;
1892 char *fn; 1791 char *fn;
@@ -1894,26 +1793,27 @@ flush_trust (void *cls,
1894 struct GNUNET_PeerIdentity pid; 1793 struct GNUNET_PeerIdentity pid;
1895 1794
1896 if (cp->ppd.trust == cp->disk_trust) 1795 if (cp->ppd.trust == cp->disk_trust)
1897 return GNUNET_OK; /* unchanged */ 1796 return GNUNET_OK; /* unchanged */
1898 GNUNET_assert (0 != cp->ppd.pid); 1797 GNUNET_assert (0 != cp->ppd.pid);
1899 GNUNET_PEER_resolve (cp->ppd.pid, 1798 GNUNET_PEER_resolve (cp->ppd.pid, &pid);
1900 &pid);
1901 fn = get_trust_filename (&pid); 1799 fn = get_trust_filename (&pid);
1902 if (cp->ppd.trust == 0) 1800 if (cp->ppd.trust == 0)
1903 { 1801 {
1904 if ((0 != UNLINK (fn)) && (errno != ENOENT)) 1802 if ((0 != UNLINK (fn)) && (errno != ENOENT))
1905 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 1803 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1906 GNUNET_ERROR_TYPE_BULK, "unlink", fn); 1804 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
1907 } 1805 }
1908 else 1806 else
1909 { 1807 {
1910 trust = htonl (cp->ppd.trust); 1808 trust = htonl (cp->ppd.trust);
1911 if (sizeof(uint32_t) == GNUNET_DISK_fn_write (fn, &trust, 1809 if (sizeof (uint32_t) == GNUNET_DISK_fn_write (fn, &trust,
1912 sizeof(uint32_t), 1810 sizeof (uint32_t),
1913 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE 1811 GNUNET_DISK_PERM_USER_READ |
1914 | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ)) 1812 GNUNET_DISK_PERM_USER_WRITE |
1915 cp->disk_trust = cp->ppd.trust; 1813 GNUNET_DISK_PERM_GROUP_READ |
1916 } 1814 GNUNET_DISK_PERM_OTHER_READ))
1815 cp->disk_trust = cp->ppd.trust;
1816 }
1917 GNUNET_free (fn); 1817 GNUNET_free (fn);
1918 return GNUNET_OK; 1818 return GNUNET_OK;
1919} 1819}
@@ -1930,7 +1830,7 @@ flush_trust (void *cls,
1930 */ 1830 */
1931void 1831void
1932GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp, 1832GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
1933 uint64_t pref) 1833 uint64_t pref)
1934{ 1834{
1935 cp->inc_preference += pref; 1835 cp->inc_preference += pref;
1936} 1836}
@@ -1943,22 +1843,17 @@ GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
1943 * @param tc task context, not used 1843 * @param tc task context, not used
1944 */ 1844 */
1945static void 1845static void
1946cron_flush_trust (void *cls, 1846cron_flush_trust (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1947 const struct GNUNET_SCHEDULER_TaskContext *tc)
1948{ 1847{
1949 1848
1950 if (NULL == cp_map) 1849 if (NULL == cp_map)
1951 return; 1850 return;
1952 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1851 GNUNET_CONTAINER_multihashmap_iterate (cp_map, &flush_trust, NULL);
1953 &flush_trust,
1954 NULL);
1955 if (NULL == tc) 1852 if (NULL == tc)
1956 return; 1853 return;
1957 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1854 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1958 return; 1855 return;
1959 GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ, 1856 GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ, &cron_flush_trust, NULL);
1960 &cron_flush_trust,
1961 NULL);
1962} 1857}
1963 1858
1964 1859
@@ -1976,7 +1871,7 @@ GSF_connected_peer_init_ ()
1976 &trustDirectory)); 1871 &trustDirectory));
1977 GNUNET_DISK_directory_create (trustDirectory); 1872 GNUNET_DISK_directory_create (trustDirectory);
1978 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH, 1873 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
1979 &cron_flush_trust, NULL); 1874 &cron_flush_trust, NULL);
1980} 1875}
1981 1876
1982 1877
@@ -1988,13 +1883,10 @@ GSF_connected_peer_init_ ()
1988 * @param value value in the hash map (peer entry) 1883 * @param value value in the hash map (peer entry)
1989 * @return GNUNET_YES (we should continue to iterate) 1884 * @return GNUNET_YES (we should continue to iterate)
1990 */ 1885 */
1991static int 1886static int
1992clean_peer (void *cls, 1887clean_peer (void *cls, const GNUNET_HashCode * key, void *value)
1993 const GNUNET_HashCode * key,
1994 void *value)
1995{ 1888{
1996 GSF_peer_disconnect_handler_ (NULL, 1889 GSF_peer_disconnect_handler_ (NULL, (const struct GNUNET_PeerIdentity *) key);
1997 (const struct GNUNET_PeerIdentity*) key);
1998 return GNUNET_YES; 1890 return GNUNET_YES;
1999} 1891}
2000 1892
@@ -2006,9 +1898,7 @@ void
2006GSF_connected_peer_done_ () 1898GSF_connected_peer_done_ ()
2007{ 1899{
2008 cron_flush_trust (NULL, NULL); 1900 cron_flush_trust (NULL, NULL);
2009 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1901 GNUNET_CONTAINER_multihashmap_iterate (cp_map, &clean_peer, NULL);
2010 &clean_peer,
2011 NULL);
2012 GNUNET_CONTAINER_multihashmap_destroy (cp_map); 1902 GNUNET_CONTAINER_multihashmap_destroy (cp_map);
2013 cp_map = NULL; 1903 cp_map = NULL;
2014 GNUNET_free (trustDirectory); 1904 GNUNET_free (trustDirectory);
@@ -2024,16 +1914,14 @@ GSF_connected_peer_done_ ()
2024 * @param value value in the hash map (peer entry) 1914 * @param value value in the hash map (peer entry)
2025 * @return GNUNET_YES (we should continue to iterate) 1915 * @return GNUNET_YES (we should continue to iterate)
2026 */ 1916 */
2027static int 1917static int
2028clean_local_client (void *cls, 1918clean_local_client (void *cls, const GNUNET_HashCode * key, void *value)
2029 const GNUNET_HashCode * key,
2030 void *value)
2031{ 1919{
2032 const struct GSF_LocalClient *lc = cls; 1920 const struct GSF_LocalClient *lc = cls;
2033 struct GSF_ConnectedPeer *cp = value; 1921 struct GSF_ConnectedPeer *cp = value;
2034 unsigned int i; 1922 unsigned int i;
2035 1923
2036 for (i=0;i<CS2P_SUCCESS_LIST_SIZE;i++) 1924 for (i = 0; i < CS2P_SUCCESS_LIST_SIZE; i++)
2037 if (cp->ppd.last_client_replies[i] == lc) 1925 if (cp->ppd.last_client_replies[i] == lc)
2038 cp->ppd.last_client_replies[i] = NULL; 1926 cp->ppd.last_client_replies[i] = NULL;
2039 return GNUNET_YES; 1927 return GNUNET_YES;
@@ -2050,10 +1938,9 @@ void
2050GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc) 1938GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc)
2051{ 1939{
2052 if (NULL == cp_map) 1940 if (NULL == cp_map)
2053 return; /* already cleaned up */ 1941 return; /* already cleaned up */
2054 GNUNET_CONTAINER_multihashmap_iterate (cp_map, 1942 GNUNET_CONTAINER_multihashmap_iterate (cp_map,
2055 &clean_local_client, 1943 &clean_local_client, (void *) lc);
2056 (void*) lc);
2057} 1944}
2058 1945
2059 1946