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.c85
1 files changed, 34 insertions, 51 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index 859d9275f..d4c81d509 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -332,15 +332,14 @@ get_trust_filename (const struct GNUNET_PeerIdentity *id)
332 * @return connection latency 332 * @return connection latency
333 */ 333 */
334static struct GNUNET_TIME_Relative 334static struct GNUNET_TIME_Relative
335get_latency (const struct GNUNET_ATS_Information *atsi, 335get_latency (const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
336 unsigned int atsi_count)
337{ 336{
338 unsigned int i; 337 unsigned int i;
339 338
340 for (i=0;i<atsi_count;i++) 339 for (i = 0; i < atsi_count; i++)
341 if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY) 340 if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY)
342 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 341 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
343 ntohl (atsi->value)); 342 ntohl (atsi->value));
344 return GNUNET_TIME_UNIT_SECONDS; 343 return GNUNET_TIME_UNIT_SECONDS;
345} 344}
346 345
@@ -354,8 +353,7 @@ get_latency (const struct GNUNET_ATS_Information *atsi,
354 */ 353 */
355static void 354static void
356update_atsi (struct GSF_ConnectedPeer *cp, 355update_atsi (struct GSF_ConnectedPeer *cp,
357 const struct GNUNET_ATS_Information *atsi, 356 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
358 unsigned int atsi_count)
359{ 357{
360 struct GNUNET_TIME_Relative latency; 358 struct GNUNET_TIME_Relative latency;
361 359
@@ -402,7 +400,7 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf);
402 */ 400 */
403static void 401static void
404ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 402ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
405 int32_t amount, struct GNUNET_TIME_Relative res_delay); 403 int32_t amount, struct GNUNET_TIME_Relative res_delay);
406 404
407 405
408/** 406/**
@@ -425,11 +423,9 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
425 423
426 if (0 != cp->inc_preference) 424 if (0 != cp->inc_preference)
427 { 425 {
428 GNUNET_ATS_change_preference (ats, 426 GNUNET_ATS_change_preference (ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
429 &target, 427 (double) cp->inc_preference,
430 GNUNET_ATS_PREFERENCE_BANDWIDTH, 428 GNUNET_ATS_PREFERENCE_END);
431 (double) cp->inc_preference,
432 GNUNET_ATS_PREFERENCE_END);
433 cp->inc_preference = 0; 429 cp->inc_preference = 0;
434 } 430 }
435 431
@@ -442,9 +438,8 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
442 /* reservation already done! */ 438 /* reservation already done! */
443 pth->was_reserved = GNUNET_YES; 439 pth->was_reserved = GNUNET_YES;
444 cp->rc = 440 cp->rc =
445 GNUNET_ATS_reserve_bandwidth (ats, &target, 441 GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
446 DBLOCK_SIZE, 442 &ats_reserve_callback, cp);
447 &ats_reserve_callback, cp);
448 } 443 }
449 GNUNET_assert (pth->cth == NULL); 444 GNUNET_assert (pth->cth == NULL);
450 pth->cth_in_progress++; 445 pth->cth_in_progress++;
@@ -525,9 +520,8 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
525 GNUNET_PEER_resolve (cp->ppd.pid, &target); 520 GNUNET_PEER_resolve (cp->ppd.pid, &target);
526 cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK; 521 cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
527 cp->rc = 522 cp->rc =
528 GNUNET_ATS_reserve_bandwidth (ats, &target, 523 GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
529 DBLOCK_SIZE, 524 &ats_reserve_callback, cp);
530 &ats_reserve_callback, cp);
531} 525}
532 526
533 527
@@ -543,15 +537,14 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
543 */ 537 */
544static void 538static void
545ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 539ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
546 int32_t amount, struct GNUNET_TIME_Relative res_delay) 540 int32_t amount, struct GNUNET_TIME_Relative res_delay)
547{ 541{
548 struct GSF_ConnectedPeer *cp = cls; 542 struct GSF_ConnectedPeer *cp = cls;
549 struct GSF_PeerTransmitHandle *pth; 543 struct GSF_PeerTransmitHandle *pth;
550 544
551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
552 "Reserved %d bytes / need to wait %llu ms for reservation\n", 546 "Reserved %d bytes / need to wait %llu ms for reservation\n",
553 (int) amount, 547 (int) amount, (unsigned long long) res_delay.rel_value);
554 (unsigned long long) res_delay.rel_value);
555 cp->rc = NULL; 548 cp->rc = NULL;
556 if (0 == amount) 549 if (0 == amount)
557 { 550 {
@@ -587,22 +580,20 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
587struct GSF_ConnectedPeer * 580struct GSF_ConnectedPeer *
588GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 581GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
589 const struct GNUNET_ATS_Information *atsi, 582 const struct GNUNET_ATS_Information *atsi,
590 unsigned int atsi_count) 583 unsigned int atsi_count)
591{ 584{
592 struct GSF_ConnectedPeer *cp; 585 struct GSF_ConnectedPeer *cp;
593 char *fn; 586 char *fn;
594 uint32_t trust; 587 uint32_t trust;
595 588
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s\n",
597 "Connected to peer %s\n", 590 GNUNET_i2s (peer));
598 GNUNET_i2s (peer));
599 cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); 591 cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer));
600 cp->ppd.pid = GNUNET_PEER_intern (peer); 592 cp->ppd.pid = GNUNET_PEER_intern (peer);
601 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); 593 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
602 cp->rc = 594 cp->rc =
603 GNUNET_ATS_reserve_bandwidth (ats, peer, 595 GNUNET_ATS_reserve_bandwidth (ats, peer, DBLOCK_SIZE,
604 DBLOCK_SIZE, 596 &ats_reserve_callback, cp);
605 &ats_reserve_callback, cp);
606 fn = get_trust_filename (peer); 597 fn = get_trust_filename (peer);
607 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && 598 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
608 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) 599 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
@@ -613,11 +604,9 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
613 GNUNET_CONTAINER_multihashmap_put (cp_map, &peer->hashPubKey, 604 GNUNET_CONTAINER_multihashmap_put (cp_map, &peer->hashPubKey,
614 cp, 605 cp,
615 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 606 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
616 GNUNET_STATISTICS_set (GSF_stats, 607 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
617 gettext_noop 608 GNUNET_CONTAINER_multihashmap_size (cp_map),
618 ("# peers connected"), 609 GNUNET_NO);
619 GNUNET_CONTAINER_multihashmap_size (cp_map),
620 GNUNET_NO);
621 update_atsi (cp, atsi, atsi_count); 610 update_atsi (cp, atsi, atsi_count);
622 GSF_push_start_ (cp); 611 GSF_push_start_ (cp);
623 return cp; 612 return cp;
@@ -681,9 +670,8 @@ int
681GSF_handle_p2p_migration_stop_ (void *cls, 670GSF_handle_p2p_migration_stop_ (void *cls,
682 const struct GNUNET_PeerIdentity *other, 671 const struct GNUNET_PeerIdentity *other,
683 const struct GNUNET_MessageHeader *message, 672 const struct GNUNET_MessageHeader *message,
684 const struct GNUNET_ATS_Information 673 const struct GNUNET_ATS_Information *atsi,
685 *atsi, 674 unsigned int atsi_count)
686 unsigned int atsi_count)
687{ 675{
688 struct GSF_ConnectedPeer *cp; 676 struct GSF_ConnectedPeer *cp;
689 const struct MigrationStopMessage *msm; 677 const struct MigrationStopMessage *msm;
@@ -697,9 +685,8 @@ GSF_handle_p2p_migration_stop_ (void *cls,
697 return GNUNET_OK; 685 return GNUNET_OK;
698 } 686 }
699 GNUNET_STATISTICS_update (GSF_stats, 687 GNUNET_STATISTICS_update (GSF_stats,
700 gettext_noop 688 gettext_noop ("# migration stop messages received"),
701 ("# migration stop messages received"), 689 1, GNUNET_NO);
702 1, GNUNET_NO);
703 bt = GNUNET_TIME_relative_ntoh (msm->duration); 690 bt = GNUNET_TIME_relative_ntoh (msm->duration);
704 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 691 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
705 _("Migration of content to peer `%s' blocked for %llu ms\n"), 692 _("Migration of content to peer `%s' blocked for %llu ms\n"),
@@ -841,8 +828,8 @@ get_randomized_delay ()
841 ret = 828 ret =
842 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 829 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
843 GNUNET_CRYPTO_random_u32 830 GNUNET_CRYPTO_random_u32
844 (GNUNET_CRYPTO_QUALITY_WEAK, 831 (GNUNET_CRYPTO_QUALITY_WEAK,
845 2 * GSF_avg_latency.rel_value + 1)); 832 2 * GSF_avg_latency.rel_value + 1));
846 GNUNET_STATISTICS_update (GSF_stats, 833 GNUNET_STATISTICS_update (GSF_stats,
847 gettext_noop 834 gettext_noop
848 ("# artificial delays introduced (ms)"), 835 ("# artificial delays introduced (ms)"),
@@ -1179,7 +1166,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1179 return NULL; 1166 return NULL;
1180 } 1167 }
1181 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO)) 1168 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1182 cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity*) &opt[bits++]); 1169 cp = GSF_peer_get_ ((const struct GNUNET_PeerIdentity *) &opt[bits++]);
1183 else 1170 else
1184 cp = cps; 1171 cp = cps;
1185 if (cp == NULL) 1172 if (cp == NULL)
@@ -1323,9 +1310,7 @@ GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
1323 0) ? (const char *) &opt[bits] : NULL, 1310 0) ? (const char *) &opt[bits] : NULL,
1324 bfsize, ntohl (gm->filter_mutator), 1311 bfsize, ntohl (gm->filter_mutator),
1325 1 /* anonymity */ , 1312 1 /* anonymity */ ,
1326 (uint32_t) priority, ttl, spid, 1313 (uint32_t) priority, ttl, spid, GNUNET_PEER_intern (other), NULL, 0, /* replies_seen */
1327 GNUNET_PEER_intern (other),
1328 NULL, 0, /* replies_seen */
1329 &handle_p2p_reply, peerreq); 1314 &handle_p2p_reply, peerreq);
1330 GNUNET_assert (NULL != pr); 1315 GNUNET_assert (NULL != pr);
1331 peerreq->pr = pr; 1316 peerreq->pr = pr;
@@ -1547,11 +1532,9 @@ GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer)
1547 GNUNET_assert (GNUNET_YES == 1532 GNUNET_assert (GNUNET_YES ==
1548 GNUNET_CONTAINER_multihashmap_remove (cp_map, 1533 GNUNET_CONTAINER_multihashmap_remove (cp_map,
1549 &peer->hashPubKey, cp)); 1534 &peer->hashPubKey, cp));
1550 GNUNET_STATISTICS_set (GSF_stats, 1535 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
1551 gettext_noop 1536 GNUNET_CONTAINER_multihashmap_size (cp_map),
1552 ("# peers connected"), 1537 GNUNET_NO);
1553 GNUNET_CONTAINER_multihashmap_size (cp_map),
1554 GNUNET_NO);
1555 if (NULL != cp->migration_pth) 1538 if (NULL != cp->migration_pth)
1556 { 1539 {
1557 GSF_peer_transmit_cancel_ (cp->migration_pth); 1540 GSF_peer_transmit_cancel_ (cp->migration_pth);