diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-12-07 15:09:29 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-12-07 15:09:29 +0000 |
commit | 811e9e592ec037114b016889609f59d19f414011 (patch) | |
tree | 837d1eb538f926aafc9c6a1d78da06aa613d196d /src/dv/gnunet-service-dv.c | |
parent | dc7c73c5b7bff9940bd404cf74f58c56345ab6f0 (diff) | |
download | gnunet-811e9e592ec037114b016889609f59d19f414011.tar.gz gnunet-811e9e592ec037114b016889609f59d19f414011.zip |
initial dv changes for atsi information handling, test case BROKEN
Diffstat (limited to 'src/dv/gnunet-service-dv.c')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 78 |
1 files changed, 64 insertions, 14 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index d3897f23d..78e63facc 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -27,9 +27,6 @@ | |||
27 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
28 | * @author Nathan Evans | 28 | * @author Nathan Evans |
29 | * | 29 | * |
30 | * TODO: The gossip rates need to be worked out. Probably many other things | ||
31 | * as well. | ||
32 | * | ||
33 | */ | 30 | */ |
34 | #include "platform.h" | 31 | #include "platform.h" |
35 | #include "gnunet_client_lib.h" | 32 | #include "gnunet_client_lib.h" |
@@ -1298,6 +1295,48 @@ void send_message_delayed (void *cls, | |||
1298 | } | 1295 | } |
1299 | #endif | 1296 | #endif |
1300 | 1297 | ||
1298 | /** | ||
1299 | * Get distance information from 'atsi'. | ||
1300 | * | ||
1301 | * @param atsi performance data | ||
1302 | * @return connected transport distance | ||
1303 | */ | ||
1304 | static uint32_t | ||
1305 | get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
1306 | { | ||
1307 | while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && | ||
1308 | (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) ) | ||
1309 | atsi++; | ||
1310 | if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) | ||
1311 | { | ||
1312 | GNUNET_break (0); | ||
1313 | /* FIXME: we do not have distance data? Assume direct neighbor. */ | ||
1314 | return DIRECT_NEIGHBOR_COST; | ||
1315 | } | ||
1316 | return ntohl (atsi->value); | ||
1317 | } | ||
1318 | |||
1319 | /** | ||
1320 | * Find latency information in 'atsi'. | ||
1321 | * | ||
1322 | * @param atsi performance data | ||
1323 | * @return connection latency | ||
1324 | */ | ||
1325 | static struct GNUNET_TIME_Relative | ||
1326 | get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
1327 | { | ||
1328 | while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && | ||
1329 | (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) ) | ||
1330 | atsi++; | ||
1331 | if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) | ||
1332 | { | ||
1333 | GNUNET_break (0); | ||
1334 | /* how can we not have latency data? */ | ||
1335 | return GNUNET_TIME_UNIT_SECONDS; | ||
1336 | } | ||
1337 | /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */ | ||
1338 | return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, ntohl (atsi->value)); | ||
1339 | } | ||
1301 | 1340 | ||
1302 | /** | 1341 | /** |
1303 | * Core handler for dv data messages. Whatever this message | 1342 | * Core handler for dv data messages. Whatever this message |
@@ -1341,6 +1380,8 @@ handle_dv_data_message (void *cls, | |||
1341 | int ret; | 1380 | int ret; |
1342 | size_t packed_message_size; | 1381 | size_t packed_message_size; |
1343 | char *cbuf; | 1382 | char *cbuf; |
1383 | uint32_t distance; /* Distance information */ | ||
1384 | struct GNUNET_TIME_Relative latency; /* Latency information */ | ||
1344 | 1385 | ||
1345 | packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data); | 1386 | packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data); |
1346 | #if DEBUG_DV | 1387 | #if DEBUG_DV |
@@ -1350,7 +1391,6 @@ handle_dv_data_message (void *cls, | |||
1350 | 1391 | ||
1351 | if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader)) | 1392 | if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader)) |
1352 | { | 1393 | { |
1353 | |||
1354 | #if DEBUG_DV | 1394 | #if DEBUG_DV |
1355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1356 | "`%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)); | 1396 | "`%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)); |
@@ -1358,6 +1398,9 @@ handle_dv_data_message (void *cls, | |||
1358 | return GNUNET_SYSERR; | 1398 | return GNUNET_SYSERR; |
1359 | } | 1399 | } |
1360 | 1400 | ||
1401 | /* Iterate over ATS_Information to get distance and latency */ | ||
1402 | latency = get_atsi_latency(atsi); | ||
1403 | distance = get_atsi_distance(atsi); | ||
1361 | dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, | 1404 | dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, |
1362 | &peer->hashPubKey); | 1405 | &peer->hashPubKey); |
1363 | if (dn == NULL) | 1406 | if (dn == NULL) |
@@ -1481,9 +1524,6 @@ handle_dv_data_message (void *cls, | |||
1481 | if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity))) | 1524 | if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity))) |
1482 | { | 1525 | { |
1483 | /* FIXME: create stat: routing loop-discard! */ | 1526 | /* FIXME: create stat: routing loop-discard! */ |
1484 | #if DEBUG_DV_PEER_NUMBERS | ||
1485 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\n\n\nLoopy loo message\n\n\n"); | ||
1486 | #endif | ||
1487 | 1527 | ||
1488 | #if DEBUG_DV_MESSAGES | 1528 | #if DEBUG_DV_MESSAGES |
1489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1588,14 +1628,14 @@ neighbor_send_task (void *cls, | |||
1588 | struct PendingMessage *pending_message; | 1628 | struct PendingMessage *pending_message; |
1589 | 1629 | ||
1590 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 1630 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
1591 | { | 1631 | { |
1592 | #if DEBUG_DV_GOSSIP | 1632 | #if DEBUG_DV_GOSSIP |
1593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1633 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1594 | "%s: Called with reason shutdown, shutting down!\n", | 1634 | "%s: Called with reason shutdown, shutting down!\n", |
1595 | GNUNET_i2s(&my_identity)); | 1635 | GNUNET_i2s(&my_identity)); |
1596 | #endif | 1636 | #endif |
1597 | return; | 1637 | return; |
1598 | } | 1638 | } |
1599 | 1639 | ||
1600 | if (send_context->fast_gossip_list_head != NULL) | 1640 | if (send_context->fast_gossip_list_head != NULL) |
1601 | { | 1641 | { |
@@ -2465,10 +2505,17 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, | |||
2465 | #if DEBUG_DV_MESSAGES | 2505 | #if DEBUG_DV_MESSAGES |
2466 | 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); | 2506 | 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); |
2467 | #endif | 2507 | #endif |
2468 | handle_dv_data_message(NULL, &referrer->pending_messages[i].sender, | 2508 | struct GNUNET_TRANSPORT_ATS_Information atsi[3]; |
2509 | atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); | ||
2510 | atsi[0].value = htonl (referrer->pending_messages[i].distance); | ||
2511 | atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); | ||
2512 | atsi[1].value = htonl ((uint32_t)referrer->pending_messages[i].latency.rel_value); | ||
2513 | atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | ||
2514 | atsi[2].value = htonl (0); | ||
2515 | handle_dv_data_message(NULL, | ||
2516 | &referrer->pending_messages[i].sender, | ||
2469 | referrer->pending_messages[i].message, | 2517 | referrer->pending_messages[i].message, |
2470 | referrer->pending_messages[i].latency, | 2518 | (const struct GNUNET_TRANSPORT_ATS_Information *)&atsi); |
2471 | referrer->pending_messages[i].distance); | ||
2472 | GNUNET_free(referrer->pending_messages[i].message); | 2519 | GNUNET_free(referrer->pending_messages[i].message); |
2473 | referrer->pending_messages[i].sender_id = 0; | 2520 | referrer->pending_messages[i].sender_id = 0; |
2474 | } | 2521 | } |
@@ -2849,8 +2896,11 @@ handle_core_connect (void *cls, | |||
2849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2850 | "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance); | 2897 | "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance); |
2851 | #endif | 2898 | #endif |
2899 | uint32_t distance; | ||
2852 | 2900 | ||
2853 | if ((distance == DIRECT_NEIGHBOR_COST) && (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL)) | 2901 | distance = get_atsi_distance (atsi); |
2902 | if ((distance == DIRECT_NEIGHBOR_COST) && | ||
2903 | (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL)) | ||
2854 | { | 2904 | { |
2855 | peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext)); | 2905 | peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext)); |
2856 | neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); | 2906 | neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); |