[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r6172 - GNUnet/src/applications/fs/gap
From: |
gnunet |
Subject: |
[GNUnet-SVN] r6172 - GNUnet/src/applications/fs/gap |
Date: |
Wed, 6 Feb 2008 12:41:24 -0700 (MST) |
Author: grothoff
Date: 2008-02-06 12:41:23 -0700 (Wed, 06 Feb 2008)
New Revision: 6172
Modified:
GNUnet/src/applications/fs/gap/gap.c
GNUnet/src/applications/fs/gap/gap.h
GNUnet/src/applications/fs/gap/plan.c
GNUnet/src/applications/fs/gap/shared.h
Log:
towards ttl and prio and score calculations
Modified: GNUnet/src/applications/fs/gap/gap.c
===================================================================
--- GNUnet/src/applications/fs/gap/gap.c 2008-02-06 16:38:53 UTC (rev
6171)
+++ GNUnet/src/applications/fs/gap/gap.c 2008-02-06 19:41:23 UTC (rev
6172)
@@ -244,6 +244,7 @@
rl->anonymityLevel = 1;
rl->type = type;
rl->value = priority;
+ rl->remaining_value = priority > 0 ? priority - 1 : 0;
rl->expiration = GNUNET_get_time () + ttl * GNUNET_CRON_SECONDS;
rl->next = table[index];
rl->response_target = GNUNET_FS_PT_intern (respond_to);
@@ -325,6 +326,37 @@
return value;
}
+/**
+ * Compute the average priority of inbound requests
+ * (rounded up).
+ */
+unsigned int
+GNUNET_FS_GAP_get_average_priority()
+{
+ struct RequestList * rl;
+ unsigned long long tot;
+ unsigned int i;
+ unsigned int active;
+
+ tot = 0;
+ active = 0;
+ GNUNET_mutex_lock (GNUNET_FS_lock);
+ for (i = 0; i < table_size; i++)
+ {
+ rl = table[i];
+ while (rl != NULL)
+ {
+ tot += rl->value;
+ active++;
+ rl = rl->next;
+ }
+ }
+ GNUNET_mutex_unlock (GNUNET_FS_lock);
+ if (active == 0)
+ return 0;
+ return (unsigned int) (tot / active);
+}
+
int
GNUNET_FS_GAP_init (GNUNET_CoreAPIForPlugins * capi)
{
Modified: GNUnet/src/applications/fs/gap/gap.h
===================================================================
--- GNUnet/src/applications/fs/gap/gap.h 2008-02-06 16:38:53 UTC (rev
6171)
+++ GNUnet/src/applications/fs/gap/gap.h 2008-02-06 19:41:23 UTC (rev
6172)
@@ -91,4 +91,11 @@
GNUNET_CronTime expiration,
unsigned int size, const DBlock * data);
+/**
+ * Compute the average priority of inbound requests
+ * (rounded up).
+ */
+unsigned int
+GNUNET_FS_GAP_get_average_priority(void);
+
#endif
Modified: GNUnet/src/applications/fs/gap/plan.c
===================================================================
--- GNUnet/src/applications/fs/gap/plan.c 2008-02-06 16:38:53 UTC (rev
6171)
+++ GNUnet/src/applications/fs/gap/plan.c 2008-02-06 19:41:23 UTC (rev
6172)
@@ -30,6 +30,7 @@
#include "pid_table.h"
#include "fs_dht.h"
#include "fs.h"
+#include "gap.h"
#include "shared.h"
/**
@@ -331,6 +332,14 @@
struct RankingPeerContext *rpc = data;
struct PeerRankings *rank;
struct PeerHistoryList *history;
+ long long history_score;
+ unsigned int proximity_score;
+ GNUNET_CronTime now;
+ GNUNET_CronTime last;
+ unsigned int prio;
+ unsigned int ttl;
+ unsigned int allowable_prio;
+ int score;
rank = GNUNET_malloc (sizeof (struct PeerRankings));
memset (rank, 0, sizeof (struct PeerRankings));
@@ -343,23 +352,65 @@
history = rpc->info->history;
while ((history != NULL) && (history->peer != rank->peer))
history = history->next;
+ }
+ now = GNUNET_get_time();
+ history_score = 0; /* no bias from history */
+ if ( (history != NULL) &&
+ (history->request_count > 0) )
+ {
+ last = history->last_response_time;
+ if (last >= now)
+ last = now - 1;
+ /* the more responses we have in relation
+ to the number of requests we sent, the
+ higher we score; the score is the more
+ significant the more recent the last
+ response was */
+ history_score
+ = ((1LL<<30) * history->response_count) / (history->request_count *
(now - last));
+ if (history->response_count == 0)
+ history_score = - history->request_count;
}
- if (history != NULL)
+ /* check query proximity */
+ proximity_score = GNUNET_hash_distance_u32 (&rpc->request->queries[0],
&identity->hashPubKey);
+
+ /* generate score, ttl and priority */
+ prio = rpc->request->last_prio_used + 1; /* increase over time */
+ if (prio < history->last_good_prio)
+ prio = history->last_good_prio - 1; /* fall over time */
+ if (prio > 1)
{
- /* how do we score the history? */
+ allowable_prio = GNUNET_FS_GAP_get_average_priority() + 1;
+ if (prio > allowable_prio)
+ prio = allowable_prio;
}
+ ttl = rpc->request->last_ttl_used;
+ if (prio > 0)
+ {
+ ttl = 1 << 30; /* bound only by prio */
+ }
else
{
- /* what are good start values? */
- }
+ if (rpc->request->response_client == NULL)
+ ttl = 0; /* initiator expiration is always "now" */
+ else
+ ttl = (int) (((long long) (rpc->request->expiration - now)) /
GNUNET_CRON_SECONDS);
+ ttl = ttl - TTL_DECREMENT -
+ GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 2 * TTL_DECREMENT);
+ if (ttl > 0) /* integer underflow */
+ ttl = - (1<<30);
+ }
+ ttl = GNUNET_FS_HELPER_bound_ttl(ttl, prio);
+ rank->prio = prio;
+ rank->ttl = ttl;
- /* check query proximity */
+ /* compute combined score */
+ score = 0; /* FIXME */
+ if (score <= - (1<<16))
+ rank->score = 1;
+ else
+ rank->score = (1<<16) + score;
- /* generate score, ttl and priority */
- rank->prio = 42; /* FIXME */
- rank->ttl = 112; /* FIXME */
- rank->score = 1; /* FIXME */
-
/* insert into ranking list */
rank->next = rpc->rankings;
rpc->rankings = rank;
@@ -385,7 +436,7 @@
struct ClientInfoList *info;
struct PeerRankings *rank;
struct RankingPeerContext rpc;
- GNUNET_PeerIdentity peer;
+ GNUNET_PeerIdentity peerId;
unsigned int target_count;
unsigned int i;
unsigned int total_peers;
@@ -443,9 +494,9 @@
{
rank = rpc.rankings;
rpc.rankings = rank->next;
- GNUNET_FS_PT_resolve(rank->peer, &peer);
+ GNUNET_FS_PT_resolve(rank->peer, &peerId);
if (rank->score != 0)
- coreAPI->reserve_downstream_bandwidth(&peer,
+ coreAPI->reserve_downstream_bandwidth(&peerId,
- rank->reserved_bandwidth);
GNUNET_FS_PT_change_rc (rank->peer, -1);
GNUNET_free (rank);
@@ -472,6 +523,10 @@
+ req->bloomfilter_size + (req->key_count - 1) * sizeof (GNUNET_HashCode);
if (size > available)
return 0;
+ if ( (prio > req->remaining_value) &&
+ (req->response_client == NULL) )
+ prio = req->remaining_value;
+ ttl = GNUNET_FS_HELPER_bound_ttl(ttl, prio);
msg->header.size = htons (size);
msg->header.type = htons (GNUNET_P2P_PROTO_GAP_QUERY);
msg->type = htonl (req->type);
@@ -487,8 +542,9 @@
(char *) &msg->queries[req->key_count],
req->bloomfilter_size);
req->last_request_time = GNUNET_get_time ();
+ req->last_prio_used = prio;
req->last_ttl_used = ttl;
- req->value = prio;
+ req->remaining_value -= prio;
return size;
}
@@ -641,7 +697,7 @@
hl = find_or_create_history_entry (cl, responder);
hl->response_count++;
hl->last_good_ttl = success->last_ttl_used;
- hl->last_good_prio = success->value;
+ hl->last_good_prio = success->last_prio_used;
hl->last_response_time = GNUNET_get_time ();
hl->response_count++;
GNUNET_mutex_unlock (GNUNET_FS_lock);
Modified: GNUnet/src/applications/fs/gap/shared.h
===================================================================
--- GNUnet/src/applications/fs/gap/shared.h 2008-02-06 16:38:53 UTC (rev
6171)
+++ GNUnet/src/applications/fs/gap/shared.h 2008-02-06 19:41:23 UTC (rev
6172)
@@ -164,9 +164,21 @@
/**
* Priority used for the last request.
*/
+ unsigned int last_prio_used;
+
+ /**
+ * Total value of the request (the priority
+ * that we accepted for the inbound query).
+ */
unsigned int value;
/**
+ * Remaining value of the request (invalid
+ * if response_client == NULL).
+ */
+ unsigned int remaining_value;
+
+ /**
* The queries of this request. At least one,
* if there are more, the key count field will say
* so.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r6172 - GNUnet/src/applications/fs/gap,
gnunet <=