From f44c0036572d5557d2496748a4190a61e40e61ff Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 22 Oct 2011 21:59:27 +0000 Subject: replacing 0-terminated atsi-array with array+length in core API (and the core-connect IPC) --- src/fs/gnunet-service-fs.c | 14 ++++++++++---- src/fs/gnunet-service-fs_cp.c | 43 ++++++++++++++++++++++--------------------- src/fs/gnunet-service-fs_cp.h | 8 ++++++-- 3 files changed, 38 insertions(+), 27 deletions(-) (limited to 'src/fs') diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 6ea47c2e2..c5933d989 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -220,13 +220,15 @@ GSF_test_get_load_too_high_ (uint32_t priority) * for loopback messages where we are both sender and receiver) * @param message the actual message * @param atsi performance information + * @param atsi_count number of records in 'atsi' * @return GNUNET_OK to keep the connection open, * GNUNET_SYSERR to close it (signal serious error) */ static int handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct GSF_ConnectedPeer *cp; @@ -299,13 +301,15 @@ consider_forwarding (void *cls, struct GSF_PendingRequest *pr, * for loopback messages where we are both sender and receiver) * @param message the actual message * @param atsi performance information + * @param atsi_count number of records in 'atsi' * @return GNUNET_OK to keep the connection open, * GNUNET_SYSERR to close it (signal serious error) */ static int handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct GSF_PendingRequest *pr; @@ -456,16 +460,18 @@ consider_peer_for_forwarding (void *cls, const GNUNET_HashCode * key, * @param cls closure, not used * @param peer peer identity this notification is about * @param atsi performance information + * @param atsi_count number of records in 'atsi' */ static void peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct GSF_ConnectedPeer *cp; if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity))) return; - cp = GSF_peer_connect_handler_ (peer, atsi); + cp = GSF_peer_connect_handler_ (peer, atsi, atsi_count); if (NULL == cp) return; GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp); 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) * Find latency information in 'atsi'. * * @param atsi performance data + * @param atsi_count number of records in 'atsi' * @return connection latency */ static struct GNUNET_TIME_Relative -get_latency (const struct GNUNET_ATS_Information *atsi) +get_latency (const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { - if (atsi == NULL) - return GNUNET_TIME_UNIT_SECONDS; - while ((ntohl (atsi->type) != GNUNET_ATS_ARRAY_TERMINATOR) && - (ntohl (atsi->type) != GNUNET_ATS_QUALITY_NET_DELAY)) - atsi++; - if (ntohl (atsi->type) == GNUNET_ATS_ARRAY_TERMINATOR) - { - /* We sometime have no latency data, i.e. if the address came from - peerinfo and we never had a chance to play transport-level - PING/PONG yet. Assume 1s in that case. */ - return GNUNET_TIME_UNIT_SECONDS; - } - return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - ntohl (atsi->value)); + unsigned int i; + + for (i=0;itype) == GNUNET_ATS_QUALITY_NET_DELAY) + return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, + ntohl (atsi->value)); + return GNUNET_TIME_UNIT_SECONDS; } @@ -355,14 +350,16 @@ get_latency (const struct GNUNET_ATS_Information *atsi) * * @param cp peer record to update * @param atsi transport performance data + * @param atsi_count number of records in 'atsi' */ static void update_atsi (struct GSF_ConnectedPeer *cp, - const struct GNUNET_ATS_Information *atsi) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct GNUNET_TIME_Relative latency; - latency = get_latency (atsi); + latency = get_latency (atsi, atsi_count); GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency); /* LATER: merge atsi into cp's performance data (if we ever care...) */ } @@ -584,11 +581,13 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, * * @param peer identity of peer that connected * @param atsi performance data for the connection + * @param atsi_count number of records in 'atsi' * @return handle to connected peer entry */ struct GSF_ConnectedPeer * GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi) + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count) { struct GSF_ConnectedPeer *cp; char *fn; @@ -619,7 +618,7 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, ("# peers connected"), GNUNET_CONTAINER_multihashmap_size (cp_map), GNUNET_NO); - update_atsi (cp, atsi); + update_atsi (cp, atsi, atsi_count); GSF_push_start_ (cp); return cp; } @@ -674,6 +673,7 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer) * for loopback messages where we are both sender and receiver) * @param message the actual message * @param atsi performance information + * @param atsi_count number of records in 'atsi' * @return GNUNET_OK to keep the connection open, * GNUNET_SYSERR to close it (signal serious error) */ @@ -682,7 +682,8 @@ GSF_handle_p2p_migration_stop_ (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information - *atsi) + *atsi, + unsigned int atsi_count) { struct GSF_ConnectedPeer *cp; const struct MigrationStopMessage *msm; @@ -710,7 +711,7 @@ GSF_handle_p2p_migration_stop_ (void *cls, cp->mig_revive_task = GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); } - update_atsi (cp, atsi); + update_atsi (cp, atsi, atsi_count); return GNUNET_OK; } diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h index c725dee75..8923513c7 100644 --- a/src/fs/gnunet-service-fs_cp.h +++ b/src/fs/gnunet-service-fs_cp.h @@ -168,11 +168,13 @@ struct GSF_PeerTransmitHandle; * * @param peer identity of peer that connected * @param atsi performance data for the connection + * @param atsi_count number of records in 'atsi' * @return handle to connected peer entry */ struct GSF_ConnectedPeer * GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi); + const struct GNUNET_ATS_Information *atsi, + unsigned int atsi_count); /** @@ -260,6 +262,7 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, * for loopback messages where we are both sender and receiver) * @param message the actual message * @param atsi performance information + * @param atsi_count number of records in 'atsi' * @return GNUNET_OK to keep the connection open, * GNUNET_SYSERR to close it (signal serious error) */ @@ -268,7 +271,8 @@ GSF_handle_p2p_migration_stop_ (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information - *atsi); + *atsi, + unsigned int atsi_count); /** -- cgit v1.2.3