aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-01-25 10:55:49 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-01-25 10:55:49 +0000
commit302168de1e43aec3d2d2dfe3fd6707b0f3f68300 (patch)
tree241c25a1c9630f701e4b15977f679e4f6286ccf9 /src/testbed/gnunet-service-testbed.c
parentf4ac441409d20d314d3733cf454dece1aae42e99 (diff)
downloadgnunet-302168de1e43aec3d2d2dfe3fd6707b0f3f68300.tar.gz
gnunet-302168de1e43aec3d2d2dfe3fd6707b0f3f68300.zip
separate hello cache as module
Diffstat (limited to 'src/testbed/gnunet-service-testbed.c')
-rw-r--r--src/testbed/gnunet-service-testbed.c124
1 files changed, 4 insertions, 120 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 282e5a4e8..d741b7fc1 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -24,7 +24,6 @@
24 * @author Sree Harsha Totakura 24 * @author Sree Harsha Totakura
25 */ 25 */
26 26
27#include "platform.h"
28#include "gnunet-service-testbed.h" 27#include "gnunet-service-testbed.h"
29 28
30#include <zlib.h> 29#include <zlib.h>
@@ -138,18 +137,6 @@ static struct ForwardedOperationContext *fopcq_head;
138static struct ForwardedOperationContext *fopcq_tail; 137static struct ForwardedOperationContext *fopcq_tail;
139 138
140/** 139/**
141 * DLL head for least recently used hello cache entries; least recently used
142 * cache items are at the head
143 */
144static struct HelloCacheEntry *lru_hcache_head;
145
146/**
147 * DLL tail for least recently used hello cache entries; recently used cache
148 * items are at the tail
149 */
150static struct HelloCacheEntry *lru_hcache_tail;
151
152/**
153 * Array of hosts 140 * Array of hosts
154 */ 141 */
155static struct GNUNET_TESTBED_Host **host_list; 142static struct GNUNET_TESTBED_Host **host_list;
@@ -175,11 +162,6 @@ static struct Peer **peer_list;
175static struct GNUNET_CONTAINER_MultiHashMap *ss_map; 162static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
176 163
177/** 164/**
178 * Hashmap to maintain HELLO cache
179 */
180static struct GNUNET_CONTAINER_MultiHashMap *hello_cache;
181
182/**
183 * The event mask for the events we listen from sub-controllers 165 * The event mask for the events we listen from sub-controllers
184 */ 166 */
185static uint64_t event_mask; 167static uint64_t event_mask;
@@ -204,11 +186,6 @@ static unsigned int slave_list_size;
204 */ 186 */
205static unsigned int peer_list_size; 187static unsigned int peer_list_size;
206 188
207/**
208 * The size of hello cache
209 */
210static unsigned int hello_cache_size;
211
212/*********/ 189/*********/
213/* Tasks */ 190/* Tasks */
214/*********/ 191/*********/
@@ -225,87 +202,6 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
225 202
226 203
227/** 204/**
228 * Looks up in the hello cache and returns the HELLO of the given peer
229 *
230 * @param id the peer identity of the peer whose HELLO has to be looked up
231 * @return the HELLO message; NULL if not found
232 */
233static const struct GNUNET_MessageHeader *
234hello_cache_lookup (const struct GNUNET_PeerIdentity *id)
235{
236 struct HelloCacheEntry *entry;
237
238 if (NULL == hello_cache)
239 return NULL;
240 entry = GNUNET_CONTAINER_multihashmap_get (hello_cache, &id->hashPubKey);
241 if (NULL == entry)
242 return NULL;
243 GNUNET_CONTAINER_DLL_remove (lru_hcache_head, lru_hcache_tail, entry);
244 GNUNET_CONTAINER_DLL_insert_tail (lru_hcache_head, lru_hcache_tail, entry);
245 return entry->hello;
246}
247
248
249/**
250 * Removes the given hello cache centry from hello cache and frees its resources
251 *
252 * @param entry the entry to remove
253 */
254static void
255hello_cache_remove (struct HelloCacheEntry *entry)
256{
257 GNUNET_CONTAINER_DLL_remove (lru_hcache_head, lru_hcache_tail, entry);
258 GNUNET_assert (GNUNET_YES ==
259 GNUNET_CONTAINER_multihashmap_remove (hello_cache,
260 &entry->key,
261 entry));
262 GNUNET_free (entry->hello);
263 GNUNET_free (entry);
264}
265
266
267/**
268 * Caches the HELLO of the given peer. Updates the HELLO if it was already
269 * cached before
270 *
271 * @param id the peer identity of the peer whose HELLO has to be cached
272 * @param hello the HELLO message
273 */
274static void
275hello_cache_add (const struct GNUNET_PeerIdentity *id,
276 const struct GNUNET_MessageHeader *hello)
277{
278 struct HelloCacheEntry *entry;
279
280 if (NULL == hello_cache)
281 return;
282 entry = GNUNET_CONTAINER_multihashmap_get (hello_cache, &id->hashPubKey);
283 if (NULL == entry)
284 {
285 entry = GNUNET_malloc (sizeof (struct HelloCacheEntry));
286 memcpy (&entry->key, &id->hashPubKey, sizeof (struct GNUNET_HashCode));
287 if (GNUNET_CONTAINER_multihashmap_size (hello_cache) == hello_cache_size)
288 {
289 GNUNET_assert (NULL != lru_hcache_head);
290 hello_cache_remove (lru_hcache_head);
291 }
292 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put
293 (hello_cache,
294 &entry->key,
295 entry,
296 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
297 }
298 else
299 {
300 GNUNET_CONTAINER_DLL_remove (lru_hcache_head, lru_hcache_tail, entry);
301 GNUNET_free (entry->hello);
302 }
303 entry->hello = GNUNET_copy_message (hello);
304 GNUNET_CONTAINER_DLL_insert_tail (lru_hcache_head, lru_hcache_tail, entry);
305}
306
307
308/**
309 * Function called to notify a client about the connection begin ready to queue 205 * Function called to notify a client about the connection begin ready to queue
310 * more data. "buf" will be NULL and "size" zero if the connection was closed 206 * more data. "buf" will be NULL and "size" zero if the connection was closed
311 * for writing in the meantime. 207 * for writing in the meantime.
@@ -2496,7 +2392,7 @@ hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2496 LOG_DEBUG ("0x%llx: Received HELLO of %s\n", 2392 LOG_DEBUG ("0x%llx: Received HELLO of %s\n",
2497 occ->op_id, GNUNET_i2s (&occ->peer_identity)); 2393 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2498 occ->hello = GNUNET_malloc (msize); 2394 occ->hello = GNUNET_malloc (msize);
2499 hello_cache_add (&occ->peer_identity, hello); 2395 TESTBED_hello_cache_add (&occ->peer_identity, hello);
2500 memcpy (occ->hello, hello, msize); 2396 memcpy (occ->hello, hello, msize);
2501 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); 2397 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2502 occ->ghh = NULL; 2398 occ->ghh = NULL;
@@ -2541,7 +2437,7 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2541 LOG_DEBUG ("0x%llx: Acquiring HELLO of peer %s\n", 2437 LOG_DEBUG ("0x%llx: Acquiring HELLO of peer %s\n",
2542 occ->op_id, GNUNET_i2s (&occ->peer_identity)); 2438 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2543 /* Lookup for HELLO in hello cache */ 2439 /* Lookup for HELLO in hello cache */
2544 if (NULL != (hello = hello_cache_lookup (&occ->peer_identity))) 2440 if (NULL != (hello = TESTBED_hello_cache_lookup (&occ->peer_identity)))
2545 { 2441 {
2546 LOG_DEBUG ("0x%llx: HELLO of peer %s found in cache\n", 2442 LOG_DEBUG ("0x%llx: HELLO of peer %s found in cache\n",
2547 occ->op_id, GNUNET_i2s (&occ->peer_identity)); 2443 occ->op_id, GNUNET_i2s (&occ->peer_identity));
@@ -3429,16 +3325,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3429 GNUNET_free_non_null (hostname); 3325 GNUNET_free_non_null (hostname);
3430 GNUNET_CONFIGURATION_destroy (our_config); 3326 GNUNET_CONFIGURATION_destroy (our_config);
3431 /* Free hello cache */ 3327 /* Free hello cache */
3432 if (NULL != hello_cache) 3328 TESTBED_cache_clear ();
3433 GNUNET_assert
3434 (GNUNET_CONTAINER_multihashmap_size (hello_cache) <= hello_cache_size);
3435 while (NULL != lru_hcache_head)
3436 hello_cache_remove (lru_hcache_head);
3437 if (NULL != hello_cache)
3438 {
3439 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (hello_cache));
3440 GNUNET_CONTAINER_multihashmap_destroy (hello_cache);
3441 }
3442} 3329}
3443 3330
3444 3331
@@ -3516,16 +3403,13 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
3516 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED", 3403 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
3517 "HELLO_CACHE_SIZE", 3404 "HELLO_CACHE_SIZE",
3518 &num)); 3405 &num));
3519 hello_cache_size = (unsigned int) num; 3406 TESTBED_cache_init ((unsigned int) num);
3520 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string 3407 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
3521 (cfg, "testbed", "HOSTNAME", &hostname)); 3408 (cfg, "testbed", "HOSTNAME", &hostname));
3522 our_config = GNUNET_CONFIGURATION_dup (cfg); 3409 our_config = GNUNET_CONFIGURATION_dup (cfg);
3523 GNUNET_SERVER_add_handlers (server, message_handlers); 3410 GNUNET_SERVER_add_handlers (server, message_handlers);
3524 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); 3411 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
3525 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO); 3412 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
3526 if (1 < hello_cache_size)
3527 hello_cache = GNUNET_CONTAINER_multihashmap_create (hello_cache_size / 2,
3528 GNUNET_YES);
3529 shutdown_task_id = 3413 shutdown_task_id =
3530 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, 3414 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
3531 GNUNET_SCHEDULER_PRIORITY_IDLE, 3415 GNUNET_SCHEDULER_PRIORITY_IDLE,