allow peer connect call directly from peer started callback
authorNathan S. Evans <evans@in.tum.de>
Wed, 9 Mar 2011 11:08:00 +0000 (11:08 +0000)
committerNathan S. Evans <evans@in.tum.de>
Wed, 9 Mar 2011 11:08:00 +0000 (11:08 +0000)
src/testing/testing.c

index e6671c99a2f7a605c2f2e2cfffba9ff2cdb66dc5..bfdc30a557f25ac861a0c8acd70f2d21f1e8e109 100644 (file)
@@ -216,6 +216,27 @@ testing_init (void *cls,
 }
 #endif
 
+/**
+ * Notify of a peer being up and running.  Scheduled as a task
+ * so that variables which may need to be set are set before
+ * the connect callback can set up new operations.
+ *
+ * @param cls the testing daemon
+ * @param tc task scheduler context
+ */
+static void
+notify_daemon_started (void *cls,
+                       const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_TESTING_Daemon *d = cls;
+  GNUNET_TESTING_NotifyDaemonRunning cb;
+
+  cb = d->cb;
+  d->cb = NULL;
+  if (NULL != cb)
+    cb (d->cb_cls, &d->id, d->cfg, d, NULL);
+}
+
 /**
  * Finite-state machine for starting GNUnet.
  *
@@ -671,10 +692,11 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     #endif
 
       GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
-      cb = d->cb;
+      GNUNET_SCHEDULER_add_now(&notify_daemon_started, d);
+      /*cb = d->cb;
       d->cb = NULL;
-      if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */
-        cb (d->cb_cls, &d->id, d->cfg, d, NULL);
+      if (NULL != cb)
+        cb (d->cb_cls, &d->id, d->cfg, d, NULL);*/
       d->running = GNUNET_YES;
       d->phase = SP_GET_HELLO;
 #endif