/*
This file is part of GNUnet.
- (C) 2012 Christian Grothoff (and other contributing authors)
+ (C) 2008--2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
/**
- * @file testbed/gnunet-service-testbed_cache.h
+ * @file testbed/gnunet-service-testbed_cache.c
* @brief testbed cache implementation
* @author Sree Harsha Totakura
*/
* Time to expire a cache entry
*/
#define CACHE_EXPIRY \
- GNUNET_TIME_UNIT_FOREVER_REL //GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
/**
/**
* The transport handle to the peer corresponding to this entry; can be NULL
*/
- struct GNUNET_TRANSPORT_Handle *transport_handle_;
+ struct GNUNET_TRANSPORT_Handle *transport_handle;
/**
* The operation handle for transport handle
*/
- struct GNUNET_TESTBED_Operation *transport_op_;
+ struct GNUNET_TESTBED_Operation *transport_op;
/**
* The core handle to the peer corresponding to this entry; can be NULL
/**
* Looks up in the cache and returns the entry
*
- * @param id the peer identity of the peer whose corresponding entry has to be looked up
+ * @param key the peer identity of the peer whose corresponding entry has to be
+ * looked up
* @return the HELLO message; NULL if not found
*/
static struct CacheEntry *
GNUNET_free (ctxt);
}
LOG_DEBUG ("Cleaning up handles from an entry in cache\n");
- if (NULL != entry->transport_handle_)
+ if (NULL != entry->transport_handle)
+ GNUNET_assert (NULL != entry->transport_op);
+ if (NULL != entry->transport_op)
{
- GNUNET_assert (NULL != entry->transport_op_);
- GNUNET_TESTBED_operation_done (entry->transport_op_);
- entry->transport_op_ = NULL;
+ GNUNET_TESTBED_operation_done (entry->transport_op);
+ entry->transport_op = NULL;
}
- if (NULL != entry->core_handle)
+ if (NULL != entry->core_op)
{
- GNUNET_assert (NULL != entry->core_op);
GNUNET_TESTBED_operation_done (entry->core_op);
entry->core_op = NULL;
}
+ GNUNET_assert (NULL == entry->core_handle);
if (NULL != entry->cfg)
{
GNUNET_CONFIGURATION_destroy (entry->cfg);
switch (cgh->type)
{
case CGT_TRANSPORT_HANDLE:
- if (NULL == entry->transport_handle_)
+ if (NULL == entry->transport_handle)
continue;
break;
case CGT_CORE_HANDLE:
if (NULL == entry->core_handle)
continue;
+ if (NULL == entry->peer_identity) /* Our CORE connection isn't ready yet */
+ continue;
break;
}
break;
cgh->nctxt);
}
LOG_DEBUG ("Calling notify for handle type %u\n", cgh->type);
- cgh->cb (cgh->cb_cls, entry->core_handle, entry->transport_handle_,
+ cgh->cb (cgh->cb_cls, entry->core_handle, entry->transport_handle,
entry->peer_identity);
}
*
* @param cls closure
* @param peer the peer that connected
- * @param ats performance data
- * @param ats_count number of entries in ats (excluding 0-termination)
*/
static void
transport_peer_connect_notify_cb (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_PeerIdentity *peer)
{
peer_connect_notify_cb (cls, peer, CGT_TRANSPORT_HANDLE);
}
GNUNET_assert (NULL != entry);
LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id);
- entry->transport_handle_ =
+ entry->transport_handle =
GNUNET_TRANSPORT_connect (entry->cfg, NULL, entry, NULL,
&transport_peer_connect_notify_cb, NULL);
- if (NULL == entry->transport_handle_)
+ if (NULL == entry->transport_handle)
{
GNUNET_break (0);
return;
{
struct CacheEntry *entry = cls;
- if (NULL == entry->transport_handle_)
+ if (NULL == entry->transport_handle)
return;
- GNUNET_TRANSPORT_disconnect (entry->transport_handle_);
- entry->transport_handle_ = NULL;
+ GNUNET_TRANSPORT_disconnect (entry->transport_handle);
+ entry->transport_handle = NULL;
}
return;
}
GNUNET_assert (NULL == entry->peer_identity);
+ GNUNET_break (NULL != server);
entry->core_handle = server;
entry->peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
memcpy (entry->peer_identity, my_identity,
*
* @param cls closure
* @param peer peer identity this notification is about
- * @param atsi performance data for the connection
- * @param atsi_count number of records in 'atsi'
*/
static void
-core_peer_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+core_peer_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
{
peer_connect_notify_cb (cls, peer, CGT_CORE_HANDLE);
}
GNUNET_assert (NULL != entry);
LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->peer_id);
- /* void?: We also get the handle when the connection to CORE is successful */
- (void) GNUNET_CORE_connect (entry->cfg, entry, /* closure */
- &core_startup_cb, /* core startup notify */
- &core_peer_connect_cb, /* peer connect notify */
- NULL, /* peer disconnect notify */
- NULL, /* inbound notify */
- GNUNET_NO, /* inbound header only? */
- NULL, /* outbound notify */
- GNUNET_NO, /* outbound header only? */
- no_handlers);
+ entry->core_handle =
+ GNUNET_CORE_connect (entry->cfg, entry, /* closure */
+ &core_startup_cb, /* core startup notify */
+ &core_peer_connect_cb, /* peer connect notify */
+ NULL, /* peer disconnect notify */
+ NULL, /* inbound notify */
+ GNUNET_NO, /* inbound header only? */
+ NULL, /* outbound notify */
+ GNUNET_NO, /* outbound header only? */
+ no_handlers);
}
* lookup in the cache; if not, a new operation is started to open the transport
* handle and will be given in the callback when it is available.
*
- * @param cls the cache entry
+ * @param peer_id the index of the peer
+ * @param cgh the CacheGetHandle
+ * @param cfg the configuration with which the transport handle has to be
+ * created if it was not present in the cache
+ * @param target the peer identify of the peer whose connection to
+ * TRANSPORT/CORE (depending on the type of 'cgh') subsystem will be
+ * notified through the connect_notify_cb. Can be NULL
+ * @param connect_notify_cb the callback to call when the given target peer is
+ * connected. This callback will only be called once or never again (in
+ * case the target peer cannot be connected). Can be NULL
+ * @param connect_notify_cb_cls the closure for the above callback
+ * @return the handle which can be used to cancel or mark that the handle is no
+ * longer being used
*/
static struct GSTCacheGetHandle *
cache_get_handle (unsigned int peer_id, struct GSTCacheGetHandle *cgh,
switch (cgh->type)
{
case CGT_TRANSPORT_HANDLE:
- handle = entry->transport_handle_;
+ handle = entry->transport_handle;
if (NULL != handle)
LOG_DEBUG ("Found TRANSPORT handle in cache for peer %u\n",
entry->peer_id);
if (NULL != handle)
{
if (GNUNET_SCHEDULER_NO_TASK == entry->notify_task)
- entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
+ {
+ if (NULL != search_suitable_cgh (entry, entry->cgh_qhead))
+ entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
+ }
return cgh;
}
+ op = NULL;
switch (cgh->type)
{
case CGT_TRANSPORT_HANDLE:
- if (NULL != entry->transport_op_)
+ if (NULL != entry->transport_op)
return cgh;
op = GNUNET_TESTBED_operation_create_ (entry, &opstart_get_handle_transport,
&oprelease_get_handle_transport);
- entry->transport_op_ = op;
+ entry->transport_op = op;
break;
case CGT_CORE_HANDLE:
if (NULL != entry->core_op)
&oprelease_get_handle_core);
entry->core_op = op;
break;
+ default:
+ GNUNET_assert (0);
}
GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op);
GNUNET_TESTBED_operation_begin_wait_ (op);
GNUNET_break (0 == entry->demand);
LOG_DEBUG ("Clearing entry %u of %u\n", ++ncleared, cache_size);
GNUNET_CONTAINER_multihashmap_remove (cache, key, value);
- if (0 == entry->demand)
- close_handles (entry);
+ close_handles (entry);
GNUNET_free_non_null (entry->hello);
GNUNET_break (GNUNET_SCHEDULER_NO_TASK == entry->expire_task);
- GNUNET_break (NULL == entry->transport_handle_);
- GNUNET_break (NULL == entry->transport_op_);
- GNUNET_break (NULL == entry->core_handle);
- GNUNET_break (NULL == entry->core_op);
- GNUNET_break (NULL == entry->cfg);
+ GNUNET_assert (NULL == entry->transport_handle);
+ GNUNET_assert (NULL == entry->transport_op);
+ GNUNET_assert (NULL == entry->core_handle);
+ GNUNET_assert (NULL == entry->core_op);
+ GNUNET_assert (NULL == entry->cfg);
GNUNET_assert (NULL == entry->cgh_qhead);
GNUNET_assert (NULL == entry->cgh_qtail);
GNUNET_assert (NULL == entry->nctxt_qhead);
GNUNET_CONTAINER_multihashmap_iterate (cache, &cache_clear_iterator, NULL);
GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (cache));
GNUNET_CONTAINER_multihashmap_destroy (cache);
+ cache = NULL;
+ lru_cache_size = 0;
+ lru_cache_threshold_size = 0;
+ cache_size = 0;
+ lru_cache_head = NULL;
+ lru_cache_tail = NULL;
}
* connected. This callback will only be called once or never again (in
* case the target peer cannot be connected). Can be NULL
* @param connect_notify_cb_cls the closure for the above callback
- * @return the handle which can be used cancel or mark that the handle is no
+ * @return the handle which can be used to cancel or mark that the handle is no
* longer being used
*/
struct GSTCacheGetHandle *
* connected. This callback will only be called once or never again (in
* case the target peer cannot be connected). Can be NULL
* @param connect_notify_cb_cls the closure for the above callback
- * @return the handle which can be used cancel or mark that the handle is no
+ * @return the handle which can be used to cancel or mark that the handle is no
* longer being used
*/
struct GSTCacheGetHandle *
* Caches the HELLO of the given peer. Updates the HELLO if it was already
* cached before
*
- * @param id the peer identity of the peer whose HELLO has to be cached
+ * @param peer_id the peer identity of the peer whose HELLO has to be cached
* @param hello the HELLO message
*/
void