aboutsummaryrefslogtreecommitdiff
path: root/src/dv
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-08-04 13:26:21 +0000
committerChristian Grothoff <christian@grothoff.org>2016-08-04 13:26:21 +0000
commiteec2c020a1dc14565e0c79dfe8216636a29fefda (patch)
tree37a255f5d47bb062c995705efb4c7dc1540a196d /src/dv
parent1d94ddddab8ba2ec45ad00878cab6a29eddf51d9 (diff)
downloadgnunet-eec2c020a1dc14565e0c79dfe8216636a29fefda.tar.gz
gnunet-eec2c020a1dc14565e0c79dfe8216636a29fefda.zip
-finish dv conversion to new core MQ API
Diffstat (limited to 'src/dv')
-rw-r--r--src/dv/gnunet-service-dv.c77
1 files changed, 31 insertions, 46 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 3b79b474f..11ec13387 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -134,7 +134,7 @@ struct DirectNeighbor
134 /** 134 /**
135 * Identity of the peer. 135 * Identity of the peer.
136 */ 136 */
137 const struct GNUNET_PeerIdentity *peer; 137 struct GNUNET_PeerIdentity peer;
138 138
139 /** 139 /**
140 * Session ID we use whenever we create a set union with 140 * Session ID we use whenever we create a set union with
@@ -678,7 +678,7 @@ build_set (void *cls)
678 /* we have added all elements to the set, run the operation */ 678 /* we have added all elements to the set, run the operation */
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "Finished building my SET for peer `%s' with %u elements, committing\n", 680 "Finished building my SET for peer `%s' with %u elements, committing\n",
681 GNUNET_i2s (neighbor->peer), 681 GNUNET_i2s (&neighbor->peer),
682 neighbor->consensus_elements); 682 neighbor->consensus_elements);
683 GNUNET_SET_commit (neighbor->set_op, 683 GNUNET_SET_commit (neighbor->set_op,
684 neighbor->my_set); 684 neighbor->my_set);
@@ -701,7 +701,7 @@ build_set (void *cls)
701 &my_identity, 701 &my_identity,
702 sizeof (my_identity))) && 702 sizeof (my_identity))) &&
703 (0 != memcmp (&target->peer, 703 (0 != memcmp (&target->peer,
704 neighbor->peer, 704 &neighbor->peer,
705 sizeof (struct GNUNET_PeerIdentity))) ) 705 sizeof (struct GNUNET_PeerIdentity))) )
706 { 706 {
707 /* Add target if it is not the neighbor or this peer */ 707 /* Add target if it is not the neighbor or this peer */
@@ -734,26 +734,26 @@ handle_direct_connect (struct DirectNeighbor *neighbor)
734 734
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "Direct connection to %s established, routing table exchange begins.\n", 736 "Direct connection to %s established, routing table exchange begins.\n",
737 GNUNET_i2s (neighbor->peer)); 737 GNUNET_i2s (&neighbor->peer));
738 GNUNET_STATISTICS_update (stats, 738 GNUNET_STATISTICS_update (stats,
739 "# peers connected (1-hop)", 739 "# peers connected (1-hop)",
740 1, GNUNET_NO); 740 1, GNUNET_NO);
741 route = GNUNET_CONTAINER_multipeermap_get (all_routes, 741 route = GNUNET_CONTAINER_multipeermap_get (all_routes,
742 neighbor->peer); 742 &neighbor->peer);
743 if (NULL != route) 743 if (NULL != route)
744 { 744 {
745 GNUNET_assert (GNUNET_YES == 745 GNUNET_assert (GNUNET_YES ==
746 GNUNET_CONTAINER_multipeermap_remove (all_routes, 746 GNUNET_CONTAINER_multipeermap_remove (all_routes,
747 neighbor->peer, 747 &neighbor->peer,
748 route)); 748 route));
749 send_disconnect_to_plugin (neighbor->peer); 749 send_disconnect_to_plugin (&neighbor->peer);
750 release_route (route); 750 release_route (route);
751 GNUNET_free (route); 751 GNUNET_free (route);
752 } 752 }
753 753
754 neighbor->direct_route = GNUNET_new (struct Route); 754 neighbor->direct_route = GNUNET_new (struct Route);
755 neighbor->direct_route->next_hop = neighbor; 755 neighbor->direct_route->next_hop = neighbor;
756 neighbor->direct_route->target.peer = *neighbor->peer; 756 neighbor->direct_route->target.peer = neighbor->peer;
757 allocate_route (neighbor->direct_route, DIRECT_NEIGHBOR_COST); 757 allocate_route (neighbor->direct_route, DIRECT_NEIGHBOR_COST);
758 758
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -765,7 +765,7 @@ handle_direct_connect (struct DirectNeighbor *neighbor)
765 GNUNET_CRYPTO_hash (&my_identity, 765 GNUNET_CRYPTO_hash (&my_identity,
766 sizeof (my_identity), 766 sizeof (my_identity),
767 &h1); 767 &h1);
768 GNUNET_CRYPTO_hash (neighbor->peer, 768 GNUNET_CRYPTO_hash (&neighbor->peer,
769 sizeof (struct GNUNET_PeerIdentity), 769 sizeof (struct GNUNET_PeerIdentity),
770 &h2); 770 &h2);
771 GNUNET_CRYPTO_hash_xor (&h1, 771 GNUNET_CRYPTO_hash_xor (&h1,
@@ -799,7 +799,7 @@ handle_direct_connect (struct DirectNeighbor *neighbor)
799 { 799 {
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
801 "Starting SET listen operation with peer `%s'\n", 801 "Starting SET listen operation with peer `%s'\n",
802 GNUNET_i2s(&neighbor->peer)); 802 GNUNET_i2s (&neighbor->peer));
803 neighbor->listen_handle = GNUNET_SET_listen (cfg, 803 neighbor->listen_handle = GNUNET_SET_listen (cfg,
804 GNUNET_SET_OPERATION_UNION, 804 GNUNET_SET_OPERATION_UNION,
805 &neighbor->real_session_id, 805 &neighbor->real_session_id,
@@ -851,10 +851,10 @@ handle_core_connect (void *cls,
851 "Core connected to %s (distance unknown)\n", 851 "Core connected to %s (distance unknown)\n",
852 GNUNET_i2s (peer)); 852 GNUNET_i2s (peer));
853 neighbor = GNUNET_new (struct DirectNeighbor); 853 neighbor = GNUNET_new (struct DirectNeighbor);
854 neighbor->peer = peer; 854 neighbor->peer = *peer;
855 GNUNET_assert (GNUNET_YES == 855 GNUNET_assert (GNUNET_YES ==
856 GNUNET_CONTAINER_multipeermap_put (direct_neighbors, 856 GNUNET_CONTAINER_multipeermap_put (direct_neighbors,
857 neighbor->peer, 857 &neighbor->peer,
858 neighbor, 858 neighbor,
859 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 859 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
860 neighbor->connected = GNUNET_YES; 860 neighbor->connected = GNUNET_YES;
@@ -1056,19 +1056,12 @@ handle_direct_disconnect (struct DirectNeighbor *neighbor)
1056 GNUNET_CONTAINER_multipeermap_iterate (all_routes, 1056 GNUNET_CONTAINER_multipeermap_iterate (all_routes,
1057 &cull_routes, 1057 &cull_routes,
1058 neighbor); 1058 neighbor);
1059 if (NULL != neighbor->cth)
1060 {
1061 GNUNET_CORE_notify_transmit_ready_cancel (neighbor->cth);
1062 neighbor->cth = NULL;
1063 }
1064
1065 if (NULL != neighbor->direct_route) 1059 if (NULL != neighbor->direct_route)
1066 { 1060 {
1067 release_route (neighbor->direct_route); 1061 release_route (neighbor->direct_route);
1068 GNUNET_free (neighbor->direct_route); 1062 GNUNET_free (neighbor->direct_route);
1069 neighbor->direct_route = NULL; 1063 neighbor->direct_route = NULL;
1070 } 1064 }
1071
1072 if (NULL != neighbor->neighbor_table_consensus) 1065 if (NULL != neighbor->neighbor_table_consensus)
1073 { 1066 {
1074 GNUNET_CONTAINER_multipeermap_iterate (neighbor->neighbor_table_consensus, 1067 GNUNET_CONTAINER_multipeermap_iterate (neighbor->neighbor_table_consensus,
@@ -1189,7 +1182,7 @@ handle_ats_update (void *cls,
1189 neighbor->peer = address->peer; 1182 neighbor->peer = address->peer;
1190 GNUNET_assert (GNUNET_YES == 1183 GNUNET_assert (GNUNET_YES ==
1191 GNUNET_CONTAINER_multipeermap_put (direct_neighbors, 1184 GNUNET_CONTAINER_multipeermap_put (direct_neighbors,
1192 &address->peer, 1185 &neighbor->peer,
1193 neighbor, 1186 neighbor,
1194 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1187 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1195 neighbor->connected = GNUNET_NO; /* not yet */ 1188 neighbor->connected = GNUNET_NO; /* not yet */
@@ -1363,6 +1356,7 @@ handle_set_union_result (void *cls,
1363 struct DirectNeighbor *neighbor = cls; 1356 struct DirectNeighbor *neighbor = cls;
1364 struct DirectNeighbor *dn; 1357 struct DirectNeighbor *dn;
1365 struct Target *target; 1358 struct Target *target;
1359 const struct Target *ctarget;
1366 char *status_str; 1360 char *status_str;
1367 1361
1368 switch (status) 1362 switch (status)
@@ -1395,7 +1389,11 @@ handle_set_union_result (void *cls,
1395 GNUNET_break_op (0); 1389 GNUNET_break_op (0);
1396 return; 1390 return;
1397 } 1391 }
1398 if ( (NULL != (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, &((struct Target *) element->data)->peer))) && (DIRECT_NEIGHBOR_COST == dn->distance) ) 1392 ctarget = element->data;
1393 if ( (NULL !=
1394 (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
1395 &ctarget->peer))) &&
1396 (DIRECT_NEIGHBOR_COST == dn->distance) )
1399 { 1397 {
1400 /* this is a direct neighbor of ours, we do not care about routes 1398 /* this is a direct neighbor of ours, we do not care about routes
1401 to this peer */ 1399 to this peer */
@@ -1515,7 +1513,7 @@ listen_set_union (void *cls,
1515 return; /* why??? */ 1513 return; /* why??? */
1516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1517 "Starting to create consensus with %s\n", 1515 "Starting to create consensus with %s\n",
1518 GNUNET_i2s (neighbor->peer)); 1516 GNUNET_i2s (&neighbor->peer));
1519 if (NULL != neighbor->set_op) 1517 if (NULL != neighbor->set_op)
1520 { 1518 {
1521 GNUNET_SET_operation_cancel (neighbor->set_op); 1519 GNUNET_SET_operation_cancel (neighbor->set_op);
@@ -1581,7 +1579,7 @@ check_dv_route_message (void *cls,
1581 const struct RouteMessage *rm) 1579 const struct RouteMessage *rm)
1582{ 1580{
1583 const struct GNUNET_MessageHeader *payload; 1581 const struct GNUNET_MessageHeader *payload;
1584 1582
1585 if (ntohs (rm->header.size) < sizeof (struct RouteMessage) + sizeof (struct GNUNET_MessageHeader)) 1583 if (ntohs (rm->header.size) < sizeof (struct RouteMessage) + sizeof (struct GNUNET_MessageHeader))
1586 { 1584 {
1587 GNUNET_break_op (0); 1585 GNUNET_break_op (0);
@@ -1595,7 +1593,7 @@ check_dv_route_message (void *cls,
1595 } 1593 }
1596 return GNUNET_OK; 1594 return GNUNET_OK;
1597} 1595}
1598 1596
1599 1597
1600/** 1598/**
1601 * Core handler for DV data messages. Whatever this message 1599 * Core handler for DV data messages. Whatever this message
@@ -1610,9 +1608,10 @@ static void
1610handle_dv_route_message (void *cls, 1608handle_dv_route_message (void *cls,
1611 const struct RouteMessage *rm) 1609 const struct RouteMessage *rm)
1612{ 1610{
1611 struct DirectNeighbor *neighbor = cls;
1613 const struct GNUNET_MessageHeader *payload; 1612 const struct GNUNET_MessageHeader *payload;
1614 struct Route *route; 1613 struct Route *route;
1615 struct DirectNeighbor *neighbor; 1614 struct DirectNeighbor *nneighbor;
1616 struct DirectNeighbor *dn; 1615 struct DirectNeighbor *dn;
1617 struct Target *target; 1616 struct Target *target;
1618 uint32_t distance; 1617 uint32_t distance;
@@ -1623,7 +1622,7 @@ handle_dv_route_message (void *cls,
1623 1622
1624 distance = ntohl (rm->distance); 1623 distance = ntohl (rm->distance);
1625 payload = (const struct GNUNET_MessageHeader *) &rm[1]; 1624 payload = (const struct GNUNET_MessageHeader *) &rm[1];
1626 strncpy (prev, GNUNET_i2s (peer), 4); 1625 strncpy (prev, GNUNET_i2s (&neighbor->peer), 4);
1627 strncpy (me, GNUNET_i2s (&my_identity), 4); 1626 strncpy (me, GNUNET_i2s (&my_identity), 4);
1628 strncpy (src, GNUNET_i2s (&rm->sender), 4); 1627 strncpy (src, GNUNET_i2s (&rm->sender), 4);
1629 strncpy (dst, GNUNET_i2s (&rm->target), 4); 1628 strncpy (dst, GNUNET_i2s (&rm->target), 4);
@@ -1662,13 +1661,6 @@ handle_dv_route_message (void *cls,
1662 (distance < DEFAULT_FISHEYE_DEPTH) ) 1661 (distance < DEFAULT_FISHEYE_DEPTH) )
1663 { 1662 {
1664 /* don't have reverse route yet, learn it! */ 1663 /* don't have reverse route yet, learn it! */
1665 neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
1666 peer);
1667 if (NULL == neighbor)
1668 {
1669 GNUNET_break (0);
1670 return;
1671 }
1672 target = GNUNET_new (struct Target); 1664 target = GNUNET_new (struct Target);
1673 target->peer = rm->sender; 1665 target->peer = rm->sender;
1674 target->distance = htonl (distance); 1666 target->distance = htonl (distance);
@@ -1708,13 +1700,6 @@ handle_dv_route_message (void *cls,
1708 "Learning sender %s at distance %u from forwarding!\n", 1700 "Learning sender %s at distance %u from forwarding!\n",
1709 GNUNET_i2s (&rm->sender), 1701 GNUNET_i2s (&rm->sender),
1710 1 + distance); 1702 1 + distance);
1711 neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
1712 peer);
1713 if (NULL == neighbor)
1714 {
1715 GNUNET_break (0);
1716 return;
1717 }
1718 target = GNUNET_new (struct Target); 1703 target = GNUNET_new (struct Target);
1719 target->peer = rm->sender; 1704 target->peer = rm->sender;
1720 target->distance = htonl (distance); 1705 target->distance = htonl (distance);
@@ -1737,9 +1722,9 @@ handle_dv_route_message (void *cls,
1737 &rm->target); 1722 &rm->target);
1738 if (NULL == route) 1723 if (NULL == route)
1739 { 1724 {
1740 neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, 1725 nneighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
1741 &rm->target); 1726 &rm->target);
1742 if (NULL == neighbor) 1727 if (NULL == nneighbor)
1743 { 1728 {
1744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1745 "No route to %s, not routing %u bytes!\n", 1730 "No route to %s, not routing %u bytes!\n",
@@ -1753,12 +1738,12 @@ handle_dv_route_message (void *cls,
1753 } 1738 }
1754 else 1739 else
1755 { 1740 {
1756 neighbor = route->next_hop; 1741 nneighbor = route->next_hop;
1757 } 1742 }
1758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1759 "Forwarding message to %s\n", 1744 "Forwarding message to %s\n",
1760 GNUNET_i2s (neighbor->peer)); 1745 GNUNET_i2s (&nneighbor->peer));
1761 forward_payload (neighbor, 1746 forward_payload (nneighbor,
1762 distance + 1, 1747 distance + 1,
1763 &rm->sender, 1748 &rm->sender,
1764 &rm->target, 1749 &rm->target,
@@ -1838,7 +1823,7 @@ cleanup_neighbor (struct DirectNeighbor *neighbor)
1838 handle_direct_disconnect (neighbor); 1823 handle_direct_disconnect (neighbor);
1839 GNUNET_assert (GNUNET_YES == 1824 GNUNET_assert (GNUNET_YES ==
1840 GNUNET_CONTAINER_multipeermap_remove (direct_neighbors, 1825 GNUNET_CONTAINER_multipeermap_remove (direct_neighbors,
1841 neighbor->peer, 1826 &neighbor->peer,
1842 neighbor)); 1827 neighbor));
1843 GNUNET_free (neighbor); 1828 GNUNET_free (neighbor);
1844} 1829}