diff options
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r-- | src/fs/gnunet-service-fs_cp.c | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index b9302e645..fc9c44785 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -328,25 +328,20 @@ get_trust_filename (const struct GNUNET_PeerIdentity *id) | |||
328 | * Find latency information in 'atsi'. | 328 | * Find latency information in 'atsi'. |
329 | * | 329 | * |
330 | * @param atsi performance data | 330 | * @param atsi performance data |
331 | * @param atsi_count number of records in 'atsi' | ||
331 | * @return connection latency | 332 | * @return connection latency |
332 | */ | 333 | */ |
333 | static struct GNUNET_TIME_Relative | 334 | static struct GNUNET_TIME_Relative |
334 | get_latency (const struct GNUNET_ATS_Information *atsi) | 335 | get_latency (const struct GNUNET_ATS_Information *atsi, |
336 | unsigned int atsi_count) | ||
335 | { | 337 | { |
336 | if (atsi == NULL) | 338 | unsigned int i; |
337 | return GNUNET_TIME_UNIT_SECONDS; | 339 | |
338 | while ((ntohl (atsi->type) != GNUNET_ATS_ARRAY_TERMINATOR) && | 340 | for (i=0;i<atsi_count;i++) |
339 | (ntohl (atsi->type) != GNUNET_ATS_QUALITY_NET_DELAY)) | 341 | if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY) |
340 | atsi++; | 342 | return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
341 | if (ntohl (atsi->type) == GNUNET_ATS_ARRAY_TERMINATOR) | 343 | ntohl (atsi->value)); |
342 | { | 344 | return GNUNET_TIME_UNIT_SECONDS; |
343 | /* We sometime have no latency data, i.e. if the address came from | ||
344 | peerinfo and we never had a chance to play transport-level | ||
345 | PING/PONG yet. Assume 1s in that case. */ | ||
346 | return GNUNET_TIME_UNIT_SECONDS; | ||
347 | } | ||
348 | return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | ||
349 | ntohl (atsi->value)); | ||
350 | } | 345 | } |
351 | 346 | ||
352 | 347 | ||
@@ -355,14 +350,16 @@ get_latency (const struct GNUNET_ATS_Information *atsi) | |||
355 | * | 350 | * |
356 | * @param cp peer record to update | 351 | * @param cp peer record to update |
357 | * @param atsi transport performance data | 352 | * @param atsi transport performance data |
353 | * @param atsi_count number of records in 'atsi' | ||
358 | */ | 354 | */ |
359 | static void | 355 | static void |
360 | update_atsi (struct GSF_ConnectedPeer *cp, | 356 | update_atsi (struct GSF_ConnectedPeer *cp, |
361 | const struct GNUNET_ATS_Information *atsi) | 357 | const struct GNUNET_ATS_Information *atsi, |
358 | unsigned int atsi_count) | ||
362 | { | 359 | { |
363 | struct GNUNET_TIME_Relative latency; | 360 | struct GNUNET_TIME_Relative latency; |
364 | 361 | ||
365 | latency = get_latency (atsi); | 362 | latency = get_latency (atsi, atsi_count); |
366 | GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency); | 363 | GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency); |
367 | /* LATER: merge atsi into cp's performance data (if we ever care...) */ | 364 | /* LATER: merge atsi into cp's performance data (if we ever care...) */ |
368 | } | 365 | } |
@@ -584,11 +581,13 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
584 | * | 581 | * |
585 | * @param peer identity of peer that connected | 582 | * @param peer identity of peer that connected |
586 | * @param atsi performance data for the connection | 583 | * @param atsi performance data for the connection |
584 | * @param atsi_count number of records in 'atsi' | ||
587 | * @return handle to connected peer entry | 585 | * @return handle to connected peer entry |
588 | */ | 586 | */ |
589 | struct GSF_ConnectedPeer * | 587 | struct GSF_ConnectedPeer * |
590 | GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, | 588 | GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, |
591 | const struct GNUNET_ATS_Information *atsi) | 589 | const struct GNUNET_ATS_Information *atsi, |
590 | unsigned int atsi_count) | ||
592 | { | 591 | { |
593 | struct GSF_ConnectedPeer *cp; | 592 | struct GSF_ConnectedPeer *cp; |
594 | char *fn; | 593 | char *fn; |
@@ -619,7 +618,7 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, | |||
619 | ("# peers connected"), | 618 | ("# peers connected"), |
620 | GNUNET_CONTAINER_multihashmap_size (cp_map), | 619 | GNUNET_CONTAINER_multihashmap_size (cp_map), |
621 | GNUNET_NO); | 620 | GNUNET_NO); |
622 | update_atsi (cp, atsi); | 621 | update_atsi (cp, atsi, atsi_count); |
623 | GSF_push_start_ (cp); | 622 | GSF_push_start_ (cp); |
624 | return cp; | 623 | return cp; |
625 | } | 624 | } |
@@ -674,6 +673,7 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) | |||
674 | * for loopback messages where we are both sender and receiver) | 673 | * for loopback messages where we are both sender and receiver) |
675 | * @param message the actual message | 674 | * @param message the actual message |
676 | * @param atsi performance information | 675 | * @param atsi performance information |
676 | * @param atsi_count number of records in 'atsi' | ||
677 | * @return GNUNET_OK to keep the connection open, | 677 | * @return GNUNET_OK to keep the connection open, |
678 | * GNUNET_SYSERR to close it (signal serious error) | 678 | * GNUNET_SYSERR to close it (signal serious error) |
679 | */ | 679 | */ |
@@ -682,7 +682,8 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
682 | const struct GNUNET_PeerIdentity *other, | 682 | const struct GNUNET_PeerIdentity *other, |
683 | const struct GNUNET_MessageHeader *message, | 683 | const struct GNUNET_MessageHeader *message, |
684 | const struct GNUNET_ATS_Information | 684 | const struct GNUNET_ATS_Information |
685 | *atsi) | 685 | *atsi, |
686 | unsigned int atsi_count) | ||
686 | { | 687 | { |
687 | struct GSF_ConnectedPeer *cp; | 688 | struct GSF_ConnectedPeer *cp; |
688 | const struct MigrationStopMessage *msm; | 689 | const struct MigrationStopMessage *msm; |
@@ -710,7 +711,7 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
710 | cp->mig_revive_task = | 711 | cp->mig_revive_task = |
711 | GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); | 712 | GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); |
712 | } | 713 | } |
713 | update_atsi (cp, atsi); | 714 | update_atsi (cp, atsi, atsi_count); |
714 | return GNUNET_OK; | 715 | return GNUNET_OK; |
715 | } | 716 | } |
716 | 717 | ||