diff options
Diffstat (limited to 'src/dv/gnunet-service-dv.c')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 280 |
1 files changed, 123 insertions, 157 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 4b68f69b1..876d056ac 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -662,8 +662,7 @@ static unsigned long long max_table_size; | |||
662 | * respective neighbor. | 662 | * respective neighbor. |
663 | */ | 663 | */ |
664 | static int | 664 | static int |
665 | find_destination (void *cls, | 665 | find_destination (void *cls, struct GNUNET_CONTAINER_HeapNode *node, |
666 | struct GNUNET_CONTAINER_HeapNode *node, | ||
667 | void *element, GNUNET_CONTAINER_HeapCostType cost) | 666 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
668 | { | 667 | { |
669 | struct FindDestinationContext *fdc = cls; | 668 | struct FindDestinationContext *fdc = cls; |
@@ -752,21 +751,20 @@ transmit_to_plugin (void *cls, size_t size, void *buf) | |||
752 | while ((NULL != (reply = plugin_pending_head)) && | 751 | while ((NULL != (reply = plugin_pending_head)) && |
753 | (size >= off + (msize = ntohs (reply->msg->size)))) | 752 | (size >= off + (msize = ntohs (reply->msg->size)))) |
754 | { | 753 | { |
755 | GNUNET_CONTAINER_DLL_remove (plugin_pending_head, | 754 | GNUNET_CONTAINER_DLL_remove (plugin_pending_head, plugin_pending_tail, |
756 | plugin_pending_tail, reply); | 755 | reply); |
757 | memcpy (&cbuf[off], reply->msg, msize); | 756 | memcpy (&cbuf[off], reply->msg, msize); |
758 | GNUNET_free (reply); | 757 | GNUNET_free (reply); |
759 | off += msize; | 758 | off += msize; |
760 | } | 759 | } |
761 | 760 | ||
762 | if (plugin_pending_head != NULL) | 761 | if (plugin_pending_head != NULL) |
763 | plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, | 762 | plugin_transmit_handle = |
764 | ntohs | 763 | GNUNET_SERVER_notify_transmit_ready (client_handle, |
765 | (plugin_pending_head->msg-> | 764 | ntohs (plugin_pending_head-> |
766 | size), | 765 | msg->size), |
767 | GNUNET_TIME_UNIT_FOREVER_REL, | 766 | GNUNET_TIME_UNIT_FOREVER_REL, |
768 | &transmit_to_plugin, | 767 | &transmit_to_plugin, NULL); |
769 | NULL); | ||
770 | 768 | ||
771 | return off; | 769 | return off; |
772 | } | 770 | } |
@@ -783,8 +781,7 @@ transmit_to_plugin (void *cls, size_t size, void *buf) | |||
783 | */ | 781 | */ |
784 | void | 782 | void |
785 | send_to_plugin (const struct GNUNET_PeerIdentity *sender, | 783 | send_to_plugin (const struct GNUNET_PeerIdentity *sender, |
786 | const struct GNUNET_MessageHeader *message, | 784 | const struct GNUNET_MessageHeader *message, size_t message_size, |
787 | size_t message_size, | ||
788 | struct GNUNET_PeerIdentity *distant_neighbor, size_t cost) | 785 | struct GNUNET_PeerIdentity *distant_neighbor, size_t cost) |
789 | { | 786 | { |
790 | struct GNUNET_DV_MessageReceived *received_msg; | 787 | struct GNUNET_DV_MessageReceived *received_msg; |
@@ -877,14 +874,13 @@ try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
877 | return; /* Message send already in progress */ | 874 | return; /* Message send already in progress */ |
878 | 875 | ||
879 | if ((pending != NULL) && (coreAPI != NULL)) | 876 | if ((pending != NULL) && (coreAPI != NULL)) |
880 | core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI, | 877 | core_transmit_handle = |
881 | GNUNET_YES, | 878 | GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES, |
882 | pending->importance, | 879 | pending->importance, |
883 | pending->timeout, | 880 | pending->timeout, |
884 | &pending->recipient, | 881 | &pending->recipient, |
885 | pending->msg_size, | 882 | pending->msg_size, |
886 | &core_transmit_notify, | 883 | &core_transmit_notify, NULL); |
887 | NULL); | ||
888 | } | 884 | } |
889 | 885 | ||
890 | 886 | ||
@@ -1003,9 +999,9 @@ send_message_via (const struct GNUNET_PeerIdentity *sender, | |||
1003 | find_context.via = recipient; | 999 | find_context.via = recipient; |
1004 | find_context.tid = 0; | 1000 | find_context.tid = 0; |
1005 | GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, | 1001 | GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, |
1006 | &send_context-> | 1002 | &send_context->distant_peer-> |
1007 | distant_peer->hashPubKey, | 1003 | hashPubKey, &find_specific_id, |
1008 | &find_specific_id, &find_context); | 1004 | &find_context); |
1009 | 1005 | ||
1010 | if (find_context.tid == 0) | 1006 | if (find_context.tid == 0) |
1011 | { | 1007 | { |
@@ -1019,8 +1015,9 @@ send_message_via (const struct GNUNET_PeerIdentity *sender, | |||
1019 | if (0 == (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity)))) | 1015 | if (0 == (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity)))) |
1020 | { | 1016 | { |
1021 | sender_id = 0; | 1017 | sender_id = 0; |
1022 | source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, | 1018 | source = |
1023 | &sender->hashPubKey); | 1019 | GNUNET_CONTAINER_multihashmap_get (extended_neighbors, |
1020 | &sender->hashPubKey); | ||
1024 | if (source != NULL) | 1021 | if (source != NULL) |
1025 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1022 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1026 | "%s: send_message_via found %s, myself in extended peer list???\n", | 1023 | "%s: send_message_via found %s, myself in extended peer list???\n", |
@@ -1028,8 +1025,9 @@ send_message_via (const struct GNUNET_PeerIdentity *sender, | |||
1028 | } | 1025 | } |
1029 | else | 1026 | else |
1030 | { | 1027 | { |
1031 | source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, | 1028 | source = |
1032 | &sender->hashPubKey); | 1029 | GNUNET_CONTAINER_multihashmap_get (extended_neighbors, |
1030 | &sender->hashPubKey); | ||
1033 | if (source == NULL) | 1031 | if (source == NULL) |
1034 | { | 1032 | { |
1035 | /* sender unknown to us, drop! */ | 1033 | /* sender unknown to us, drop! */ |
@@ -1067,8 +1065,7 @@ send_message_via (const struct GNUNET_PeerIdentity *sender, | |||
1067 | "DV", &shortname, GNUNET_i2s (recipient), msg_size); | 1065 | "DV", &shortname, GNUNET_i2s (recipient), msg_size); |
1068 | #endif | 1066 | #endif |
1069 | 1067 | ||
1070 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, | 1068 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail, |
1071 | core_pending_tail, | ||
1072 | core_pending_tail, pending_message); | 1069 | core_pending_tail, pending_message); |
1073 | 1070 | ||
1074 | GNUNET_SCHEDULER_add_now (try_core_send, NULL); | 1071 | GNUNET_SCHEDULER_add_now (try_core_send, NULL); |
@@ -1117,10 +1114,9 @@ static int | |||
1117 | send_message (const struct GNUNET_PeerIdentity *recipient, | 1114 | send_message (const struct GNUNET_PeerIdentity *recipient, |
1118 | const struct GNUNET_PeerIdentity *sender, | 1115 | const struct GNUNET_PeerIdentity *sender, |
1119 | const struct DistantNeighbor *specific_neighbor, | 1116 | const struct DistantNeighbor *specific_neighbor, |
1120 | const struct GNUNET_MessageHeader *message, | 1117 | const struct GNUNET_MessageHeader *message, size_t message_size, |
1121 | size_t message_size, | 1118 | unsigned int importance, unsigned int uid, |
1122 | unsigned int importance, | 1119 | struct GNUNET_TIME_Relative timeout) |
1123 | unsigned int uid, struct GNUNET_TIME_Relative timeout) | ||
1124 | { | 1120 | { |
1125 | p2p_dv_MESSAGE_Data *toSend; | 1121 | p2p_dv_MESSAGE_Data *toSend; |
1126 | unsigned int msg_size; | 1122 | unsigned int msg_size; |
@@ -1160,12 +1156,13 @@ send_message (const struct GNUNET_PeerIdentity *recipient, | |||
1160 | } | 1156 | } |
1161 | recipient_id = target->referrer_id; | 1157 | recipient_id = target->referrer_id; |
1162 | 1158 | ||
1163 | source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, | 1159 | source = |
1164 | &sender->hashPubKey); | 1160 | GNUNET_CONTAINER_multihashmap_get (extended_neighbors, |
1161 | &sender->hashPubKey); | ||
1165 | if (source == NULL) | 1162 | if (source == NULL) |
1166 | { | 1163 | { |
1167 | if (0 != (memcmp (&my_identity, | 1164 | if (0 != |
1168 | sender, sizeof (struct GNUNET_PeerIdentity)))) | 1165 | (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity)))) |
1169 | { | 1166 | { |
1170 | /* sender unknown to us, drop! */ | 1167 | /* sender unknown to us, drop! */ |
1171 | return GNUNET_SYSERR; | 1168 | return GNUNET_SYSERR; |
@@ -1229,8 +1226,7 @@ send_message (const struct GNUNET_PeerIdentity *recipient, | |||
1229 | "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n", | 1226 | "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n", |
1230 | my_short_id); | 1227 | my_short_id); |
1231 | } | 1228 | } |
1232 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, | 1229 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail, |
1233 | core_pending_tail, | ||
1234 | core_pending_tail, pending_message); | 1230 | core_pending_tail, pending_message); |
1235 | #if DEBUG_DV | 1231 | #if DEBUG_DV |
1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1292,8 +1288,7 @@ checkPeerID (void *cls, const GNUNET_HashCode * key, void *value) | |||
1292 | * @param message the actual message | 1288 | * @param message the actual message |
1293 | */ | 1289 | */ |
1294 | void | 1290 | void |
1295 | tokenized_message_handler (void *cls, | 1291 | tokenized_message_handler (void *cls, void *client, |
1296 | void *client, | ||
1297 | const struct GNUNET_MessageHeader *message) | 1292 | const struct GNUNET_MessageHeader *message) |
1298 | { | 1293 | { |
1299 | struct TokenizedMessageContext *ctx = client; | 1294 | struct TokenizedMessageContext *ctx = client; |
@@ -1335,13 +1330,9 @@ send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1335 | 1330 | ||
1336 | if (msg_ctx != NULL) | 1331 | if (msg_ctx != NULL) |
1337 | { | 1332 | { |
1338 | send_message (&msg_ctx->dest, | 1333 | send_message (&msg_ctx->dest, &msg_ctx->sender, NULL, msg_ctx->message, |
1339 | &msg_ctx->sender, | 1334 | msg_ctx->message_size, default_dv_priority, msg_ctx->uid, |
1340 | NULL, | 1335 | GNUNET_TIME_relative_get_forever ()); |
1341 | msg_ctx->message, | ||
1342 | msg_ctx->message_size, | ||
1343 | default_dv_priority, | ||
1344 | msg_ctx->uid, GNUNET_TIME_relative_get_forever ()); | ||
1345 | GNUNET_free (msg_ctx->message); | 1336 | GNUNET_free (msg_ctx->message); |
1346 | GNUNET_free (msg_ctx); | 1337 | GNUNET_free (msg_ctx); |
1347 | } | 1338 | } |
@@ -1404,8 +1395,7 @@ get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi) | |||
1404 | * @param atsi transport ATS information (latency, distance, etc.) | 1395 | * @param atsi transport ATS information (latency, distance, etc.) |
1405 | */ | 1396 | */ |
1406 | static int | 1397 | static int |
1407 | handle_dv_data_message (void *cls, | 1398 | handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
1408 | const struct GNUNET_PeerIdentity *peer, | ||
1409 | const struct GNUNET_MessageHeader *message, | 1399 | const struct GNUNET_MessageHeader *message, |
1410 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1400 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1411 | { | 1401 | { |
@@ -1478,8 +1468,9 @@ handle_dv_data_message (void *cls, | |||
1478 | } | 1468 | } |
1479 | else | 1469 | else |
1480 | { | 1470 | { |
1481 | pos = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, | 1471 | pos = |
1482 | &peer->hashPubKey); | 1472 | GNUNET_CONTAINER_multihashmap_get (extended_neighbors, |
1473 | &peer->hashPubKey); | ||
1483 | } | 1474 | } |
1484 | #else | 1475 | #else |
1485 | pos = dn->referee_head; | 1476 | pos = dn->referee_head; |
@@ -1547,11 +1538,9 @@ handle_dv_data_message (void *cls, | |||
1547 | tkm_ctx.peer = peer; | 1538 | tkm_ctx.peer = peer; |
1548 | tkm_ctx.distant = pos; | 1539 | tkm_ctx.distant = pos; |
1549 | tkm_ctx.uid = ntohl (incoming->uid); | 1540 | tkm_ctx.uid = ntohl (incoming->uid); |
1550 | if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST, | 1541 | if (GNUNET_OK != |
1551 | &tkm_ctx, | 1542 | GNUNET_SERVER_mst_receive (coreMST, &tkm_ctx, cbuf, packed_message_size, |
1552 | cbuf, | 1543 | GNUNET_NO, GNUNET_NO)) |
1553 | packed_message_size, | ||
1554 | GNUNET_NO, GNUNET_NO)) | ||
1555 | { | 1544 | { |
1556 | GNUNET_break_op (0); | 1545 | GNUNET_break_op (0); |
1557 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1546 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1634,14 +1623,11 @@ handle_dv_data_message (void *cls, | |||
1634 | else | 1623 | else |
1635 | #endif | 1624 | #endif |
1636 | { | 1625 | { |
1637 | ret = send_message (destination, | 1626 | ret = |
1638 | original_sender, | 1627 | send_message (destination, original_sender, NULL, packed_message, |
1639 | NULL, | 1628 | packed_message_size, default_dv_priority, |
1640 | packed_message, | 1629 | ntohl (incoming->uid), |
1641 | packed_message_size, | 1630 | GNUNET_TIME_relative_get_forever ()); |
1642 | default_dv_priority, | ||
1643 | ntohl (incoming->uid), | ||
1644 | GNUNET_TIME_relative_get_forever ()); | ||
1645 | } | 1631 | } |
1646 | if (ret != GNUNET_SYSERR) | 1632 | if (ret != GNUNET_SYSERR) |
1647 | return GNUNET_OK; | 1633 | return GNUNET_OK; |
@@ -1756,17 +1742,17 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1756 | (about->hidden == GNUNET_NO) && | 1742 | (about->hidden == GNUNET_NO) && |
1757 | #endif | 1743 | #endif |
1758 | (to != NULL) && | 1744 | (to != NULL) && |
1759 | (0 != memcmp (&about->identity, | 1745 | (0 != |
1760 | &to->identity, sizeof (struct GNUNET_PeerIdentity))) && | 1746 | memcmp (&about->identity, &to->identity, |
1761 | (about->pkey != NULL)) | 1747 | sizeof (struct GNUNET_PeerIdentity))) && (about->pkey != NULL)) |
1762 | { | 1748 | { |
1763 | #if DEBUG_DV_GOSSIP_SEND | 1749 | #if DEBUG_DV_GOSSIP_SEND |
1764 | encPeerAbout = GNUNET_strdup (GNUNET_i2s (&about->identity)); | 1750 | encPeerAbout = GNUNET_strdup (GNUNET_i2s (&about->identity)); |
1765 | encPeerTo = GNUNET_strdup (GNUNET_i2s (&to->identity)); | 1751 | encPeerTo = GNUNET_strdup (GNUNET_i2s (&to->identity)); |
1766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1767 | "%s: Sending info about peer %s id %u to directly connected peer %s\n", | 1753 | "%s: Sending info about peer %s id %u to directly connected peer %s\n", |
1768 | GNUNET_i2s (&my_identity), | 1754 | GNUNET_i2s (&my_identity), encPeerAbout, about->our_id, |
1769 | encPeerAbout, about->our_id, encPeerTo); | 1755 | encPeerTo); |
1770 | GNUNET_free (encPeerAbout); | 1756 | GNUNET_free (encPeerAbout); |
1771 | GNUNET_free (encPeerTo); | 1757 | GNUNET_free (encPeerTo); |
1772 | #endif | 1758 | #endif |
@@ -1791,8 +1777,7 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1791 | memcpy (&message->neighbor, &about->identity, | 1777 | memcpy (&message->neighbor, &about->identity, |
1792 | sizeof (struct GNUNET_PeerIdentity)); | 1778 | sizeof (struct GNUNET_PeerIdentity)); |
1793 | 1779 | ||
1794 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, | 1780 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail, |
1795 | core_pending_tail, | ||
1796 | core_pending_tail, pending_message); | 1781 | core_pending_tail, pending_message); |
1797 | 1782 | ||
1798 | GNUNET_SCHEDULER_add_now (try_core_send, NULL); | 1783 | GNUNET_SCHEDULER_add_now (try_core_send, NULL); |
@@ -1834,14 +1819,13 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1834 | * @param message the actual message | 1819 | * @param message the actual message |
1835 | */ | 1820 | */ |
1836 | static void | 1821 | static void |
1837 | handle_start (void *cls, | 1822 | handle_start (void *cls, struct GNUNET_SERVER_Client *client, |
1838 | struct GNUNET_SERVER_Client *client, | ||
1839 | const struct GNUNET_MessageHeader *message) | 1823 | const struct GNUNET_MessageHeader *message) |
1840 | { | 1824 | { |
1841 | 1825 | ||
1842 | #if DEBUG_DV | 1826 | #if DEBUG_DV |
1843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' request from client\n", |
1844 | "Received `%s' request from client\n", "START"); | 1828 | "START"); |
1845 | #endif | 1829 | #endif |
1846 | 1830 | ||
1847 | client_handle = client; | 1831 | client_handle = client; |
@@ -1886,8 +1870,7 @@ send_iterator (void *cls, const GNUNET_HashCode * key, void *abs_value) | |||
1886 | * @param message the actual message | 1870 | * @param message the actual message |
1887 | */ | 1871 | */ |
1888 | void | 1872 | void |
1889 | handle_dv_send_message (void *cls, | 1873 | handle_dv_send_message (void *cls, struct GNUNET_SERVER_Client *client, |
1890 | struct GNUNET_SERVER_Client *client, | ||
1891 | const struct GNUNET_MessageHeader *message) | 1874 | const struct GNUNET_MessageHeader *message) |
1892 | { | 1875 | { |
1893 | struct GNUNET_DV_SendMessage *send_msg; | 1876 | struct GNUNET_DV_SendMessage *send_msg; |
@@ -2139,8 +2122,8 @@ distant_neighbor_free (struct DistantNeighbor *referee) | |||
2139 | referrer = referee->referrer; | 2122 | referrer = referee->referrer; |
2140 | if (referrer != NULL) | 2123 | if (referrer != NULL) |
2141 | { | 2124 | { |
2142 | GNUNET_CONTAINER_DLL_remove (referrer->referee_head, | 2125 | GNUNET_CONTAINER_DLL_remove (referrer->referee_head, referrer->referee_tail, |
2143 | referrer->referee_tail, referee); | 2126 | referee); |
2144 | } | 2127 | } |
2145 | GNUNET_CONTAINER_heap_remove_node (referee->max_loc); | 2128 | GNUNET_CONTAINER_heap_remove_node (referee->max_loc); |
2146 | GNUNET_CONTAINER_heap_remove_node (referee->min_loc); | 2129 | GNUNET_CONTAINER_heap_remove_node (referee->min_loc); |
@@ -2191,8 +2174,8 @@ direct_neighbor_free (struct DirectNeighbor *direct) | |||
2191 | * @return GNUNET_YES to continue iteration, GNUNET_NO to stop | 2174 | * @return GNUNET_YES to continue iteration, GNUNET_NO to stop |
2192 | */ | 2175 | */ |
2193 | static int | 2176 | static int |
2194 | schedule_disconnect_messages (void *cls, | 2177 | schedule_disconnect_messages (void *cls, const GNUNET_HashCode * key, |
2195 | const GNUNET_HashCode * key, void *value) | 2178 | void *value) |
2196 | { | 2179 | { |
2197 | struct DisconnectContext *disconnect_context = cls; | 2180 | struct DisconnectContext *disconnect_context = cls; |
2198 | struct DirectNeighbor *disconnected = disconnect_context->direct; | 2181 | struct DirectNeighbor *disconnected = disconnect_context->direct; |
@@ -2219,8 +2202,7 @@ schedule_disconnect_messages (void *cls, | |||
2219 | disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT); | 2202 | disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT); |
2220 | disconnect_message->peer_id = htonl (disconnect_context->distant->our_id); | 2203 | disconnect_message->peer_id = htonl (disconnect_context->distant->our_id); |
2221 | 2204 | ||
2222 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, | 2205 | GNUNET_CONTAINER_DLL_insert_after (core_pending_head, core_pending_tail, |
2223 | core_pending_tail, | ||
2224 | core_pending_tail, pending_message); | 2206 | core_pending_tail, pending_message); |
2225 | 2207 | ||
2226 | GNUNET_SCHEDULER_add_now (try_core_send, NULL); | 2208 | GNUNET_SCHEDULER_add_now (try_core_send, NULL); |
@@ -2305,8 +2287,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2305 | * To be called on core init/fail. | 2287 | * To be called on core init/fail. |
2306 | */ | 2288 | */ |
2307 | void | 2289 | void |
2308 | core_init (void *cls, | 2290 | core_init (void *cls, struct GNUNET_CORE_Handle *server, |
2309 | struct GNUNET_CORE_Handle *server, | ||
2310 | const struct GNUNET_PeerIdentity *identity, | 2291 | const struct GNUNET_PeerIdentity *identity, |
2311 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 2292 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
2312 | { | 2293 | { |
@@ -2404,8 +2385,8 @@ update_matching_neighbors (void *cls, const GNUNET_HashCode * key, void *value) | |||
2404 | * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise | 2385 | * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise |
2405 | */ | 2386 | */ |
2406 | static int | 2387 | static int |
2407 | add_distant_all_direct_neighbors (void *cls, | 2388 | add_distant_all_direct_neighbors (void *cls, const GNUNET_HashCode * key, |
2408 | const GNUNET_HashCode * key, void *value) | 2389 | void *value) |
2409 | { | 2390 | { |
2410 | struct DirectNeighbor *direct = (struct DirectNeighbor *) value; | 2391 | struct DirectNeighbor *direct = (struct DirectNeighbor *) value; |
2411 | struct DistantNeighbor *distant = (struct DistantNeighbor *) cls; | 2392 | struct DistantNeighbor *distant = (struct DistantNeighbor *) cls; |
@@ -2541,13 +2522,13 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2541 | #if DEBUG_DV_PEER_NUMBERS | 2522 | #if DEBUG_DV_PEER_NUMBERS |
2542 | char *encAbout; | 2523 | char *encAbout; |
2543 | 2524 | ||
2544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s Received sender id (%u)!\n", |
2545 | "%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id); | 2526 | "DV SERVICE", referrer_peer_id); |
2546 | #endif | 2527 | #endif |
2547 | 2528 | ||
2548 | now = GNUNET_TIME_absolute_get (); | 2529 | now = GNUNET_TIME_absolute_get (); |
2549 | neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, | 2530 | neighbor = |
2550 | &peer->hashPubKey); | 2531 | GNUNET_CONTAINER_multihashmap_get (extended_neighbors, &peer->hashPubKey); |
2551 | neighbor_update = GNUNET_malloc (sizeof (struct NeighborUpdateInfo)); | 2532 | neighbor_update = GNUNET_malloc (sizeof (struct NeighborUpdateInfo)); |
2552 | neighbor_update->neighbor = neighbor; | 2533 | neighbor_update->neighbor = neighbor; |
2553 | neighbor_update->cost = cost; | 2534 | neighbor_update->cost = cost; |
@@ -2576,11 +2557,9 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2576 | 2557 | ||
2577 | /* Either we do not know this peer, or we already do but via a different immediate peer */ | 2558 | /* Either we do not know this peer, or we already do but via a different immediate peer */ |
2578 | if ((neighbor == NULL) || | 2559 | if ((neighbor == NULL) || |
2579 | (GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, | 2560 | (GNUNET_CONTAINER_multihashmap_get_multiple |
2580 | &peer->hashPubKey, | 2561 | (extended_neighbors, &peer->hashPubKey, &update_matching_neighbors, |
2581 | &update_matching_neighbors, | 2562 | neighbor_update) != GNUNET_SYSERR)) |
2582 | neighbor_update) != | ||
2583 | GNUNET_SYSERR)) | ||
2584 | { | 2563 | { |
2585 | #if AT_MOST_ONE | 2564 | #if AT_MOST_ONE |
2586 | if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */ | 2565 | if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */ |
@@ -2630,12 +2609,12 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2630 | } | 2609 | } |
2631 | 2610 | ||
2632 | neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor)); | 2611 | neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor)); |
2633 | GNUNET_CONTAINER_DLL_insert (referrer->referee_head, | 2612 | GNUNET_CONTAINER_DLL_insert (referrer->referee_head, referrer->referee_tail, |
2634 | referrer->referee_tail, neighbor); | 2613 | neighbor); |
2635 | neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap, | 2614 | neighbor->max_loc = |
2636 | neighbor, cost); | 2615 | GNUNET_CONTAINER_heap_insert (neighbor_max_heap, neighbor, cost); |
2637 | neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap, | 2616 | neighbor->min_loc = |
2638 | neighbor, cost); | 2617 | GNUNET_CONTAINER_heap_insert (neighbor_min_heap, neighbor, cost); |
2639 | neighbor->referrer = referrer; | 2618 | neighbor->referrer = referrer; |
2640 | memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); | 2619 | memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); |
2641 | if (pkey != NULL) /* pkey will be null on direct neighbor addition */ | 2620 | if (pkey != NULL) /* pkey will be null on direct neighbor addition */ |
@@ -2679,12 +2658,11 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2679 | atsi[0].value = htonl (referrer->pending_messages[i].distance); | 2658 | atsi[0].value = htonl (referrer->pending_messages[i].distance); |
2680 | atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); | 2659 | atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); |
2681 | atsi[1].value = | 2660 | atsi[1].value = |
2682 | htonl ((uint32_t) referrer->pending_messages[i]. | 2661 | htonl ((uint32_t) referrer->pending_messages[i].latency. |
2683 | latency.rel_value); | 2662 | rel_value); |
2684 | atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 2663 | atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
2685 | atsi[2].value = htonl (0); | 2664 | atsi[2].value = htonl (0); |
2686 | handle_dv_data_message (NULL, | 2665 | handle_dv_data_message (NULL, &referrer->pending_messages[i].sender, |
2687 | &referrer->pending_messages[i].sender, | ||
2688 | referrer->pending_messages[i].message, | 2666 | referrer->pending_messages[i].message, |
2689 | (const struct GNUNET_TRANSPORT_ATS_Information | 2667 | (const struct GNUNET_TRANSPORT_ATS_Information |
2690 | *) &atsi); | 2668 | *) &atsi); |
@@ -2733,9 +2711,8 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2733 | #endif | 2711 | #endif |
2734 | } | 2712 | } |
2735 | #if DEBUG_DV | 2713 | #if DEBUG_DV |
2736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: Size of extended_neighbors is %d\n", |
2737 | "%s: Size of extended_neighbors is %d\n", "dv", | 2715 | "dv", GNUNET_CONTAINER_multihashmap_size (extended_neighbors)); |
2738 | GNUNET_CONTAINER_multihashmap_size (extended_neighbors)); | ||
2739 | #endif | 2716 | #endif |
2740 | 2717 | ||
2741 | GNUNET_free (neighbor_update); | 2718 | GNUNET_free (neighbor_update); |
@@ -2756,8 +2733,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer, | |||
2756 | * @param atsi performance data | 2733 | * @param atsi performance data |
2757 | */ | 2734 | */ |
2758 | static int | 2735 | static int |
2759 | handle_dv_disconnect_message (void *cls, | 2736 | handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
2760 | const struct GNUNET_PeerIdentity *peer, | ||
2761 | const struct GNUNET_MessageHeader *message, | 2737 | const struct GNUNET_MessageHeader *message, |
2762 | const struct GNUNET_TRANSPORT_ATS_Information | 2738 | const struct GNUNET_TRANSPORT_ATS_Information |
2763 | *atsi) | 2739 | *atsi) |
@@ -2772,8 +2748,8 @@ handle_dv_disconnect_message (void *cls, | |||
2772 | return GNUNET_SYSERR; /* invalid message */ | 2748 | return GNUNET_SYSERR; /* invalid message */ |
2773 | } | 2749 | } |
2774 | 2750 | ||
2775 | referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, | 2751 | referrer = |
2776 | &peer->hashPubKey); | 2752 | GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey); |
2777 | if (referrer == NULL) | 2753 | if (referrer == NULL) |
2778 | return GNUNET_OK; | 2754 | return GNUNET_OK; |
2779 | 2755 | ||
@@ -2806,8 +2782,7 @@ handle_dv_disconnect_message (void *cls, | |||
2806 | * @param atsi performance data | 2782 | * @param atsi performance data |
2807 | */ | 2783 | */ |
2808 | static int | 2784 | static int |
2809 | handle_dv_gossip_message (void *cls, | 2785 | handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer, |
2810 | const struct GNUNET_PeerIdentity *peer, | ||
2811 | const struct GNUNET_MessageHeader *message, | 2786 | const struct GNUNET_MessageHeader *message, |
2812 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 2787 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
2813 | { | 2788 | { |
@@ -2834,14 +2809,14 @@ handle_dv_gossip_message (void *cls, | |||
2834 | GNUNET_free (encPeerFrom); | 2809 | GNUNET_free (encPeerFrom); |
2835 | #endif | 2810 | #endif |
2836 | 2811 | ||
2837 | referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, | 2812 | referrer = |
2838 | &peer->hashPubKey); | 2813 | GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey); |
2839 | if (referrer == NULL) | 2814 | if (referrer == NULL) |
2840 | return GNUNET_OK; | 2815 | return GNUNET_OK; |
2841 | 2816 | ||
2842 | addUpdateNeighbor (&enc_message->neighbor, &enc_message->pkey, | 2817 | addUpdateNeighbor (&enc_message->neighbor, &enc_message->pkey, |
2843 | ntohl (enc_message->neighbor_id), | 2818 | ntohl (enc_message->neighbor_id), referrer, |
2844 | referrer, ntohl (enc_message->cost) + 1); | 2819 | ntohl (enc_message->cost) + 1); |
2845 | 2820 | ||
2846 | return GNUNET_OK; | 2821 | return GNUNET_OK; |
2847 | } | 2822 | } |
@@ -2897,8 +2872,8 @@ add_all_extended_peers (void *cls, const GNUNET_HashCode * key, void *value) | |||
2897 | * GNUNET_NO if not. | 2872 | * GNUNET_NO if not. |
2898 | */ | 2873 | */ |
2899 | static int | 2874 | static int |
2900 | gossip_all_to_all_iterator (void *cls, | 2875 | gossip_all_to_all_iterator (void *cls, const GNUNET_HashCode * key, |
2901 | const GNUNET_HashCode * key, void *abs_value) | 2876 | void *abs_value) |
2902 | { | 2877 | { |
2903 | struct DirectNeighbor *direct = abs_value; | 2878 | struct DirectNeighbor *direct = abs_value; |
2904 | 2879 | ||
@@ -3007,8 +2982,7 @@ add_all_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value) | |||
3007 | * @param err_msg NULL if successful, otherwise contains error message | 2982 | * @param err_msg NULL if successful, otherwise contains error message |
3008 | */ | 2983 | */ |
3009 | static void | 2984 | static void |
3010 | process_peerinfo (void *cls, | 2985 | process_peerinfo (void *cls, const struct GNUNET_PeerIdentity *peer, |
3011 | const struct GNUNET_PeerIdentity *peer, | ||
3012 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 2986 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
3013 | { | 2987 | { |
3014 | struct PeerIteratorContext *peerinfo_iterator = cls; | 2988 | struct PeerIteratorContext *peerinfo_iterator = cls; |
@@ -3034,13 +3008,12 @@ process_peerinfo (void *cls, | |||
3034 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3008 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3035 | "Failed to get peerinfo information for this peer, retrying!\n"); | 3009 | "Failed to get peerinfo information for this peer, retrying!\n"); |
3036 | #endif | 3010 | #endif |
3037 | peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle, | 3011 | peerinfo_iterator->ic = |
3038 | &peerinfo_iterator->neighbor-> | 3012 | GNUNET_PEERINFO_iterate (peerinfo_handle, |
3039 | identity, | 3013 | &peerinfo_iterator->neighbor->identity, |
3040 | GNUNET_TIME_relative_multiply | 3014 | GNUNET_TIME_relative_multiply |
3041 | (GNUNET_TIME_UNIT_SECONDS, | 3015 | (GNUNET_TIME_UNIT_SECONDS, 3), |
3042 | 3), &process_peerinfo, | 3016 | &process_peerinfo, peerinfo_iterator); |
3043 | peerinfo_iterator); | ||
3044 | } | 3017 | } |
3045 | else | 3018 | else |
3046 | { | 3019 | { |
@@ -3111,8 +3084,7 @@ process_peerinfo (void *cls, | |||
3111 | * @param atsi performance data | 3084 | * @param atsi performance data |
3112 | */ | 3085 | */ |
3113 | static void | 3086 | static void |
3114 | handle_core_connect (void *cls, | 3087 | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
3115 | const struct GNUNET_PeerIdentity *peer, | ||
3116 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 3088 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
3117 | { | 3089 | { |
3118 | struct DirectNeighbor *neighbor; | 3090 | struct DirectNeighbor *neighbor; |
@@ -3146,12 +3118,11 @@ handle_core_connect (void *cls, | |||
3146 | about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST); | 3118 | about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST); |
3147 | peerinfo_iterator->distant = about; | 3119 | peerinfo_iterator->distant = about; |
3148 | peerinfo_iterator->neighbor = neighbor; | 3120 | peerinfo_iterator->neighbor = neighbor; |
3149 | peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle, | 3121 | peerinfo_iterator->ic = |
3150 | peer, | 3122 | GNUNET_PEERINFO_iterate (peerinfo_handle, peer, |
3151 | GNUNET_TIME_relative_multiply | 3123 | GNUNET_TIME_relative_multiply |
3152 | (GNUNET_TIME_UNIT_SECONDS, | 3124 | (GNUNET_TIME_UNIT_SECONDS, 3), |
3153 | 3), &process_peerinfo, | 3125 | &process_peerinfo, peerinfo_iterator); |
3154 | peerinfo_iterator); | ||
3155 | 3126 | ||
3156 | if ((about != NULL) && (about->pkey == NULL)) | 3127 | if ((about != NULL) && (about->pkey == NULL)) |
3157 | { | 3128 | { |
@@ -3257,9 +3228,9 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
3257 | } | 3228 | } |
3258 | 3229 | ||
3259 | GNUNET_assert (neighbor->referee_tail == NULL); | 3230 | GNUNET_assert (neighbor->referee_tail == NULL); |
3260 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors, | 3231 | if (GNUNET_NO == |
3261 | &peer->hashPubKey, | 3232 | GNUNET_CONTAINER_multihashmap_remove (direct_neighbors, &peer->hashPubKey, |
3262 | neighbor)) | 3233 | neighbor)) |
3263 | { | 3234 | { |
3264 | GNUNET_break (0); | 3235 | GNUNET_break (0); |
3265 | } | 3236 | } |
@@ -3278,8 +3249,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
3278 | * @param c configuration to use | 3249 | * @param c configuration to use |
3279 | */ | 3250 | */ |
3280 | static void | 3251 | static void |
3281 | run (void *cls, | 3252 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
3282 | struct GNUNET_SERVER_Handle *server, | ||
3283 | const struct GNUNET_CONFIGURATION_Handle *c) | 3253 | const struct GNUNET_CONFIGURATION_Handle *c) |
3284 | { | 3254 | { |
3285 | unsigned long long max_hosts; | 3255 | unsigned long long max_hosts; |
@@ -3321,12 +3291,9 @@ run (void *cls, | |||
3321 | 3291 | ||
3322 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 3292 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
3323 | coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */ | 3293 | coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */ |
3324 | &core_init, | 3294 | &core_init, &handle_core_connect, |
3325 | &handle_core_connect, | 3295 | &handle_core_disconnect, NULL, NULL, GNUNET_NO, |
3326 | &handle_core_disconnect, | 3296 | NULL, GNUNET_NO, core_handlers); |
3327 | NULL, | ||
3328 | NULL, | ||
3329 | GNUNET_NO, NULL, GNUNET_NO, core_handlers); | ||
3330 | 3297 | ||
3331 | if (coreAPI == NULL) | 3298 | if (coreAPI == NULL) |
3332 | return; | 3299 | return; |
@@ -3342,8 +3309,9 @@ run (void *cls, | |||
3342 | } | 3309 | } |
3343 | 3310 | ||
3344 | /* Scheduled the task to clean up when shutdown is called */ | 3311 | /* Scheduled the task to clean up when shutdown is called */ |
3345 | cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 3312 | cleanup_task = |
3346 | &shutdown_task, NULL); | 3313 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
3314 | &shutdown_task, NULL); | ||
3347 | } | 3315 | } |
3348 | 3316 | ||
3349 | 3317 | ||
@@ -3358,8 +3326,6 @@ int | |||
3358 | main (int argc, char *const *argv) | 3326 | main (int argc, char *const *argv) |
3359 | { | 3327 | { |
3360 | return (GNUNET_OK == | 3328 | return (GNUNET_OK == |
3361 | GNUNET_SERVICE_run (argc, | 3329 | GNUNET_SERVICE_run (argc, argv, "dv", GNUNET_SERVICE_OPTION_NONE, |
3362 | argv, | 3330 | &run, NULL)) ? 0 : 1; |
3363 | "dv", | ||
3364 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | ||
3365 | } | 3331 | } |