aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-24 22:44:22 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-24 22:44:22 +0000
commitad9e7ee447a687725cc29138703502c0d23dd9cb (patch)
tree41d83455117804defc6f2ecd1218df570eac293d /src/fs
parenta2467fb0dcd123ad6ed0cab821ac9cec5d63d01a (diff)
downloadgnunet-ad9e7ee447a687725cc29138703502c0d23dd9cb.tar.gz
gnunet-ad9e7ee447a687725cc29138703502c0d23dd9cb.zip
hacking on fs features
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs.h4
-rw-r--r--src/fs/gnunet-service-fs.c126
2 files changed, 88 insertions, 42 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index a7ae457d5..b3bf24e2a 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -157,7 +157,7 @@
157/** 157/**
158 * Bandwidth value of an (effectively) 0-priority query. 158 * Bandwidth value of an (effectively) 0-priority query.
159 */ 159 */
160#define QUERY_BANDWIDTH_VALUE 0.001 160#define QUERY_BANDWIDTH_VALUE 1
161 161
162/** 162/**
163 * Bandwidth value of a 0-priority content (must be 163 * Bandwidth value of a 0-priority content (must be
@@ -166,7 +166,7 @@
166 * since it can take many queries to get one piece of 166 * since it can take many queries to get one piece of
167 * content). 167 * content).
168 */ 168 */
169#define CONTENT_BANDWIDTH_VALUE 0.8 169#define CONTENT_BANDWIDTH_VALUE 800
170 170
171/** 171/**
172 * By which amount do we decrement the TTL for simple forwarding / 172 * By which amount do we decrement the TTL for simple forwarding /
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index ccdd76de2..e49ff17cd 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -23,13 +23,16 @@
23 * @brief gnunet anonymity protocol implementation 23 * @brief gnunet anonymity protocol implementation
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * FIXME:
27 * - TTL/priority calculations are absent!
28 * TODO: 26 * TODO:
29 * - have non-zero preference / priority for requests we initiate! 27 * - trust not properly received and pushed back to peerinfo!
30 * - implement hot-path routing decision procedure 28 * - bound_priority by priorities used by other peers
31 * - implement: bound_priority, test_load_too_high 29 * - have a way to drop queries based on load
32 * - statistics 30 * - introduce random latency in processing
31 * - consider more precise latency estimation (per-peer & request)
32 * - better algorithm for priority selection for requests we initiate?
33 * - tell other peers to stop migration if our PUTs fail (or if
34 * we don't support migration per configuration?)
35 * - more statistics
33 */ 36 */
34#include "platform.h" 37#include "platform.h"
35#include <float.h> 38#include <float.h>
@@ -48,7 +51,6 @@
48 51
49/** 52/**
50 * Maximum number of outgoing messages we queue per peer. 53 * Maximum number of outgoing messages we queue per peer.
51 * FIXME: make configurable?
52 */ 54 */
53#define MAX_QUEUE_PER_PEER 16 55#define MAX_QUEUE_PER_PEER 16
54 56
@@ -204,9 +206,14 @@ struct ConnectedPeer
204 206
205 /** 207 /**
206 * Increase in traffic preference still to be submitted 208 * Increase in traffic preference still to be submitted
207 * to the core service for this peer. FIXME: double or 'uint64_t'? 209 * to the core service for this peer.
208 */ 210 */
209 double inc_preference; 211 uint64_t inc_preference;
212
213 /**
214 * Trust delta to still commit to the system.
215 */
216 uint32_t trust_delta;
210 217
211 /** 218 /**
212 * The peer's identity. 219 * The peer's identity.
@@ -480,7 +487,6 @@ struct PendingRequest
480 struct GNUNET_DATASTORE_QueueEntry *qe; 487 struct GNUNET_DATASTORE_QueueEntry *qe;
481 488
482 /** 489 /**
483
484 * Size of the 'bf' (in bytes). 490 * Size of the 'bf' (in bytes).
485 */ 491 */
486 size_t bf_size; 492 size_t bf_size;
@@ -1247,7 +1253,11 @@ peer_disconnect_handler (void *cls,
1247 &consider_migration, 1253 &consider_migration,
1248 pos); 1254 pos);
1249 } 1255 }
1250 1256 if (cp->trust_delta > 0)
1257 {
1258 /* FIXME: push trust back to peerinfo!
1259 (need better peerinfo API!) */
1260 }
1251 GNUNET_PEER_change_rc (cp->pid, -1); 1261 GNUNET_PEER_change_rc (cp->pid, -1);
1252 GNUNET_PEER_decrement_rcs (cp->last_p2p_replies, P2P_SUCCESS_LIST_SIZE); 1262 GNUNET_PEER_decrement_rcs (cp->last_p2p_replies, P2P_SUCCESS_LIST_SIZE);
1253 if (NULL != cp->cth) 1263 if (NULL != cp->cth)
@@ -1856,11 +1866,6 @@ target_reservation_cb (void *cls,
1856 return; 1866 return;
1857 } 1867 }
1858 no_route = GNUNET_NO; 1868 no_route = GNUNET_NO;
1859 /* FIXME: check against DBLOCK_SIZE and possibly return
1860 amount to reserve; however, this also needs to work
1861 with testcases which currently start out with a far
1862 too low per-peer bw limit, so they would never send
1863 anything. Big issue. */
1864 if (amount == 0) 1869 if (amount == 0)
1865 { 1870 {
1866 if (pr->cp == NULL) 1871 if (pr->cp == NULL)
@@ -1997,7 +2002,13 @@ target_peer_select_cb (void *cls,
1997 2002
1998 /* 1) check that this peer is not the initiator */ 2003 /* 1) check that this peer is not the initiator */
1999 if (cp == pr->cp) 2004 if (cp == pr->cp)
2000 return GNUNET_YES; /* skip */ 2005 {
2006#if DEBUG_FS
2007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2008 "Skipping initiator in forwarding selection\n");
2009#endif
2010 return GNUNET_YES; /* skip */
2011 }
2001 2012
2002 /* 2) check if we have already (recently) forwarded to this peer */ 2013 /* 2) check if we have already (recently) forwarded to this peer */
2003 pc = 0; 2014 pc = 0;
@@ -2022,13 +2033,47 @@ target_peer_select_cb (void *cls,
2022 "Re-trying query that was previously transmitted %u times to this peer\n", 2033 "Re-trying query that was previously transmitted %u times to this peer\n",
2023 (unsigned int) pc); 2034 (unsigned int) pc);
2024#endif 2035#endif
2025 // 3) calculate how much we'd like to forward to this peer 2036 /* 3) calculate how much we'd like to forward to this peer,
2026 score = 42; // FIXME! 2037 starting with a random value that is strong enough
2027 // FIXME: also need API to gather data on responsiveness 2038 to at least give any peer a chance sometimes
2028 // of this peer (we have fields for that in 'cp', but 2039 (compared to the other factors that come later) */
2029 // they are never set!) 2040 /* 3a) count successful (recent) routes from cp for same source */
2030 2041 if (pr->cp != NULL)
2042 {
2043 score = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2044 P2P_SUCCESS_LIST_SIZE);
2045 for (i=0;i<P2P_SUCCESS_LIST_SIZE;i++)
2046 if (cp->last_p2p_replies[i] == pr->cp->pid)
2047 score += 1; /* likely successful based on hot path */
2048 }
2049 else
2050 {
2051 score = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2052 CS2P_SUCCESS_LIST_SIZE);
2053 for (i=0;i<CS2P_SUCCESS_LIST_SIZE;i++)
2054 if (cp->last_client_replies[i] == pr->client_request_list->client_list->client)
2055 score += 1; /* likely successful based on hot path */
2056 }
2057 /* 3b) include latency */
2058 if (cp->avg_delay.value < 4 * TTL_DECREMENT)
2059 score += 1; /* likely fast based on latency */
2060 /* 3c) include priorities */
2061 if (cp->avg_priority <= pr->remaining_priority / 2.0)
2062 score += 1; /* likely successful based on priorities */
2063 /* 3d) penalize for queue size */
2064 score -= (2.0 * cp->pending_requests / (double) MAX_QUEUE_PER_PEER);
2065 /* 3e) include peer proximity */
2066 score -= (2.0 * (GNUNET_CRYPTO_hash_distance_u32 (key,
2067 &pr->query)) / (double) UINT32_MAX);
2031 /* store best-fit in closure */ 2068 /* store best-fit in closure */
2069#if DEBUG_FS
2070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2071 "Peer `%s' gets score %f for forwarding query, max is %f\n",
2072 GNUNET_h2s (key),
2073 score,
2074 psc->target_score);
2075#endif
2076 score++; /* avoid zero */
2032 if (score > psc->target_score) 2077 if (score > psc->target_score)
2033 { 2078 {
2034 psc->target_score = score; 2079 psc->target_score = score;
@@ -2066,7 +2111,7 @@ bound_ttl (int32_t ttl_in, uint32_t prio)
2066 2111
2067 2112
2068/** 2113/**
2069 * We're processing a GET request from another peer and have decided 2114 * We're processing a GET request and have decided
2070 * to forward it to other peers. This function is called periodically 2115 * to forward it to other peers. This function is called periodically
2071 * and should forward the request to other peers until we have all 2116 * and should forward the request to other peers until we have all
2072 * possible replies. If we have transmitted the *only* reply to 2117 * possible replies. If we have transmitted the *only* reply to
@@ -2100,11 +2145,11 @@ forward_request_task (void *cls,
2100 return; /* configured to not do P2P search */ 2145 return; /* configured to not do P2P search */
2101 /* (1) select target */ 2146 /* (1) select target */
2102 psc.pr = pr; 2147 psc.pr = pr;
2103 psc.target_score = DBL_MIN; 2148 psc.target_score = -DBL_MAX;
2104 GNUNET_CONTAINER_multihashmap_iterate (connected_peers, 2149 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
2105 &target_peer_select_cb, 2150 &target_peer_select_cb,
2106 &psc); 2151 &psc);
2107 if (psc.target_score == DBL_MIN) 2152 if (psc.target_score == -DBL_MAX)
2108 { 2153 {
2109 delay = get_processing_delay (); 2154 delay = get_processing_delay ();
2110#if DEBUG_FS 2155#if DEBUG_FS
@@ -2120,7 +2165,6 @@ forward_request_task (void *cls,
2120 return; /* nobody selected */ 2165 return; /* nobody selected */
2121 } 2166 }
2122 /* (3) update TTL/priority */ 2167 /* (3) update TTL/priority */
2123
2124 if (pr->client_request_list != NULL) 2168 if (pr->client_request_list != NULL)
2125 { 2169 {
2126 /* FIXME: use better algorithm!? */ 2170 /* FIXME: use better algorithm!? */
@@ -2139,10 +2183,6 @@ forward_request_task (void *cls,
2139 pr->ttl); 2183 pr->ttl);
2140#endif 2184#endif
2141 } 2185 }
2142 else
2143 {
2144 /* FIXME: should we do something here as well!? */
2145 }
2146 2186
2147 /* (3) reserve reply bandwidth */ 2187 /* (3) reserve reply bandwidth */
2148 cp = GNUNET_CONTAINER_multihashmap_get (connected_peers, 2188 cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
@@ -2153,10 +2193,10 @@ forward_request_task (void *cls,
2153 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 2193 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
2154 GNUNET_BANDWIDTH_value_init (UINT32_MAX), 2194 GNUNET_BANDWIDTH_value_init (UINT32_MAX),
2155 DBLOCK_SIZE * 2, 2195 DBLOCK_SIZE * 2,
2156 (uint64_t) cp->inc_preference, 2196 cp->inc_preference,
2157 &target_reservation_cb, 2197 &target_reservation_cb,
2158 pr); 2198 pr);
2159 cp->inc_preference = 0.0; 2199 cp->inc_preference = 0;
2160} 2200}
2161 2201
2162 2202
@@ -2574,6 +2614,7 @@ handle_p2p_put (void *cls,
2574 GNUNET_HashCode query; 2614 GNUNET_HashCode query;
2575 struct ProcessReplyClosure prq; 2615 struct ProcessReplyClosure prq;
2576 const struct SBlock *sb; 2616 const struct SBlock *sb;
2617 struct ConnectedPeer *cps;
2577 2618
2578 msize = ntohs (message->size); 2619 msize = ntohs (message->size);
2579 if (msize < sizeof (struct PutMessage)) 2620 if (msize < sizeof (struct PutMessage))
@@ -2629,6 +2670,10 @@ handle_p2p_put (void *cls,
2629 &query, 2670 &query,
2630 &process_reply, 2671 &process_reply,
2631 &prq); 2672 &prq);
2673 cps = GNUNET_CONTAINER_multihashmap_get (connected_peers,
2674 &other->hashPubKey);
2675 cps->inc_preference += CONTENT_BANDWIDTH_VALUE + 1000 * prq.priority;
2676 cps->trust_delta += prq.priority;
2632 if (GNUNET_YES == active_migration) 2677 if (GNUNET_YES == active_migration)
2633 { 2678 {
2634#if DEBUG_FS 2679#if DEBUG_FS
@@ -2907,7 +2952,13 @@ static uint32_t
2907bound_priority (uint32_t prio_in, 2952bound_priority (uint32_t prio_in,
2908 struct ConnectedPeer *cp) 2953 struct ConnectedPeer *cp)
2909{ 2954{
2910 return 0; // FIXME! 2955 if (cp->trust_delta > prio_in)
2956 {
2957 cp->trust_delta -= prio_in;
2958 return prio_in;
2959 }
2960 // FIXME: get out trust in the target peer from peerinfo!
2961 return 0;
2911} 2962}
2912 2963
2913 2964
@@ -2973,7 +3024,6 @@ handle_p2p_get (void *cls,
2973 size_t bfsize; 3024 size_t bfsize;
2974 uint32_t ttl_decrement; 3025 uint32_t ttl_decrement;
2975 enum GNUNET_BLOCK_Type type; 3026 enum GNUNET_BLOCK_Type type;
2976 double preference;
2977 int have_ns; 3027 int have_ns;
2978 3028
2979 msize = ntohs(message->size); 3029 msize = ntohs(message->size);
@@ -3195,11 +3245,7 @@ handle_p2p_get (void *cls,
3195 GNUNET_NO); 3245 GNUNET_NO);
3196 3246
3197 /* calculate change in traffic preference */ 3247 /* calculate change in traffic preference */
3198 preference = (double) pr->priority; 3248 cps->inc_preference += pr->priority * 1000 + QUERY_BANDWIDTH_VALUE;
3199 if (preference < QUERY_BANDWIDTH_VALUE)
3200 preference = QUERY_BANDWIDTH_VALUE;
3201 cps->inc_preference += preference;
3202
3203 /* process locally */ 3249 /* process locally */
3204 if (type == GNUNET_BLOCK_TYPE_DBLOCK) 3250 if (type == GNUNET_BLOCK_TYPE_DBLOCK)
3205 type = GNUNET_BLOCK_TYPE_ANY; /* to get on-demand as well */ 3251 type = GNUNET_BLOCK_TYPE_ANY; /* to get on-demand as well */