diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-10 23:36:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-10 23:36:06 +0000 |
commit | 8ca1ffeec596540b9b225d094c8acf622beaeb10 (patch) | |
tree | c2918650c0facbefa4e9160f05685dc3cd008b52 /src/dv | |
parent | fdc6131af11cb2ecbce11536eb0d526bdfae3e52 (diff) | |
download | gnunet-8ca1ffeec596540b9b225d094c8acf622beaeb10.tar.gz gnunet-8ca1ffeec596540b9b225d094c8acf622beaeb10.zip |
-misc dv fixes
Diffstat (limited to 'src/dv')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 117 |
1 files changed, 73 insertions, 44 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 97289aa54..d5eca28c7 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -205,7 +205,7 @@ struct DirectNeighbor | |||
205 | * NULL if we are not currently building it. | 205 | * NULL if we are not currently building it. |
206 | * Keys are peer identities, values are 'struct Target' entries. | 206 | * Keys are peer identities, values are 'struct Target' entries. |
207 | * Note that the distances in the targets are from the point-of-view | 207 | * Note that the distances in the targets are from the point-of-view |
208 | * of the peer, not from us! | 208 | * of the other peer, not from us! |
209 | */ | 209 | */ |
210 | struct GNUNET_CONTAINER_MultiPeerMap *neighbor_table_consensus; | 210 | struct GNUNET_CONTAINER_MultiPeerMap *neighbor_table_consensus; |
211 | 211 | ||
@@ -543,8 +543,8 @@ send_connect_to_plugin (const struct GNUNET_PeerIdentity *target, | |||
543 | { | 543 | { |
544 | struct GNUNET_DV_ConnectMessage cm; | 544 | struct GNUNET_DV_ConnectMessage cm; |
545 | 545 | ||
546 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
547 | "Delivering CONNECT about peer `%s' with distance %u\n", | 547 | "Delivering CONNECT about peer %s with distance %u\n", |
548 | GNUNET_i2s (target), distance); | 548 | GNUNET_i2s (target), distance); |
549 | cm.header.size = htons (sizeof (cm)); | 549 | cm.header.size = htons (sizeof (cm)); |
550 | cm.header.type = htons (GNUNET_MESSAGE_TYPE_DV_CONNECT); | 550 | cm.header.type = htons (GNUNET_MESSAGE_TYPE_DV_CONNECT); |
@@ -738,6 +738,7 @@ allocate_route (struct Route *route, | |||
738 | 738 | ||
739 | if (distance >= DEFAULT_FISHEYE_DEPTH) | 739 | if (distance >= DEFAULT_FISHEYE_DEPTH) |
740 | { | 740 | { |
741 | route->target.distance = htonl (distance); | ||
741 | route->set_offset = UINT_MAX; /* invalid slot */ | 742 | route->set_offset = UINT_MAX; /* invalid slot */ |
742 | return; | 743 | return; |
743 | } | 744 | } |
@@ -774,15 +775,8 @@ static void | |||
774 | move_route (struct Route *route, | 775 | move_route (struct Route *route, |
775 | uint32_t new_distance) | 776 | uint32_t new_distance) |
776 | { | 777 | { |
777 | unsigned int i; | ||
778 | |||
779 | release_route (route); | 778 | release_route (route); |
780 | if (new_distance >= DEFAULT_FISHEYE_DEPTH) | 779 | allocate_route (route, new_distance); |
781 | return; /* no longer interesting for 'consensi' */ | ||
782 | i = get_consensus_slot (new_distance); | ||
783 | route->set_offset = i; | ||
784 | consensi[new_distance].targets[i] = route; | ||
785 | route->target.distance = htonl (new_distance); | ||
786 | } | 780 | } |
787 | 781 | ||
788 | 782 | ||
@@ -840,6 +834,7 @@ build_set (void *cls) | |||
840 | route = consensi[neighbor->consensus_insertion_distance].targets[neighbor->consensus_insertion_offset]; | 834 | route = consensi[neighbor->consensus_insertion_distance].targets[neighbor->consensus_insertion_offset]; |
841 | GNUNET_assert (NULL != route); | 835 | GNUNET_assert (NULL != route); |
842 | target = &route->target; | 836 | target = &route->target; |
837 | GNUNET_assert (ntohl (target->distance) < DEFAULT_FISHEYE_DEPTH); | ||
843 | element.size = sizeof (struct Target); | 838 | element.size = sizeof (struct Target); |
844 | element.type = htons (0); /* do we need this? */ | 839 | element.type = htons (0); /* do we need this? */ |
845 | element.data = target; | 840 | element.data = target; |
@@ -898,7 +893,7 @@ handle_direct_connect (struct DirectNeighbor *neighbor) | |||
898 | 893 | ||
899 | neighbor->direct_route = GNUNET_new (struct Route); | 894 | neighbor->direct_route = GNUNET_new (struct Route); |
900 | neighbor->direct_route->next_hop = neighbor; | 895 | neighbor->direct_route->next_hop = neighbor; |
901 | neighbor->direct_route->target.peer= neighbor->peer; | 896 | neighbor->direct_route->target.peer = neighbor->peer; |
902 | allocate_route (neighbor->direct_route, DIRECT_NEIGHBOR_COST); | 897 | allocate_route (neighbor->direct_route, DIRECT_NEIGHBOR_COST); |
903 | 898 | ||
904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1035,16 +1030,22 @@ check_possible_route (void *cls, | |||
1035 | struct Target *target = value; | 1030 | struct Target *target = value; |
1036 | struct Route *route; | 1031 | struct Route *route; |
1037 | 1032 | ||
1033 | if (GNUNET_YES == | ||
1034 | GNUNET_CONTAINER_multipeermap_contains (direct_neighbors, | ||
1035 | key)) | ||
1036 | return GNUNET_YES; /* direct route, do not care about alternatives */ | ||
1038 | route = GNUNET_CONTAINER_multipeermap_get (all_routes, | 1037 | route = GNUNET_CONTAINER_multipeermap_get (all_routes, |
1039 | key); | 1038 | key); |
1040 | if (NULL != route) | 1039 | if (NULL != route) |
1041 | { | 1040 | { |
1041 | /* we have an existing route, check how it compares with going via 'target' */ | ||
1042 | if (ntohl (route->target.distance) > ntohl (target->distance) + 1) | 1042 | if (ntohl (route->target.distance) > ntohl (target->distance) + 1) |
1043 | { | 1043 | { |
1044 | /* this 'target' is cheaper than the existing route; switch to alternative route! */ | 1044 | /* via 'target' is cheaper than the existing route; switch to alternative route! */ |
1045 | move_route (route, ntohl (target->distance) + 1); | 1045 | move_route (route, ntohl (target->distance) + 1); |
1046 | route->next_hop = neighbor; | 1046 | route->next_hop = neighbor; |
1047 | send_distance_change_to_plugin (&target->peer, ntohl (target->distance) + 1); | 1047 | send_distance_change_to_plugin (&target->peer, |
1048 | ntohl (target->distance) + 1); | ||
1048 | } | 1049 | } |
1049 | return GNUNET_YES; /* got a route to this target already */ | 1050 | return GNUNET_YES; /* got a route to this target already */ |
1050 | } | 1051 | } |
@@ -1203,6 +1204,9 @@ cull_routes (void *cls, | |||
1203 | static void | 1204 | static void |
1204 | handle_direct_disconnect (struct DirectNeighbor *neighbor) | 1205 | handle_direct_disconnect (struct DirectNeighbor *neighbor) |
1205 | { | 1206 | { |
1207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1208 | "Culling routes via %s due to direct disconnect\n", | ||
1209 | GNUNET_i2s (&neighbor->peer)); | ||
1206 | GNUNET_CONTAINER_multipeermap_iterate (all_routes, | 1210 | GNUNET_CONTAINER_multipeermap_iterate (all_routes, |
1207 | &cull_routes, | 1211 | &cull_routes, |
1208 | neighbor); | 1212 | neighbor); |
@@ -1284,15 +1288,10 @@ handle_ats_update (void *cls, | |||
1284 | uint32_t network = GNUNET_ATS_NET_UNSPECIFIED; | 1288 | uint32_t network = GNUNET_ATS_NET_UNSPECIFIED; |
1285 | 1289 | ||
1286 | if (GNUNET_NO == active) | 1290 | if (GNUNET_NO == active) |
1287 | return; | 1291 | return; |
1288 | distance = get_atsi_distance (ats, ats_count); | 1292 | distance = get_atsi_distance (ats, ats_count); |
1289 | network = get_atsi_network (ats, ats_count); | 1293 | network = get_atsi_network (ats, ats_count); |
1290 | 1294 | ||
1291 | /* | ||
1292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1293 | "ATS says distance to %s is %u\n", | ||
1294 | GNUNET_i2s (&address->peer), | ||
1295 | (unsigned int) distance);*/ | ||
1296 | /* check if entry exists */ | 1295 | /* check if entry exists */ |
1297 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 1296 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
1298 | &address->peer); | 1297 | &address->peer); |
@@ -1300,7 +1299,12 @@ handle_ats_update (void *cls, | |||
1300 | { | 1299 | { |
1301 | if (GNUNET_ATS_NET_UNSPECIFIED != network) | 1300 | if (GNUNET_ATS_NET_UNSPECIFIED != network) |
1302 | neighbor->network = network; | 1301 | neighbor->network = network; |
1303 | 1302 | if (neighbor->distance == distance) | |
1303 | return; /* nothing new to see here, move along */ | ||
1304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1305 | "ATS says distance to %s is now %u\n", | ||
1306 | GNUNET_i2s (&address->peer), | ||
1307 | (unsigned int) distance); | ||
1304 | if ( (DIRECT_NEIGHBOR_COST == neighbor->distance) && | 1308 | if ( (DIRECT_NEIGHBOR_COST == neighbor->distance) && |
1305 | (DIRECT_NEIGHBOR_COST == distance) ) | 1309 | (DIRECT_NEIGHBOR_COST == distance) ) |
1306 | return; /* no change */ | 1310 | return; /* no change */ |
@@ -1322,6 +1326,10 @@ handle_ats_update (void *cls, | |||
1322 | handle_direct_connect (neighbor); | 1326 | handle_direct_connect (neighbor); |
1323 | return; | 1327 | return; |
1324 | } | 1328 | } |
1329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1330 | "ATS says distance to %s is now %u\n", | ||
1331 | GNUNET_i2s (&address->peer), | ||
1332 | (unsigned int) distance); | ||
1325 | neighbor = GNUNET_new (struct DirectNeighbor); | 1333 | neighbor = GNUNET_new (struct DirectNeighbor); |
1326 | neighbor->peer = address->peer; | 1334 | neighbor->peer = address->peer; |
1327 | GNUNET_assert (GNUNET_YES == | 1335 | GNUNET_assert (GNUNET_YES == |
@@ -1355,28 +1363,37 @@ check_target_removed (void *cls, | |||
1355 | 1363 | ||
1356 | new_target = GNUNET_CONTAINER_multipeermap_get (neighbor->neighbor_table_consensus, | 1364 | new_target = GNUNET_CONTAINER_multipeermap_get (neighbor->neighbor_table_consensus, |
1357 | key); | 1365 | key); |
1358 | if (NULL == new_target) | 1366 | current_route = GNUNET_CONTAINER_multipeermap_get (all_routes, |
1367 | key); | ||
1368 | if (NULL != new_target) | ||
1359 | { | 1369 | { |
1360 | /* target was revoked, check if it was used */ | 1370 | /* target was in old set, is in new set */ |
1361 | current_route = GNUNET_CONTAINER_multipeermap_get (all_routes, | 1371 | if ( (NULL != current_route) && |
1362 | key); | 1372 | (current_route->next_hop == neighbor) && |
1363 | if ( (NULL == current_route) || | 1373 | (current_route->target.distance != new_target->distance) ) |
1364 | (current_route->next_hop != neighbor) ) | ||
1365 | { | 1374 | { |
1366 | /* didn't matter, wasn't used */ | 1375 | /* need to recalculate routes due to distance change */ |
1367 | return GNUNET_OK; | 1376 | neighbor->target_removed = GNUNET_YES; |
1368 | } | 1377 | } |
1369 | /* remove existing route */ | ||
1370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1371 | "Lost route to %s\n", | ||
1372 | GNUNET_i2s (¤t_route->target.peer)); | ||
1373 | GNUNET_assert (GNUNET_YES == | ||
1374 | GNUNET_CONTAINER_multipeermap_remove (all_routes, key, current_route)); | ||
1375 | send_disconnect_to_plugin (¤t_route->target.peer); | ||
1376 | GNUNET_free (current_route); | ||
1377 | neighbor->target_removed = GNUNET_YES; | ||
1378 | return GNUNET_OK; | 1378 | return GNUNET_OK; |
1379 | } | 1379 | } |
1380 | /* target was revoked, check if it was used */ | ||
1381 | if ( (NULL == current_route) || | ||
1382 | (current_route->next_hop != neighbor) ) | ||
1383 | { | ||
1384 | /* didn't matter, wasn't used */ | ||
1385 | return GNUNET_OK; | ||
1386 | } | ||
1387 | /* remove existing route */ | ||
1388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1389 | "Lost route to %s\n", | ||
1390 | GNUNET_i2s (¤t_route->target.peer)); | ||
1391 | GNUNET_assert (GNUNET_YES == | ||
1392 | GNUNET_CONTAINER_multipeermap_remove (all_routes, key, current_route)); | ||
1393 | send_disconnect_to_plugin (¤t_route->target.peer); | ||
1394 | release_route (current_route); | ||
1395 | GNUNET_free (current_route); | ||
1396 | neighbor->target_removed = GNUNET_YES; | ||
1380 | return GNUNET_OK; | 1397 | return GNUNET_OK; |
1381 | } | 1398 | } |
1382 | 1399 | ||
@@ -1431,7 +1448,7 @@ check_target_added (void *cls, | |||
1431 | } | 1448 | } |
1432 | return GNUNET_OK; | 1449 | return GNUNET_OK; |
1433 | } | 1450 | } |
1434 | if (ntohl (current_route->target.distance) >= ntohl (target->distance) + 1) | 1451 | if (ntohl (current_route->target.distance) <= ntohl (target->distance) + 1) |
1435 | { | 1452 | { |
1436 | /* alternative, shorter route exists, ignore */ | 1453 | /* alternative, shorter route exists, ignore */ |
1437 | return GNUNET_OK; | 1454 | return GNUNET_OK; |
@@ -1520,13 +1537,24 @@ handle_set_union_result (void *cls, | |||
1520 | GNUNET_break_op (0); | 1537 | GNUNET_break_op (0); |
1521 | return; | 1538 | return; |
1522 | } | 1539 | } |
1540 | if (GNUNET_YES == | ||
1541 | GNUNET_CONTAINER_multipeermap_contains (direct_neighbors, | ||
1542 | &((struct Target *) element->data)->peer)) | ||
1543 | { | ||
1544 | /* this is a direct neighbor of ours, we do not care about routes | ||
1545 | to this peer */ | ||
1546 | return; | ||
1547 | } | ||
1523 | target = GNUNET_new (struct Target); | 1548 | target = GNUNET_new (struct Target); |
1524 | memcpy (target, element->data, sizeof (struct Target)); | 1549 | memcpy (target, element->data, sizeof (struct Target)); |
1525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1526 | "Received information about peer `%s' with distance %u\n", | 1551 | "Received information about peer `%s' with distance %u from SET\n", |
1527 | GNUNET_i2s (&target->peer), ntohl(target->distance) + 1); | 1552 | GNUNET_i2s (&target->peer), |
1553 | ntohl (target->distance) + 1); | ||
1554 | |||
1528 | if (NULL == neighbor->neighbor_table_consensus) | 1555 | if (NULL == neighbor->neighbor_table_consensus) |
1529 | neighbor->neighbor_table_consensus = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1556 | neighbor->neighbor_table_consensus |
1557 | = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | ||
1530 | if (GNUNET_YES != | 1558 | if (GNUNET_YES != |
1531 | GNUNET_CONTAINER_multipeermap_put (neighbor->neighbor_table_consensus, | 1559 | GNUNET_CONTAINER_multipeermap_put (neighbor->neighbor_table_consensus, |
1532 | &target->peer, | 1560 | &target->peer, |
@@ -1566,8 +1594,8 @@ handle_set_union_result (void *cls, | |||
1566 | neighbor->neighbor_table_consensus = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1594 | neighbor->neighbor_table_consensus = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
1567 | if (NULL != neighbor->neighbor_table) | 1595 | if (NULL != neighbor->neighbor_table) |
1568 | GNUNET_CONTAINER_multipeermap_iterate (neighbor->neighbor_table, | 1596 | GNUNET_CONTAINER_multipeermap_iterate (neighbor->neighbor_table, |
1569 | &check_target_removed, | 1597 | &check_target_removed, |
1570 | neighbor); | 1598 | neighbor); |
1571 | if (GNUNET_YES == neighbor->target_removed) | 1599 | if (GNUNET_YES == neighbor->target_removed) |
1572 | { | 1600 | { |
1573 | /* check if we got an alternative for the removed routes */ | 1601 | /* check if we got an alternative for the removed routes */ |
@@ -1940,6 +1968,7 @@ free_direct_neighbors (void *cls, | |||
1940 | void *value) | 1968 | void *value) |
1941 | { | 1969 | { |
1942 | struct DirectNeighbor *neighbor = value; | 1970 | struct DirectNeighbor *neighbor = value; |
1971 | |||
1943 | cleanup_neighbor (neighbor); | 1972 | cleanup_neighbor (neighbor); |
1944 | return GNUNET_YES; | 1973 | return GNUNET_YES; |
1945 | } | 1974 | } |