diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-24 17:58:02 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-24 17:58:02 +0000 |
commit | 1b51c48808587b91655e5798bb81d550c3b2f1a8 (patch) | |
tree | a9de48e7965174883f4c255af6744b89280d552e /src/dht | |
parent | 87666a4506350d93292909c37afdfe3514e86455 (diff) | |
download | gnunet-1b51c48808587b91655e5798bb81d550c3b2f1a8.tar.gz gnunet-1b51c48808587b91655e5798bb81d550c3b2f1a8.zip |
Code refactoring
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 114 | ||||
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 4 |
2 files changed, 57 insertions, 61 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index b607bb0ec..332156d00 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -126,11 +126,6 @@ | |||
126 | #define PREDECESSOR_FINGER_ID 64 | 126 | #define PREDECESSOR_FINGER_ID 64 |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Wrap around in peer identity circle. | ||
130 | */ | ||
131 | #define PEER_IDENTITES_WRAP_AROUND pow(2, 64) - 1 | ||
132 | |||
133 | /** | ||
134 | * FIXME: Its use only at 3 places check if you can remove it. | 129 | * FIXME: Its use only at 3 places check if you can remove it. |
135 | * To check if a finger is predecessor or not. | 130 | * To check if a finger is predecessor or not. |
136 | */ | 131 | */ |
@@ -1705,7 +1700,6 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1, | |||
1705 | peer1_value = GNUNET_ntohll (peer1_value); | 1700 | peer1_value = GNUNET_ntohll (peer1_value); |
1706 | peer2_value = GNUNET_ntohll (peer2_value); | 1701 | peer2_value = GNUNET_ntohll (peer2_value); |
1707 | 1702 | ||
1708 | // TODO: Can use a simpler (to understand) idea here! | ||
1709 | if (peer1_value == value) | 1703 | if (peer1_value == value) |
1710 | { | 1704 | { |
1711 | return *peer1; | 1705 | return *peer1; |
@@ -1715,32 +1709,31 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1, | |||
1715 | { | 1709 | { |
1716 | return *peer2; | 1710 | return *peer2; |
1717 | } | 1711 | } |
1718 | 1712 | ||
1719 | if (peer2_value < peer1_value) | 1713 | if (value < peer1_value && peer1_value < peer2_value) |
1720 | { | 1714 | { |
1721 | if ((peer2_value < value) && (value < peer1_value)) | 1715 | return *peer1; |
1722 | { | 1716 | } |
1723 | return *peer1; | 1717 | else if (value < peer2_value && peer2_value < peer1_value) |
1724 | } | 1718 | { |
1725 | else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || | 1719 | return *peer2; |
1726 | ((0 < value) && (value < peer2_value))) | 1720 | } |
1727 | { | 1721 | else if (peer1_value < value && value < peer2_value) |
1728 | return *peer2; | 1722 | { |
1729 | } | 1723 | return *peer2; |
1724 | } | ||
1725 | else if (peer2_value < value && value < peer1_value) | ||
1726 | { | ||
1727 | return *peer1; | ||
1728 | } | ||
1729 | else if (peer1_value < peer2_value && peer2_value < value) | ||
1730 | { | ||
1731 | return *peer1; | ||
1732 | } | ||
1733 | else // if (peer2_value < peer1_value && peer1_value < value) | ||
1734 | { | ||
1735 | return *peer2; | ||
1730 | } | 1736 | } |
1731 | |||
1732 | //if (peer1_value < peer2_value) | ||
1733 | //{ | ||
1734 | if ((peer1_value < value) && (value < peer2_value)) | ||
1735 | { | ||
1736 | return *peer2; | ||
1737 | } | ||
1738 | //else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || | ||
1739 | // ((0 < value) && (value < peer1_value))) | ||
1740 | //{ | ||
1741 | return *peer1; | ||
1742 | //} | ||
1743 | // } | ||
1744 | } | 1737 | } |
1745 | 1738 | ||
1746 | 1739 | ||
@@ -1764,37 +1757,40 @@ select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1, | |||
1764 | peer1_value = GNUNET_ntohll (peer1_value); | 1757 | peer1_value = GNUNET_ntohll (peer1_value); |
1765 | peer2_value = GNUNET_ntohll (peer2_value); | 1758 | peer2_value = GNUNET_ntohll (peer2_value); |
1766 | 1759 | ||
1767 | if (peer1_value == value) | 1760 | if (peer1_value == value) |
1761 | { | ||
1768 | return *peer1; | 1762 | return *peer1; |
1763 | } | ||
1769 | 1764 | ||
1770 | if (peer2_value == value) | 1765 | if (peer2_value == value) |
1766 | { | ||
1771 | return *peer2; | 1767 | return *peer2; |
1772 | 1768 | } | |
1773 | if (peer1_value < peer2_value) | 1769 | |
1770 | if (value < peer1_value && peer1_value < peer2_value) | ||
1774 | { | 1771 | { |
1775 | if ((peer1_value < value) && (value < peer2_value)) | 1772 | return *peer2; |
1776 | { | 1773 | } |
1777 | return *peer1; | 1774 | else if (value < peer2_value && peer2_value < peer1_value) |
1778 | } | 1775 | { |
1779 | else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || | 1776 | return *peer1; |
1780 | ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer1_value))) | 1777 | } |
1781 | { | 1778 | else if (peer1_value < value && value < peer2_value) |
1782 | return *peer2; | 1779 | { |
1783 | } | 1780 | return *peer1; |
1781 | } | ||
1782 | else if (peer2_value < value && value < peer1_value) | ||
1783 | { | ||
1784 | return *peer2; | ||
1785 | } | ||
1786 | else if (peer1_value < peer2_value && peer2_value < value) | ||
1787 | { | ||
1788 | return *peer2; | ||
1789 | } | ||
1790 | else // if (peer2_value < peer1_value && peer1_value < value) | ||
1791 | { | ||
1792 | return *peer1; | ||
1784 | } | 1793 | } |
1785 | |||
1786 | // if (peer2_value < peer1_value) | ||
1787 | //{ | ||
1788 | if ((peer2_value < value) && (value < peer1_value)) | ||
1789 | { | ||
1790 | return *peer2; | ||
1791 | } | ||
1792 | //else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) || | ||
1793 | // ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer2_value))) | ||
1794 | //{ | ||
1795 | return *peer1; | ||
1796 | //} | ||
1797 | // } | ||
1798 | } | 1794 | } |
1799 | 1795 | ||
1800 | #if 0 | 1796 | #if 0 |
@@ -2089,7 +2085,7 @@ compare_friend_and_current_closest_peer (void *cls, | |||
2089 | * @return Updated closest_peer | 2085 | * @return Updated closest_peer |
2090 | */ | 2086 | */ |
2091 | static struct Closest_Peer | 2087 | static struct Closest_Peer |
2092 | init_current_successor (struct GNUNET_PeerIdentity my_identity, | 2088 | init_closest_peer (struct GNUNET_PeerIdentity my_identity, |
2093 | uint64_t destination_finger_value, | 2089 | uint64_t destination_finger_value, |
2094 | unsigned int is_predecessor) | 2090 | unsigned int is_predecessor) |
2095 | { | 2091 | { |
@@ -2123,9 +2119,9 @@ find_local_best_known_next_hop (uint64_t destination_finger_value, | |||
2123 | struct Closest_Peer current_closest_peer; | 2119 | struct Closest_Peer current_closest_peer; |
2124 | 2120 | ||
2125 | /* Initialize current_successor to my_identity. */ | 2121 | /* Initialize current_successor to my_identity. */ |
2126 | current_closest_peer = init_current_successor (my_identity, | 2122 | current_closest_peer = init_closest_peer (my_identity, |
2127 | destination_finger_value, | 2123 | destination_finger_value, |
2128 | is_predecessor); | 2124 | is_predecessor); |
2129 | 2125 | ||
2130 | /* Compare each friend entry with current_successor and update current_successor | 2126 | /* Compare each friend entry with current_successor and update current_successor |
2131 | * with friend if its closest. */ | 2127 | * with friend if its closest. */ |
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 5c5479f96..bc6a08ebc 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -913,7 +913,7 @@ successor_stats_cont (void *cls, | |||
913 | 913 | ||
914 | successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, | 914 | successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, |
915 | GNUNET_NO); | 915 | GNUNET_NO); |
916 | 916 | //TODO:Check if comparison is correct. | |
917 | if ((start_val == val) && (count == num_peers)) | 917 | if ((start_val == val) && (count == num_peers)) |
918 | { | 918 | { |
919 | DEBUG("CIRCLE COMPLETED after %u tries", tries); | 919 | DEBUG("CIRCLE COMPLETED after %u tries", tries); |
@@ -1257,7 +1257,7 @@ main (int argc, char *const *argv) | |||
1257 | delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 1257 | delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); |
1258 | delay_put = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1); | 1258 | delay_put = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1); |
1259 | delay_get = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); | 1259 | delay_get = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); |
1260 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); | 1260 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3); |
1261 | replication = 1; /* default replication */ | 1261 | replication = 1; /* default replication */ |
1262 | rc = 0; | 1262 | rc = 0; |
1263 | if (GNUNET_OK != | 1263 | if (GNUNET_OK != |