/*
This file is part of GNUnet.
- (C) 2009-2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009-2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
#include "gnunet-service-xdht_datacache.h"
#include "gnunet-service-xdht_neighbours.h"
#include "gnunet-service-xdht_routing.h"
-#include <fenv.h>
#include "dht.h"
/**
/**
* When does the content expire?
*/
- struct GNUNET_TIME_Absolute expiration_time;
+ struct GNUNET_TIME_AbsoluteNBO expiration_time;
/**
* The key of the corresponding GET request.
* Task that sends FIND FINGER TRAIL requests. This task is started when we have
* get our first friend.
*/
-static GNUNET_SCHEDULER_TaskIdentifier find_finger_trail_task;
+static struct GNUNET_SCHEDULER_Task * find_finger_trail_task;
/**
* Task that sends verify successor message. This task is started when we get
* our successor for the first time.
*/
-static GNUNET_SCHEDULER_TaskIdentifier send_verify_successor_task;
+static struct GNUNET_SCHEDULER_Task * send_verify_successor_task;
/**
* Task that sends verify successor message. This task is started when we get
* our successor for the first time.
*/
-static GNUNET_SCHEDULER_TaskIdentifier send_verify_successor_retry_task;
+static struct GNUNET_SCHEDULER_Task * send_verify_successor_retry_task;
/**
* Task that sends verify successor message. This task is started when we get
* our successor for the first time.
*/
-static GNUNET_SCHEDULER_TaskIdentifier send_notify_new_successor_retry_task;
+static struct GNUNET_SCHEDULER_Task * send_notify_new_successor_retry_task;
/**
* Identity of this peer.
*/
unsigned int track_topology;
-/**
- * Should I be a malicious peer and drop the PUT/GET packets?
- * if 0 then NOT malicious.
- */
-unsigned int act_malicious;
-
/**
* Count of fingers found. Ideally we should have O(logn) fingers for a
* stable network.
size_t msize;
peer->th = NULL;
- while ((NULL != (pending = peer->head)) &&
- (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us))
+ while ( (NULL != (pending = peer->head)) &&
+ (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us) )
{
+ GNUNET_STATISTICS_update (GDS_stats,
+ gettext_noop
+ ("# Messages dropped (CORE timeout)"),
+ 1,
+ GNUNET_NO);
peer->pending_count--;
- GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending);
+ GNUNET_CONTAINER_DLL_remove (peer->head,
+ peer->tail,
+ pending);
GNUNET_free (pending);
}
if (NULL == pending)
{
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop
- ("# Bytes transmitted to other peers"), msize,
+ ("# Bytes transmitted to other peers"),
+ msize,
GNUNET_NO);
memcpy (&cbuf[off], pending->msg, msize);
off += msize;
}
-#if ENABLE_MALICIOUS
-/**
- * Set the ENABLE_MALICIOUS value to malicious.
- * @param malicious
- */
-int
-GDS_NEIGHBOURS_act_malicious (unsigned int malicious)
-{
- act_malicious = malicious;
- return GNUNET_OK;
-}
-#endif
-
/**
* Construct a trail setup message and forward it to target_friend
* @param source_peer Peer which wants to setup the trail
* the pointer to friend in routing table rather than gnunet_peeridentity.
* if yes then we should keep friend info in.h andmake lot of changes.
* Construct a trail teardown message and forward it to target friend.
+ *
* @param trail_id Unique identifier of the trail.
* @param trail_direction Direction of trail.
* @param target_friend Friend to get this message.
*/
void
-GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id,
+GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_HashCode *trail_id,
unsigned int trail_direction,
- struct GNUNET_PeerIdentity peer)
+ const struct GNUNET_PeerIdentity *peer)
{
struct PeerTrailTearDownMessage *ttdm;
struct P2PPendingMessage *pending;
size_t msize;
msize = sizeof (struct PeerTrailTearDownMessage);
-
if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
{
GNUNET_break (0);
return;
}
- /*FIXME:In what case friend can be null. ?*/
if (NULL == (target_friend =
- GNUNET_CONTAINER_multipeermap_get (friend_peermap, &peer)));
- return;
+ GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)))
+ {
+ /* FIXME: In what case friend can be null. ?*/
+ GNUNET_break (0);
+ return;
+ }
if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
{
pending->msg = &ttdm->header;
ttdm->header.size = htons (msize);
ttdm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN);
- ttdm->trail_id = trail_id;
+ ttdm->trail_id = *trail_id;
ttdm->trail_direction = htonl (trail_direction);
/* Send the message to chosen friend. */
void
GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
enum GNUNET_BLOCK_Type block_type,
- enum GNUNET_DHT_RouteOption options,
- uint32_t desired_replication_level,
- struct GNUNET_PeerIdentity best_known_dest,
- struct GNUNET_HashCode intermediate_trail_id,
- struct GNUNET_PeerIdentity *target_peer,
+ enum GNUNET_DHT_RouteOption options,
+ uint32_t desired_replication_level,
+ struct GNUNET_PeerIdentity best_known_dest,
+ struct GNUNET_HashCode intermediate_trail_id,
+ struct GNUNET_PeerIdentity *target_peer,
uint32_t hop_count,
uint32_t put_path_length,
struct GNUNET_PeerIdentity *put_path,
}
/* In case we are sending the request to a finger, then send across all of its
trail.*/
-#if ENABLE_MALICIOUS
- if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
- &successor.next_hop))
- {
- struct FingerInfo *next_hop_finger;
- unsigned int i;
-
- next_hop_finger = &finger_table[successor.finger_table_index];
- for (i = 0; i < next_hop_finger->trails_count; i++)
- {
- if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
- {
- if(0 == next_hop_finger->trail_list[i].trail_length)
- {
- GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
- best_known_dest, intermediate_trail_id, &next_hop,
- 0, 1, &my_identity, expiration_time,
- data, data_size);
- return;
- }
- next_hop = next_hop_finger->trail_list[i].trail_head->peer;
- GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
- best_known_dest,
- next_hop_finger->trail_list[i].trail_id,
- &next_hop, 0, 1, &my_identity,
- expiration_time,
- data, data_size);
- }
- }
- return;
- }
-#endif
GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
best_known_dest, intermediate_trail_id, &next_hop,
0, 1, &my_identity, expiration_time,
return;
}
-#if ENABLE_MALICIOUS
- struct GNUNET_PeerIdentity next_hop;
- if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
- &successor.next_hop))
- {
- struct FingerInfo *next_hop_finger;
- unsigned int i;
-
- next_hop_finger = &finger_table[successor.finger_table_index];
- for (i = 0; i < next_hop_finger->trails_count; i++)
- {
- if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
- {
- if(0 == next_hop_finger->trail_list[i].trail_length)
- {
- GDS_NEIGHBOURS_send_get (key, block_type, options,
- desired_replication_level,
- best_known_dest,intermediate_trail_id,
- &successor.next_hop,
- 0, 1, &my_identity);
- return;
- }
- next_hop = next_hop_finger->trail_list[i].trail_head->peer;
- GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
- best_known_dest,
- next_hop_finger->trail_list[i].trail_id,
- &next_hop, 0, 1, &my_identity);
- }
- }
- return;
- }
-#endif
GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
best_known_dest,intermediate_trail_id, &successor.next_hop,
0, 1, &my_identity);
/**
* Send the get result to requesting client.
+ *
* @param key Key of the requested data.
* @param type Block type
* @param target_peer Next peer to forward the message to.
if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
{
put_path_length = 0;
- msize = msize - put_path_length;
- return;
+ msize = msize - put_path_length * sizeof (struct GNUNET_PeerIdentity);
}
if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
get_result->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_GET_RESULT);
get_result->key = *key;
get_result->querying_peer = *source_peer;
- get_result->expiration_time = expiration;
+ get_result->expiration_time = GNUNET_TIME_absolute_hton (expiration);
get_result->get_path_length = htonl (get_path_length);
get_result->put_path_length = htonl (put_path_length);
paths = (struct GNUNET_PeerIdentity *)&get_result[1];
* finger identity through this random friend.
*
* @param cls closure for this task
- * @param tc the context under which the task is running
*/
static void
-send_find_finger_trail_message (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_find_finger_trail_message (void *cls)
{
struct FriendInfo *target_friend;
struct GNUNET_HashCode trail_id;
{
next_hop = GDS_ROUTING_get_next_hop (new_trail_id, GDS_ROUTING_SRC_TO_DEST);
GDS_ROUTING_remove_trail (new_trail_id);
- GDS_NEIGHBOURS_send_trail_teardown (new_trail_id,
+ GDS_NEIGHBOURS_send_trail_teardown (&new_trail_id,
GDS_ROUTING_SRC_TO_DEST,
- *next_hop);
+ next_hop);
return;
}
struct Trail *replace_trail = &finger->trail_list[largest_trail_index];
next_hop = GDS_ROUTING_get_next_hop (replace_trail->trail_id, GDS_ROUTING_SRC_TO_DEST);
GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (replace_trail->trail_id));
- GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id,
+ GDS_NEIGHBOURS_send_trail_teardown (&replace_trail->trail_id,
GDS_ROUTING_SRC_TO_DEST,
- *next_hop);
+ next_hop);
/* Free the trail. */
while (NULL != (trail_element = replace_trail->trail_head))
friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap,
&new_trail[0]);
}
-
+ GNUNET_assert (NULL != friend);
friend->trails_count++;
for (i = 0; i < new_trail_length; i++)
{
}
GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id));
friend->trails_count--;
- GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id,
+ GDS_NEIGHBOURS_send_trail_teardown (&trail->trail_id,
GDS_ROUTING_SRC_TO_DEST,
- friend->id);
+ &friend->id);
}
send_all_finger_trails_teardown (struct FingerInfo *finger)
{
unsigned int i;
+
for (i = 0; i < finger->trails_count; i++)
{
struct Trail *trail;
+
trail = &finger->trail_list[i];
- if (GNUNET_YES == trail->is_present);
+ if (GNUNET_YES == trail->is_present)
{
send_trail_teardown (finger, trail);
trail->is_present = GNUNET_NO;
* Periodic task to verify current successor. There can be multiple trails to reach
* to successor, choose the shortest one and send verify successor message
* across that trail.
+ *
* @param cls closure for this task
- * @param tc the context under which the task is running
*/
static void
-send_verify_successor_message (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_verify_successor_message (void *cls)
{
struct FriendInfo *target_friend;
struct GNUNET_HashCode trail_id;
successor = &finger_table[0];
/* This task will be scheduled when the result for Verify Successor is received. */
- send_verify_successor_task = GNUNET_SCHEDULER_NO_TASK;
+ send_verify_successor_task = NULL;
/* When verify successor is being called for first time *for current context*
* cls will be NULL. If send_verify_successor_retry_task is not NO_TASK, we
* --> Waiting for notify confirmation. again don't wait for it. notify
* confirmation will not succeded.
*/
- if (send_verify_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
+ if (send_verify_successor_retry_task != NULL)
{
/* FIXME: Are we scheduling retry task as soon as we send verify message.
If yes then here before making this task, first check if the message
trail_id = trail->trail_id;
if (NULL == GDS_ROUTING_get_next_hop(trail_id,GDS_ROUTING_SRC_TO_DEST))
{
- DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line",
- GNUNET_i2s(&my_identity), GNUNET_h2s(&trail->trail_id), __LINE__);
+ DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u",
+ GNUNET_i2s (&my_identity),
+ GNUNET_h2s (&trail->trail_id),
+ __LINE__);
GNUNET_break(0);
return;
}
current_search_finger_index = PREDECESSOR_FINGER_ID;
if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &successor->finger_identity))
{
- if (GNUNET_SCHEDULER_NO_TASK == send_verify_successor_task)
+ if (NULL == send_verify_successor_task)
{
send_verify_successor_task =
GNUNET_SCHEDULER_add_now (&send_verify_successor_message, NULL);
finger, and free the finger. */
send_all_finger_trails_teardown (existing_finger);
free_finger (existing_finger, finger_table_index);
- return;
}
if (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &my_identity))
{
if (finger_trail_length > 0)
- GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id,
+ GDS_NEIGHBOURS_send_trail_teardown (&finger_trail_id,
GDS_ROUTING_SRC_TO_DEST,
- finger_trail[0]);
+ &finger_trail[0]);
else
- GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id,
+ GDS_NEIGHBOURS_send_trail_teardown (&finger_trail_id,
GDS_ROUTING_SRC_TO_DEST,
- finger_identity);
+ &finger_identity);
}
}
}
struct GNUNET_PeerIdentity best_known_dest;
struct GNUNET_HashCode received_intermediate_trail_id;
struct GNUNET_HashCode intermediate_trail_id;
- struct GNUNET_PeerIdentity *next_hop;
+ struct GNUNET_PeerIdentity next_hop;
struct GNUNET_PeerIdentity *next_routing_hop;
enum GNUNET_DHT_RouteOption options;
struct GNUNET_HashCode test_key;
GNUNET_break_op (0);
return GNUNET_OK;
}
-#if ENABLE_MALICIOUS
- if(1 == act_malicious)
- {
- DEBUG("\n I AM MALICIOUS PUT_REQUEST_DROPPED for key = %ss",GNUNET_h2s(&put->key));
- return GNUNET_OK;
- }
-#endif
GNUNET_STATISTICS_update (GDS_stats,
gettext_noop
("# Bytes received from other peers"), (int64_t) msize,
{
switch (GNUNET_BLOCK_evaluate (GDS_block_context,
ntohl (put->block_type),
+ GNUNET_BLOCK_EO_NONE,
NULL, /* query */
NULL, 0, /* bloom filer */
NULL, 0, /* xquery */
key_value = GNUNET_ntohll (key_value);
successor = find_local_best_known_next_hop (key_value,
GDS_FINGER_TYPE_NON_PREDECESSOR);
- next_hop = GNUNET_new (struct GNUNET_PeerIdentity);
- *next_hop = successor.next_hop;
+ next_hop = successor.next_hop;
intermediate_trail_id = successor.trail_id;
best_known_dest = successor.best_known_destination;
GDS_ROUTING_SRC_TO_DEST);
if (NULL != next_routing_hop)
{
- next_hop = next_routing_hop;
+ next_hop = *next_routing_hop;
intermediate_trail_id = received_intermediate_trail_id;
best_known_dest = current_best_known_dest;
}
&(put->key),putlen, pp, ntohl (put->block_type),
payload_size, payload);
}
- else
- {
-#if ENABLE_MALICIOUS
- if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
- &successor.next_hop))
- {
- struct FingerInfo *next_hop_finger;
- unsigned int i;
-
- next_hop_finger = &finger_table[successor.finger_table_index];
- for (i = 0; i < next_hop_finger->trails_count; i++)
- {
- if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
- {
- if(0 == next_hop_finger->trail_list[i].trail_length)
- {
- GDS_NEIGHBOURS_send_put (&put->key,
- ntohl (put->block_type),ntohl (put->options),
- ntohl (put->desired_replication_level),
- best_known_dest, intermediate_trail_id, next_hop,
- hop_count, putlen, pp,
- GNUNET_TIME_absolute_ntoh (put->expiration_time),
- payload, payload_size);
- return GNUNET_OK;
- }
- next_hop = &next_hop_finger->trail_list[i].trail_head->peer;
- GDS_NEIGHBOURS_send_put (&put->key,
- ntohl (put->block_type),ntohl (put->options),
- ntohl (put->desired_replication_level),
- best_known_dest,
- next_hop_finger->trail_list[i].trail_id,
- next_hop, hop_count, putlen, pp,
- GNUNET_TIME_absolute_ntoh (put->expiration_time),
- payload, payload_size);
- }
- }
- return GNUNET_OK;
- }
-#endif
GDS_NEIGHBOURS_send_put (&put->key,
ntohl (put->block_type),ntohl (put->options),
ntohl (put->desired_replication_level),
- best_known_dest, intermediate_trail_id, next_hop,
+ best_known_dest, intermediate_trail_id, &next_hop,
hop_count, putlen, pp,
GNUNET_TIME_absolute_ntoh (put->expiration_time),
payload, payload_size);
- }
return GNUNET_OK;
}
struct GNUNET_HashCode intermediate_trail_id;
struct GNUNET_HashCode received_intermediate_trail_id;
struct Closest_Peer successor;
- struct GNUNET_PeerIdentity *next_hop;
+ struct GNUNET_PeerIdentity next_hop;
struct GNUNET_PeerIdentity *next_routing_hop;
uint32_t get_length;
uint64_t key_value;
return GNUNET_YES;
}
-#if ENABLE_MALICIOUS
- if(1 == act_malicious)
- {
- DEBUG("I am malicious,GET_REQUEST_DROPPED for key = %s. \n",GNUNET_h2s(&get->key));
- return GNUNET_OK;
- }
-#endif
current_best_known_dest = get->best_known_destination;
received_intermediate_trail_id = get->intermediate_trail_id;
get_path = (const struct GNUNET_PeerIdentity *)&get[1];
successor = find_local_best_known_next_hop (key_value,
GDS_FINGER_TYPE_NON_PREDECESSOR);
- next_hop = GNUNET_new (struct GNUNET_PeerIdentity);
- *next_hop = successor.next_hop;
+ next_hop = successor.next_hop;
best_known_dest = successor.best_known_destination;
intermediate_trail_id = successor.trail_id;
/* I am not the final destination. I am part of trail to reach final dest. */
GDS_ROUTING_SRC_TO_DEST);
if (NULL != next_routing_hop)
{
- next_hop = next_routing_hop;
+ next_hop = *next_routing_hop;
best_known_dest = current_best_known_dest;
intermediate_trail_id = received_intermediate_trail_id;
}
else
{
-#if ENABLE_MALICIOUS
- if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
- &successor.next_hop))
- {
- struct FingerInfo *next_hop_finger;
- unsigned int i;
-
- next_hop_finger = &finger_table[successor.finger_table_index];
- for (i = 0; i < next_hop_finger->trails_count; i++)
- {
- if(0 == next_hop_finger->trail_list[i].trail_length)
- {
- GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
- get->desired_replication_level, best_known_dest,
- intermediate_trail_id, next_hop, hop_count,
- get_length, gp);
- return GNUNET_OK;
- }
- if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
- {
- next_hop = &next_hop_finger->trail_list[i].trail_head->peer;
- GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
- get->desired_replication_level, best_known_dest,
- next_hop_finger->trail_list[i].trail_id,
- next_hop, hop_count,
- get_length, gp);
- }
- }
- return GNUNET_OK;
- }
-#endif
GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
get->desired_replication_level, best_known_dest,
- intermediate_trail_id, next_hop, hop_count,
+ intermediate_trail_id, &next_hop, hop_count,
get_length, gp);
}
return GNUNET_YES;
if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &(get_path[0]))))
{
- GDS_CLIENTS_handle_reply (get_result->expiration_time, &(get_result->key),
+ GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (get_result->expiration_time),
+ &(get_result->key),
getlen, get_path, putlen,
put_path, get_result->type, payload_size, payload);
return GNUNET_YES;
GDS_NEIGHBOURS_send_get_result (&(get_result->key), get_result->type,
&get_path[current_path_index - 1],
&(get_result->querying_peer), putlen, put_path,
- getlen, get_path, get_result->expiration_time,
+ getlen, get_path,
+ GNUNET_TIME_absolute_ntoh (get_result->expiration_time),
payload, payload_size);
return GNUNET_YES;
}
struct GNUNET_PeerIdentity *trail_list;
unsigned int i;
- trail = GNUNET_new (struct Trail);
-
/* Get the shortest trail to reach to current successor. */
for (i = 0; i < finger->trails_count; i++)
{
struct FingerInfo *current_predecessor;
int i;
unsigned int j;
+ unsigned int len;
current_predecessor = &finger_table[PREDECESSOR_FINGER_ID];
/* Check if trail_src_to_me contains current_predecessor. */
for (i = 0; i < trail_src_to_me_len; i++)
{
- if(0 != GNUNET_CRYPTO_cmp_peer_identity(&trail_src_to_me[i],
- ¤t_predecessor->finger_identity))
- continue;
+ if (0 != GNUNET_CRYPTO_cmp_peer_identity(&trail_src_to_me[i],
+ ¤t_predecessor->finger_identity))
+ continue;
*trail_src_to_curr_pred_length = i;
trail_src_to_curr_pred = GNUNET_malloc (*trail_src_to_curr_pred_length *
sizeof(struct GNUNET_PeerIdentity));
- for(j = 0; j < i;j++)
+ for (j = 0; j < i; j++)
trail_src_to_curr_pred[j] = trail_src_to_me[j];
return trail_src_to_curr_pred;
}
&trail_me_to_curr_pred_length);
/* Check if trail contains the source_peer. */
- for(i = trail_me_to_curr_pred_length - 1; i >= 0; i--)
+ for (i = trail_me_to_curr_pred_length - 1; i >= 0; i--)
{
- if(0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer,
- &trail_me_to_curr_pred[i]))
+ if (0 != GNUNET_CRYPTO_cmp_peer_identity (&source_peer,
+ &trail_me_to_curr_pred[i]))
continue;
- /* Source is NOT part of trail. */
- i = i+1;
-
- /* Source is the last element in the trail to reach to my pred.
- Source is direct friend of the pred. */
- if (trail_me_to_curr_pred_length == i)
- {
- *trail_src_to_curr_pred_length = 0;
- return NULL;
- }
-
- *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i;
- trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)*
- *trail_src_to_curr_pred_length);
-
- for(j = 0; j < *trail_src_to_curr_pred_length; i++,j++)
- {
- trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i];
- }
- GNUNET_free_non_null(trail_me_to_curr_pred);
- return trail_src_to_curr_pred;
+ /* Source is NOT part of trail. */
+ i++;
+
+ /* Source is the last element in the trail to reach to my pred.
+ Source is direct friend of the pred. */
+ if (trail_me_to_curr_pred_length == i)
+ {
+ *trail_src_to_curr_pred_length = 0;
+ GNUNET_free_non_null (trail_me_to_curr_pred);
+ return NULL;
+ }
+
+ *trail_src_to_curr_pred_length = trail_me_to_curr_pred_length - i;
+ trail_src_to_curr_pred = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)*
+ *trail_src_to_curr_pred_length);
+
+ for (j = 0; j < *trail_src_to_curr_pred_length; i++,j++)
+ trail_src_to_curr_pred[j] = trail_me_to_curr_pred[i];
+ GNUNET_free_non_null (trail_me_to_curr_pred);
+ return trail_src_to_curr_pred;
}
- unsigned int len;
trail_src_to_curr_pred = check_for_duplicate_entries (trail_src_to_me,
trail_src_to_me_len,
trail_me_to_curr_pred,
unsigned int num_retries_scheduled;
};
+
void
-send_notify_new_successor (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext
- * tc);
+send_notify_new_successor (void *cls);
+
/**
* Check if the peer which sent us verify successor result message is still ours
GNUNET_STATISTICS_set (GDS_stats, key, succ, 0);
GNUNET_free (key);
}
- if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK)
+ if (send_verify_successor_task == NULL)
send_verify_successor_task =
GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time,
&send_verify_successor_message,
successor_times--;
- if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK)
+ if (send_verify_successor_task == NULL)
send_verify_successor_task =
GNUNET_SCHEDULER_add_delayed(verify_successor_next_send_time,
&send_verify_successor_message,
notify_ctx->succesor_trail_id = trail_id;
notify_ctx->target_friend = target_friend;
notify_ctx->num_retries_scheduled = 0;
+ GNUNET_free_non_null (trail_me_to_probable_succ);
// TODO: Check if we should verify before schedule if already scheduled.
GNUNET_SCHEDULER_add_now(&send_notify_new_successor, (void*)notify_ctx);
-
- return;
}
void
-send_notify_new_successor (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext
- * tc)
+send_notify_new_successor (void *cls)
{
- struct SendNotifyContext *ctx = (struct SendNotifyContext *) cls;
+ struct SendNotifyContext *ctx = cls;
GDS_NEIGHBOURS_send_notify_new_successor (ctx->source_peer,
ctx->successor,
ctx->target_friend);
if (0 == ctx->num_retries_scheduled &&
- send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
+ send_notify_new_successor_retry_task != NULL)
{
// Result from previous notify successos hasn't arrived, so the retry task
// hasn't been cancelled! Already a new notify successor must be called.
old_notify_ctx = GNUNET_SCHEDULER_cancel(send_notify_new_successor_retry_task);
GNUNET_free (old_notify_ctx->successor_trail);
GNUNET_free (old_notify_ctx);
- send_notify_new_successor_retry_task = GNUNET_SCHEDULER_NO_TASK;
+ send_notify_new_successor_retry_task = NULL;
}
ctx->num_retries_scheduled++;
if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity)))
{
/* Cancel Retry Task */
- if (GNUNET_SCHEDULER_NO_TASK != send_verify_successor_retry_task)
+ if (NULL != send_verify_successor_retry_task)
{
struct VerifySuccessorContext *ctx;
ctx = GNUNET_SCHEDULER_cancel(send_verify_successor_retry_task);
GNUNET_free(ctx);
- send_verify_successor_retry_task = GNUNET_SCHEDULER_NO_TASK;
+ send_verify_successor_retry_task = NULL;
}
compare_and_update_successor (current_successor,
probable_successor, trail, trail_length);
{
/* Here it may happen that source peer has found a new successor, and removed
the trail, Hence no entry found in the routing table. Fail silently.*/
- DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line",
- GNUNET_i2s(&my_identity), GNUNET_h2s(&trail_id), __LINE__);
+ DEBUG (" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u",
+ GNUNET_i2s (&my_identity),
+ GNUNET_h2s (&trail_id),
+ __LINE__);
GNUNET_break_op(0);
return GNUNET_OK;
}
compare_and_update_predecessor (source, trail, trail_length);
target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer);
+ GNUNET_assert (NULL != target_friend);
GDS_NEIGHBOURS_send_notify_succcessor_confirmation (trail_id,
GDS_ROUTING_DEST_TO_SRC,
target_friend);
*/
// TODO: cancel schedule of notify_successor_retry_task
- if (send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
+ if (send_notify_new_successor_retry_task != NULL)
{
struct SendNotifyContext *notify_ctx;
notify_ctx = GNUNET_SCHEDULER_cancel(send_notify_new_successor_retry_task);
GNUNET_free (notify_ctx->successor_trail);
GNUNET_free (notify_ctx);
- send_notify_new_successor_retry_task = GNUNET_SCHEDULER_NO_TASK;
+ send_notify_new_successor_retry_task = NULL;
}
- if (send_verify_successor_task == GNUNET_SCHEDULER_NO_TASK)
+ if (send_verify_successor_task == NULL)
{
verify_successor_next_send_time.rel_value_us =
DHT_SEND_VERIFY_SUCCESSOR_INTERVAL.rel_value_us +
next_hop = GDS_ROUTING_get_next_hop (trail_id, trail_direction);
if (NULL == next_hop)
{
- DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line",
- GNUNET_i2s(&my_identity), GNUNET_h2s(&trail_id), __LINE__);
+ DEBUG(" NO ENTRY FOUND IN %s ROUTING TABLE for trail id %s, line %u",
+ GNUNET_i2s (&my_identity),
+ GNUNET_h2s(&trail_id),
+ __LINE__);
GNUNET_break (0);
return GNUNET_SYSERR;
}
/* If not final destination, then send a trail teardown message to next hop.*/
GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop));
GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id));
- GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, *next_hop);
+ GDS_NEIGHBOURS_send_trail_teardown (&trail_id, trail_direction, next_hop);
}
return GNUNET_OK;
if (0 != GNUNET_CONTAINER_multipeermap_size (friend_peermap))
return;
- if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task)
+ if (NULL != find_finger_trail_task)
{
GNUNET_SCHEDULER_cancel (find_finger_trail_task);
- find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK;
+ find_finger_trail_task = NULL;
}
else
GNUNET_break (0);
* selected after some time out. This is to ensure that both peers have added
* each other as their friend. */
/* Got a first connection, good time to start with FIND FINGER TRAIL requests...*/
- if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task)
+ if (NULL == find_finger_trail_task)
{
find_finger_trail_task = GNUNET_SCHEDULER_add_now (&send_find_finger_trail_message, NULL);
}
{NULL, 0, 0}
};
-#if ENABLE_MALICIOUS
- act_malicious = 0;
-#endif
-
core_api =
GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect,
&handle_core_disconnect, NULL, GNUNET_NO, NULL,
GNUNET_CONTAINER_multipeermap_destroy (friend_peermap);
friend_peermap = NULL;
- if (GNUNET_SCHEDULER_NO_TASK != find_finger_trail_task)
+ if (NULL != find_finger_trail_task)
{
GNUNET_SCHEDULER_cancel (find_finger_trail_task);
- find_finger_trail_task = GNUNET_SCHEDULER_NO_TASK;
+ find_finger_trail_task = NULL;
}
- if (GNUNET_SCHEDULER_NO_TASK != send_verify_successor_task)
+ if (NULL != send_verify_successor_task)
{
GNUNET_SCHEDULER_cancel (send_verify_successor_task);
- send_verify_successor_task = GNUNET_SCHEDULER_NO_TASK;
+ send_verify_successor_task = NULL;
}
- if (GNUNET_SCHEDULER_NO_TASK != send_verify_successor_retry_task)
+ if (NULL != send_verify_successor_retry_task)
{
struct VerifySuccessorContext *ctx;
ctx = GNUNET_SCHEDULER_cancel (send_verify_successor_retry_task);
GNUNET_free(ctx);
- send_verify_successor_retry_task = GNUNET_SCHEDULER_NO_TASK;
+ send_verify_successor_retry_task = NULL;
}
- if (send_notify_new_successor_retry_task != GNUNET_SCHEDULER_NO_TASK)
+ if (send_notify_new_successor_retry_task != NULL)
{
struct SendNotifyContext *notify_ctx;
notify_ctx = GNUNET_SCHEDULER_cancel(send_notify_new_successor_retry_task);
GNUNET_free (notify_ctx->successor_trail);
GNUNET_free (notify_ctx);
- send_notify_new_successor_retry_task = GNUNET_SCHEDULER_NO_TASK;
+ send_notify_new_successor_retry_task = NULL;
}
}