[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25933 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25933 - gnunet/src/testbed |
Date: |
Tue, 29 Jan 2013 16:10:19 +0100 |
Author: harsha
Date: 2013-01-29 16:10:19 +0100 (Tue, 29 Jan 2013)
New Revision: 25933
Modified:
gnunet/src/testbed/gnunet-service-testbed_hc.c
gnunet/src/testbed/gnunet-service-testbed_oc.c
Log:
caching transport handles
Modified: gnunet/src/testbed/gnunet-service-testbed_hc.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed_hc.c 2013-01-29 13:55:14 UTC
(rev 25932)
+++ gnunet/src/testbed/gnunet-service-testbed_hc.c 2013-01-29 15:10:19 UTC
(rev 25933)
@@ -121,6 +121,11 @@
* Number of operations this cache entry is being used
*/
unsigned int demand;
+
+ /**
+ * The id of the peer this entry corresponds to
+ */
+ unsigned int peer_id;
};
/**
@@ -184,13 +189,11 @@
{
struct CacheEntry *entry;
- GNUNET_assert ((NULL != th));
+ GNUNET_assert (NULL != th);
entry = cache_lookup (pid);
if (NULL == entry)
return NULL;
- if (0 == entry->demand)
- GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
- if ((NULL != th) && (NULL != entry->transport_handle))
+ if (NULL != entry->transport_handle)
*th = entry->transport_handle;
return entry;
}
@@ -202,25 +205,30 @@
/* We keep the entry in the hash table so that the HELLO can still be found
in cache; we will however disconnect the core and transport handles */
GNUNET_assert (0 == entry->demand);
- GNUNET_assert (NULL != entry->cfg);
- GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
+ if ((NULL != entry->next) || (NULL != entry->prev))
+ GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
+ LOG_DEBUG ("Cleaning up handles from an entry in cache\n");
if (NULL != entry->transport_handle)
{
GNUNET_assert (NULL != entry->transport_op);
GNUNET_TESTBED_operation_done (entry->transport_op);
entry->transport_op = NULL;
}
- GNUNET_CONFIGURATION_destroy (entry->cfg);
- entry->cfg = NULL;
+ if (NULL != entry->cfg)
+ {
+ GNUNET_CONFIGURATION_destroy (entry->cfg);
+ entry->cfg = NULL;
+ }
}
static struct CacheEntry *
-add_entry (const struct GNUNET_HashCode *key)
+add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id)
{
struct CacheEntry *entry;
entry = GNUNET_malloc (sizeof (struct CacheEntry));
+ entry->peer_id = peer_id;
memcpy (&entry->key, key, sizeof (struct GNUNET_HashCode));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (cache, &entry->key,
@@ -261,7 +269,7 @@
struct CacheEntry *entry = cls;
GNUNET_assert (NULL != entry);
- LOG_DEBUG ("Opening a transport connection\n");
+ LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id);
entry->transport_handle = GNUNET_TRANSPORT_connect (entry->cfg,
NULL, NULL,
NULL,
@@ -315,9 +323,11 @@
{
GNUNET_assert (NULL != entry);
LOG_DEBUG ("Found existing transport handle in cache\n");
+ if (0 == entry->demand)
+ GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
}
if (NULL == entry)
- entry = add_entry (&key);
+ entry = add_entry (&key, peer_id);
if (NULL == entry->cfg)
entry->cfg = GNUNET_CONFIGURATION_dup (cfg);
entry->demand++;
@@ -333,7 +343,6 @@
{
case CGT_TRANSPORT_HANDLE:
GNUNET_assert (NULL == entry->transport_op);
- LOG_DEBUG ("Creating an operation for opening transport handle");
entry->transport_op = GNUNET_TESTBED_operation_create_ (entry,
&opstart_get_handle_transport,
&oprelease_get_handle_transport);
GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds,
@@ -366,6 +375,8 @@
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)
+ cache_remove (entry);
GNUNET_free_non_null (entry->hello);
GNUNET_break (NULL == entry->transport_handle);
GNUNET_break (NULL == entry->cfg);
@@ -413,6 +424,7 @@
GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh)
{
GNUNET_assert (NULL != cgh->entry);
+ GNUNET_assert (0 < cgh->entry->demand);
cgh->entry->demand--;
if (GNUNET_NO == cgh->entry->cghq_head->notify_called)
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cgh->entry->notify_task);
@@ -486,7 +498,8 @@
entry = cache_lookup (&key);
if (NULL == entry)
return NULL;
- LOG_DEBUG ("HELLO found for peer %u\n", peer_id);
+ if (NULL != entry->hello)
+ LOG_DEBUG ("HELLO found for peer %u\n", peer_id);
return entry->hello;
}
@@ -508,7 +521,7 @@
GNUNET_CRYPTO_hash (&peer_id, sizeof (peer_id), &key);
entry = GNUNET_CONTAINER_multihashmap_get (cache, &key);
if (NULL == entry)
- entry = add_entry (&key);
+ entry = add_entry (&key, peer_id);
GNUNET_free_non_null (entry->hello);
entry->hello = GNUNET_copy_message (hello);
}
Modified: gnunet/src/testbed/gnunet-service-testbed_oc.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed_oc.c 2013-01-29 13:55:14 UTC
(rev 25932)
+++ gnunet/src/testbed/gnunet-service-testbed_oc.c 2013-01-29 15:10:19 UTC
(rev 25933)
@@ -41,9 +41,14 @@
/**
* The transport handle
*/
- struct GNUNET_TRANSPORT_Handle *th;
+ struct GNUNET_TRANSPORT_Handle *th_;
/**
+ * The GetCacheHandle for the p1th transport handle
+ */
+ struct GSTCacheGetHandle *cgh_th;
+
+ /**
* the try connect handle
*/
struct GNUNET_TRANSPORT_TryConnectHandle *tch;
@@ -97,6 +102,11 @@
struct GNUNET_TRANSPORT_Handle *p1th;
/**
+ * The GetCacheHandle for the p1th transport handle
+ */
+ struct GSTGetCacheHandle *gch_p1th;
+
+ /**
* Core handles of the first peer; used to notify when second peer connects
to it
*/
struct GNUNET_CORE_Handle *ch;
@@ -219,11 +229,6 @@
struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
/**
- * The local operation we create for this overlay connection
- */
- struct GNUNET_TESTBED_Operation *lop;
-
- /**
* The transport try connect context
*/
struct TryConnectContext tcc;
@@ -415,9 +420,9 @@
GNUNET_TRANSPORT_disconnect (occ->p1th);
occ->peer->reference_cnt--;
}
- if (NULL != occ->tcc.th)
+ if (NULL != occ->tcc.cgh_th)
{
- GNUNET_TRANSPORT_disconnect (occ->tcc.th);
+ GST_cache_get_handle_done (occ->tcc.cgh_th);
GST_peer_list[occ->other_peer_id]->reference_cnt--;
}
if ((GNUNET_YES == occ->peer->destroy_flag) &&
@@ -590,11 +595,12 @@
return;
GNUNET_assert (NULL == tcc->tch);
GNUNET_assert (NULL != tcc->pid);
- GNUNET_assert (NULL != tcc->th);
+ GNUNET_assert (NULL != tcc->th_);
+ GNUNET_assert (NULL != tcc->cgh_th);
LOG_DEBUG ("0x%llx: Trail %u to connect to peer %s\n", tcc->op_id,
tcc->retries, GNUNET_i2s (tcc->pid));
tcc->tch =
- GNUNET_TRANSPORT_try_connect (tcc->th, tcc->pid, &try_connect_cb, tcc);
+ GNUNET_TRANSPORT_try_connect (tcc->th_, tcc->pid, &try_connect_cb, tcc);
}
@@ -690,7 +696,7 @@
LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n", occ->op_id,
GNUNET_i2s (&occ->peer_identity), other_peer_str);
occ->ohh =
- GNUNET_TRANSPORT_offer_hello (occ->tcc.th, occ->hello,
+ GNUNET_TRANSPORT_offer_hello (occ->tcc.th_, occ->hello,
occ_hello_sent_cb, occ);
if (NULL == occ->ohh)
{
@@ -709,6 +715,35 @@
/**
+ * Callback from cache with needed handles set
+ *
+ * @param cls the closure passed to GST_cache_get_handle_transport()
+ * @param ch the handle to CORE. Can be NULL if it is not requested
+ * @param th the handle to TRANSPORT. Can be NULL if it is not requested
+ */
+static void
+p2_transport_connect_cache_callback (void *cls, struct GNUNET_CORE_Handle *ch,
+ struct GNUNET_TRANSPORT_Handle *th)
+{
+ struct OverlayConnectContext *occ = cls;
+
+ if (NULL == th)
+ {
+ GNUNET_asprintf (&occ->emsg, "0x%llx: Cannot connect to TRANSPORT of %s",
+ occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
+ GNUNET_SCHEDULER_cancel (occ->timeout_task);
+ occ->timeout_task =
+ GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
+ return;
+ }
+ occ->tcc.th_ = th;
+ GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s",
+ occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
+ occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
+}
+
+
+/**
* Connects to the transport of the other peer if it is a local peer and
* schedules the send hello task
*
@@ -724,19 +759,13 @@
if (NULL == occ->peer2_controller)
{
GST_peer_list[occ->other_peer_id]->reference_cnt++;
- occ->tcc.th =
- GNUNET_TRANSPORT_connect (GST_peer_list[occ->other_peer_id]->
- details.local.cfg, &occ->other_peer_identity,
- NULL, NULL, NULL, NULL);
- if (NULL == occ->tcc.th)
- {
- GNUNET_asprintf (&occ->emsg, "0x%llx: Cannot connect to TRANSPORT of %s",
- occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
- GNUNET_SCHEDULER_cancel (occ->timeout_task);
- occ->timeout_task =
- GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
- return;
- }
+ occ->tcc.cgh_th =
+ GST_cache_get_handle_transport (occ->other_peer_id,
+ GST_peer_list[occ->other_peer_id]->
+ details.local.cfg,
+ &p2_transport_connect_cache_callback,
+ occ);
+ return;
}
GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s",
occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
@@ -1282,11 +1311,6 @@
static void
cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
{
- if (NULL != rocc->lop)
- {
- GNUNET_TESTBED_operation_release_ (rocc->lop);
- return;
- }
LOG_DEBUG ("0x%llx: Cleaning up rocc\n", rocc->op_id);
if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id)
GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
@@ -1298,7 +1322,8 @@
GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch);
if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task)
GNUNET_SCHEDULER_cancel (rocc->tcc.task);
- GNUNET_TRANSPORT_disconnect (rocc->tcc.th);
+ //GNUNET_TRANSPORT_disconnect (rocc->tcc.th_);
+ GST_cache_get_handle_done (rocc->tcc.cgh_th);
rocc->peer->reference_cnt--;
if ((GNUNET_YES == rocc->peer->destroy_flag) &&
(0 == rocc->peer->reference_cnt))
@@ -1410,7 +1435,7 @@
LOG_DEBUG ("0x%llx: Offering HELLO of peer %4s to local peer with id: %u\n",
rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id);
rocc->ohh =
- GNUNET_TRANSPORT_offer_hello (rocc->tcc.th, rocc->hello,
+ GNUNET_TRANSPORT_offer_hello (rocc->tcc.th_, rocc->hello,
rocc_hello_sent_cb, rocc);
if (NULL == rocc->ohh)
rocc->attempt_connect_task_id =
@@ -1424,52 +1449,32 @@
/**
- * Callback which will be called when remote overlay connect operation is
- * started
+ * Callback from cache with needed handles set
*
- * @param cls the remote overlay connect context
+ * @param cls the closure passed to GST_cache_get_handle_transport()
+ * @param ch the handle to CORE. Can be NULL if it is not requested
+ * @param th the handle to TRANSPORT. Can be NULL if it is not requested
*/
-static void
-opstart_remote_overlay_connect (void *cls)
+static void
+rocc_cache_get_handle_transport_cb (void *cls, struct GNUNET_CORE_Handle *ch,
+ struct GNUNET_TRANSPORT_Handle *th)
{
struct RemoteOverlayConnectCtx *rocc = cls;
-
- GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->timeout_rocc_task_id);
- rocc->tcc.op_id = rocc->op_id;
- rocc->tcc.th =
- GNUNET_TRANSPORT_connect (rocc->peer->details.local.cfg, NULL, rocc,
NULL,
- &transport_connect_notify, NULL);
- if (NULL == rocc->tcc.th)
+
+ if (NULL == th)
{
rocc->timeout_rocc_task_id =
GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc);
return;
}
+ rocc->tcc.th_ = th;
rocc->tcc.pid = &rocc->a_id;
rocc->attempt_connect_task_id =
- GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
- rocc->timeout_rocc_task_id =
- GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
+ GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
}
/**
- * Callback which will be called when remote overlay connect operation is
- * released
- *
- * @param cls the remote overlay connect context
- */
-static void
-oprelease_remote_overlay_connect (void *cls)
-{
- struct RemoteOverlayConnectCtx *rocc = cls;
-
- GNUNET_assert (NULL != rocc->lop);
- rocc->lop = NULL;
- cleanup_rocc (rocc);
-}
-
-/**
* Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
*
* @param cls NULL
@@ -1541,12 +1546,12 @@
rocc->peer->reference_cnt++;
rocc->hello = GNUNET_malloc (hsize);
memcpy (rocc->hello, msg->hello, hsize);
- rocc->lop =
- GNUNET_TESTBED_operation_create_ (rocc, &opstart_remote_overlay_connect,
- &oprelease_remote_overlay_connect);
- /* This operation needs only 1 connection to transport */
- GNUNET_TESTBED_operation_queue_insert2_ (GST_opq_openfds, rocc->lop, 1);
- GNUNET_TESTBED_operation_begin_wait_ (rocc->lop);
+ rocc->tcc.cgh_th = GST_cache_get_handle_transport (peer_id,
+
rocc->peer->details.local.cfg,
+
&rocc_cache_get_handle_transport_cb,
+ rocc);
+ rocc->timeout_rocc_task_id =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25933 - gnunet/src/testbed,
gnunet <=