* @author Christian Grothoff
* @author Nathan Evans
*
- * TODO: The gossip rates need to be worked out. Probably many other things
- * as well.
- *
*/
#include "platform.h"
#include "gnunet_client_lib.h"
#include "gnunet_hello_lib.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_crypto_lib.h"
+#include "gnunet_statistics_service.h"
#include "dv.h"
/**
*/
static const struct GNUNET_CONFIGURATION_Handle *cfg;
-/**
- * The scheduler for this service.
- */
-static struct GNUNET_SCHEDULER_Handle *sched;
/**
* The client, the DV plugin connected to us. Hopefully
*/
static void
try_core_send (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PendingMessage *pending;
pending = core_pending_head;
if (core_transmit_handle != NULL)
return; /* Message send already in progress */
- if (pending != NULL)
- core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, pending->importance, pending->timeout, &pending->recipient, pending->msg_size, &core_transmit_notify, NULL);
+ if ((pending != NULL) && (coreAPI != NULL))
+ core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI,
+ GNUNET_YES,
+ pending->importance,
+ pending->timeout,
+ &pending->recipient,
+ pending->msg_size,
+ &core_transmit_notify, NULL);
}
+
/**
* Function called to notify a client about the socket
* being ready to queue more data. "buf" will be
}
/*reply = core_pending_head;*/
- GNUNET_SCHEDULER_add_now(sched, &try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now(&try_core_send, NULL);
/*if (reply != NULL)
- core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL);*/
+ core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL);*/
return off;
}
core_pending_tail,
pending_message);
- GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now(try_core_send, NULL);
return GNUNET_YES;
}
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient));
#endif
- GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now(try_core_send, NULL);
return (int) cost;
}
}
#endif
+/**
+ * Get distance information from 'atsi'.
+ *
+ * @param atsi performance data
+ * @return connected transport distance
+ */
+static uint32_t
+get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) )
+ atsi++;
+ if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+ {
+ GNUNET_break (0);
+ /* FIXME: we do not have distance data? Assume direct neighbor. */
+ return DIRECT_NEIGHBOR_COST;
+ }
+ return ntohl (atsi->value);
+}
+
+/**
+ * Find latency information in 'atsi'.
+ *
+ * @param atsi performance data
+ * @return connection latency
+ */
+static struct GNUNET_TIME_Relative
+get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+ while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+ (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) )
+ atsi++;
+ if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+ {
+ GNUNET_break (0);
+ /* how can we not have latency data? */
+ return GNUNET_TIME_UNIT_SECONDS;
+ }
+ /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */
+ return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, ntohl (atsi->value));
+}
/**
* Core handler for dv data messages. Whatever this message
* @param cls closure
* @param peer peer which sent the message (immediate sender)
* @param message the message
- * @param latency the latency of the connection we received the message from
- * @param distance the distance to the immediate peer
- */
-static int handle_dv_data_message (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+ * @param atsi transport ATS information (latency, distance, etc.)
+ */
+static int
+handle_dv_data_message (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ const struct GNUNET_MessageHeader * message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
const struct GNUNET_MessageHeader *packed_message;
int ret;
size_t packed_message_size;
char *cbuf;
+ uint32_t distance; /* Distance information */
+ struct GNUNET_TIME_Relative latency; /* Latency information */
packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data);
#if DEBUG_DV
if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
{
-
#if DEBUG_DV
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"`%s': Message sizes don't add up, total size %u, expected at least %u!\n", "dv service", ntohs(incoming->header.size), sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader));
return GNUNET_SYSERR;
}
+ /* Iterate over ATS_Information to get distance and latency */
+ latency = get_atsi_latency(atsi);
+ distance = get_atsi_distance(atsi);
dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
&peer->hashPubKey);
if (dn == NULL)
pos = pos->next;
}
#endif
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "%s: unknown sender (%u), Message uid %u from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity));
found_pos = -1;
for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++)
if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity)))
{
/* FIXME: create stat: routing loop-discard! */
-#if DEBUG_DV_PEER_NUMBERS
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\n\n\nLoopy loo message\n\n\n");
-#endif
#if DEBUG_DV_MESSAGES
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
#endif
#if DELAY_FORWARDS
- if (GNUNET_TIME_absolute_get_duration(pos->last_gossip).value < GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2).value)
+ if (GNUNET_TIME_absolute_get_duration(pos->last_gossip).abs_value < GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2).abs_value)
{
delayed_context = GNUNET_malloc(sizeof(struct DelayedMessageContext));
memcpy(&delayed_context->dest, destination, sizeof(struct GNUNET_PeerIdentity));
memcpy(delayed_context->message, packed_message, packed_message_size);
delayed_context->message_size = packed_message_size;
delayed_context->uid = ntohl(incoming->uid);
- GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2500), &send_message_delayed, delayed_context);
+ GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2500), &send_message_delayed, delayed_context);
return GNUNET_OK;
}
else
else
{
#if DEBUG_MESSAGE_DROP
- direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity));
+ char *direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s: DROPPING MESSAGE type %d, forwarding failed! Message immediately from %s!\n", GNUNET_i2s(&my_identity), ntohs(((struct GNUNET_MessageHeader *)&incoming[1])->type), direct_id);
+ GNUNET_free (direct_id);
#endif
return GNUNET_SYSERR;
}
*/
int print_neighbors (void *cls,
const GNUNET_HashCode * key,
- void *value)
+ void *abs_value)
{
- struct DistantNeighbor *distant_neighbor = value;
+ struct DistantNeighbor *distant_neighbor = abs_value;
char my_shortname[5];
char referrer_shortname[5];
memcpy(&my_shortname, GNUNET_i2s(&my_identity), 4);
p2p_dv_MESSAGE_NeighborInfo *message;
struct PendingMessage *pending_message;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
- {
+ if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ {
#if DEBUG_DV_GOSSIP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s: Called with reason shutdown, shutting down!\n",
GNUNET_i2s(&my_identity));
#endif
- return;
- }
+ return;
+ }
if (send_context->fast_gossip_list_head != NULL)
{
core_pending_tail,
pending_message);
- GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now(try_core_send, NULL);
/*if (core_transmit_handle == NULL)
- core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);*/
+ core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);*/
}
#if DEBUG_DV_PEER_NUMBERS
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: still in fast send mode\n");
#endif
- send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
+ send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context);
}
else
{
#if DEBUG_DV_PEER_NUMBERS
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: entering slow send mode\n");
#endif
- send_context->task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_DV_DEFAULT_SEND_INTERVAL, &neighbor_send_task, send_context);
+ send_context->task = GNUNET_SCHEDULER_add_delayed(GNUNET_DV_DEFAULT_SEND_INTERVAL, &neighbor_send_task, send_context);
}
return;
*/
int send_iterator (void *cls,
const GNUNET_HashCode * key,
- void *value)
+ void *abs_value)
{
struct DV_SendContext *send_context = cls;
- struct DistantNeighbor *distant_neighbor = value;
+ struct DistantNeighbor *distant_neighbor = abs_value;
if (memcmp(distant_neighbor->referrer, send_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */
{
static int handle_dv_gossip_message (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance);
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi);
static int handle_dv_disconnect_message (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance);
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi);
/** End forward declarations **/
GNUNET_CONTAINER_DLL_remove (referrer->referee_head,
referrer->referee_tail, referee);
}
- GNUNET_CONTAINER_heap_remove_node (neighbor_max_heap, referee->max_loc);
- GNUNET_CONTAINER_heap_remove_node (neighbor_min_heap, referee->min_loc);
+ GNUNET_CONTAINER_heap_remove_node (referee->max_loc);
+ GNUNET_CONTAINER_heap_remove_node (referee->min_loc);
GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors,
&referee->identity.hashPubKey);
GNUNET_free_non_null (referee->pkey);
send_context = direct->send_context;
if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(sched, send_context->task);
+ GNUNET_SCHEDULER_cancel(send_context->task);
about_list = send_context->fast_gossip_list_head;
while (about_list != NULL)
core_pending_tail,
pending_message);
- GNUNET_SCHEDULER_add_now(sched, try_core_send, NULL);
+ GNUNET_SCHEDULER_add_now(try_core_send, NULL);
/*if (core_transmit_handle == NULL)
- core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), ¬ify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);*/
+ core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), ¬ify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);*/
return GNUNET_YES;
}
GNUNET_CONTAINER_heap_destroy(neighbor_min_heap);
GNUNET_CORE_disconnect (coreAPI);
+ coreAPI = NULL;
GNUNET_PEERINFO_disconnect(peerinfo_handle);
GNUNET_SERVER_mst_destroy(coreMST);
GNUNET_free_non_null(my_short_id);
if (server == NULL)
{
- GNUNET_SCHEDULER_cancel(sched, cleanup_task);
- GNUNET_SCHEDULER_add_now(sched, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_cancel(cleanup_task);
+ GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
return;
}
#if DEBUG_DV
*/
static int add_pkey_to_extended (void *cls,
const GNUNET_HashCode * key,
- void *value)
+ void *abs_value)
{
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls;
- struct DistantNeighbor *distant_neighbor = value;
+ struct DistantNeighbor *distant_neighbor = abs_value;
if (distant_neighbor->pkey == NULL)
{
GNUNET_free(encPeerTo);
#endif
/*if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(sched, send_context->task);*/
+ GNUNET_SCHEDULER_cancel(send_context->task);*/
- send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
+ send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context);
return GNUNET_YES;
}
* not added)
*/
static struct DistantNeighbor *
-addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
+addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
unsigned int referrer_peer_id,
struct DirectNeighbor *referrer, unsigned int cost)
{
#if DEBUG_DV_MESSAGES
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", my_short_id, referrer_peer_id);
#endif
- handle_dv_data_message(NULL, &referrer->pending_messages[i].sender, referrer->pending_messages[i].message, referrer->pending_messages[i].latency, referrer->pending_messages[i].distance);
+ struct GNUNET_TRANSPORT_ATS_Information atsi[3];
+ atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ atsi[0].value = htonl (referrer->pending_messages[i].distance);
+ atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ atsi[1].value = htonl ((uint32_t)referrer->pending_messages[i].latency.rel_value);
+ atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ atsi[2].value = htonl (0);
+ handle_dv_data_message(NULL,
+ &referrer->pending_messages[i].sender,
+ referrer->pending_messages[i].message,
+ (const struct GNUNET_TRANSPORT_ATS_Information *)&atsi);
GNUNET_free(referrer->pending_messages[i].message);
referrer->pending_messages[i].sender_id = 0;
}
* @param cls closure
* @param peer peer which sent the message (immediate sender)
* @param message the message
- * @param latency the latency of the connection we received the message from
- * @param distance the distance to the immediate peer
+ * @param atsi performance data
*/
static int handle_dv_disconnect_message (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct DirectNeighbor *referrer;
struct DistantNeighbor *distant;
* @param cls closure
* @param peer peer which sent the message (immediate sender)
* @param message the message
- * @param latency the latency of the connection we received the message from
- * @param distance the distance to the immediate peer
+ * @param atsi performance data
*/
-static int handle_dv_gossip_message (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+static int
+handle_dv_gossip_message (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct DirectNeighbor *referrer;
p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo *)message;
*
* @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
*/
-static int add_all_extended_peers (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+add_all_extended_peers (void *cls,
+ const GNUNET_HashCode * key,
+ void *value)
{
struct NeighborSendContext *send_context = (struct NeighborSendContext *)cls;
struct DistantNeighbor *distant = (struct DistantNeighbor *)value;
* iterate,
* GNUNET_NO if not.
*/
-static int gossip_all_to_all_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+gossip_all_to_all_iterator (void *cls,
+ const GNUNET_HashCode * key,
+ void *abs_value)
{
- struct DirectNeighbor *direct = value;
+ struct DirectNeighbor *direct = abs_value;
GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &add_all_extended_peers, direct->send_context);
if (direct->send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(sched, direct->send_context->task);
+ GNUNET_SCHEDULER_cancel(direct->send_context->task);
- direct->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, direct->send_context);
+ direct->send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, direct->send_context);
return GNUNET_YES;
}
{
GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &gossip_all_to_all_iterator, NULL);
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
&gossip_all_to_all,
NULL);
*
* @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
*/
-static int add_all_direct_neighbors (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+add_all_direct_neighbors (void *cls,
+ const GNUNET_HashCode * key,
+ void *value)
{
struct DirectNeighbor *direct = (struct DirectNeighbor *)value;
struct DirectNeighbor *to = (struct DirectNeighbor *)cls;
send_context->fast_gossip_list_tail,
gossip_entry);
if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel(sched, send_context->task);
+ GNUNET_SCHEDULER_cancel(send_context->task);
- send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
+ send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context);
//tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
//neighbor_send_task(send_context, &tc);
return GNUNET_YES;
* @param cls closure
* @param peer id of the peer, NULL for last call
* @param hello hello message for the peer (can be NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
*/
static void
process_peerinfo (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Message *hello)
+ const struct GNUNET_HELLO_Message *hello,
+ const char *err_msg)
{
struct PeerIteratorContext *peerinfo_iterator = cls;
struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
char *neighbor_pid;
#endif
int sent;
-
+ if (err_msg != NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("Error in communication with PEERINFO service\n"));
+ /* return; */
+ }
if (peer == NULL)
{
if (distant->pkey == NULL)
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped about %s to %d direct peers\n", GNUNET_i2s(&my_identity), neighbor_pid, sent);
GNUNET_free(neighbor_pid);
#endif
- neighbor->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, neighbor->send_context);
+ neighbor->send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, neighbor->send_context);
}
}
*
* @param cls closure
* @param peer peer identity this notification is about
- * @param latency reported latency of the connection with peer
- * @param distance reported distance (DV) to peer
+ * @param atsi performance data
*/
-void handle_core_connect (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+static void
+handle_core_connect (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct DirectNeighbor *neighbor;
struct DistantNeighbor *about;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance);
#endif
+ uint32_t distance;
+
+ /* Check for connect to self message */
+ if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ return;
- if ((distance == DIRECT_NEIGHBOR_COST) && (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
+ distance = get_atsi_distance (atsi);
+ if ((distance == DIRECT_NEIGHBOR_COST) &&
+ (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
{
peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext));
neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor));
struct DistantNeighbor *referee;
struct FindDestinationContext fdc;
struct DisconnectContext disconnect_context;
+ struct PendingMessage *pending_pos;
#if DEBUG_DV
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s: Receives core peer disconnect message!\n", "dv");
#endif
+ /* Check for disconnect from self message */
+ if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+ return;
+
neighbor =
GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
+
if (neighbor == NULL)
{
return;
}
+
+ pending_pos = core_pending_head;
+ while (NULL != pending_pos)
+ {
+ if (0 == memcmp(&pending_pos->recipient, &neighbor->identity, sizeof(struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_CONTAINER_DLL_remove(core_pending_head, core_pending_tail, pending_pos);
+ pending_pos = core_pending_head;
+ }
+ else
+ pending_pos = pending_pos->next;
+ }
+
while (NULL != (referee = neighbor->referee_head))
distant_neighbor_free (referee);
GNUNET_assert (neighbor->referee_tail == NULL);
if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors,
- &peer->hashPubKey, neighbor))
+ &peer->hashPubKey, neighbor))
{
GNUNET_break(0);
}
- if ((neighbor->send_context != NULL) && (neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK))
- GNUNET_SCHEDULER_cancel(sched, neighbor->send_context->task);
+ if ((neighbor->send_context != NULL) &&
+ (neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK))
+ GNUNET_SCHEDULER_cancel(neighbor->send_context->task);
GNUNET_free (neighbor);
}
* Process dv requests.
*
* @param cls closure
- * @param scheduler scheduler to use
* @param server the initialized server
* @param c configuration to use
*/
static void
run (void *cls,
- struct GNUNET_SCHEDULER_Handle *scheduler,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
unsigned long long max_hosts;
- sched = scheduler;
cfg = c;
/* FIXME: Read from config, or calculate, or something other than this! */
GNUNET_SERVER_add_handlers (server, plugin_handlers);
coreAPI =
- GNUNET_CORE_connect (sched,
- cfg,
- GNUNET_TIME_relative_get_forever(),
+ GNUNET_CORE_connect (cfg,
+ 1,
NULL, /* FIXME: anything we want to pass around? */
&core_init,
&handle_core_connect,
coreMST = GNUNET_SERVER_mst_create (&tokenized_message_handler,
NULL);
- peerinfo_handle = GNUNET_PEERINFO_connect(sched, cfg);
+ peerinfo_handle = GNUNET_PEERINFO_connect(cfg);
if (peerinfo_handle == NULL)
{
}
/* Scheduled the task to clean up when shutdown is called */
- cleanup_task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task,
+ NULL);
}