adm->source_peer = source_peer;
adm->destination_peer = destination_peer;
adm->trail_id = trail_id;
-
- if (trail_length > 0)
- {
- peer_list = (struct GNUNET_PeerIdentity *)&adm[1];
- memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length);
- }
+ peer_list = (struct GNUNET_PeerIdentity *)&adm[1];
+ memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * trail_length);
+
/* Send the message to chosen friend. */
GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending);
target_friend->pending_count++;
int trail_length)
{
int i;
- int lowest_index = -1;
for (i = 0; i < trail_length; i++)
{
if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i]))
- //lowest_index = i;
return i;
}
- return lowest_index;
+ return -1;
}
}
}
+static struct GNUNET_TIME_Relative next_send_time;
/*
* Choose a random friend. Calculate the next finger identity to search,from
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct FriendInfo *target_friend;
- struct GNUNET_TIME_Relative next_send_time;
+ //struct GNUNET_TIME_Relative next_send_time;
struct GNUNET_HashCode trail_id;
struct GNUNET_HashCode intermediate_trail_id;
unsigned int is_predecessor;
uint64_t finger_id_value;
-
+
/* Schedule another send_find_finger_trail_message task. */
- next_send_time.rel_value_us =
- DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
- GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us);
find_finger_trail_task =
- GNUNET_SCHEDULER_add_delayed (next_send_time, &send_find_finger_trail_message,
+ GNUNET_SCHEDULER_add_delayed (next_send_time,
+ &send_find_finger_trail_message,
NULL);
/* No space in my routing table. (Source and destination peers also store entries
i++;
}
*new_trail_length = j+1;
- GNUNET_assert((j+1) == (trail_length - 1)); //FIXME: remove it afterwards.
return new_trail;
}
}
&successor->finger_identity))
{
current_search_finger_index = 0;
+ /* We slow down the find_finger_trail_task as we have completed the circle. */
+ next_send_time = GNUNET_TIME_STD_BACKOFF(next_send_time);
+
return;
}
- struct FingerInfo *prev_finger;
- prev_finger = &finger_table[finger_table_index - 1];
+
+ struct FingerInfo prev_finger;
+ prev_finger = finger_table[finger_table_index - 1];
if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity,
- &prev_finger->finger_identity))
+ &prev_finger.finger_identity))
{
current_search_finger_index--;
return;
return peer;
}
+#if 0
+/**
+ * Check if peer is already present in the trail.
+ * @param peer
+ * @param trail
+ * @param trail_length
+ * @return
+ */
+static struct GNUNET_PeerIdentity *
+check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail,
+ unsigned int trail_length,
+ unsigned int *updated_trail_length)
+{
+ struct GNUNET_PeerIdentity *updated_trail;
+ unsigned int i;
+ unsigned int j;
+
+ /* It may happen that there are more than one peer present twice.
+ but we don't want to*/
+ for(i = 0;i < trail_length; i++)
+ {
+ for(j = i+1; j < trail_length; j++)
+ {
+ if(0 != GNUNET_CRYPTO_cmp_peer_identity (&trail[i],&trail[j]))
+ continue;
+
+ /* If you found a duplicate entry in the trail, then you should
+ * have the entry at i should point to next of entry stored at j*/
+
+ /* In case j = (trail_length - 1), then it should NULL. */
+
+ }
+ }
+}
+#endif
/*
* Core handle for PeerTrailSetupMessage.
struct GNUNET_HashCode trail_id;
unsigned int is_predecessor;
uint32_t trail_length;
+ unsigned int i;
size_t msize;
msize = ntohs (message->size);
is_predecessor = ntohl (trail_setup->is_predecessor);
intermediate_trail_id = trail_setup->intermediate_trail_id;
+ /* Did the friend insert its ID in the trail list? */
+ if (trail_length > 0 &&
+ 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer)))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
/* If I was the source and got the message back, then set trail length to 0.*/
if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source))
{
trail_length = 0;
}
- /* Did the friend insert its ID in the trail list? */
- if (trail_length > 0 &&
- 0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer)))
+ /* Check if you are present in the trail seen so far? */
+ if(trail_length > 0)
{
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
+ for (i = 0; i < trail_length ; i++)
+ {
+ if(0 == GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity))
+ {
+ //Here if you already were present in the trail. then you
+ // shoudl trail length to i + 1
+ trail_length = i+1;
+ break;
+ }
+ }
}
-
+
/* Is my routing table full? */
if (GNUNET_YES == GDS_ROUTING_threshold_reached())
{
}
#endif
+ /*TODO:URGENT Check if I am already present in the trail. If yes then its an error,
+ as in trail setup we ensure that it should never happen. */
+
/* Am I the one who initiated the query? */
if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity)))
{
&source_peer)))
{
trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer,
- trail,
- trail_length,
- &trail_src_to_curr_pred_len);
+ trail,
+ trail_length,
+ &trail_src_to_curr_pred_len);
}
else
{
/* Remove the existing successor. */
remove_existing_finger (current_successor, 0);
+ /* TODO URGENT: Check if any peer is present more than once, if yes then shorten
+ the trail. before sending it across the network. */
/* Generate a new trail id to reach to your new successor. */
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
&trail_id, sizeof (trail_id));
msize = ntohs (message->size);
/* In this message we pass the whole trail from source to destination as we
* are adding that trail.*/
+ //FIXME: failed when run with 1000 pears. check why.
if (msize < sizeof (struct PeerAddTrailMessage))
{
GNUNET_break_op (0);
/* got a first connection, good time to start with FIND FINGER TRAIL requests...*/
if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task)
+ {
+ next_send_time.rel_value_us =
+ DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+ DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us);
find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL);
+ }
}