aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-13 11:57:50 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-13 11:57:50 +0000
commitebb34dfd2bf39750d1f125b73af41eea3ab156d4 (patch)
treee932775c9e624d11912712b2004147d61b6eb4f7 /src/dht/gnunet-service-dht.c
parente82ae411a399b4c1089162c2ec7582caf652c010 (diff)
downloadgnunet-ebb34dfd2bf39750d1f125b73af41eea3ab156d4.tar.gz
gnunet-ebb34dfd2bf39750d1f125b73af41eea3ab156d4.zip
dce
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c129
1 files changed, 5 insertions, 124 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index a6211b39d..1b4d4f43a 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -49,10 +49,6 @@
49#include "dht.h" 49#include "dht.h"
50#include <fenv.h> 50#include <fenv.h>
51 51
52#define PRINT_TABLES GNUNET_NO
53
54#define REAL_DISTANCE GNUNET_NO
55
56#define EXTRA_CHECKS GNUNET_NO 52#define EXTRA_CHECKS GNUNET_NO
57 53
58/** 54/**
@@ -874,8 +870,6 @@ update_network_size_estimate (void *cls,
874} 870}
875 871
876 872
877
878
879/** 873/**
880 * Forward declaration. 874 * Forward declaration.
881 */ 875 */
@@ -1354,45 +1348,6 @@ find_bucket_by_peer (const struct PeerInfo *peer)
1354} 1348}
1355#endif 1349#endif
1356 1350
1357#if PRINT_TABLES
1358/**
1359 * Print the complete routing table for this peer.
1360 */
1361static void
1362print_routing_table ()
1363{
1364 int bucket;
1365 struct PeerInfo *pos;
1366 char char_buf[30000];
1367 int char_pos;
1368
1369 memset (char_buf, 0, sizeof (char_buf));
1370 char_pos = 0;
1371 char_pos +=
1372 sprintf (&char_buf[char_pos], "Printing routing table for peer %s\n",
1373 my_short_id);
1374 //fprintf(stderr, "Printing routing table for peer %s\n", my_short_id);
1375 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
1376 {
1377 pos = k_buckets[bucket].head;
1378 char_pos += sprintf (&char_buf[char_pos], "Bucket %d:\n", bucket);
1379 //fprintf(stderr, "Bucket %d:\n", bucket);
1380 while (pos != NULL)
1381 {
1382 //fprintf(stderr, "\tPeer %s, best bucket %d, %d bits match\n", GNUNET_i2s(&pos->id), find_bucket(&pos->id.hashPubKey), GNUNET_CRYPTO_hash_matching_bits(&pos->id.hashPubKey, &my_identity.hashPubKey));
1383 char_pos +=
1384 sprintf (&char_buf[char_pos],
1385 "\tPeer %s, best bucket %d, %d bits match\n",
1386 GNUNET_i2s (&pos->id), find_bucket (&pos->id.hashPubKey),
1387 GNUNET_CRYPTO_hash_matching_bits (&pos->id.hashPubKey,
1388 &my_identity.hashPubKey));
1389 pos = pos->next;
1390 }
1391 }
1392 fprintf (stderr, "%s", char_buf);
1393 fflush (stderr);
1394}
1395#endif
1396 1351
1397/** 1352/**
1398 * Find a routing table entry from a peer identity 1353 * Find a routing table entry from a peer identity
@@ -1426,6 +1381,8 @@ find_peer_by_id (const struct GNUNET_PeerIdentity *peer)
1426static void 1381static void
1427update_core_preference (void *cls, 1382update_core_preference (void *cls,
1428 const struct GNUNET_SCHEDULER_TaskContext *tc); 1383 const struct GNUNET_SCHEDULER_TaskContext *tc);
1384
1385
1429/** 1386/**
1430 * Function called with statistics about the given peer. 1387 * Function called with statistics about the given peer.
1431 * 1388 *
@@ -1613,10 +1570,6 @@ enable_next_bucket ()
1613 to_remove = GNUNET_CONTAINER_multihashmap_create (bucket_size); 1570 to_remove = GNUNET_CONTAINER_multihashmap_create (bucket_size);
1614 pos = k_buckets[lowest_bucket].head; 1571 pos = k_buckets[lowest_bucket].head;
1615 1572
1616#if PRINT_TABLES
1617 fprintf (stderr, "Printing RT before new bucket\n");
1618 print_routing_table ();
1619#endif
1620 /* Populate the array of peers which should be in the next lowest bucket */ 1573 /* Populate the array of peers which should be in the next lowest bucket */
1621 while (pos != NULL) 1574 while (pos != NULL)
1622 { 1575 {
@@ -1630,12 +1583,9 @@ enable_next_bucket ()
1630 GNUNET_CONTAINER_multihashmap_iterate (to_remove, &move_lowest_bucket, NULL); 1583 GNUNET_CONTAINER_multihashmap_iterate (to_remove, &move_lowest_bucket, NULL);
1631 GNUNET_CONTAINER_multihashmap_destroy (to_remove); 1584 GNUNET_CONTAINER_multihashmap_destroy (to_remove);
1632 lowest_bucket = lowest_bucket - 1; 1585 lowest_bucket = lowest_bucket - 1;
1633#if PRINT_TABLES
1634 fprintf (stderr, "Printing RT after new bucket\n");
1635 print_routing_table ();
1636#endif
1637} 1586}
1638 1587
1588
1639/** 1589/**
1640 * Find the closest peer in our routing table to the 1590 * Find the closest peer in our routing table to the
1641 * given hashcode. 1591 * given hashcode.
@@ -1755,70 +1705,6 @@ forward_message (const struct GNUNET_MessageHeader *msg, struct PeerInfo *peer,
1755 peer->send_task = GNUNET_SCHEDULER_add_now (&try_core_send, peer); 1705 peer->send_task = GNUNET_SCHEDULER_add_now (&try_core_send, peer);
1756} 1706}
1757 1707
1758#if DO_PING
1759/**
1760 * Task used to send ping messages to peers so that
1761 * they don't get disconnected.
1762 *
1763 * @param cls the peer to send a ping message to
1764 * @param tc context, reason, etc.
1765 */
1766static void
1767periodic_ping_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1768{
1769 struct PeerInfo *peer = cls;
1770 struct GNUNET_MessageHeader ping_message;
1771 struct DHT_MessageContext msg_ctx;
1772
1773 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1774 return;
1775
1776 ping_message.size = htons (sizeof (struct GNUNET_MessageHeader));
1777 ping_message.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_PING);
1778
1779 memset (&msg_ctx, 0, sizeof (struct DHT_MessageContext));
1780#if DEBUG_PING
1781 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s:%s Sending periodic ping to %s\n",
1782 my_short_id, "DHT", GNUNET_i2s (&peer->id));
1783#endif
1784 forward_message (&ping_message, peer, &msg_ctx);
1785 peer->ping_task =
1786 GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PING_DELAY, &periodic_ping_task,
1787 peer);
1788}
1789
1790/**
1791 * Schedule PING messages for the top X peers in each
1792 * bucket of the routing table (so core won't disconnect them!)
1793 */
1794void
1795schedule_ping_messages ()
1796{
1797 unsigned int bucket;
1798 unsigned int count;
1799 struct PeerInfo *pos;
1800
1801 for (bucket = lowest_bucket; bucket < MAX_BUCKETS; bucket++)
1802 {
1803 pos = k_buckets[bucket].head;
1804 count = 0;
1805 while (pos != NULL)
1806 {
1807 if ((count < bucket_size) && (pos->ping_task == GNUNET_SCHEDULER_NO_TASK))
1808 GNUNET_SCHEDULER_add_now (&periodic_ping_task, pos);
1809 else if ((count >= bucket_size) &&
1810 (pos->ping_task != GNUNET_SCHEDULER_NO_TASK))
1811 {
1812 GNUNET_SCHEDULER_cancel (pos->ping_task);
1813 pos->ping_task = GNUNET_SCHEDULER_NO_TASK;
1814 }
1815 pos = pos->next;
1816 count++;
1817 }
1818 }
1819}
1820#endif
1821
1822 1708
1823/** 1709/**
1824 * Task run to check for messages that need to be sent to a client. 1710 * Task run to check for messages that need to be sent to a client.
@@ -1828,11 +1714,9 @@ schedule_ping_messages ()
1828static void 1714static void
1829process_pending_messages (struct ClientList *client) 1715process_pending_messages (struct ClientList *client)
1830{ 1716{
1831 if (client->pending_head == NULL) 1717 if ( (client->pending_head == NULL) ||
1832 return; 1718 (client->transmit_handle != NULL) )
1833 if (client->transmit_handle != NULL)
1834 return; 1719 return;
1835
1836 client->transmit_handle = 1720 client->transmit_handle =
1837 GNUNET_SERVER_notify_transmit_ready (client->client_handle, 1721 GNUNET_SERVER_notify_transmit_ready (client->client_handle,
1838 ntohs (client->pending_head-> 1722 ntohs (client->pending_head->
@@ -4673,9 +4557,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
4673#endif 4557#endif
4674 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size) 4558 if ((k_buckets[lowest_bucket].peers_size) >= bucket_size)
4675 enable_next_bucket (); 4559 enable_next_bucket ();
4676#if DO_PING
4677 schedule_ping_messages ();
4678#endif
4679 newly_found_peers++; 4560 newly_found_peers++;
4680 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey, ret, 4561 GNUNET_CONTAINER_multihashmap_put (all_known_peers, &peer->hashPubKey, ret,
4681 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 4562 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);