diff options
-rw-r--r-- | src/dv/gnunet-service-dv.c | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 3882ed36f..7d86fc24c 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -1344,44 +1344,42 @@ send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1344 | * Get distance information from 'atsi'. | 1344 | * Get distance information from 'atsi'. |
1345 | * | 1345 | * |
1346 | * @param atsi performance data | 1346 | * @param atsi performance data |
1347 | * @param atsi_count number of entries in atsi | ||
1347 | * @return connected transport distance | 1348 | * @return connected transport distance |
1348 | */ | 1349 | */ |
1349 | static uint32_t | 1350 | static uint32_t |
1350 | get_atsi_distance (const struct GNUNET_ATS_Information *atsi) | 1351 | get_atsi_distance (const struct GNUNET_ATS_Information *atsi, |
1352 | unsigned int atsi_count) | ||
1351 | { | 1353 | { |
1352 | while ((ntohl (atsi->type) != GNUNET_ATS_ARRAY_TERMINATOR) && | 1354 | unsigned int i; |
1353 | (ntohl (atsi->type) != GNUNET_ATS_QUALITY_NET_DISTANCE)) | 1355 | |
1354 | atsi++; | 1356 | for (i=0;i<atsi_count;i++) |
1355 | if (ntohl (atsi->type) == GNUNET_ATS_ARRAY_TERMINATOR) | 1357 | if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) |
1356 | { | 1358 | return ntohl (atsi->value); |
1357 | GNUNET_break (0); | 1359 | /* FIXME: we do not have distance data? Assume direct neighbor. */ |
1358 | /* FIXME: we do not have distance data? Assume direct neighbor. */ | 1360 | return DIRECT_NEIGHBOR_COST; |
1359 | return DIRECT_NEIGHBOR_COST; | ||
1360 | } | ||
1361 | return ntohl (atsi->value); | ||
1362 | } | 1361 | } |
1363 | 1362 | ||
1364 | /** | 1363 | /** |
1365 | * Find latency information in 'atsi'. | 1364 | * Find latency information in 'atsi'. |
1366 | * | 1365 | * |
1367 | * @param atsi performance data | 1366 | * @param atsi performance data |
1367 | * @param atsi_count number of entries in atsi | ||
1368 | * @return connection latency | 1368 | * @return connection latency |
1369 | */ | 1369 | */ |
1370 | static struct GNUNET_TIME_Relative | 1370 | static struct GNUNET_TIME_Relative |
1371 | get_atsi_latency (const struct GNUNET_ATS_Information *atsi) | 1371 | get_atsi_latency (const struct GNUNET_ATS_Information *atsi, |
1372 | unsigned int atsi_count) | ||
1372 | { | 1373 | { |
1373 | while ((ntohl (atsi->type) != GNUNET_ATS_ARRAY_TERMINATOR) && | 1374 | unsigned int i; |
1374 | (ntohl (atsi->type) != GNUNET_ATS_QUALITY_NET_DELAY)) | 1375 | |
1375 | atsi++; | 1376 | for (i=0;i<atsi_count;i++) |
1376 | if (ntohl (atsi->type) == GNUNET_ATS_ARRAY_TERMINATOR) | 1377 | if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY) |
1377 | { | 1378 | return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, |
1378 | GNUNET_break (0); | 1379 | ntohl (atsi->value)); |
1379 | /* how can we not have latency data? */ | 1380 | GNUNET_break (0); |
1380 | return GNUNET_TIME_UNIT_SECONDS; | 1381 | /* how can we not have latency data? */ |
1381 | } | 1382 | return GNUNET_TIME_UNIT_SECONDS; |
1382 | /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */ | ||
1383 | return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | ||
1384 | ntohl (atsi->value)); | ||
1385 | } | 1383 | } |
1386 | 1384 | ||
1387 | /** | 1385 | /** |
@@ -1394,11 +1392,13 @@ get_atsi_latency (const struct GNUNET_ATS_Information *atsi) | |||
1394 | * @param peer peer which sent the message (immediate sender) | 1392 | * @param peer peer which sent the message (immediate sender) |
1395 | * @param message the message | 1393 | * @param message the message |
1396 | * @param atsi transport ATS information (latency, distance, etc.) | 1394 | * @param atsi transport ATS information (latency, distance, etc.) |
1395 | * @param atsi_count number of entries in atsi | ||
1397 | */ | 1396 | */ |
1398 | static int | 1397 | static int |
1399 | handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer, | 1398 | handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
1400 | const struct GNUNET_MessageHeader *message, | 1399 | const struct GNUNET_MessageHeader *message, |
1401 | const struct GNUNET_ATS_Information *atsi) | 1400 | const struct GNUNET_ATS_Information *atsi, |
1401 | unsigned int atsi_count) | ||
1402 | { | 1402 | { |
1403 | const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message; | 1403 | const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message; |
1404 | const struct GNUNET_MessageHeader *packed_message; | 1404 | const struct GNUNET_MessageHeader *packed_message; |
@@ -1451,8 +1451,8 @@ handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1451 | } | 1451 | } |
1452 | 1452 | ||
1453 | /* Iterate over ATS_Information to get distance and latency */ | 1453 | /* Iterate over ATS_Information to get distance and latency */ |
1454 | latency = get_atsi_latency (atsi); | 1454 | latency = get_atsi_latency (atsi, atsi_count); |
1455 | distance = get_atsi_distance (atsi); | 1455 | distance = get_atsi_distance (atsi, atsi_count); |
1456 | dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey); | 1456 | dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey); |
1457 | if (dn == NULL) | 1457 | if (dn == NULL) |
1458 | return GNUNET_OK; | 1458 | return GNUNET_OK; |
@@ -2075,13 +2075,15 @@ handle_dv_send_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
2075 | static int | 2075 | static int |
2076 | handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, | 2076 | handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
2077 | const struct GNUNET_MessageHeader *message, | 2077 | const struct GNUNET_MessageHeader *message, |
2078 | const struct GNUNET_ATS_Information *atsi); | 2078 | const struct GNUNET_ATS_Information *atsi, |
2079 | unsigned int atsi_count); | ||
2079 | 2080 | ||
2080 | static int | 2081 | static int |
2081 | handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, | 2082 | handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
2082 | const struct GNUNET_MessageHeader *message, | 2083 | const struct GNUNET_MessageHeader *message, |
2083 | const struct GNUNET_ATS_Information | 2084 | const struct GNUNET_ATS_Information |
2084 | *atsi); | 2085 | *atsi, |
2086 | unsigned int atsi_count); | ||
2085 | /** End forward declarations **/ | 2087 | /** End forward declarations **/ |
2086 | 2088 | ||
2087 | 2089 | ||
@@ -2649,20 +2651,17 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2649 | "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", | 2651 | "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", |
2650 | my_short_id, referrer_peer_id); | 2652 | my_short_id, referrer_peer_id); |
2651 | #endif | 2653 | #endif |
2652 | struct GNUNET_ATS_Information atsi[3]; | 2654 | struct GNUNET_ATS_Information atsi[2]; |
2653 | 2655 | ||
2654 | atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | 2656 | atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); |
2655 | atsi[0].value = htonl (referrer->pending_messages[i].distance); | 2657 | atsi[0].value = htonl (referrer->pending_messages[i].distance); |
2656 | atsi[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | 2658 | atsi[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); |
2657 | atsi[1].value = | 2659 | atsi[1].value = |
2658 | htonl ((uint32_t) referrer->pending_messages[i]. | 2660 | htonl ((uint32_t) referrer->pending_messages[i]. |
2659 | latency.rel_value); | 2661 | latency.rel_value); |
2660 | atsi[2].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); | ||
2661 | atsi[2].value = htonl (0); | ||
2662 | handle_dv_data_message (NULL, &referrer->pending_messages[i].sender, | 2662 | handle_dv_data_message (NULL, &referrer->pending_messages[i].sender, |
2663 | referrer->pending_messages[i].message, | 2663 | referrer->pending_messages[i].message, |
2664 | (const struct GNUNET_ATS_Information | 2664 | atsi, 2); |
2665 | *) &atsi); | ||
2666 | GNUNET_free (referrer->pending_messages[i].message); | 2665 | GNUNET_free (referrer->pending_messages[i].message); |
2667 | referrer->pending_messages[i].sender_id = 0; | 2666 | referrer->pending_messages[i].sender_id = 0; |
2668 | } | 2667 | } |
@@ -2728,12 +2727,14 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2728 | * @param peer peer which sent the message (immediate sender) | 2727 | * @param peer peer which sent the message (immediate sender) |
2729 | * @param message the message | 2728 | * @param message the message |
2730 | * @param atsi performance data | 2729 | * @param atsi performance data |
2730 | * @param atsi_count number of entries in atsi | ||
2731 | */ | 2731 | */ |
2732 | static int | 2732 | static int |
2733 | handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, | 2733 | handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
2734 | const struct GNUNET_MessageHeader *message, | 2734 | const struct GNUNET_MessageHeader *message, |
2735 | const struct GNUNET_ATS_Information | 2735 | const struct GNUNET_ATS_Information |
2736 | *atsi) | 2736 | *atsi, |
2737 | unsigned int atsi_count) | ||
2737 | { | 2738 | { |
2738 | struct DirectNeighbor *referrer; | 2739 | struct DirectNeighbor *referrer; |
2739 | struct DistantNeighbor *distant; | 2740 | struct DistantNeighbor *distant; |
@@ -2777,11 +2778,13 @@ handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2777 | * @param peer peer which sent the message (immediate sender) | 2778 | * @param peer peer which sent the message (immediate sender) |
2778 | * @param message the message | 2779 | * @param message the message |
2779 | * @param atsi performance data | 2780 | * @param atsi performance data |
2781 | * @param atsi_count number of entries in atsi | ||
2780 | */ | 2782 | */ |
2781 | static int | 2783 | static int |
2782 | handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, | 2784 | handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
2783 | const struct GNUNET_MessageHeader *message, | 2785 | const struct GNUNET_MessageHeader *message, |
2784 | const struct GNUNET_ATS_Information *atsi) | 2786 | const struct GNUNET_ATS_Information *atsi, |
2787 | unsigned int atsi_count) | ||
2785 | { | 2788 | { |
2786 | struct DirectNeighbor *referrer; | 2789 | struct DirectNeighbor *referrer; |
2787 | p2p_dv_MESSAGE_NeighborInfo *enc_message = | 2790 | p2p_dv_MESSAGE_NeighborInfo *enc_message = |
@@ -3079,10 +3082,12 @@ process_peerinfo (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3079 | * @param cls closure | 3082 | * @param cls closure |
3080 | * @param peer peer identity this notification is about | 3083 | * @param peer peer identity this notification is about |
3081 | * @param atsi performance data | 3084 | * @param atsi performance data |
3085 | * @param atsi_count number of entries in atsi | ||
3082 | */ | 3086 | */ |
3083 | static void | 3087 | static void |
3084 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 3088 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
3085 | const struct GNUNET_ATS_Information *atsi) | 3089 | const struct GNUNET_ATS_Information *atsi, |
3090 | unsigned int atsi_count) | ||
3086 | { | 3091 | { |
3087 | struct DirectNeighbor *neighbor; | 3092 | struct DirectNeighbor *neighbor; |
3088 | struct DistantNeighbor *about; | 3093 | struct DistantNeighbor *about; |
@@ -3095,7 +3100,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3095 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 3100 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
3096 | return; | 3101 | return; |
3097 | 3102 | ||
3098 | distance = get_atsi_distance (atsi); | 3103 | distance = get_atsi_distance (atsi, atsi_count); |
3099 | if ((distance == DIRECT_NEIGHBOR_COST) && | 3104 | if ((distance == DIRECT_NEIGHBOR_COST) && |
3100 | (GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey) | 3105 | (GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey) |
3101 | == NULL)) | 3106 | == NULL)) |