Handle null node in SimulatedEventLoopFactory better

Our tools need to deal with both a world with and without nodes.  The
easy way to do that is to allow nullptr as a node in more places to
signal that we are in a single node world.

Change-Id: I6dcbe5c1bd721d6417d30e74b79f861d741970df
diff --git a/aos/events/logging/logger_test.cc b/aos/events/logging/logger_test.cc
index 4feb401..91190e7 100644
--- a/aos/events/logging/logger_test.cc
+++ b/aos/events/logging/logger_test.cc
@@ -70,6 +70,8 @@
   // log file.
   reader.Register(&log_reader_factory);
 
+  EXPECT_EQ(log_reader_factory.node(), nullptr);
+
   std::unique_ptr<EventLoop> test_event_loop =
       log_reader_factory.MakeEventLoop("log_reader");
 
@@ -207,6 +209,8 @@
   }
 
   LogReader reader(logfile);
+  ASSERT_NE(reader.node(), nullptr);
+  EXPECT_EQ(reader.node()->name()->string_view(), "pi1");
 
   // TODO(austin): Also replay as pi2 or pi3 and make sure we see the pong
   // messages.  This won't work today yet until the log reading code gets
diff --git a/aos/events/simulated_event_loop.cc b/aos/events/simulated_event_loop.cc
index af0c02b..1dfb3af 100644
--- a/aos/events/simulated_event_loop.cc
+++ b/aos/events/simulated_event_loop.cc
@@ -739,29 +739,25 @@
 
 SimulatedEventLoopFactory::SimulatedEventLoopFactory(
     const Configuration *configuration, std::string_view node_name)
-    : configuration_(CHECK_NOTNULL(configuration)),
-      node_(configuration::GetNode(configuration, node_name)) {
-  CHECK(configuration_->has_nodes())
-      << ": Got a configuration with no nodes and node \"" << node_name
-      << "\" was selected.";
-  CHECK(node_ != nullptr) << ": Can't find node \"" << node_name
-                          << "\" in the configuration.";
-}
+    : SimulatedEventLoopFactory(
+          configuration, configuration::GetNode(configuration, node_name)) {}
 
 SimulatedEventLoopFactory::SimulatedEventLoopFactory(
     const Configuration *configuration, const Node *node)
     : configuration_(CHECK_NOTNULL(configuration)), node_(node) {
-  CHECK(configuration_->has_nodes())
-      << ": Got a configuration with no nodes and node \""
-      << node->name()->string_view() << "\" was selected.";
-  bool found = false;
-  for (const Node *node : *configuration_->nodes()) {
-    if (node == node_) {
-      found = true;
-      break;
+  if (node != nullptr) {
+    CHECK(configuration_->has_nodes())
+        << ": Got a configuration with no nodes and node \""
+        << node->name()->string_view() << "\" was selected.";
+    bool found = false;
+    for (const Node *node : *configuration_->nodes()) {
+      if (node == node_) {
+        found = true;
+        break;
+      }
     }
+    CHECK(found) << ": node must be a pointer in the configuration.";
   }
-  CHECK(found) << ": node must be a pointer in the configuration.";
 }
 
 SimulatedEventLoopFactory::~SimulatedEventLoopFactory() {}