[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r8698 - GNUnet/src/applications/dv/module
From: |
gnunet |
Subject: |
[GNUnet-SVN] r8698 - GNUnet/src/applications/dv/module |
Date: |
Tue, 14 Jul 2009 22:18:11 -0600 |
Author: nevans
Date: 2009-07-14 22:18:11 -0600 (Tue, 14 Jul 2009)
New Revision: 8698
Modified:
GNUnet/src/applications/dv/module/dv.c
Log:
return dv hops
Modified: GNUnet/src/applications/dv/module/dv.c
===================================================================
--- GNUnet/src/applications/dv/module/dv.c 2009-07-15 04:17:13 UTC (rev
8697)
+++ GNUnet/src/applications/dv/module/dv.c 2009-07-15 04:18:11 UTC (rev
8698)
@@ -39,7 +39,6 @@
/* How long to allow a message to be delayed */
#define DV_DELAY (500 * GNUNET_CRON_MILLISECONDS)
#define DV_PRIORITY 0
-#define FORWARDS_PER_SECOND 10
/**
* Statistics service.
@@ -153,7 +152,7 @@
GNUNET_free (neighbor);
if (stats != NULL)
- update_stats();
+ update_stats ();
return GNUNET_OK;
}
@@ -280,8 +279,8 @@
unsigned int importance, unsigned int maxdelay)
{
p2p_dv_MESSAGE_Data *toSend;
- int ret = GNUNET_OK;
unsigned int msg_size;
+ unsigned int cost;
struct GNUNET_dv_neighbor *neighbor;
#if DEBUG_DV_FORWARD
GNUNET_EncName encVia;
@@ -299,6 +298,7 @@
neighbor =
GNUNET_multi_hash_map_get (ctx->extended_neighbors,
&recipient->hashPubKey);
+ cost = neighbor->cost;
msg_size = ntohs (message->size) + sizeof (p2p_dv_MESSAGE_Data);
if (msg_size > GNUNET_MAX_BUFFER_SIZE - 8)
return GNUNET_SYSERR;
@@ -345,7 +345,7 @@
importance, maxdelay);
}
GNUNET_free (toSend);
- return ret;
+ return (int) cost;
}
else
{
@@ -358,9 +358,8 @@
"%s: I AM:\n%s\nAsked to send message to unknown
peer:\n%s\n\n",
&shortID, (char *) &encMe, (char *) &encRecipient);
#endif
- return GNUNET_NO;
+ return GNUNET_SYSERR;
}
-
}
/*
@@ -511,6 +510,7 @@
*
* @recipient for which peer is this message intended
* @message message being sent
+ * return cost of sent message, GNUNET_SYSERR on error
*/
int
GNUNET_DV_send_message (const GNUNET_PeerIdentity * recipient,
@@ -638,31 +638,37 @@
GNUNET_multi_hash_map_contains (ctx->extended_neighbors,
&peer->hashPubKey))
{
- if (ctx->max_table_size >
GNUNET_multi_hash_map_size(ctx->extended_neighbors))
- {
- neighbor = GNUNET_malloc (sizeof (struct GNUNET_dv_neighbor));
- neighbor->cost = cost;
- neighbor->last_activity = now;
- neighbor->neighbor = GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
- memcpy (neighbor->neighbor, peer, sizeof (GNUNET_PeerIdentity));
+ if (ctx->max_table_size >
+ GNUNET_multi_hash_map_size (ctx->extended_neighbors))
+ {
+ neighbor = GNUNET_malloc (sizeof (struct GNUNET_dv_neighbor));
+ neighbor->cost = cost;
+ neighbor->last_activity = now;
+ neighbor->neighbor = GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
+ memcpy (neighbor->neighbor, peer, sizeof (GNUNET_PeerIdentity));
- if (referrer == NULL)
- neighbor->referrer = NULL;
- else
- {
- neighbor->referrer = GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
- memcpy (neighbor->referrer, referrer, sizeof
(GNUNET_PeerIdentity));
- }
+ if (referrer == NULL)
+ neighbor->referrer = NULL;
+ else
+ {
+ neighbor->referrer =
+ GNUNET_malloc (sizeof (GNUNET_PeerIdentity));
+ memcpy (neighbor->referrer, referrer,
+ sizeof (GNUNET_PeerIdentity));
+ }
- GNUNET_multi_hash_map_put (ctx->extended_neighbors, &peer->hashPubKey,
- neighbor,
GNUNET_MultiHashMapOption_REPLACE);
+ GNUNET_multi_hash_map_put (ctx->extended_neighbors,
+ &peer->hashPubKey, neighbor,
+ GNUNET_MultiHashMapOption_REPLACE);
- GNUNET_CONTAINER_heap_insert (ctx->neighbor_max_heap, neighbor, cost);
- GNUNET_CONTAINER_heap_insert (ctx->neighbor_min_heap, neighbor, cost);
+ GNUNET_CONTAINER_heap_insert (ctx->neighbor_max_heap, neighbor,
+ cost);
+ GNUNET_CONTAINER_heap_insert (ctx->neighbor_min_heap, neighbor,
+ cost);
- if (stats != NULL)
- stats->change (stat_dv_total_peers, 1);
- }
+ if (stats != NULL)
+ stats->change (stat_dv_total_peers, 1);
+ }
}
else
{
@@ -970,15 +976,16 @@
static struct GNUNET_dv_neighbor *
chooseAboutNeighbor ()
{
- if (GNUNET_CONTAINER_heap_get_size (ctx->neighbor_min_heap) == 0)
+ unsigned int heap_size;
+ heap_size = GNUNET_CONTAINER_heap_get_size (ctx->neighbor_min_heap);
+ if (heap_size == 0)
return NULL;
#if DEBUG_DV
GNUNET_GE_LOG (coreAPI->ectx,
GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
- GNUNET_GE_BULK, "%s: Min heap size %d\nMax heap size %d\n",
- &shortID, ctx->neighbor_min_heap.size,
- ctx->neighbor_max_heap.size);
+ GNUNET_GE_BULK, "%s: Min heap size %d\n",
+ &shortID, heap_size);
#endif
return GNUNET_CONTAINER_heap_walk_get_next (ctx->neighbor_min_heap);
@@ -1089,7 +1096,7 @@
ctx->neighbor_min_heap = GNUNET_CONTAINER_heap_create (GNUNET_MIN_HEAP);
ctx->neighbor_max_heap = GNUNET_CONTAINER_heap_create (GNUNET_MAX_HEAP);
ctx->send_interval = GNUNET_DV_DEFAULT_SEND_INTERVAL;
- ctx->dvMutex = GNUNET_mutex_create (GNUNET_YES);
+ ctx->dvMutex = capi->global_lock_get ();
coreAPI = capi;
GNUNET_hash_to_enc (&coreAPI->my_identity->hashPubKey, &encMe);
strncpy ((char *) &shortID, (char *) &encMe, 4);
@@ -1190,9 +1197,7 @@
GNUNET_cron_del_job (coreAPI->cron, &maintain_dv_job,
GNUNET_DV_MAINTAIN_FREQUENCY, NULL);
- GNUNET_mutex_destroy (ctx->dvMutex);
-
- coreAPI->service_release(stats);
+ coreAPI->service_release (stats);
stats = NULL;
coreAPI = NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r8698 - GNUnet/src/applications/dv/module,
gnunet <=