diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-04-28 16:43:58 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-04-28 16:43:58 +0000 |
commit | c4b16be7d1cedfe7e17ed39fe7c2661529f5ce12 (patch) | |
tree | e7c0f61c270a3c943f7334179ab42c1211e5ab6f /src/dv/gnunet-service-dv.c | |
parent | 20360d06df924f4a02b1da30c4a3ab0fe28014ea (diff) | |
download | gnunet-c4b16be7d1cedfe7e17ed39fe7c2661529f5ce12.tar.gz gnunet-c4b16be7d1cedfe7e17ed39fe7c2661529f5ce12.zip |
in case of fire, or volcano. still not to be used by anyone for anything
Diffstat (limited to 'src/dv/gnunet-service-dv.c')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 94 |
1 files changed, 41 insertions, 53 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 445076071..f956e4cb0 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -27,13 +27,7 @@ | |||
27 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
28 | * @author Nathan Evans | 28 | * @author Nathan Evans |
29 | * | 29 | * |
30 | * TODO: Currently the final hop of a DV message assigns a 0 to the receiver | 30 | * TODO: The gossip rates need to be worked out. Probably many other things |
31 | * id field. This probably can't work(!) even if we know that the peer is | ||
32 | * a direct neighbor (unless we can trust that transport will choose that | ||
33 | * address for the peer). So the DV message will likely need to have the | ||
34 | * peer identity of the recipient. | ||
35 | * | ||
36 | * Also the gossip rates need to be worked out. Probably many other things | ||
37 | * as well. | 31 | * as well. |
38 | * | 32 | * |
39 | */ | 33 | */ |
@@ -114,6 +108,11 @@ static struct GNUNET_SCHEDULER_Handle *sched; | |||
114 | #define DV_PRIORITY 0 | 108 | #define DV_PRIORITY 0 |
115 | 109 | ||
116 | /** | 110 | /** |
111 | * The cost to a direct neighbor. We used to use 0, but 1 makes more sense. | ||
112 | */ | ||
113 | #define DIRECT_NEIGHBOR_COST 1 | ||
114 | |||
115 | /** | ||
117 | * The client, should be the DV plugin connected to us. Hopefully | 116 | * The client, should be the DV plugin connected to us. Hopefully |
118 | * this client will never change, although if the plugin dies | 117 | * this client will never change, although if the plugin dies |
119 | * and returns for some reason it may happen. | 118 | * and returns for some reason it may happen. |
@@ -179,6 +178,10 @@ struct PendingMessage *plugin_pending_head; | |||
179 | */ | 178 | */ |
180 | struct PendingMessage *plugin_pending_tail; | 179 | struct PendingMessage *plugin_pending_tail; |
181 | 180 | ||
181 | /** | ||
182 | * Handle to the peerinfo service | ||
183 | */ | ||
184 | struct GNUNET_PEERINFO_Handle *peerinfo_handle; | ||
182 | 185 | ||
183 | /** | 186 | /** |
184 | * Transmit handle to core service. | 187 | * Transmit handle to core service. |
@@ -196,8 +199,6 @@ struct PendingMessage *core_pending_head; | |||
196 | struct PendingMessage *core_pending_tail; | 199 | struct PendingMessage *core_pending_tail; |
197 | 200 | ||
198 | 201 | ||
199 | |||
200 | |||
201 | /** | 202 | /** |
202 | * Context created whenever a direct peer connects to us, | 203 | * Context created whenever a direct peer connects to us, |
203 | * used to gossip other peers to it. | 204 | * used to gossip other peers to it. |
@@ -674,7 +675,7 @@ size_t core_transmit_notify (void *cls, | |||
674 | (size >= off + (msize = ntohs (reply->msg->size)))) | 675 | (size >= off + (msize = ntohs (reply->msg->size)))) |
675 | { | 676 | { |
676 | #if DEBUG_DV | 677 | #if DEBUG_DV |
677 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`%s' : transmit_notify (core) called with size %d\n", "dv service", msize); | 678 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' : transmit_notify (core) called with size %d\n", "dv service", msize); |
678 | #endif | 679 | #endif |
679 | GNUNET_CONTAINER_DLL_remove (core_pending_head, | 680 | GNUNET_CONTAINER_DLL_remove (core_pending_head, |
680 | core_pending_tail, | 681 | core_pending_tail, |
@@ -751,7 +752,7 @@ send_message_via (const struct GNUNET_PeerIdentity * sender, | |||
751 | #if DEBUG_DV | 752 | #if DEBUG_DV |
752 | memcpy(&shortname, GNUNET_i2s(&specific_neighbor->identity), 4); | 753 | memcpy(&shortname, GNUNET_i2s(&specific_neighbor->identity), 4); |
753 | shortname[4] = '\0'; | 754 | shortname[4] = '\0'; |
754 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: Notifying core of send to destination `%s' via `%s' size %u\n", "DV", &shortname, GNUNET_i2s(&specific_neighbor->referrer->identity), msg_size); | 755 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send to destination `%s' via `%s' size %u\n", "DV", &shortname, GNUNET_i2s(&specific_neighbor->referrer->identity), msg_size); |
755 | #endif | 756 | #endif |
756 | 757 | ||
757 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, | 758 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, |
@@ -761,7 +762,7 @@ send_message_via (const struct GNUNET_PeerIdentity * sender, | |||
761 | if (core_transmit_handle == NULL) | 762 | if (core_transmit_handle == NULL) |
762 | core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, send_context->importance, send_context->timeout, &specific_neighbor->referrer->identity, msg_size, &core_transmit_notify, NULL); | 763 | core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, send_context->importance, send_context->timeout, &specific_neighbor->referrer->identity, msg_size, &core_transmit_notify, NULL); |
763 | else | 764 | else |
764 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`%s': Failed to schedule pending transmission (must be one in progress!)\n", "dv service"); | 765 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s': Failed to schedule pending transmission (must be one in progress!)\n", "dv service"); |
765 | 766 | ||
766 | return (int) cost; | 767 | return (int) cost; |
767 | } | 768 | } |
@@ -840,7 +841,7 @@ send_message (const struct GNUNET_PeerIdentity * recipient, | |||
840 | core_pending_tail, | 841 | core_pending_tail, |
841 | pending_message); | 842 | pending_message); |
842 | #if DEBUG_DV | 843 | #if DEBUG_DV |
843 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient)); | 844 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient)); |
844 | #endif | 845 | #endif |
845 | if (core_transmit_handle == NULL) | 846 | if (core_transmit_handle == NULL) |
846 | core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, importance, timeout, &target->referrer->identity, msg_size, &core_transmit_notify, NULL); | 847 | core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, importance, timeout, &target->referrer->identity, msg_size, &core_transmit_notify, NULL); |
@@ -913,7 +914,7 @@ static int handle_dv_data_message (void *cls, | |||
913 | if (pos == NULL) | 914 | if (pos == NULL) |
914 | { | 915 | { |
915 | #if DEBUG_DV | 916 | #if DEBUG_DV |
916 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 917 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
917 | "%s: unknown sender (%d), size of extended_peers is %d!\n", "dv", ntohl(incoming->sender), GNUNET_CONTAINER_multihashmap_size (ctx.extended_neighbors)); | 918 | "%s: unknown sender (%d), size of extended_peers is %d!\n", "dv", ntohl(incoming->sender), GNUNET_CONTAINER_multihashmap_size (ctx.extended_neighbors)); |
918 | #endif | 919 | #endif |
919 | /* unknown sender */ | 920 | /* unknown sender */ |
@@ -931,8 +932,8 @@ static int handle_dv_data_message (void *cls, | |||
931 | { | 932 | { |
932 | packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset]; | 933 | packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset]; |
933 | #if DEBUG_DV | 934 | #if DEBUG_DV |
934 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 935 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
935 | "%s: Receives %s message for me, size %d type %d!\n", "dv", "DV DATA", ntohs(packed_message->size), ntohs(packed_message->type)); | 936 | "%s: Receives %s message for me, size %d type %d, cost %u!\n", "dv", "DV DATA", ntohs(packed_message->size), ntohs(packed_message->type), pos->cost); |
936 | #endif | 937 | #endif |
937 | GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP); | 938 | GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP); |
938 | GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA); | 939 | GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA); |
@@ -1174,7 +1175,7 @@ void handle_dv_send_message (void *cls, | |||
1174 | if (client_handle == NULL) | 1175 | if (client_handle == NULL) |
1175 | { | 1176 | { |
1176 | client_handle = client; | 1177 | client_handle = client; |
1177 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1178 | "%s: Setting initial client handle, never received `%s' message?\n", "dv", "START"); | 1179 | "%s: Setting initial client handle, never received `%s' message?\n", "dv", "START"); |
1179 | } | 1180 | } |
1180 | else if (client_handle != client) | 1181 | else if (client_handle != client) |
@@ -1290,6 +1291,7 @@ shutdown_task (void *cls, | |||
1290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n"); | 1291 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n"); |
1291 | #endif | 1292 | #endif |
1292 | GNUNET_CORE_disconnect (coreAPI); | 1293 | GNUNET_CORE_disconnect (coreAPI); |
1294 | GNUNET_PEERINFO_disconnect(peerinfo_handle); | ||
1293 | #if DEBUG_DV | 1295 | #if DEBUG_DV |
1294 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n"); | 1296 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n"); |
1295 | #endif | 1297 | #endif |
@@ -1487,7 +1489,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO | |||
1487 | GNUNET_free(neighbor_update); | 1489 | GNUNET_free(neighbor_update); |
1488 | return; | 1490 | return; |
1489 | } | 1491 | } |
1490 | if (max->cost > 0) | 1492 | if (max->cost > 1) |
1491 | { | 1493 | { |
1492 | /* only free if this is not a direct connection; | 1494 | /* only free if this is not a direct connection; |
1493 | we could theoretically have more direct | 1495 | we could theoretically have more direct |
@@ -1518,7 +1520,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO | |||
1518 | neighbor->referrer_id = referrer_peer_id; | 1520 | neighbor->referrer_id = referrer_peer_id; |
1519 | neighbor->our_id = our_id; | 1521 | neighbor->our_id = our_id; |
1520 | neighbor->hidden = | 1522 | neighbor->hidden = |
1521 | (cost == 0) ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) == | 1523 | (cost == DIRECT_NEIGHBOR_COST) ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) == |
1522 | 0) : GNUNET_NO; | 1524 | 0) : GNUNET_NO; |
1523 | GNUNET_CONTAINER_multihashmap_put (ctx.extended_neighbors, &peer->hashPubKey, | 1525 | GNUNET_CONTAINER_multihashmap_put (ctx.extended_neighbors, &peer->hashPubKey, |
1524 | neighbor, | 1526 | neighbor, |
@@ -1537,25 +1539,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO | |||
1537 | GNUNET_CONTAINER_multihashmap_iterate(ctx.extended_neighbors, &print_neighbors, NULL); | 1539 | GNUNET_CONTAINER_multihashmap_iterate(ctx.extended_neighbors, &print_neighbors, NULL); |
1538 | #endif | 1540 | #endif |
1539 | GNUNET_free(neighbor_update); | 1541 | GNUNET_free(neighbor_update); |
1540 | /* Old logic to remove entry and replace, not needed now as we only want to remove when full | 1542 | |
1541 | * or when the referring peer disconnects from us. | ||
1542 | * | ||
1543 | * FIXME: add new functionality, or check if it already exists (i forget) | ||
1544 | */ | ||
1545 | /* | ||
1546 | GNUNET_DLL_remove (neighbor->referrer->referee_head, | ||
1547 | neighbor->referrer->referee_tail, neighbor); | ||
1548 | neighbor->referrer = referrer; | ||
1549 | GNUNET_DLL_insert (referrer->referee_head, | ||
1550 | referrer->referee_tail, neighbor); | ||
1551 | GNUNET_CONTAINER_heap_update_cost (ctx.neighbor_max_heap, | ||
1552 | neighbor->max_loc, cost); | ||
1553 | GNUNET_CONTAINER_heap_update_cost (ctx.neighbor_min_heap, | ||
1554 | neighbor->min_loc, cost); | ||
1555 | neighbor->referrer_id = referrer_peer_id; | ||
1556 | neighbor->last_activity = now; | ||
1557 | neighbor->cost = cost; | ||
1558 | */ | ||
1559 | } | 1543 | } |
1560 | 1544 | ||
1561 | 1545 | ||
@@ -1658,8 +1642,8 @@ static int handle_dv_gossip_message (void *cls, | |||
1658 | 1642 | ||
1659 | static void | 1643 | static void |
1660 | process_peerinfo (void *cls, | 1644 | process_peerinfo (void *cls, |
1661 | const struct GNUNET_PeerIdentity *peer, | 1645 | const struct GNUNET_PeerIdentity *peer, |
1662 | const struct GNUNET_HELLO_Message *hello, uint32_t trust) | 1646 | const struct GNUNET_HELLO_Message *hello, uint32_t trust) |
1663 | { | 1647 | { |
1664 | struct PeerIteratorContext *peerinfo_iterator = cls; | 1648 | struct PeerIteratorContext *peerinfo_iterator = cls; |
1665 | struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor; | 1649 | struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor; |
@@ -1704,7 +1688,7 @@ void handle_core_connect (void *cls, | |||
1704 | "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance); | 1688 | "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance); |
1705 | #endif | 1689 | #endif |
1706 | 1690 | ||
1707 | if ((distance == 0) && (GNUNET_CONTAINER_multihashmap_get(ctx.direct_neighbors, &peer->hashPubKey) == NULL)) | 1691 | if ((distance == DIRECT_NEIGHBOR_COST) && (GNUNET_CONTAINER_multihashmap_get(ctx.direct_neighbors, &peer->hashPubKey) == NULL)) |
1708 | { | 1692 | { |
1709 | peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext)); | 1693 | peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext)); |
1710 | neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); | 1694 | neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); |
@@ -1716,15 +1700,14 @@ void handle_core_connect (void *cls, | |||
1716 | GNUNET_CONTAINER_multihashmap_put (ctx.direct_neighbors, | 1700 | GNUNET_CONTAINER_multihashmap_put (ctx.direct_neighbors, |
1717 | &peer->hashPubKey, | 1701 | &peer->hashPubKey, |
1718 | neighbor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1702 | neighbor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1719 | addUpdateNeighbor (peer, NULL, 0, neighbor, 0); | 1703 | addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST); |
1720 | peerinfo_iterator->neighbor = neighbor; | 1704 | peerinfo_iterator->neighbor = neighbor; |
1721 | peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (cfg, | 1705 | peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle, |
1722 | sched, | 1706 | peer, |
1723 | peer, | 1707 | 0, |
1724 | 0, | 1708 | GNUNET_TIME_UNIT_FOREVER_REL, |
1725 | GNUNET_TIME_relative_multiply | 1709 | &process_peerinfo, |
1726 | (GNUNET_TIME_UNIT_SECONDS, 15), | 1710 | peerinfo_iterator); |
1727 | &process_peerinfo, peerinfo_iterator); | ||
1728 | /* Only add once we get the publicKey of this guy | 1711 | /* Only add once we get the publicKey of this guy |
1729 | * | 1712 | * |
1730 | * neighbor->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, neighbor->send_context); | 1713 | * neighbor->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, neighbor->send_context); |
@@ -1734,7 +1717,7 @@ void handle_core_connect (void *cls, | |||
1734 | { | 1717 | { |
1735 | #if DEBUG_DV | 1718 | #if DEBUG_DV |
1736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1719 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1737 | "%s: Distance (%d) greater than 0 or already know about peer (%s), not re-adding!\n", "dv", distance, GNUNET_i2s(peer)); | 1720 | "%s: Distance (%d) greater than %d or already know about peer (%s), not re-adding!\n", "dv", distance, DIRECT_NEIGHBOR_COST, GNUNET_i2s(peer)); |
1738 | #endif | 1721 | #endif |
1739 | return; | 1722 | return; |
1740 | } | 1723 | } |
@@ -1810,8 +1793,6 @@ run (void *cls, | |||
1810 | client_transmit_timeout = GNUNET_TIME_relative_get_forever(); /* Only timeout on disconnect */ | 1793 | client_transmit_timeout = GNUNET_TIME_relative_get_forever(); /* Only timeout on disconnect */ |
1811 | default_dv_delay = GNUNET_TIME_relative_get_forever(); /* Only timeout on disconnect */ | 1794 | default_dv_delay = GNUNET_TIME_relative_get_forever(); /* Only timeout on disconnect */ |
1812 | 1795 | ||
1813 | //client_transmit_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5); | ||
1814 | //default_dv_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5); | ||
1815 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 1796 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
1816 | coreAPI = | 1797 | coreAPI = |
1817 | GNUNET_CORE_connect (sched, | 1798 | GNUNET_CORE_connect (sched, |
@@ -1829,7 +1810,14 @@ run (void *cls, | |||
1829 | 1810 | ||
1830 | if (coreAPI == NULL) | 1811 | if (coreAPI == NULL) |
1831 | return; | 1812 | return; |
1832 | /* load (server); Huh? */ | 1813 | |
1814 | peerinfo_handle = GNUNET_PEERINFO_connect(sched, cfg); | ||
1815 | |||
1816 | if (peerinfo_handle == NULL) | ||
1817 | { | ||
1818 | GNUNET_CORE_disconnect(coreAPI); | ||
1819 | return; | ||
1820 | } | ||
1833 | 1821 | ||
1834 | /* Scheduled the task to clean up when shutdown is called */ | 1822 | /* Scheduled the task to clean up when shutdown is called */ |
1835 | cleanup_task = GNUNET_SCHEDULER_add_delayed (sched, | 1823 | cleanup_task = GNUNET_SCHEDULER_add_delayed (sched, |