-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / transport-testing.c
index dcd95053b176f004a79c5744fc01ce23bd514fe6..fd5cc4701d21786f8e2676f48924668f0864f10d 100644 (file)
@@ -104,7 +104,6 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
   if (p->nc != NULL)
     p->nc (p->cb_cls, peer, ats, ats_count);
 
-#if VERBOSE
   char *p2_s;
 
   if (p2 != NULL)
@@ -115,8 +114,6 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
                    "Peers %s connected to peer %u (`%s')\n", p2_s, p->no,
                    GNUNET_i2s (&p->id));
   GNUNET_free (p2_s);
-#endif
-
 
   /* Find ConnectingContext */
   struct ConnectingContext *cc = find_connecting_context (p->tth, p, p2);
@@ -192,26 +189,15 @@ get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message)
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
                                       message, &p->id));
-#if VERBOSE
-  size_t size =
-      GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) message);
-#endif
   GNUNET_free_non_null (p->hello);
   p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message);
 
-#if VERBOSE
-  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
-                   "New HELLO for peer %u (`%s') with size %u\n", p->no,
-                   GNUNET_i2s (&p->id), size);
-#endif
-
   if (p->start_cb != NULL)
   {
-#if VERBOSE
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
                      "Peer %u (`%s') successfully started\n", p->no,
                      GNUNET_i2s (&p->id));
-#endif
+
     p->start_cb (p, p->cb_cls);
     p->start_cb = NULL;
   }
@@ -318,7 +304,8 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
   }
 
   p->arm_proc =
-      GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+      GNUNET_OS_start_process (GNUNET_YES,
+                              NULL, NULL, "gnunet-service-arm",
                                "gnunet-service-arm", "-c", cfgname,
 #if VERBOSE_PEERS
                                "-L", "DEBUG",
@@ -347,7 +334,6 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle
   GNUNET_assert (p->ghh != NULL);
 
   GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p);
-
   return p;
 }
 
@@ -435,7 +421,8 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle
     goto fail;
 
   p->arm_proc =
-      GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+      GNUNET_OS_start_process (GNUNET_YES, 
+                              NULL, NULL, "gnunet-service-arm",
                                "gnunet-service-arm", "-c", cfgname,
 #if VERBOSE_PEERS
                                "-L", "DEBUG",
@@ -513,27 +500,32 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth,
 
   GNUNET_CONTAINER_DLL_remove (tth->p_head, tth->p_tail, p);
 
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
+                   "Peer %u (`%s') stopped \n", p->no,
+                   GNUNET_i2s (&p->id));
+
   GNUNET_free (p);
   p = NULL;
 }
 
 /**
- * Initiate peer p1 to connect to peer p2
- * Get peer p2's HELLO and offer it to p1
- * p1 then tries to connect to p2
+ * Connect the given peers and call the callback when both peers report the
+ * inbound connection. Remarks: start_peer's notify_connect callback can be called
+ * before.
+ *
+ * @param tth transport testing handle
  * @param p1 peer 1
  * @param p2 peer 2
  * @param cb the callback to call when both peers notified that they are connected
- * @param cb_cls callback cls (or a pointer to the
- *        GNUNET_TRANSPORT_TESTING_ConnectRequest itself if null)
- * @return connect context
+ * @param cls callback cls
+ * @return a connect request handle
  */
 GNUNET_TRANSPORT_TESTING_ConnectRequest
-GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
-                                        *tth, struct PeerContext *p1,
+GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth,
+                                        struct PeerContext *p1,
                                         struct PeerContext *p2,
                                         GNUNET_TRANSPORT_TESTING_connect_cb cb,
-                                        void *cb_cls)
+                                        void *cls)
 {
   GNUNET_assert (tth != NULL);
 
@@ -547,8 +539,8 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle
   cc->p2 = p2;
 
   cc->cb = cb;
-  if (cb_cls != NULL)
-    cc->cb_cls = cb_cls;
+  if (cls != NULL)
+    cc->cb_cls = cls;
   else
     cc->cb_cls = cc;
 
@@ -669,7 +661,7 @@ GNUNET_TRANSPORT_TESTING_init ()
       return NULL;
     }
 
-    if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES))
+    if (GNUNET_OK != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES, GNUNET_YES))
       fs = 0;
 
     if (0 != (fs % HOSTKEYFILESIZE))