aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/dht/gnunet-service-dht.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c572
1 files changed, 259 insertions, 313 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 19250d07b..1721e73af 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -984,9 +984,8 @@ get_average_send_delay ()
984 } 984 }
985 985
986 average_time = GNUNET_TIME_relative_divide (average_time, divisor); 986 average_time = GNUNET_TIME_relative_divide (average_time, divisor);
987 fprintf (stderr, 987 fprintf (stderr, "Avg send delay: %u sends is %llu\n", divisor,
988 "Avg send delay: %u sends is %llu\n", 988 (unsigned long long) average_time.abs_value);
989 divisor, (unsigned long long) average_time.abs_value);
990 return average_time; 989 return average_time;
991} 990}
992#endif 991#endif
@@ -1088,8 +1087,7 @@ try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1088 if (reply_counter >= MAX_REPLY_TIMES) 1087 if (reply_counter >= MAX_REPLY_TIMES)
1089 reply_counter = 0; 1088 reply_counter = 0;
1090 peer->th = 1089 peer->th =
1091 GNUNET_CORE_notify_transmit_ready (coreAPI, 1090 GNUNET_CORE_notify_transmit_ready (coreAPI, GNUNET_YES,
1092 GNUNET_YES,
1093 pending->importance, 1091 pending->importance,
1094 pending->timeout, &peer->id, ssize, 1092 pending->timeout, &peer->id, ssize,
1095 &core_transmit_notify, peer); 1093 &core_transmit_notify, peer);
@@ -1162,8 +1160,7 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1162 result_message->hop_count = htonl (msg_ctx->hop_count + 1); 1160 result_message->hop_count = htonl (msg_ctx->hop_count + 1);
1163 GNUNET_assert (GNUNET_OK == 1161 GNUNET_assert (GNUNET_OK ==
1164 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom, 1162 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom,
1165 result_message-> 1163 result_message->bloomfilter,
1166 bloomfilter,
1167 DHT_BLOOM_SIZE)); 1164 DHT_BLOOM_SIZE));
1168 result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id); 1165 result_message->unique_id = GNUNET_htonll (msg_ctx->unique_id);
1169 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 1166 memcpy (&result_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
@@ -1177,8 +1174,8 @@ forward_result_message (const struct GNUNET_MessageHeader *msg,
1177 msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity))); 1174 msg_ctx->path_history_len * (sizeof (struct GNUNET_PeerIdentity)));
1178#if DEBUG_DHT > 1 1175#if DEBUG_DHT > 1
1179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1180 "%s:%s Adding pending message size %d for peer %s\n", 1177 "%s:%s Adding pending message size %d for peer %s\n", my_short_id,
1181 my_short_id, "DHT", msize, GNUNET_i2s (&peer->id)); 1178 "DHT", msize, GNUNET_i2s (&peer->id));
1182#endif 1179#endif
1183 peer->pending_count++; 1180 peer->pending_count++;
1184 increment_stats ("# pending messages scheduled"); 1181 increment_stats ("# pending messages scheduled");
@@ -1477,9 +1474,9 @@ find_peer_by_id (const struct GNUNET_PeerIdentity *peer)
1477} 1474}
1478 1475
1479/* Forward declaration */ 1476/* Forward declaration */
1480static void 1477static void update_core_preference (void *cls,
1481update_core_preference (void *cls, 1478 const struct GNUNET_SCHEDULER_TaskContext
1482 const struct GNUNET_SCHEDULER_TaskContext *tc); 1479 *tc);
1483/** 1480/**
1484 * Function called with statistics about the given peer. 1481 * Function called with statistics about the given peer.
1485 * 1482 *
@@ -1532,14 +1529,12 @@ update_core_preference (void *cls,
1532 matching = 63; 1529 matching = 63;
1533 } 1530 }
1534 preference = 1LL << matching; 1531 preference = 1LL << matching;
1535 peer->info_ctx = GNUNET_CORE_peer_change_preference (coreAPI, 1532 peer->info_ctx =
1536 &peer->id, 1533 GNUNET_CORE_peer_change_preference (coreAPI, &peer->id,
1537 GNUNET_TIME_UNIT_FOREVER_REL, 1534 GNUNET_TIME_UNIT_FOREVER_REL,
1538 GNUNET_BANDWIDTH_VALUE_MAX, 1535 GNUNET_BANDWIDTH_VALUE_MAX, 0,
1539 0, 1536 preference,
1540 preference, 1537 &update_core_preference_finish, peer);
1541 &update_core_preference_finish,
1542 peer);
1543} 1538}
1544 1539
1545 1540
@@ -1557,12 +1552,12 @@ static void
1557remove_peer (struct PeerInfo *peer, unsigned int bucket) 1552remove_peer (struct PeerInfo *peer, unsigned int bucket)
1558{ 1553{
1559 GNUNET_assert (k_buckets[bucket].peers_size > 0); 1554 GNUNET_assert (k_buckets[bucket].peers_size > 0);
1560 GNUNET_CONTAINER_DLL_remove (k_buckets[bucket].head, 1555 GNUNET_CONTAINER_DLL_remove (k_buckets[bucket].head, k_buckets[bucket].tail,
1561 k_buckets[bucket].tail, peer); 1556 peer);
1562 k_buckets[bucket].peers_size--; 1557 k_buckets[bucket].peers_size--;
1563#if CHANGE_LOWEST 1558#if CHANGE_LOWEST
1564 if ((bucket == lowest_bucket) && (k_buckets[lowest_bucket].peers_size == 0) 1559 if ((bucket == lowest_bucket) && (k_buckets[lowest_bucket].peers_size == 0) &&
1565 && (lowest_bucket < MAX_BUCKETS - 1)) 1560 (lowest_bucket < MAX_BUCKETS - 1))
1566 lowest_bucket++; 1561 lowest_bucket++;
1567#endif 1562#endif
1568} 1563}
@@ -1589,8 +1584,8 @@ delete_peer (struct PeerInfo *peer, unsigned int bucket)
1589 if (peer_pos == NULL) 1584 if (peer_pos == NULL)
1590 { 1585 {
1591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1586 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1592 "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id, 1587 "%s:%s: Expected peer `%s' in bucket %d\n", my_short_id, "DHT",
1593 "DHT", GNUNET_i2s (&peer->id), bucket); 1588 GNUNET_i2s (&peer->id), bucket);
1594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1589 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1595 "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer resides in bucket: %d\n", 1590 "%s:%s: Lowest bucket: %d, find_current_bucket: %d, peer resides in bucket: %d\n",
1596 my_short_id, "DHT", lowest_bucket, 1591 my_short_id, "DHT", lowest_bucket,
@@ -1677,8 +1672,7 @@ enable_next_bucket ()
1677 while (pos != NULL) 1672 while (pos != NULL)
1678 { 1673 {
1679 if (find_bucket (&pos->id.hashPubKey) < lowest_bucket) 1674 if (find_bucket (&pos->id.hashPubKey) < lowest_bucket)
1680 GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey, 1675 GNUNET_CONTAINER_multihashmap_put (to_remove, &pos->id.hashPubKey, pos,
1681 pos,
1682 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1676 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1683 pos = pos->next; 1677 pos = pos->next;
1684 } 1678 }
@@ -1747,8 +1741,8 @@ find_closest_peer (const GNUNET_HashCode * hc)
1747 * @param msg_ctx the context of the message (hop count, bloom, etc.) 1741 * @param msg_ctx the context of the message (hop count, bloom, etc.)
1748 */ 1742 */
1749static void 1743static void
1750forward_message (const struct GNUNET_MessageHeader *msg, 1744forward_message (const struct GNUNET_MessageHeader *msg, struct PeerInfo *peer,
1751 struct PeerInfo *peer, struct DHT_MessageContext *msg_ctx) 1745 struct DHT_MessageContext *msg_ctx)
1752{ 1746{
1753 struct GNUNET_DHT_P2PRouteMessage *route_message; 1747 struct GNUNET_DHT_P2PRouteMessage *route_message;
1754 struct P2PPendingMessage *pending; 1748 struct P2PPendingMessage *pending;
@@ -1758,8 +1752,8 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1758 1752
1759 increment_stats (STAT_ROUTE_FORWARDS); 1753 increment_stats (STAT_ROUTE_FORWARDS);
1760 GNUNET_assert (peer != NULL); 1754 GNUNET_assert (peer != NULL);
1761 if ((msg_ctx->closest != GNUNET_YES) 1755 if ((msg_ctx->closest != GNUNET_YES) &&
1762 && (peer == find_closest_peer (&msg_ctx->key))) 1756 (peer == find_closest_peer (&msg_ctx->key)))
1763 increment_stats (STAT_ROUTE_FORWARDS_CLOSEST); 1757 increment_stats (STAT_ROUTE_FORWARDS_CLOSEST);
1764 1758
1765 msize = 1759 msize =
@@ -1782,8 +1776,7 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1782 if (msg_ctx->bloom != NULL) 1776 if (msg_ctx->bloom != NULL)
1783 GNUNET_assert (GNUNET_OK == 1777 GNUNET_assert (GNUNET_OK ==
1784 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom, 1778 GNUNET_CONTAINER_bloomfilter_get_raw_data (msg_ctx->bloom,
1785 route_message-> 1779 route_message->bloomfilter,
1786 bloomfilter,
1787 DHT_BLOOM_SIZE)); 1780 DHT_BLOOM_SIZE));
1788 memcpy (&route_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 1781 memcpy (&route_message->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
1789 memcpy (&route_message[1], msg, ntohs (msg->size)); 1782 memcpy (&route_message[1], msg, ntohs (msg->size));
@@ -1801,8 +1794,8 @@ forward_message (const struct GNUNET_MessageHeader *msg,
1801 } 1794 }
1802#if DEBUG_DHT > 1 1795#if DEBUG_DHT > 1
1803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1804 "%s:%s Adding pending message size %d for peer %s\n", 1797 "%s:%s Adding pending message size %d for peer %s\n", my_short_id,
1805 my_short_id, "DHT", msize, GNUNET_i2s (&peer->id)); 1798 "DHT", msize, GNUNET_i2s (&peer->id));
1806#endif 1799#endif
1807 peer->pending_count++; 1800 peer->pending_count++;
1808 increment_stats ("# pending messages scheduled"); 1801 increment_stats ("# pending messages scheduled");
@@ -1835,9 +1828,8 @@ periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1835 1828
1836 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 1829 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
1837#if DEBUG_PING 1830#if DEBUG_PING
1838 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1831 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s:%s Sending periodic ping to %s\n",
1839 "%s:%s Sending periodic ping to %s\n", my_short_id, "DHT", 1832 my_short_id, "DHT", GNUNET_i2s (&peer->id));
1840 GNUNET_i2s (&peer->id));
1841#endif 1833#endif
1842 forward_message (&ping_message, peer, &msg_ctx); 1834 forward_message (&ping_message, peer, &msg_ctx);
1843 peer->ping_task = 1835 peer->ping_task =
@@ -1864,8 +1856,8 @@ schedule_ping_messages ()
1864 { 1856 {
1865 if ((count < bucket_size) && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK)) 1857 if ((count < bucket_size) && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK))
1866 GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos); 1858 GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos);
1867 else if ((count >= bucket_size) 1859 else if ((count >= bucket_size) &&
1868 && (pos->ping_task != GNUNET_SCHEDULER_NO_TASK)) 1860 (pos->ping_task != GNUNET_SCHEDULER_NO_TASK))
1869 { 1861 {
1870 GNUNET_SCHEDULER_cancel (pos->ping_task); 1862 GNUNET_SCHEDULER_cancel (pos->ping_task);
1871 pos->ping_task = GNUNET_SCHEDULER_NO_TASK; 1863 pos->ping_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1893,8 +1885,8 @@ process_pending_messages (struct ClientList *client)
1893 1885
1894 client->transmit_handle = 1886 client->transmit_handle =
1895 GNUNET_SERVER_notify_transmit_ready (client->client_handle, 1887 GNUNET_SERVER_notify_transmit_ready (client->client_handle,
1896 ntohs (client->pending_head-> 1888 ntohs (client->pending_head->msg->
1897 msg->size), 1889 size),
1898 GNUNET_TIME_UNIT_FOREVER_REL, 1890 GNUNET_TIME_UNIT_FOREVER_REL,
1899 &send_generic_reply, client); 1891 &send_generic_reply, client);
1900} 1892}
@@ -1930,8 +1922,8 @@ send_generic_reply (void *cls, size_t size, void *buf)
1930 while ((NULL != (reply = client->pending_head)) && 1922 while ((NULL != (reply = client->pending_head)) &&
1931 (size >= off + (msize = ntohs (reply->msg->size)))) 1923 (size >= off + (msize = ntohs (reply->msg->size))))
1932 { 1924 {
1933 GNUNET_CONTAINER_DLL_remove (client->pending_head, 1925 GNUNET_CONTAINER_DLL_remove (client->pending_head, client->pending_tail,
1934 client->pending_tail, reply); 1926 reply);
1935 memcpy (&cbuf[off], reply->msg, msize); 1927 memcpy (&cbuf[off], reply->msg, msize);
1936 GNUNET_free (reply); 1928 GNUNET_free (reply);
1937 off += msize; 1929 off += msize;
@@ -1956,8 +1948,7 @@ static void
1956add_pending_message (struct ClientList *client, 1948add_pending_message (struct ClientList *client,
1957 struct PendingMessage *pending_message) 1949 struct PendingMessage *pending_message)
1958{ 1950{
1959 GNUNET_CONTAINER_DLL_insert_after (client->pending_head, 1951 GNUNET_CONTAINER_DLL_insert_after (client->pending_head, client->pending_tail,
1960 client->pending_tail,
1961 client->pending_tail, pending_message); 1952 client->pending_tail, pending_message);
1962 process_pending_messages (client); 1953 process_pending_messages (client);
1963} 1954}
@@ -1987,8 +1978,8 @@ send_reply_to_client (struct ClientList *client,
1987 unsigned int i; 1978 unsigned int i;
1988#endif 1979#endif
1989#if DEBUG_DHT 1980#if DEBUG_DHT
1990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Sending reply to client.\n",
1991 "`%s:%s': Sending reply to client.\n", my_short_id, "DHT"); 1982 my_short_id, "DHT");
1992#endif 1983#endif
1993 msize = ntohs (message->size); 1984 msize = ntohs (message->size);
1994 tsize = 1985 tsize =
@@ -2049,14 +2040,13 @@ consider_peer (struct GNUNET_PeerIdentity *peer)
2049 2040
2050 if ((GNUNET_YES == 2041 if ((GNUNET_YES ==
2051 GNUNET_CONTAINER_multihashmap_contains (all_known_peers, 2042 GNUNET_CONTAINER_multihashmap_contains (all_known_peers,
2052 &peer->hashPubKey)) 2043 &peer->hashPubKey)) ||
2053 || (0 == 2044 (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))))
2054 memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))))
2055 return GNUNET_NO; /* We already know this peer (are connected even!) */ 2045 return GNUNET_NO; /* We already know this peer (are connected even!) */
2056 bucket = find_current_bucket (&peer->hashPubKey); 2046 bucket = find_current_bucket (&peer->hashPubKey);
2057 2047
2058 if ((k_buckets[bucket].peers_size < bucket_size) 2048 if ((k_buckets[bucket].peers_size < bucket_size) ||
2059 || ((bucket == lowest_bucket) && (lowest_bucket > 0))) 2049 ((bucket == lowest_bucket) && (lowest_bucket > 0)))
2060 return GNUNET_YES; 2050 return GNUNET_YES;
2061 2051
2062 return GNUNET_NO; 2052 return GNUNET_NO;
@@ -2083,8 +2073,8 @@ remove_forward_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2083 if (record->head == NULL) /* No more entries in DLL */ 2073 if (record->head == NULL) /* No more entries in DLL */
2084 { 2074 {
2085 GNUNET_assert (GNUNET_YES == 2075 GNUNET_assert (GNUNET_YES ==
2086 GNUNET_CONTAINER_multihashmap_remove 2076 GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap,
2087 (forward_list.hashmap, &record->key, record)); 2077 &record->key, record));
2088 GNUNET_free (record); 2078 GNUNET_free (record);
2089 } 2079 }
2090 if (source_info->find_peers_responded != NULL) 2080 if (source_info->find_peers_responded != NULL)
@@ -2127,10 +2117,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2127 GNUNET_break_op (0); 2117 GNUNET_break_op (0);
2128 2118
2129 hello_msg = &msg[1]; 2119 hello_msg = &msg[1];
2130 if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) 2120 if ((ntohs (hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) ||
2131 || (GNUNET_SYSERR == 2121 (GNUNET_SYSERR ==
2132 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 2122 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello_msg,
2133 hello_msg, &new_peer))) 2123 &new_peer)))
2134 { 2124 {
2135 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2125 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2136 "%s:%s Received non-HELLO message type in find peer result message!\n", 2126 "%s:%s Received non-HELLO message type in find peer result message!\n",
@@ -2168,13 +2158,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2168#if DEBUG_DHT_ROUTING 2158#if DEBUG_DHT_ROUTING
2169 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2159 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2170 { 2160 {
2171 dhtlog_handle->insert_route (NULL, 2161 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2172 msg_ctx->unique_id, 2162 msg_ctx->hop_count, GNUNET_SYSERR,
2173 DHTLOG_RESULT, 2163 &my_identity, &msg_ctx->key, msg_ctx->peer,
2174 msg_ctx->hop_count, 2164 NULL);
2175 GNUNET_SYSERR,
2176 &my_identity,
2177 &msg_ctx->key, msg_ctx->peer, NULL);
2178 } 2165 }
2179#endif 2166#endif
2180 if (msg_ctx->bloom != NULL) 2167 if (msg_ctx->bloom != NULL)
@@ -2216,10 +2203,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2216#if DEBUG_DHT_ROUTING 2203#if DEBUG_DHT_ROUTING
2217 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2204 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2218 { 2205 {
2219 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 2206 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2220 DHTLOG_RESULT, msg_ctx->hop_count, 2207 msg_ctx->hop_count, GNUNET_YES,
2221 GNUNET_YES, &my_identity, 2208 &my_identity, &msg_ctx->key, msg_ctx->peer,
2222 &msg_ctx->key, msg_ctx->peer, NULL); 2209 NULL);
2223 } 2210 }
2224#endif 2211#endif
2225 increment_stats (STAT_RESULTS_TO_CLIENT); 2212 increment_stats (STAT_RESULTS_TO_CLIENT);
@@ -2268,12 +2255,10 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2268#if DEBUG_DHT_ROUTING 2255#if DEBUG_DHT_ROUTING
2269 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2256 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2270 { 2257 {
2271 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 2258 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_RESULT,
2272 DHTLOG_RESULT, 2259 msg_ctx->hop_count, GNUNET_NO,
2273 msg_ctx->hop_count, 2260 &my_identity, &msg_ctx->key,
2274 GNUNET_NO, &my_identity, 2261 msg_ctx->peer, &pos->source);
2275 &msg_ctx->key, msg_ctx->peer,
2276 &pos->source);
2277 } 2262 }
2278#endif 2263#endif
2279 forward_result_message (msg, peer_info, msg_ctx); 2264 forward_result_message (msg, peer_info, msg_ctx);
@@ -2320,11 +2305,9 @@ route_result_message (struct GNUNET_MessageHeader *msg,
2320 * to stop iteration. 2305 * to stop iteration.
2321 */ 2306 */
2322static int 2307static int
2323datacache_get_iterator (void *cls, 2308datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
2324 struct GNUNET_TIME_Absolute exp, 2309 const GNUNET_HashCode * key, size_t size,
2325 const GNUNET_HashCode * key, 2310 const char *data, enum GNUNET_BLOCK_Type type)
2326 size_t size, const char *data,
2327 enum GNUNET_BLOCK_Type type)
2328{ 2311{
2329 struct DHT_MessageContext *msg_ctx = cls; 2312 struct DHT_MessageContext *msg_ctx = cls;
2330 struct DHT_MessageContext *new_msg_ctx; 2313 struct DHT_MessageContext *new_msg_ctx;
@@ -2346,29 +2329,25 @@ datacache_get_iterator (void *cls,
2346 2329
2347 put_entry = (const struct DHTPutEntry *) data; 2330 put_entry = (const struct DHTPutEntry *) data;
2348 2331
2349 if (size != sizeof (struct DHTPutEntry) + 2332 if (size !=
2350 put_entry->data_size + 2333 sizeof (struct DHTPutEntry) + put_entry->data_size +
2351 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity))) 2334 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)))
2352 { 2335 {
2353 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2336 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2354 "Path + data size doesn't add up for data inserted into datacache!\nData size %d, path length %d, expected %d, got %d\n", 2337 "Path + data size doesn't add up for data inserted into datacache!\nData size %d, path length %d, expected %d, got %d\n",
2355 put_entry->data_size, put_entry->path_length, 2338 put_entry->data_size, put_entry->path_length,
2356 sizeof (struct DHTPutEntry) + put_entry->data_size 2339 sizeof (struct DHTPutEntry) + put_entry->data_size +
2357 +
2358 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)), 2340 (put_entry->path_length * sizeof (struct GNUNET_PeerIdentity)),
2359 size); 2341 size);
2360 msg_ctx->do_forward = GNUNET_NO; 2342 msg_ctx->do_forward = GNUNET_NO;
2361 return GNUNET_OK; 2343 return GNUNET_OK;
2362 } 2344 }
2363 2345
2364 eval = GNUNET_BLOCK_evaluate (block_context, 2346 eval =
2365 type, 2347 GNUNET_BLOCK_evaluate (block_context, type, key, &msg_ctx->reply_bf,
2366 key, 2348 msg_ctx->reply_bf_mutator, msg_ctx->xquery,
2367 &msg_ctx->reply_bf, 2349 msg_ctx->xquery_size, &put_entry[1],
2368 msg_ctx->reply_bf_mutator, 2350 put_entry->data_size);
2369 msg_ctx->xquery,
2370 msg_ctx->xquery_size, &put_entry[1],
2371 put_entry->data_size);
2372 2351
2373 switch (eval) 2352 switch (eval)
2374 { 2353 {
@@ -2437,14 +2416,14 @@ datacache_get_iterator (void *cls,
2437 break; 2416 break;
2438 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: 2417 case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE:
2439#if DEBUG_DHT 2418#if DEBUG_DHT
2440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s:%s': Duplicate block error\n",
2441 "`%s:%s': Duplicate block error\n", my_short_id, "DHT"); 2420 my_short_id, "DHT");
2442#endif 2421#endif
2443 break; 2422 break;
2444 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: 2423 case GNUNET_BLOCK_EVALUATION_RESULT_INVALID:
2445#if DEBUG_DHT 2424#if DEBUG_DHT
2446 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2425 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "`%s:%s': Invalid request error\n",
2447 "`%s:%s': Invalid request error\n", my_short_id, "DHT"); 2426 my_short_id, "DHT");
2448#endif 2427#endif
2449 break; 2428 break;
2450 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: 2429 case GNUNET_BLOCK_EVALUATION_REQUEST_VALID:
@@ -2478,9 +2457,8 @@ datacache_get_iterator (void *cls,
2478 * @param msg the message to be routed 2457 * @param msg the message to be routed
2479 * @param msg_ctx the context containing all pertinent information about the message 2458 * @param msg_ctx the context containing all pertinent information about the message
2480 */ 2459 */
2481static void 2460static void route_message (const struct GNUNET_MessageHeader *msg,
2482route_message (const struct GNUNET_MessageHeader *msg, 2461 struct DHT_MessageContext *msg_ctx);
2483 struct DHT_MessageContext *msg_ctx);
2484 2462
2485 2463
2486/** 2464/**
@@ -2535,17 +2513,16 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2535 } 2513 }
2536 else 2514 else
2537 { 2515 {
2538 msg_ctx->reply_bf = GNUNET_CONTAINER_bloomfilter_init (end, 2516 msg_ctx->reply_bf =
2539 bf_size, 2517 GNUNET_CONTAINER_bloomfilter_init (end, bf_size,
2540 GNUNET_DHT_GET_BLOOMFILTER_K); 2518 GNUNET_DHT_GET_BLOOMFILTER_K);
2541 } 2519 }
2542 type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type); 2520 type = (enum GNUNET_BLOCK_Type) ntohl (get_msg->type);
2543#if DEBUG_DHT 2521#if DEBUG_DHT
2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2545 "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n", 2523 "`%s:%s': Received `%s' request, message type %u, key %s, uid %llu\n",
2546 my_short_id, 2524 my_short_id, "DHT", "GET", type, GNUNET_h2s (&msg_ctx->key),
2547 "DHT", "GET", 2525 msg_ctx->unique_id);
2548 type, GNUNET_h2s (&msg_ctx->key), msg_ctx->unique_id);
2549#endif 2526#endif
2550 increment_stats (STAT_GETS); 2527 increment_stats (STAT_GETS);
2551 results = 0; 2528 results = 0;
@@ -2558,10 +2535,9 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2558#endif 2535#endif
2559 msg_ctx->do_forward = GNUNET_YES; 2536 msg_ctx->do_forward = GNUNET_YES;
2560 if (datacache != NULL) 2537 if (datacache != NULL)
2561 results 2538 results =
2562 = GNUNET_DATACACHE_get (datacache, 2539 GNUNET_DATACACHE_get (datacache, &msg_ctx->key, type,
2563 &msg_ctx->key, type, 2540 &datacache_get_iterator, msg_ctx);
2564 &datacache_get_iterator, msg_ctx);
2565#if DEBUG_DHT 2541#if DEBUG_DHT
2566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2567 "`%s:%s': Found %d results for `%s' request uid %llu\n", 2543 "`%s:%s': Found %d results for `%s' request uid %llu\n",
@@ -2573,30 +2549,25 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2573 if ((debug_routes) && (dhtlog_handle != NULL)) 2549 if ((debug_routes) && (dhtlog_handle != NULL))
2574 { 2550 {
2575 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, 2551 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
2576 msg_ctx->hop_count, GNUNET_YES, 2552 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2577 &my_identity, &msg_ctx->key); 2553 &msg_ctx->key);
2578 } 2554 }
2579 2555
2580 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2556 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2581 { 2557 {
2582 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2558 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2583 msg_ctx->hop_count, GNUNET_YES, 2559 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2584 &my_identity, &msg_ctx->key, 2560 &msg_ctx->key, msg_ctx->peer, NULL);
2585 msg_ctx->peer, NULL);
2586 } 2561 }
2587#endif 2562#endif
2588 } 2563 }
2589 else 2564 else
2590 { 2565 {
2591 /* check query valid */ 2566 /* check query valid */
2592 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID 2567 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID ==
2593 == GNUNET_BLOCK_evaluate (block_context, 2568 GNUNET_BLOCK_evaluate (block_context, type, &msg_ctx->key,
2594 type, 2569 &msg_ctx->reply_bf, msg_ctx->reply_bf_mutator,
2595 &msg_ctx->key, 2570 msg_ctx->xquery, msg_ctx->xquery_size, NULL, 0))
2596 &msg_ctx->reply_bf,
2597 msg_ctx->reply_bf_mutator,
2598 msg_ctx->xquery,
2599 msg_ctx->xquery_size, NULL, 0))
2600 { 2571 {
2601 GNUNET_break_op (0); 2572 GNUNET_break_op (0);
2602 msg_ctx->do_forward = GNUNET_NO; 2573 msg_ctx->do_forward = GNUNET_NO;
@@ -2609,8 +2580,8 @@ handle_dht_get (const struct GNUNET_MessageHeader *msg,
2609 if ((debug_routes) && (dhtlog_handle != NULL)) 2580 if ((debug_routes) && (dhtlog_handle != NULL))
2610 { 2581 {
2611 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET, 2582 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_GET,
2612 msg_ctx->hop_count, GNUNET_NO, 2583 msg_ctx->hop_count, GNUNET_NO, &my_identity,
2613 &my_identity, &msg_ctx->key); 2584 &msg_ctx->key);
2614 } 2585 }
2615#endif 2586#endif
2616 } 2587 }
@@ -2667,11 +2638,10 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2667 ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage); 2638 ntohs (find_msg->size) - sizeof (struct GNUNET_DHT_FindPeerMessage);
2668 other_hello = GNUNET_malloc (other_hello_size); 2639 other_hello = GNUNET_malloc (other_hello_size);
2669 memcpy (other_hello, &find_peer_message[1], other_hello_size); 2640 memcpy (other_hello, &find_peer_message[1], other_hello_size);
2670 if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) == 2641 if ((GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) other_hello) == 0)
2671 0)
2672 || (GNUNET_OK != 2642 || (GNUNET_OK !=
2673 GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *) 2643 GNUNET_HELLO_get_id ((struct GNUNET_HELLO_Message *) other_hello,
2674 other_hello, &peer_id))) 2644 &peer_id)))
2675 { 2645 {
2676 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2646 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2677 "Received invalid HELLO message in find peer request!\n"); 2647 "Received invalid HELLO message in find peer request!\n");
@@ -2802,8 +2772,8 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2802 memcpy (&find_peer_result[1], my_hello, hello_size); 2772 memcpy (&find_peer_result[1], my_hello, hello_size);
2803#if DEBUG_DHT 2773#if DEBUG_DHT
2804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2805 "`%s': Sending hello size %d to requesting peer.\n", 2775 "`%s': Sending hello size %d to requesting peer.\n", "DHT",
2806 "DHT", hello_size); 2776 hello_size);
2807#endif 2777#endif
2808 2778
2809 new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext)); 2779 new_msg_ctx = GNUNET_malloc (sizeof (struct DHT_MessageContext));
@@ -2829,8 +2799,8 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2829 if ((debug_routes) && (dhtlog_handle != NULL)) 2799 if ((debug_routes) && (dhtlog_handle != NULL))
2830 { 2800 {
2831 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER, 2801 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER,
2832 msg_ctx->hop_count, GNUNET_YES, 2802 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2833 &my_identity, &msg_ctx->key); 2803 &msg_ctx->key);
2834 } 2804 }
2835#endif 2805#endif
2836 GNUNET_free_non_null (other_hello); 2806 GNUNET_free_non_null (other_hello);
@@ -2845,8 +2815,8 @@ handle_dht_find_peer (const struct GNUNET_MessageHeader *find_msg,
2845 * @param cls closure (a struct RepublishContext) 2815 * @param cls closure (a struct RepublishContext)
2846 * @param tc runtime context for this task 2816 * @param tc runtime context for this task
2847 */ 2817 */
2848static void 2818static void republish_content (void *cls,
2849republish_content (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 2819 const struct GNUNET_SCHEDULER_TaskContext *tc);
2850 2820
2851/** 2821/**
2852 * Server handler for initiating local dht put requests 2822 * Server handler for initiating local dht put requests
@@ -2881,8 +2851,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2881 /** Log routes that die due to high load! */ 2851 /** Log routes that die due to high load! */
2882 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2852 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2883 msg_ctx->hop_count, GNUNET_SYSERR, 2853 msg_ctx->hop_count, GNUNET_SYSERR,
2884 &my_identity, &msg_ctx->key, 2854 &my_identity, &msg_ctx->key, msg_ctx->peer,
2885 msg_ctx->peer, NULL); 2855 NULL);
2886 } 2856 }
2887#endif 2857#endif
2888 return; 2858 return;
@@ -2900,8 +2870,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2900 { 2870 {
2901 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2871 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2902 msg_ctx->hop_count, GNUNET_SYSERR, 2872 msg_ctx->hop_count, GNUNET_SYSERR,
2903 &my_identity, &msg_ctx->key, 2873 &my_identity, &msg_ctx->key, msg_ctx->peer,
2904 msg_ctx->peer, NULL); 2874 NULL);
2905 } 2875 }
2906#endif 2876#endif
2907 /* invalid reply */ 2877 /* invalid reply */
@@ -2916,8 +2886,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2916 { 2886 {
2917 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2887 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2918 msg_ctx->hop_count, GNUNET_SYSERR, 2888 msg_ctx->hop_count, GNUNET_SYSERR,
2919 &my_identity, &msg_ctx->key, 2889 &my_identity, &msg_ctx->key, msg_ctx->peer,
2920 msg_ctx->peer, NULL); 2890 NULL);
2921 } 2891 }
2922#endif 2892#endif
2923 /* invalid wrapper: key mismatch! */ 2893 /* invalid wrapper: key mismatch! */
@@ -2938,8 +2908,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2938 if ((debug_routes) && (dhtlog_handle != NULL)) 2908 if ((debug_routes) && (dhtlog_handle != NULL))
2939 { 2909 {
2940 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, 2910 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
2941 msg_ctx->hop_count, GNUNET_NO, 2911 msg_ctx->hop_count, GNUNET_NO, &my_identity,
2942 &my_identity, &msg_ctx->key); 2912 &msg_ctx->key);
2943 } 2913 }
2944 } 2914 }
2945#endif 2915#endif
@@ -2961,16 +2931,15 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2961 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 2931 if ((debug_routes_extended) && (dhtlog_handle != NULL))
2962 { 2932 {
2963 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 2933 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
2964 msg_ctx->hop_count, GNUNET_YES, 2934 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2965 &my_identity, &msg_ctx->key, msg_ctx->peer, 2935 &msg_ctx->key, msg_ctx->peer, NULL);
2966 NULL);
2967 } 2936 }
2968 2937
2969 if ((debug_routes) && (dhtlog_handle != NULL)) 2938 if ((debug_routes) && (dhtlog_handle != NULL))
2970 { 2939 {
2971 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT, 2940 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_PUT,
2972 msg_ctx->hop_count, GNUNET_YES, 2941 msg_ctx->hop_count, GNUNET_YES, &my_identity,
2973 &my_identity, &msg_ctx->key); 2942 &msg_ctx->key);
2974 } 2943 }
2975#endif 2944#endif
2976 2945
@@ -2995,10 +2964,10 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
2995 msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity)); 2964 msg_ctx->path_history_len * sizeof (struct GNUNET_PeerIdentity));
2996 } 2965 }
2997 2966
2998 ret = GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size, 2967 ret =
2999 (const char *) put_entry, put_type, 2968 GNUNET_DATACACHE_put (datacache, &msg_ctx->key, put_size,
3000 GNUNET_TIME_absolute_ntoh 2969 (const char *) put_entry, put_type,
3001 (put_msg->expiration)); 2970 GNUNET_TIME_absolute_ntoh (put_msg->expiration));
3002 GNUNET_free (put_entry); 2971 GNUNET_free (put_entry);
3003 2972
3004 if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES)) 2973 if ((ret == GNUNET_YES) && (do_republish == GNUNET_YES))
@@ -3006,8 +2975,8 @@ handle_dht_put (const struct GNUNET_MessageHeader *msg,
3006 put_context = GNUNET_malloc (sizeof (struct RepublishContext)); 2975 put_context = GNUNET_malloc (sizeof (struct RepublishContext));
3007 memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode)); 2976 memcpy (&put_context->key, &msg_ctx->key, sizeof (GNUNET_HashCode));
3008 put_context->type = put_type; 2977 put_context->type = put_type;
3009 GNUNET_SCHEDULER_add_delayed (dht_republish_frequency, 2978 GNUNET_SCHEDULER_add_delayed (dht_republish_frequency, &republish_content,
3010 &republish_content, put_context); 2979 put_context);
3011 } 2980 }
3012 } 2981 }
3013 else 2982 else
@@ -3102,17 +3071,16 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
3102 if (GNUNET_YES == paper_forwarding) 3071 if (GNUNET_YES == paper_forwarding)
3103 { 3072 {
3104 /* FIXME: re-run replication trials with this formula */ 3073 /* FIXME: re-run replication trials with this formula */
3105 target_value = 1 + (target_replication - 1.0) / (diameter 3074 target_value =
3106 + 3075 1 + (target_replication - 1.0) / (diameter +
3107 ((float) 3076 ((float) (target_replication - 1.0) *
3108 (target_replication - 3077 hop_count));
3109 1.0) * hop_count));
3110 /* Set forward count to floor of target_value */ 3078 /* Set forward count to floor of target_value */
3111 forward_count = (unsigned int) target_value; 3079 forward_count = (unsigned int) target_value;
3112 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */ 3080 /* Subtract forward_count (floor) from target_value (yields value between 0 and 1) */
3113 target_value = target_value - forward_count; 3081 target_value = target_value - forward_count;
3114 random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3082 random_value =
3115 UINT32_MAX); 3083 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
3116 3084
3117 if (random_value < (target_value * UINT32_MAX)) 3085 if (random_value < (target_value * UINT32_MAX))
3118 forward_count += 1; 3086 forward_count += 1;
@@ -3121,10 +3089,9 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
3121 { 3089 {
3122 random_value = 0; 3090 random_value = 0;
3123 forward_count = 1; 3091 forward_count = 1;
3124 target_value = target_replication / (diameter 3092 target_value =
3125 + 3093 target_replication / (diameter +
3126 ((float) target_replication * 3094 ((float) target_replication * hop_count));
3127 hop_count));
3128 if (target_value > 1) 3095 if (target_value > 1)
3129 { 3096 {
3130 /* Set forward count to floor of target_value */ 3097 /* Set forward count to floor of target_value */
@@ -3133,8 +3100,8 @@ get_forward_count (unsigned int hop_count, size_t target_replication)
3133 target_value = target_value - forward_count; 3100 target_value = target_value - forward_count;
3134 } 3101 }
3135 else 3102 else
3136 random_value = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 3103 random_value =
3137 UINT32_MAX); 3104 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
3138 3105
3139 if (random_value < (target_value * UINT32_MAX)) 3106 if (random_value < (target_value * UINT32_MAX))
3140 forward_count += 1; 3107 forward_count += 1;
@@ -3176,9 +3143,9 @@ am_closest_peer (const GNUNET_HashCode * target,
3176 count = 0; 3143 count = 0;
3177 while ((pos != NULL) && (count < bucket_size)) 3144 while ((pos != NULL) && (count < bucket_size))
3178 { 3145 {
3179 if ((bloom != NULL) 3146 if ((bloom != NULL) &&
3180 && (GNUNET_YES == 3147 (GNUNET_YES ==
3181 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey))) 3148 GNUNET_CONTAINER_bloomfilter_test (bloom, &pos->id.hashPubKey)))
3182 { 3149 {
3183 pos = pos->next; 3150 pos = pos->next;
3184 continue; /* Skip already checked entries */ 3151 continue; /* Skip already checked entries */
@@ -3216,8 +3183,8 @@ am_closest_peer (const GNUNET_HashCode * target,
3216 * 3183 *
3217 */ 3184 */
3218static unsigned long long 3185static unsigned long long
3219converge_distance (const GNUNET_HashCode * target, 3186converge_distance (const GNUNET_HashCode * target, struct PeerInfo *peer,
3220 struct PeerInfo *peer, unsigned int hops) 3187 unsigned int hops)
3221{ 3188{
3222 unsigned long long ret; 3189 unsigned long long ret;
3223 unsigned int other_matching_bits; 3190 unsigned int other_matching_bits;
@@ -3298,8 +3265,8 @@ converge_distance (const GNUNET_HashCode * target,
3298 errno = 0; 3265 errno = 0;
3299 feclearexcept (FE_ALL_EXCEPT); 3266 feclearexcept (FE_ALL_EXCEPT);
3300 ret = (unsigned long long) pow (other_matching_bits, calc_value); 3267 ret = (unsigned long long) pow (other_matching_bits, calc_value);
3301 if ((errno != 0) || fetestexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | 3268 if ((errno != 0) ||
3302 FE_UNDERFLOW)) 3269 fetestexcept (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW))
3303 { 3270 {
3304 if (0 != fetestexcept (FE_OVERFLOW)) 3271 if (0 != fetestexcept (FE_OVERFLOW))
3305 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n"); 3272 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "FE_OVERFLOW\n");
@@ -3542,10 +3509,10 @@ select_peer (const GNUNET_HashCode * target,
3542 break; /* overflow case */ 3509 break; /* overflow case */
3543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3544 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n", 3511 "Choose %d matching bits (%d bits match me) (%.2f percent) converge ret %llu\n",
3545 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id. 3512 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->
3546 hashPubKey, target), 3513 id.hashPubKey, target),
3547 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->id. 3514 GNUNET_CRYPTO_hash_matching_bits (&sorted_closest[i]->
3548 hashPubKey, 3515 id.hashPubKey,
3549 &my_identity.hashPubKey), 3516 &my_identity.hashPubKey),
3550 (temp_converge_distance / (double) total_distance) * 100, 3517 (temp_converge_distance / (double) total_distance) * 100,
3551 temp_converge_distance); 3518 temp_converge_distance);
@@ -3576,8 +3543,8 @@ select_peer (const GNUNET_HashCode * target,
3576 target), 3543 target),
3577 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, 3544 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3578 &my_identity.hashPubKey), 3545 &my_identity.hashPubKey),
3579 (temp_converge_distance / (double) total_distance) * 3546 (temp_converge_distance / (double) total_distance) * 100,
3580 100, temp_converge_distance); 3547 temp_converge_distance);
3581 pos = pos->next; 3548 pos = pos->next;
3582 count++; 3549 count++;
3583 } 3550 }
@@ -3608,8 +3575,8 @@ select_peer (const GNUNET_HashCode * target,
3608 target), 3575 target),
3609 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey, 3576 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
3610 &my_identity.hashPubKey), 3577 &my_identity.hashPubKey),
3611 (temp_converge_distance / (double) total_distance) * 3578 (temp_converge_distance / (double) total_distance) * 100,
3612 100, temp_converge_distance); 3579 temp_converge_distance);
3613 pos = pos->next; 3580 pos = pos->next;
3614 count++; 3581 count++;
3615 } 3582 }
@@ -3750,8 +3717,9 @@ cache_response (struct DHT_MessageContext *msg_ctx)
3750 if (record->head == NULL) /* No more entries in DLL */ 3717 if (record->head == NULL) /* No more entries in DLL */
3751 { 3718 {
3752 GNUNET_assert (GNUNET_YES == 3719 GNUNET_assert (GNUNET_YES ==
3753 GNUNET_CONTAINER_multihashmap_remove 3720 GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap,
3754 (forward_list.hashmap, &record->key, record)); 3721 &record->key,
3722 record));
3755 GNUNET_free (record); 3723 GNUNET_free (record);
3756 } 3724 }
3757 if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK) 3725 if (source_info->delete_task != GNUNET_SCHEDULER_NO_TASK)
@@ -3864,8 +3832,8 @@ route_message (const struct GNUNET_MessageHeader *msg,
3864 { 3832 {
3865 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 3833 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
3866 msg_ctx->hop_count, GNUNET_SYSERR, 3834 msg_ctx->hop_count, GNUNET_SYSERR,
3867 &my_identity, &msg_ctx->key, 3835 &my_identity, &msg_ctx->key, msg_ctx->peer,
3868 msg_ctx->peer, NULL); 3836 NULL);
3869 } 3837 }
3870#endif 3838#endif
3871 if (msg_ctx->bloom != NULL) 3839 if (msg_ctx->bloom != NULL)
@@ -3887,8 +3855,8 @@ route_message (const struct GNUNET_MessageHeader *msg,
3887 msg_ctx->bloom = 3855 msg_ctx->bloom =
3888 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3856 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3889 3857
3890 if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES) 3858 if ((stop_on_closest == GNUNET_YES) && (msg_ctx->closest == GNUNET_YES) &&
3891 && (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT)) 3859 (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DHT_PUT))
3892 target_forward_count = 0; 3860 target_forward_count = 0;
3893 3861
3894 /** 3862 /**
@@ -3906,9 +3874,9 @@ route_message (const struct GNUNET_MessageHeader *msg,
3906 * testing driver) we will ignore this restriction for FIND_PEER messages so that 3874 * testing driver) we will ignore this restriction for FIND_PEER messages so that
3907 * routing tables still get constructed. 3875 * routing tables still get constructed.
3908 */ 3876 */
3909 if ((GNUNET_YES == strict_kademlia) && (msg_ctx->closest == GNUNET_YES) 3877 if ((GNUNET_YES == strict_kademlia) && (msg_ctx->closest == GNUNET_YES) &&
3910 && (msg_ctx->hop_count > 0) 3878 (msg_ctx->hop_count > 0) &&
3911 && (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER)) 3879 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_DHT_FIND_PEER))
3912 target_forward_count = 0; 3880 target_forward_count = 0;
3913 3881
3914 3882
@@ -3942,8 +3910,7 @@ route_message (const struct GNUNET_MessageHeader *msg,
3942 GNUNET_TIME_absolute_get ().abs_value); 3910 GNUNET_TIME_absolute_get ().abs_value);
3943 recent_req->bloom = 3911 recent_req->bloom =
3944 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K); 3912 GNUNET_CONTAINER_bloomfilter_init (NULL, DHT_BLOOM_SIZE, DHT_BLOOM_K);
3945 GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash, 3913 GNUNET_CONTAINER_multihashmap_put (recent.hashmap, &unique_hash, recent_req,
3946 recent_req,
3947 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 3914 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
3948 } 3915 }
3949 3916
@@ -3988,8 +3955,7 @@ route_message (const struct GNUNET_MessageHeader *msg,
3988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3989 "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n", 3956 "`%s:%s': Forwarding request key %s uid %llu to peer %s (closest %s, bits %d, distance %u)\n",
3990 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key), 3957 my_short_id, "DHT", GNUNET_h2s (&msg_ctx->key),
3991 msg_ctx->unique_id, GNUNET_i2s (&selected->id), 3958 msg_ctx->unique_id, GNUNET_i2s (&selected->id), nearest_buf,
3992 nearest_buf,
3993 GNUNET_CRYPTO_hash_matching_bits (&nearest->id.hashPubKey, 3959 GNUNET_CRYPTO_hash_matching_bits (&nearest->id.hashPubKey,
3994 msg_ctx->key), 3960 msg_ctx->key),
3995 distance (&nearest->id.hashPubKey, msg_ctx->key)); 3961 distance (&nearest->id.hashPubKey, msg_ctx->key));
@@ -3998,10 +3964,9 @@ route_message (const struct GNUNET_MessageHeader *msg,
3998#if DEBUG_DHT_ROUTING 3964#if DEBUG_DHT_ROUTING
3999 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 3965 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4000 { 3966 {
4001 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, 3967 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
4002 DHTLOG_ROUTE, msg_ctx->hop_count, 3968 msg_ctx->hop_count, GNUNET_NO,
4003 GNUNET_NO, &my_identity, 3969 &my_identity, &msg_ctx->key, msg_ctx->peer,
4004 &msg_ctx->key, msg_ctx->peer,
4005 &selected->id); 3970 &selected->id);
4006 } 3971 }
4007#endif 3972#endif
@@ -4026,9 +3991,8 @@ route_message (const struct GNUNET_MessageHeader *msg,
4026 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 3991 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4027 { 3992 {
4028 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE, 3993 dhtlog_handle->insert_route (NULL, msg_ctx->unique_id, DHTLOG_ROUTE,
4029 msg_ctx->hop_count, ret, 3994 msg_ctx->hop_count, ret, &my_identity,
4030 &my_identity, &msg_ctx->key, msg_ctx->peer, 3995 &msg_ctx->key, msg_ctx->peer, NULL);
4031 NULL);
4032 } 3996 }
4033#endif 3997#endif
4034} 3998}
@@ -4061,15 +4025,15 @@ demultiplex_message (const struct GNUNET_MessageHeader *msg,
4061 break; 4025 break;
4062 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */ 4026 case GNUNET_MESSAGE_TYPE_DHT_FIND_PEER: /* Check if closest and not started by us, check options, add to requests seen */
4063 increment_stats (STAT_FIND_PEER); 4027 increment_stats (STAT_FIND_PEER);
4064 if (((msg_ctx->hop_count > 0) 4028 if (((msg_ctx->hop_count > 0) &&
4065 && (0 != 4029 (0 !=
4066 memcmp (msg_ctx->peer, &my_identity, 4030 memcmp (msg_ctx->peer, &my_identity,
4067 sizeof (struct GNUNET_PeerIdentity)))) 4031 sizeof (struct GNUNET_PeerIdentity)))) ||
4068 || (msg_ctx->client != NULL)) 4032 (msg_ctx->client != NULL))
4069 { 4033 {
4070 cache_response (msg_ctx); 4034 cache_response (msg_ctx);
4071 if ((msg_ctx->closest == GNUNET_YES) 4035 if ((msg_ctx->closest == GNUNET_YES) ||
4072 || (msg_ctx->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) 4036 (msg_ctx->msg_options == GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE))
4073 handle_dht_find_peer (msg, msg_ctx); 4037 handle_dht_find_peer (msg, msg_ctx);
4074 } 4038 }
4075 else 4039 else
@@ -4080,8 +4044,7 @@ demultiplex_message (const struct GNUNET_MessageHeader *msg,
4080 if ((debug_routes) && (dhtlog_handle != NULL)) 4044 if ((debug_routes) && (dhtlog_handle != NULL))
4081 { 4045 {
4082 dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key); 4046 dhtlog_handle->insert_dhtkey (NULL, &msg_ctx->key);
4083 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, 4047 dhtlog_handle->insert_query (NULL, msg_ctx->unique_id, DHTLOG_FIND_PEER,
4084 DHTLOG_FIND_PEER,
4085 msg_ctx->hop_count, GNUNET_NO, 4048 msg_ctx->hop_count, GNUNET_NO,
4086 &my_identity, &msg_ctx->key); 4049 &my_identity, &msg_ctx->key);
4087 } 4050 }
@@ -4113,10 +4076,9 @@ demultiplex_message (const struct GNUNET_MessageHeader *msg,
4113 * to stop iteration. 4076 * to stop iteration.
4114 */ 4077 */
4115static int 4078static int
4116republish_content_iterator (void *cls, 4079republish_content_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
4117 struct GNUNET_TIME_Absolute exp, 4080 const GNUNET_HashCode * key, size_t size,
4118 const GNUNET_HashCode * key, 4081 const char *data, uint32_t type)
4119 size_t size, const char *data, uint32_t type)
4120{ 4082{
4121 4083
4122 struct DHT_MessageContext *new_msg_ctx; 4084 struct DHT_MessageContext *new_msg_ctx;
@@ -4227,8 +4189,8 @@ find_client_records (void *cls, const GNUNET_HashCode * key, void *value)
4227 if (record->head == NULL) /* No more entries in DLL */ 4189 if (record->head == NULL) /* No more entries in DLL */
4228 { 4190 {
4229 GNUNET_assert (GNUNET_YES == 4191 GNUNET_assert (GNUNET_YES ==
4230 GNUNET_CONTAINER_multihashmap_remove 4192 GNUNET_CONTAINER_multihashmap_remove (forward_list.hashmap,
4231 (forward_list.hashmap, &record->key, record)); 4193 &record->key, record));
4232 GNUNET_free (record); 4194 GNUNET_free (record);
4233 } 4195 }
4234 return GNUNET_YES; 4196 return GNUNET_YES;
@@ -4274,8 +4236,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
4274 4236
4275 while (NULL != (reply = found->pending_head)) 4237 while (NULL != (reply = found->pending_head))
4276 { 4238 {
4277 GNUNET_CONTAINER_DLL_remove (found->pending_head, 4239 GNUNET_CONTAINER_DLL_remove (found->pending_head, found->pending_tail,
4278 found->pending_tail, reply); 4240 reply);
4279 GNUNET_free (reply); 4241 GNUNET_free (reply);
4280 } 4242 }
4281 GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap, 4243 GNUNET_CONTAINER_multihashmap_iterate (forward_list.hashmap,
@@ -4354,13 +4316,13 @@ malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4354#endif 4316#endif
4355 increment_stats (STAT_PUT_START); 4317 increment_stats (STAT_PUT_START);
4356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4357 "%s:%s Sending malicious PUT message with hash %s\n", 4319 "%s:%s Sending malicious PUT message with hash %s\n", my_short_id,
4358 my_short_id, "DHT", GNUNET_h2s (&key)); 4320 "DHT", GNUNET_h2s (&key));
4359 demultiplex_message (&put_message.header, &msg_ctx); 4321 demultiplex_message (&put_message.header, &msg_ctx);
4360 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 4322 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
4361 (GNUNET_TIME_UNIT_MILLISECONDS, 4323 (GNUNET_TIME_UNIT_MILLISECONDS,
4362 malicious_put_frequency), 4324 malicious_put_frequency), &malicious_put_task,
4363 &malicious_put_task, NULL); 4325 NULL);
4364} 4326}
4365 4327
4366 4328
@@ -4404,13 +4366,13 @@ malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
4404#endif 4366#endif
4405 increment_stats (STAT_GET_START); 4367 increment_stats (STAT_GET_START);
4406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4407 "%s:%s Sending malicious GET message with hash %s\n", 4369 "%s:%s Sending malicious GET message with hash %s\n", my_short_id,
4408 my_short_id, "DHT", GNUNET_h2s (&key)); 4370 "DHT", GNUNET_h2s (&key));
4409 demultiplex_message (&get_message.header, &msg_ctx); 4371 demultiplex_message (&get_message.header, &msg_ctx);
4410 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 4372 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
4411 (GNUNET_TIME_UNIT_MILLISECONDS, 4373 (GNUNET_TIME_UNIT_MILLISECONDS,
4412 malicious_get_frequency), 4374 malicious_get_frequency), &malicious_get_task,
4413 &malicious_get_task, NULL); 4375 NULL);
4414} 4376}
4415#endif 4377#endif
4416 4378
@@ -4511,8 +4473,7 @@ send_find_peer_message (void *cls,
4511 temp_bloom); 4473 temp_bloom);
4512 GNUNET_assert (GNUNET_OK == 4474 GNUNET_assert (GNUNET_OK ==
4513 GNUNET_CONTAINER_bloomfilter_get_raw_data (temp_bloom, 4475 GNUNET_CONTAINER_bloomfilter_get_raw_data (temp_bloom,
4514 find_peer_msg-> 4476 find_peer_msg->bloomfilter,
4515 bloomfilter,
4516 DHT_BLOOM_SIZE)); 4477 DHT_BLOOM_SIZE));
4517 GNUNET_CONTAINER_bloomfilter_free (temp_bloom); 4478 GNUNET_CONTAINER_bloomfilter_free (temp_bloom);
4518 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext)); 4479 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
@@ -4541,7 +4502,8 @@ send_find_peer_message (void *cls,
4541 } 4502 }
4542 else 4503 else
4543 { 4504 {
4544 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 4505 next_send_time.rel_value =
4506 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
4545 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 4507 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
4546 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value - 4508 DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value -
4547 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); 4509 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
@@ -4553,8 +4515,8 @@ send_find_peer_message (void *cls,
4553 find_peer_context.start = GNUNET_TIME_absolute_get (); 4515 find_peer_context.start = GNUNET_TIME_absolute_get ();
4554 if (GNUNET_YES == do_find_peer) 4516 if (GNUNET_YES == do_find_peer)
4555 { 4517 {
4556 GNUNET_SCHEDULER_add_delayed (next_send_time, 4518 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message,
4557 &send_find_peer_message, NULL); 4519 NULL);
4558 } 4520 }
4559} 4521}
4560 4522
@@ -4568,8 +4530,7 @@ send_find_peer_message (void *cls,
4568 * @param message the actual message received 4530 * @param message the actual message received
4569 */ 4531 */
4570static void 4532static void
4571handle_dht_local_route_request (void *cls, 4533handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client,
4572 struct GNUNET_SERVER_Client *client,
4573 const struct GNUNET_MessageHeader *message) 4534 const struct GNUNET_MessageHeader *message)
4574{ 4535{
4575 const struct GNUNET_DHT_RouteMessage *dht_msg = 4536 const struct GNUNET_DHT_RouteMessage *dht_msg =
@@ -4581,10 +4542,7 @@ handle_dht_local_route_request (void *cls,
4581#if DEBUG_DHT 4542#if DEBUG_DHT
4582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4583 "`%s:%s': Received `%s' request from client, message type %d, key %s, uid %llu\n", 4544 "`%s:%s': Received `%s' request from client, message type %d, key %s, uid %llu\n",
4584 my_short_id, 4545 my_short_id, "DHT", "GENERIC", ntohs (message->type),
4585 "DHT",
4586 "GENERIC",
4587 ntohs (message->type),
4588 GNUNET_h2s (&dht_msg->key), GNUNET_ntohll (dht_msg->unique_id)); 4546 GNUNET_h2s (&dht_msg->key), GNUNET_ntohll (dht_msg->unique_id));
4589#endif 4547#endif
4590#if DEBUG_DHT_ROUTING 4548#if DEBUG_DHT_ROUTING
@@ -4625,9 +4583,9 @@ handle_dht_local_route_request (void *cls,
4625#if DEBUG_DHT_ROUTING 4583#if DEBUG_DHT_ROUTING
4626 if ((debug_routes) && (dhtlog_handle != NULL)) 4584 if ((debug_routes) && (dhtlog_handle != NULL))
4627 { 4585 {
4628 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, 4586 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, DHTLOG_GET,
4629 DHTLOG_GET, msg_ctx.hop_count, 4587 msg_ctx.hop_count, GNUNET_NO, &my_identity,
4630 GNUNET_NO, &my_identity, &msg_ctx.key); 4588 &msg_ctx.key);
4631 } 4589 }
4632#endif 4590#endif
4633 } 4591 }
@@ -4636,9 +4594,9 @@ handle_dht_local_route_request (void *cls,
4636#if DEBUG_DHT_ROUTING 4594#if DEBUG_DHT_ROUTING
4637 if ((debug_routes) && (dhtlog_handle != NULL)) 4595 if ((debug_routes) && (dhtlog_handle != NULL))
4638 { 4596 {
4639 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, 4597 dhtlog_handle->insert_query (NULL, msg_ctx.unique_id, DHTLOG_PUT,
4640 DHTLOG_PUT, msg_ctx.hop_count, 4598 msg_ctx.hop_count, GNUNET_NO, &my_identity,
4641 GNUNET_NO, &my_identity, &msg_ctx.key); 4599 &msg_ctx.key);
4642 } 4600 }
4643#endif 4601#endif
4644 } 4602 }
@@ -4719,8 +4677,8 @@ handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client,
4719#endif 4677#endif
4720 default: 4678 default:
4721 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4679 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4722 "%s:%s Unknown control command type `%d'!\n", 4680 "%s:%s Unknown control command type `%d'!\n", my_short_id,
4723 my_short_id, "DHT", ntohs (dht_control_msg->command)); 4681 "DHT", ntohs (dht_control_msg->command));
4724 break; 4682 break;
4725 } 4683 }
4726 4684
@@ -4787,8 +4745,7 @@ handle_dht_local_route_stop (void *cls, struct GNUNET_SERVER_Client *client,
4787 * 4745 *
4788 */ 4746 */
4789static int 4747static int
4790handle_dht_p2p_route_request (void *cls, 4748handle_dht_p2p_route_request (void *cls, const struct GNUNET_PeerIdentity *peer,
4791 const struct GNUNET_PeerIdentity *peer,
4792 const struct GNUNET_MessageHeader *message, 4749 const struct GNUNET_MessageHeader *message,
4793 const struct GNUNET_TRANSPORT_ATS_Information 4750 const struct GNUNET_TRANSPORT_ATS_Information
4794 *atsi) 4751 *atsi)
@@ -4809,8 +4766,8 @@ handle_dht_p2p_route_request (void *cls,
4809 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_P2P_PING) /* Throw these away. FIXME: Don't throw these away? (reply) */ 4766 if (ntohs (enc_msg->type) == GNUNET_MESSAGE_TYPE_DHT_P2P_PING) /* Throw these away. FIXME: Don't throw these away? (reply) */
4810 { 4767 {
4811#if DEBUG_PING 4768#if DEBUG_PING
4812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s Received P2P Ping message.\n",
4813 "%s:%s Received P2P Ping message.\n", my_short_id, "DHT"); 4770 my_short_id, "DHT");
4814#endif 4771#endif
4815 return GNUNET_YES; 4772 return GNUNET_YES;
4816 } 4773 }
@@ -4827,12 +4784,10 @@ handle_dht_p2p_route_request (void *cls,
4827 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4784 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4828 { 4785 {
4829 /** Log routes that die due to high load! */ 4786 /** Log routes that die due to high load! */
4830 dhtlog_handle->insert_route (NULL, 4787 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id),
4831 GNUNET_ntohll (incoming->unique_id), 4788 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4832 DHTLOG_ROUTE, 4789 GNUNET_SYSERR, &my_identity, &incoming->key,
4833 ntohl (incoming->hop_count), 4790 peer, NULL);
4834 GNUNET_SYSERR, &my_identity,
4835 &incoming->key, peer, NULL);
4836 } 4791 }
4837#endif 4792#endif
4838 return GNUNET_YES; 4793 return GNUNET_YES;
@@ -4848,12 +4803,10 @@ handle_dht_p2p_route_request (void *cls,
4848 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4803 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4849 { 4804 {
4850 /** Log routes that die due to high load! */ 4805 /** Log routes that die due to high load! */
4851 dhtlog_handle->insert_route (NULL, 4806 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id),
4852 GNUNET_ntohll (incoming->unique_id), 4807 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4853 DHTLOG_ROUTE, 4808 GNUNET_SYSERR, &my_identity, &incoming->key,
4854 ntohl (incoming->hop_count), 4809 peer, NULL);
4855 GNUNET_SYSERR, &my_identity,
4856 &incoming->key, peer, NULL);
4857 } 4810 }
4858#endif 4811#endif
4859 return GNUNET_YES; 4812 return GNUNET_YES;
@@ -4911,8 +4864,7 @@ handle_dht_p2p_route_request (void *cls,
4911 * 4864 *
4912 */ 4865 */
4913static int 4866static int
4914handle_dht_p2p_route_result (void *cls, 4867handle_dht_p2p_route_result (void *cls, const struct GNUNET_PeerIdentity *peer,
4915 const struct GNUNET_PeerIdentity *peer,
4916 const struct GNUNET_MessageHeader *message, 4868 const struct GNUNET_MessageHeader *message,
4917 const struct GNUNET_TRANSPORT_ATS_Information 4869 const struct GNUNET_TRANSPORT_ATS_Information
4918 *atsi) 4870 *atsi)
@@ -4944,12 +4896,10 @@ handle_dht_p2p_route_result (void *cls,
4944 if ((debug_routes_extended) && (dhtlog_handle != NULL)) 4896 if ((debug_routes_extended) && (dhtlog_handle != NULL))
4945 { 4897 {
4946 /** Log routes that die due to high load! */ 4898 /** Log routes that die due to high load! */
4947 dhtlog_handle->insert_route (NULL, 4899 dhtlog_handle->insert_route (NULL, GNUNET_ntohll (incoming->unique_id),
4948 GNUNET_ntohll (incoming->unique_id), 4900 DHTLOG_ROUTE, ntohl (incoming->hop_count),
4949 DHTLOG_ROUTE, 4901 GNUNET_SYSERR, &my_identity, &incoming->key,
4950 ntohl (incoming->hop_count), 4902 peer, NULL);
4951 GNUNET_SYSERR, &my_identity,
4952 &incoming->key, peer, NULL);
4953 } 4903 }
4954#endif 4904#endif
4955 return GNUNET_YES; 4905 return GNUNET_YES;
@@ -4977,8 +4927,7 @@ handle_dht_p2p_route_result (void *cls,
4977#if DEBUG_DHT 4927#if DEBUG_DHT
4978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4979 "Return message indicated a path was included, but sizes are wrong: Total size %d, enc size %d, left %d, expected %d\n", 4929 "Return message indicated a path was included, but sizes are wrong: Total size %d, enc size %d, left %d, expected %d\n",
4980 ntohs (message->size), 4930 ntohs (message->size), ntohs (enc_msg->size),
4981 ntohs (enc_msg->size),
4982 ntohs (message->size) - 4931 ntohs (message->size) -
4983 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) - 4932 sizeof (struct GNUNET_DHT_P2PRouteResultMessage) -
4984 ntohs (enc_msg->size), 4933 ntohs (enc_msg->size),
@@ -5055,8 +5004,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5055 if (coreAPI != NULL) 5004 if (coreAPI != NULL)
5056 { 5005 {
5057#if DEBUG_DHT 5006#if DEBUG_DHT
5058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s Disconnecting core!\n",
5059 "%s:%s Disconnecting core!\n", my_short_id, "DHT"); 5008 my_short_id, "DHT");
5060#endif 5009#endif
5061 GNUNET_CORE_disconnect (coreAPI); 5010 GNUNET_CORE_disconnect (coreAPI);
5062 coreAPI = NULL; 5011 coreAPI = NULL;
@@ -5077,8 +5026,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5077 if (datacache != NULL) 5026 if (datacache != NULL)
5078 { 5027 {
5079#if DEBUG_DHT 5028#if DEBUG_DHT
5080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5029 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s:%s Destroying datacache!\n",
5081 "%s:%s Destroying datacache!\n", my_short_id, "DHT"); 5030 my_short_id, "DHT");
5082#endif 5031#endif
5083 GNUNET_DATACACHE_destroy (datacache); 5032 GNUNET_DATACACHE_destroy (datacache);
5084 datacache = NULL; 5033 datacache = NULL;
@@ -5112,8 +5061,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5112 * @param publicKey the public key of this peer 5061 * @param publicKey the public key of this peer
5113 */ 5062 */
5114void 5063void
5115core_init (void *cls, 5064core_init (void *cls, struct GNUNET_CORE_Handle *server,
5116 struct GNUNET_CORE_Handle *server,
5117 const struct GNUNET_PeerIdentity *identity, 5065 const struct GNUNET_PeerIdentity *identity,
5118 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 5066 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
5119{ 5067{
@@ -5121,9 +5069,8 @@ core_init (void *cls,
5121 if (server == NULL) 5069 if (server == NULL)
5122 { 5070 {
5123#if DEBUG_DHT 5071#if DEBUG_DHT
5124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: Connection to core FAILED!\n",
5125 "%s: Connection to core FAILED!\n", "dht", 5073 "dht", GNUNET_i2s (identity));
5126 GNUNET_i2s (identity));
5127#endif 5074#endif
5128 GNUNET_SCHEDULER_cancel (cleanup_task); 5075 GNUNET_SCHEDULER_cancel (cleanup_task);
5129 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 5076 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
@@ -5175,8 +5122,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
5175 * @param atsi performance data 5122 * @param atsi performance data
5176 */ 5123 */
5177static void 5124static void
5178handle_core_connect (void *cls, 5125handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
5179 const struct GNUNET_PeerIdentity *peer,
5180 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 5126 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
5181{ 5127{
5182 struct PeerInfo *ret; 5128 struct PeerInfo *ret;
@@ -5242,8 +5188,8 @@ handle_core_connect (void *cls,
5242 if ((GNUNET_CRYPTO_hash_matching_bits 5188 if ((GNUNET_CRYPTO_hash_matching_bits
5243 (&my_identity.hashPubKey, &peer->hashPubKey) > 0) && 5189 (&my_identity.hashPubKey, &peer->hashPubKey) > 0) &&
5244 (k_buckets[peer_bucket].peers_size <= bucket_size)) 5190 (k_buckets[peer_bucket].peers_size <= bucket_size))
5245 ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, 5191 ret->preference_task =
5246 ret); 5192 GNUNET_SCHEDULER_add_now (&update_core_preference, ret);
5247#endif 5193#endif
5248 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size) 5194 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size)
5249 enable_next_bucket (); 5195 enable_next_bucket ();
@@ -5251,8 +5197,7 @@ handle_core_connect (void *cls,
5251 schedule_ping_messages (); 5197 schedule_ping_messages ();
5252#endif 5198#endif
5253 newly_found_peers++; 5199 newly_found_peers++;
5254 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey, 5200 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey, ret,
5255 ret,
5256 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 5201 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
5257 increment_stats (STAT_PEERS_KNOWN); 5202 increment_stats (STAT_PEERS_KNOWN);
5258 5203
@@ -5324,8 +5269,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
5324 * @param c configuration to use 5269 * @param c configuration to use
5325 */ 5270 */
5326static void 5271static void
5327run (void *cls, 5272run (void *cls, struct GNUNET_SERVER_Handle *server,
5328 struct GNUNET_SERVER_Handle *server,
5329 const struct GNUNET_CONFIGURATION_Handle *c) 5273 const struct GNUNET_CONFIGURATION_Handle *c)
5330{ 5274{
5331 struct GNUNET_TIME_Relative next_send_time; 5275 struct GNUNET_TIME_Relative next_send_time;
@@ -5351,8 +5295,8 @@ run (void *cls,
5351 5295
5352 if (coreAPI == NULL) 5296 if (coreAPI == NULL)
5353 return; 5297 return;
5354 transport_handle = GNUNET_TRANSPORT_connect (cfg, 5298 transport_handle =
5355 NULL, NULL, NULL, NULL, NULL); 5299 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
5356 if (transport_handle != NULL) 5300 if (transport_handle != NULL)
5357 GNUNET_TRANSPORT_get_hello (transport_handle, &process_hello, NULL); 5301 GNUNET_TRANSPORT_get_hello (transport_handle, &process_hello, NULL);
5358 else 5302 else
@@ -5397,21 +5341,21 @@ run (void *cls,
5397 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_getter")) 5341 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_getter"))
5398 { 5342 {
5399 malicious_getter = GNUNET_YES; 5343 malicious_getter = GNUNET_YES;
5400 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5344 if (GNUNET_NO ==
5401 "MALICIOUS_GET_FREQUENCY", 5345 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5402 &malicious_get_frequency)) 5346 "MALICIOUS_GET_FREQUENCY",
5347 &malicious_get_frequency))
5403 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY; 5348 malicious_get_frequency = DEFAULT_MALICIOUS_GET_FREQUENCY;
5404 } 5349 }
5405 5350
5406 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5351 if (GNUNET_YES !=
5407 "MAX_HOPS", 5352 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", "MAX_HOPS", &max_hops))
5408 &max_hops))
5409 { 5353 {
5410 max_hops = DEFAULT_MAX_HOPS; 5354 max_hops = DEFAULT_MAX_HOPS;
5411 } 5355 }
5412 5356
5413 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", 5357 if (GNUNET_YES ==
5414 "USE_MAX_HOPS")) 5358 GNUNET_CONFIGURATION_get_value_yesno (cfg, "DHT", "USE_MAX_HOPS"))
5415 { 5359 {
5416 use_max_hops = GNUNET_YES; 5360 use_max_hops = GNUNET_YES;
5417 } 5361 }
@@ -5420,9 +5364,10 @@ run (void *cls,
5420 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_putter")) 5364 GNUNET_CONFIGURATION_get_value_yesno (cfg, "dht", "malicious_putter"))
5421 { 5365 {
5422 malicious_putter = GNUNET_YES; 5366 malicious_putter = GNUNET_YES;
5423 if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_number (cfg, "DHT", 5367 if (GNUNET_NO ==
5424 "MALICIOUS_PUT_FREQUENCY", 5368 GNUNET_CONFIGURATION_get_value_number (cfg, "DHT",
5425 &malicious_put_frequency)) 5369 "MALICIOUS_PUT_FREQUENCY",
5370 &malicious_put_frequency))
5426 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY; 5371 malicious_put_frequency = DEFAULT_MALICIOUS_PUT_FREQUENCY;
5427 } 5372 }
5428 5373
@@ -5570,19 +5515,21 @@ run (void *cls,
5570 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 5515 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
5571 if (GNUNET_YES == do_find_peer) 5516 if (GNUNET_YES == do_find_peer)
5572 { 5517 {
5573 next_send_time.rel_value = DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + 5518 next_send_time.rel_value =
5519 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value +
5574 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, 5520 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
5575 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 5521 (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value /
5576 2) - 5522 2) -
5577 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value); 5523 DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value);
5578 find_peer_context.start = GNUNET_TIME_absolute_get (); 5524 find_peer_context.start = GNUNET_TIME_absolute_get ();
5579 GNUNET_SCHEDULER_add_delayed (next_send_time, 5525 GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_peer_message,
5580 &send_find_peer_message, &find_peer_context); 5526 &find_peer_context);
5581 } 5527 }
5582 5528
5583 /* Scheduled the task to clean up when shutdown is called */ 5529 /* Scheduled the task to clean up when shutdown is called */
5584 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 5530 cleanup_task =
5585 &shutdown_task, NULL); 5531 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
5532 &shutdown_task, NULL);
5586} 5533}
5587 5534
5588/** 5535/**
@@ -5597,11 +5544,10 @@ main (int argc, char *const *argv)
5597{ 5544{
5598 int ret; 5545 int ret;
5599 5546
5600 ret = (GNUNET_OK == 5547 ret =
5601 GNUNET_SERVICE_run (argc, 5548 (GNUNET_OK ==
5602 argv, 5549 GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run,
5603 "dht", 5550 NULL)) ? 0 : 1;
5604 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
5605 if (NULL != recent.hashmap) 5551 if (NULL != recent.hashmap)
5606 { 5552 {
5607 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap)); 5553 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (recent.hashmap));