summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-08-24 17:58:02 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-08-24 17:58:02 +0000
commit1b51c48808587b91655e5798bb81d550c3b2f1a8 (patch)
treea9de48e7965174883f4c255af6744b89280d552e /src
parent87666a4506350d93292909c37afdfe3514e86455 (diff)
Code refactoring
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c114
-rw-r--r--src/dht/gnunet_dht_profiler.c4
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 @@
#define PREDECESSOR_FINGER_ID 64
/**
- * Wrap around in peer identity circle.
- */
-#define PEER_IDENTITES_WRAP_AROUND pow(2, 64) - 1
-
-/**
* FIXME: Its use only at 3 places check if you can remove it.
* To check if a finger is predecessor or not.
*/
@@ -1705,7 +1700,6 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1,
peer1_value = GNUNET_ntohll (peer1_value);
peer2_value = GNUNET_ntohll (peer2_value);
- // TODO: Can use a simpler (to understand) idea here!
if (peer1_value == value)
{
return *peer1;
@@ -1715,32 +1709,31 @@ select_closest_finger (const struct GNUNET_PeerIdentity *peer1,
{
return *peer2;
}
-
- if (peer2_value < peer1_value)
+
+ if (value < peer1_value && peer1_value < peer2_value)
{
- if ((peer2_value < value) && (value < peer1_value))
- {
- return *peer1;
- }
- else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
- ((0 < value) && (value < peer2_value)))
- {
- return *peer2;
- }
+ return *peer1;
+ }
+ else if (value < peer2_value && peer2_value < peer1_value)
+ {
+ return *peer2;
+ }
+ else if (peer1_value < value && value < peer2_value)
+ {
+ return *peer2;
+ }
+ else if (peer2_value < value && value < peer1_value)
+ {
+ return *peer1;
+ }
+ else if (peer1_value < peer2_value && peer2_value < value)
+ {
+ return *peer1;
+ }
+ else // if (peer2_value < peer1_value && peer1_value < value)
+ {
+ return *peer2;
}
-
- //if (peer1_value < peer2_value)
- //{
- if ((peer1_value < value) && (value < peer2_value))
- {
- return *peer2;
- }
- //else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
- // ((0 < value) && (value < peer1_value)))
- //{
- return *peer1;
- //}
- // }
}
@@ -1764,37 +1757,40 @@ select_closest_predecessor (const struct GNUNET_PeerIdentity *peer1,
peer1_value = GNUNET_ntohll (peer1_value);
peer2_value = GNUNET_ntohll (peer2_value);
- if (peer1_value == value)
+ if (peer1_value == value)
+ {
return *peer1;
+ }
if (peer2_value == value)
+ {
return *peer2;
-
- if (peer1_value < peer2_value)
+ }
+
+ if (value < peer1_value && peer1_value < peer2_value)
{
- if ((peer1_value < value) && (value < peer2_value))
- {
- return *peer1;
- }
- else if (((peer2_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
- ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer1_value)))
- {
- return *peer2;
- }
+ return *peer2;
+ }
+ else if (value < peer2_value && peer2_value < peer1_value)
+ {
+ return *peer1;
+ }
+ else if (peer1_value < value && value < peer2_value)
+ {
+ return *peer1;
+ }
+ else if (peer2_value < value && value < peer1_value)
+ {
+ return *peer2;
+ }
+ else if (peer1_value < peer2_value && peer2_value < value)
+ {
+ return *peer2;
+ }
+ else // if (peer2_value < peer1_value && peer1_value < value)
+ {
+ return *peer1;
}
-
- // if (peer2_value < peer1_value)
- //{
- if ((peer2_value < value) && (value < peer1_value))
- {
- return *peer2;
- }
- //else if (((peer1_value < value) && (value < PEER_IDENTITES_WRAP_AROUND)) ||
- // ((PEER_IDENTITES_WRAP_AROUND > value) && (value < peer2_value)))
- //{
- return *peer1;
- //}
- // }
}
#if 0
@@ -2089,7 +2085,7 @@ compare_friend_and_current_closest_peer (void *cls,
* @return Updated closest_peer
*/
static struct Closest_Peer
-init_current_successor (struct GNUNET_PeerIdentity my_identity,
+init_closest_peer (struct GNUNET_PeerIdentity my_identity,
uint64_t destination_finger_value,
unsigned int is_predecessor)
{
@@ -2123,9 +2119,9 @@ find_local_best_known_next_hop (uint64_t destination_finger_value,
struct Closest_Peer current_closest_peer;
/* Initialize current_successor to my_identity. */
- current_closest_peer = init_current_successor (my_identity,
- destination_finger_value,
- is_predecessor);
+ current_closest_peer = init_closest_peer (my_identity,
+ destination_finger_value,
+ is_predecessor);
/* Compare each friend entry with current_successor and update current_successor
* 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,
successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
GNUNET_NO);
-
+ //TODO:Check if comparison is correct.
if ((start_val == val) && (count == num_peers))
{
DEBUG("CIRCLE COMPLETED after %u tries", tries);
@@ -1257,7 +1257,7 @@ main (int argc, char *const *argv)
delay_stats = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
delay_put = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1);
delay_get = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1);
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1);
+ timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3);
replication = 1; /* default replication */
rc = 0;
if (GNUNET_OK !=