diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
commit | 83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/dht/gnunet-service-dht_datacache.c | |
parent | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff) | |
download | gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip |
curly wars / auto-indentation
Diffstat (limited to 'src/dht/gnunet-service-dht_datacache.c')
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.c | 121 |
1 files changed, 56 insertions, 65 deletions
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index f3b2e5b2f..82cd06727 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -74,44 +74,42 @@ struct DHTPutEntry | |||
74 | */ | 74 | */ |
75 | void | 75 | void |
76 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | 76 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, |
77 | const GNUNET_HashCode *key, | 77 | const GNUNET_HashCode * key, |
78 | unsigned int put_path_length, | 78 | unsigned int put_path_length, |
79 | const struct GNUNET_PeerIdentity *put_path, | 79 | const struct GNUNET_PeerIdentity *put_path, |
80 | enum GNUNET_BLOCK_Type type, | 80 | enum GNUNET_BLOCK_Type type, size_t data_size, |
81 | size_t data_size, | 81 | const void *data) |
82 | const void *data) | ||
83 | { | 82 | { |
84 | size_t plen = data_size + put_path_length * sizeof(struct GNUNET_PeerIdentity) + sizeof(struct DHTPutEntry); | 83 | size_t plen = |
84 | data_size + put_path_length * sizeof (struct GNUNET_PeerIdentity) + | ||
85 | sizeof (struct DHTPutEntry); | ||
85 | char buf[plen]; | 86 | char buf[plen]; |
86 | struct DHTPutEntry *pe; | 87 | struct DHTPutEntry *pe; |
87 | struct GNUNET_PeerIdentity *pp; | 88 | struct GNUNET_PeerIdentity *pp; |
88 | 89 | ||
89 | if (datacache == NULL) | 90 | if (datacache == NULL) |
90 | { | 91 | { |
91 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 92 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
92 | _("%s request received, but have no datacache!\n"), | 93 | _("%s request received, but have no datacache!\n"), "PUT"); |
93 | "PUT"); | 94 | return; |
94 | return; | 95 | } |
95 | } | ||
96 | if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 96 | if (data_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
97 | { | 97 | { |
98 | GNUNET_break (0); | 98 | GNUNET_break (0); |
99 | return; | 99 | return; |
100 | } | 100 | } |
101 | /* Put size is actual data size plus struct overhead plus path length (if any) */ | 101 | /* Put size is actual data size plus struct overhead plus path length (if any) */ |
102 | GNUNET_STATISTICS_update (GDS_stats, | 102 | GNUNET_STATISTICS_update (GDS_stats, |
103 | gettext_noop ("# ITEMS stored in datacache"), 1, | 103 | gettext_noop ("# ITEMS stored in datacache"), 1, |
104 | GNUNET_NO); | 104 | GNUNET_NO); |
105 | pe = (struct DHTPutEntry *) buf; | 105 | pe = (struct DHTPutEntry *) buf; |
106 | pe->data_size = htons (data_size); | 106 | pe->data_size = htons (data_size); |
107 | pe->path_length = htons ((uint16_t) put_path_length); | 107 | pe->path_length = htons ((uint16_t) put_path_length); |
108 | pp = (struct GNUNET_PeerIdentity *) &pe[1]; | 108 | pp = (struct GNUNET_PeerIdentity *) &pe[1]; |
109 | memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); | 109 | memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); |
110 | memcpy (&pp[put_path_length], | 110 | memcpy (&pp[put_path_length], data, data_size); |
111 | data, data_size); | 111 | (void) GNUNET_DATACACHE_put (datacache, key, plen, (const char *) pe, type, |
112 | (void) GNUNET_DATACACHE_put (datacache, key, | 112 | expiration); |
113 | plen, (const char *) pe, type, | ||
114 | expiration); | ||
115 | } | 113 | } |
116 | 114 | ||
117 | 115 | ||
@@ -190,20 +188,15 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
190 | return GNUNET_OK; | 188 | return GNUNET_OK; |
191 | } | 189 | } |
192 | pp = (const struct GNUNET_PeerIdentity *) &pe[1]; | 190 | pp = (const struct GNUNET_PeerIdentity *) &pe[1]; |
193 | rdata = (const char*) &pp[put_path_length]; | 191 | rdata = (const char *) &pp[put_path_length]; |
194 | eval = | 192 | eval = |
195 | GNUNET_BLOCK_evaluate (GDS_block_context, type, key, | 193 | GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf, |
196 | ctx->reply_bf, | 194 | ctx->reply_bf_mutator, ctx->xquery, |
197 | ctx->reply_bf_mutator, | 195 | ctx->xquery_size, rdata, rdata_size); |
198 | ctx->xquery, | ||
199 | ctx->xquery_size, | ||
200 | rdata, | ||
201 | rdata_size); | ||
202 | #if DEBUG_DHT | 196 | #if DEBUG_DHT |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
204 | "Found reply for query %s in datacache, evaluation result is %d\n", | 198 | "Found reply for query %s in datacache, evaluation result is %d\n", |
205 | GNUNET_h2s (key), | 199 | GNUNET_h2s (key), (int) eval); |
206 | (int) eval); | ||
207 | #endif | 200 | #endif |
208 | ctx->eval = eval; | 201 | ctx->eval = eval; |
209 | switch (eval) | 202 | switch (eval) |
@@ -212,27 +205,26 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
212 | case GNUNET_BLOCK_EVALUATION_OK_MORE: | 205 | case GNUNET_BLOCK_EVALUATION_OK_MORE: |
213 | /* forward to local clients */ | 206 | /* forward to local clients */ |
214 | GNUNET_STATISTICS_update (GDS_stats, | 207 | GNUNET_STATISTICS_update (GDS_stats, |
215 | gettext_noop ("# Good RESULTS found in datacache"), 1, | 208 | gettext_noop |
216 | GNUNET_NO); | 209 | ("# Good RESULTS found in datacache"), 1, |
217 | GDS_CLIENTS_handle_reply (exp, | 210 | GNUNET_NO); |
218 | key, | 211 | GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, pp, type, |
219 | 0, NULL, | 212 | rdata_size, rdata); |
220 | put_path_length, pp, | ||
221 | type, rdata_size, rdata); | ||
222 | /* forward to other peers */ | 213 | /* forward to other peers */ |
223 | GDS_ROUTING_process (type, exp, | 214 | GDS_ROUTING_process (type, exp, key, put_path_length, pp, 0, NULL, rdata, |
224 | key, put_path_length, pp, | 215 | rdata_size); |
225 | 0, NULL, rdata, rdata_size); | ||
226 | break; | 216 | break; |
227 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 217 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
228 | GNUNET_STATISTICS_update (GDS_stats, | 218 | GNUNET_STATISTICS_update (GDS_stats, |
229 | gettext_noop ("# Duplicate RESULTS found in datacache"), 1, | 219 | gettext_noop |
230 | GNUNET_NO); | 220 | ("# Duplicate RESULTS found in datacache"), 1, |
221 | GNUNET_NO); | ||
231 | break; | 222 | break; |
232 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: | 223 | case GNUNET_BLOCK_EVALUATION_RESULT_INVALID: |
233 | GNUNET_STATISTICS_update (GDS_stats, | 224 | GNUNET_STATISTICS_update (GDS_stats, |
234 | gettext_noop ("# Invalid RESULTS found in datacache"), 1, | 225 | gettext_noop |
235 | GNUNET_NO); | 226 | ("# Invalid RESULTS found in datacache"), 1, |
227 | GNUNET_NO); | ||
236 | break; | 228 | break; |
237 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: | 229 | case GNUNET_BLOCK_EVALUATION_REQUEST_VALID: |
238 | GNUNET_break (0); | 230 | GNUNET_break (0); |
@@ -242,11 +234,11 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
242 | return GNUNET_SYSERR; | 234 | return GNUNET_SYSERR; |
243 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: | 235 | case GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED: |
244 | GNUNET_STATISTICS_update (GDS_stats, | 236 | GNUNET_STATISTICS_update (GDS_stats, |
245 | gettext_noop ("# Unsupported RESULTS found in datacache"), 1, | 237 | gettext_noop |
246 | GNUNET_NO); | 238 | ("# Unsupported RESULTS found in datacache"), 1, |
239 | GNUNET_NO); | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
248 | _("Unsupported block type (%u) in local response!\n"), | 241 | _("Unsupported block type (%u) in local response!\n"), type); |
249 | type); | ||
250 | break; | 242 | break; |
251 | } | 243 | } |
252 | return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; | 244 | return (eval == GNUNET_BLOCK_EVALUATION_OK_LAST) ? GNUNET_NO : GNUNET_OK; |
@@ -256,7 +248,7 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
256 | /** | 248 | /** |
257 | * Handle a GET request we've received from another peer. | 249 | * Handle a GET request we've received from another peer. |
258 | * | 250 | * |
259 | * @param key the query | 251 | * @param key the query |
260 | * @param type requested data type | 252 | * @param type requested data type |
261 | * @param xquery extended query | 253 | * @param xquery extended query |
262 | * @param xquery_size number of bytes in xquery | 254 | * @param xquery_size number of bytes in xquery |
@@ -265,28 +257,27 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
265 | * @return evaluation result for the local replies | 257 | * @return evaluation result for the local replies |
266 | */ | 258 | */ |
267 | enum GNUNET_BLOCK_EvaluationResult | 259 | enum GNUNET_BLOCK_EvaluationResult |
268 | GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, | 260 | GDS_DATACACHE_handle_get (const GNUNET_HashCode * key, |
269 | enum GNUNET_BLOCK_Type type, | 261 | enum GNUNET_BLOCK_Type type, const void *xquery, |
270 | const void *xquery, | 262 | size_t xquery_size, |
271 | size_t xquery_size, | 263 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, |
272 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, | 264 | uint32_t reply_bf_mutator) |
273 | uint32_t reply_bf_mutator) | ||
274 | { | 265 | { |
275 | struct GetRequestContext ctx; | 266 | struct GetRequestContext ctx; |
276 | 267 | ||
277 | if (datacache == NULL) | 268 | if (datacache == NULL) |
278 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 269 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
279 | GNUNET_STATISTICS_update (GDS_stats, | 270 | GNUNET_STATISTICS_update (GDS_stats, |
280 | gettext_noop ("# GET requests given to datacache"), 1, | 271 | gettext_noop ("# GET requests given to datacache"), |
281 | GNUNET_NO); | 272 | 1, GNUNET_NO); |
282 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | 273 | ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID; |
283 | ctx.key = *key; | 274 | ctx.key = *key; |
284 | ctx.xquery = xquery; | 275 | ctx.xquery = xquery; |
285 | ctx.xquery_size = xquery_size; | 276 | ctx.xquery_size = xquery_size; |
286 | ctx.reply_bf = reply_bf; | 277 | ctx.reply_bf = reply_bf; |
287 | ctx.reply_bf_mutator = reply_bf_mutator; | 278 | ctx.reply_bf_mutator = reply_bf_mutator; |
288 | (void) GNUNET_DATACACHE_get (datacache, key, type, | 279 | (void) GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator, |
289 | &datacache_get_iterator, &ctx); | 280 | &ctx); |
290 | return ctx.eval; | 281 | return ctx.eval; |
291 | } | 282 | } |
292 | 283 | ||
@@ -294,7 +285,7 @@ GDS_DATACACHE_handle_get (const GNUNET_HashCode *key, | |||
294 | /** | 285 | /** |
295 | * Initialize datacache subsystem. | 286 | * Initialize datacache subsystem. |
296 | */ | 287 | */ |
297 | void | 288 | void |
298 | GDS_DATACACHE_init () | 289 | GDS_DATACACHE_init () |
299 | { | 290 | { |
300 | datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); | 291 | datacache = GNUNET_DATACACHE_create (GDS_cfg, "dhtcache"); |