* @author Christian Grothoff
* @author Nathan Evans
*
- * TODO: The gossip rates need to be worked out. Probably many other things
- * as well.
- *
*/
#include "platform.h"
#include "gnunet_client_lib.h"
}
#endif
+/**
+ * Get distance information from 'atsi'.
+ *
+ * @param atsi performance data
+ * @return connected transport distance
+ */
+static uint32_t
+get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) )
+ atsi++;
+ if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+ {
+ GNUNET_break (0);
+ /* FIXME: we do not have distance data? Assume direct neighbor. */
+ return DIRECT_NEIGHBOR_COST;
+ }
+ return ntohl (atsi->value);
+}
+
+/**
+ * Find latency information in 'atsi'.
+ *
+ * @param atsi performance data
+ * @return connection latency
+ */
+static struct GNUNET_TIME_Relative
+get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) )
+ atsi++;
+ if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+ {
+ GNUNET_break (0);
+ /* how can we not have latency data? */
+ return GNUNET_TIME_UNIT_SECONDS;
+ }
+ /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */
+ return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, ntohl (atsi->value));
+}
/**
* Core handler for dv data messages. Whatever this message
int ret;
size_t packed_message_size;
char *cbuf;
+ uint32_t distance; /* Distance information */
+ struct GNUNET_TIME_Relative latency; /* Latency information */
packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data);
#if DEBUG_DV
if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
{
-
#if DEBUG_DV
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s': Message sizes don't add up, total size %u, expected at least %u!\n", "dv service", ntohs(incoming->header.size), sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader));
return GNUNET_SYSERR;
}
+ /* Iterate over ATS_Information to get distance and latency */
+ latency = get_atsi_latency(atsi);
+ distance = get_atsi_distance(atsi);
dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
&peer->hashPubKey);
if (dn == NULL)
if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity)))
{
/* FIXME: create stat: routing loop-discard! */
-#if DEBUG_DV_PEER_NUMBERS
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\n\n\nLoopy loo message\n\n\n");
-#endif
#if DEBUG_DV_MESSAGES
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
struct PendingMessage *pending_message;
if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
- {
+ {
#if DEBUG_DV_GOSSIP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s: Called with reason shutdown, shutting down!\n",
GNUNET_i2s(&my_identity));
#endif
- return;
- }
+ return;
+ }
if (send_context->fast_gossip_list_head != NULL)
{
#if DEBUG_DV_MESSAGES
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", my_short_id, referrer_peer_id);
#endif
- handle_dv_data_message(NULL, &referrer->pending_messages[i].sender,
+ struct GNUNET_TRANSPORT_ATS_Information atsi[3];
+ atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ atsi[0].value = htonl (referrer->pending_messages[i].distance);
+ atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ atsi[1].value = htonl ((uint32_t)referrer->pending_messages[i].latency.rel_value);
+ atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ atsi[2].value = htonl (0);
+ handle_dv_data_message(NULL,
+ &referrer->pending_messages[i].sender,
referrer->pending_messages[i].message,
- referrer->pending_messages[i].latency,
- referrer->pending_messages[i].distance);
+ (const struct GNUNET_TRANSPORT_ATS_Information *)&atsi);
GNUNET_free(referrer->pending_messages[i].message);
referrer->pending_messages[i].sender_id = 0;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance);
#endif
+ uint32_t distance;
- if ((distance == DIRECT_NEIGHBOR_COST) && (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
+ distance = get_atsi_distance (atsi);
+ if ((distance == DIRECT_NEIGHBOR_COST) &&
+ (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
{
peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext));
neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor));
#include "gnunet_testing_lib.h"
#include "gnunet_core_service.h"
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
#define TEST_ALL GNUNET_NO
static void
send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
+/**
+ * Get distance information from 'atsi'.
+ *
+ * @param atsi performance data
+ * @return connected transport distance
+ */
+static uint32_t
+get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) )
+ atsi++;
+ if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+ {
+ GNUNET_break (0);
+ /* FIXME: we do not have distance data? Assume direct neighbor. */
+ return 1;
+ }
+ return ntohl (atsi->value);
+}
+
static int
process_mtype (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct TestMessageContext *pos = cls;
struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
+#if VERBOSE
+ uint32_t distance;
+#endif
if (pos->uid != ntohl(msg->uid))
return GNUNET_OK;
+#if VERBOSE
+ distance = get_atsi_distance(atsi);
+#endif
GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity)));
if (total_other_expected_messages == 0)
{
*/
pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
1,
- TIMEOUT,
pos,
&init_notify_peer2,
NULL,
NULL,
NULL, NULL,
GNUNET_YES, NULL, GNUNET_YES, handlers);
-
}
*/
pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
1,
- TIMEOUT,
pos,
&init_notify_peer1,
NULL, NULL,
static void all_connect_handler (void *cls,
const struct
GNUNET_PeerIdentity * peer,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct GNUNET_TESTING_Daemon *d = cls;
struct GNUNET_TESTING_Daemon *second_daemon;
#if !TEST_ALL
struct TestMessageContext *temp_context;
#endif
+ uint32_t distance;
+ distance = get_atsi_distance(atsi);
+
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
d->shortname,
new_peer = GNUNET_malloc(sizeof(struct PeerContext));
new_peer->peer_handle = GNUNET_CORE_connect(cfg,
1,
- GNUNET_TIME_UNIT_FOREVER_REL,
d, NULL,
&all_connect_handler,
NULL, NULL, NULL,