gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r25958 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r25958 - gnunet/src/testbed
Date: Thu, 31 Jan 2013 11:11:48 +0100

Author: harsha
Date: 2013-01-31 11:11:48 +0100 (Thu, 31 Jan 2013)
New Revision: 25958

Modified:
   gnunet/src/testbed/gnunet-service-testbed_hc.c
Log:
- deduplicate

Modified: gnunet/src/testbed/gnunet-service-testbed_hc.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed_hc.c      2013-01-31 09:47:21 UTC 
(rev 25957)
+++ gnunet/src/testbed/gnunet-service-testbed_hc.c      2013-01-31 10:11:48 UTC 
(rev 25958)
@@ -94,6 +94,7 @@
    * The GSTCacheGetHandle reposible for creating this context
    */
   struct GSTCacheGetHandle *cgh;
+
 };
 
 
@@ -239,6 +240,7 @@
   unsigned int peer_id;
 };
 
+
 /**
  * Hashmap to maintain cache
  */
@@ -424,14 +426,12 @@
  *
  * @param cls closure
  * @param peer the peer that connected
- * @param ats performance data
- * @param ats_count number of entries in ats (excluding 0-termination)
+ * @param type the type of the handle this notification is for
  */
 static void 
 peer_connect_notify_cb (void *cls,
                         const struct GNUNET_PeerIdentity *peer,
-                        const struct GNUNET_ATS_Information *ats,
-                        uint32_t ats_count)
+                        const enum CacheGetType type)
 {
   struct CacheEntry *entry = cls;
   struct ConnectNotifyContext *ctxt;
@@ -441,6 +441,9 @@
   
   for (ctxt=entry->nctxt_qhead; NULL != ctxt; ctxt=ctxt->next)
   {
+    GNUNET_assert (NULL != ctxt->cgh);
+    if (type != ctxt->cgh->type)
+      continue;
     if (0 == memcmp (ctxt->target, peer, sizeof (struct GNUNET_PeerIdentity)))
       break;
   }
@@ -448,7 +451,6 @@
     return;
   cb = ctxt->cb;
   cb_cls = ctxt->cb_cls;
-  GNUNET_assert (NULL != ctxt->cgh);
   ctxt->cgh->nctxt = NULL;
   GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt);
   GNUNET_free (ctxt);
@@ -456,6 +458,25 @@
 }
 
 
+/**
+ * Function called to notify transport users that another
+ * peer connected to us.
+ *
+ * @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)
+{
+  peer_connect_notify_cb (cls, peer, CGT_TRANSPORT_HANDLE);
+}
+
+
 static void
 opstart_get_handle_transport (void *cls)
 {
@@ -463,11 +484,11 @@
 
   GNUNET_assert (NULL != entry);
   LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id);
-  entry->transport_handle_ = GNUNET_TRANSPORT_connect (entry->cfg,
-                                                      NULL, entry,
-                                                      NULL,
-                                                      &peer_connect_notify_cb,
-                                                      NULL);
+  entry->transport_handle_ = 
+      GNUNET_TRANSPORT_connect (entry->cfg,
+                                NULL, entry,
+                                NULL,
+                                &transport_peer_connect_notify_cb, NULL);
   if (NULL == entry->transport_handle_)
   {
     GNUNET_break (0);
@@ -506,12 +527,27 @@
  * @param server handle to the server, NULL if we failed
  * @param my_identity ID of this peer, NULL if we failed
  */
-static void core_startup_cb (void *cls,
-                             struct GNUNET_CORE_Handle * server,
-                             const struct GNUNET_PeerIdentity *
-                             my_identity)
+static void 
+core_startup_cb (void *cls,
+                 struct GNUNET_CORE_Handle * server,
+                 const struct GNUNET_PeerIdentity *my_identity)
 {
-  GNUNET_break (0);
+  struct CacheEntry *entry = cls;
+
+  if (NULL == my_identity)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  GNUNET_assert (NULL == entry->peer_identity);
+  entry->core_handle = server;
+  entry->peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+  memcpy (entry->peer_identity, my_identity,
+          sizeof (struct GNUNET_PeerIdentity));
+  if (0 == entry->demand)
+    return;
+  if (GNUNET_NO == entry->cgh_qhead->notify_called)
+    entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
 }
 
 
@@ -528,21 +564,8 @@
                       const struct GNUNET_PeerIdentity * peer,
                       const struct GNUNET_ATS_Information * atsi,
                       unsigned int atsi_count)
-{
-  struct CacheEntry *entry = cls;
-
-  if (NULL == peer)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  GNUNET_assert (NULL == entry->peer_identity);
-  entry->peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
-  memcpy (entry->peer_identity, peer, sizeof (struct GNUNET_PeerIdentity));
-  if (0 == entry->demand)
-    return;
-  if (GNUNET_NO == entry->cgh_qhead->notify_called)
-    entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
+{  
+  peer_connect_notify_cb (cls, peer, CGT_TRANSPORT_HANDLE);
 }
 
 
@@ -610,16 +633,19 @@
   case CGT_TRANSPORT_HANDLE:
     entry = cache_lookup_handles (&key, (struct GNUNET_TRANSPORT_Handle **)
                                   &handle, NULL);
+    if (NULL != handle)
+      LOG_DEBUG ("Found TRANSPORT handle in cache for peer %u\n", 
entry->peer_id);
     break;
   case CGT_CORE_HANDLE:
     entry = cache_lookup_handles (&key, NULL, 
                                   (struct GNUNET_CORE_Handle **) &handle);
+    if (NULL != handle)
+      LOG_DEBUG ("Found CORE handle in cache for peer %u\n", entry->peer_id);
     break;
   }
   if (NULL != handle)
   {
     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);
   }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]