Sort messages between nodes properly

We used to assume the realtime clocks were in sync.  This isn't
realistic.  Use the timestamps on forwarded messages in each
direction to observe the network latency and the offset between nodes.

Since time is no longer exactly linear with all the adjustments, we need
to redo how events are scheduled.  They can't be converted to the
distributed_clock once.  They need to now be converted every time they
are compared between nodes.

Change-Id: I1888c1e6a12f475c321a73aa020b0dc0bab107b3
diff --git a/aos/configuration.cc b/aos/configuration.cc
index c4f139c..bdbb463 100644
--- a/aos/configuration.cc
+++ b/aos/configuration.cc
@@ -653,9 +653,8 @@
   }
 }
 
-int GetNodeIndex(const Configuration *config, const Node *node) {
-  CHECK(config->has_nodes())
-      << ": Asking for a node from a single node configuration.";
+namespace {
+int GetNodeIndexFromConfig(const Configuration *config, const Node *node) {
   int node_index = 0;
   for (const Node *iterated_node : *config->nodes()) {
     if (iterated_node == node) {
@@ -663,12 +662,39 @@
     }
     ++node_index;
   }
-  LOG(FATAL) << "Node not found in the configuration.";
+  return -1;
+}
+}  // namespace
+
+int GetNodeIndex(const Configuration *config, const Node *node) {
+  if (!MultiNode(config)) {
+    return 0;
+  }
+
+  {
+    int node_index = GetNodeIndexFromConfig(config, node);
+    if (node_index != -1) {
+      return node_index;
+    }
+  }
+
+  const Node *result = GetNode(config, node);
+  CHECK(result != nullptr);
+
+  {
+    int node_index = GetNodeIndexFromConfig(config, node);
+    if (node_index != -1) {
+      return node_index;
+    }
+  }
+
+  LOG(FATAL) << "Node " << FlatbufferToJson(node)
+             << " not found in the configuration.";
 }
 
 std::vector<const Node *> GetNodes(const Configuration *config) {
   std::vector<const Node *> nodes;
-  if (configuration::MultiNode(config)) {
+  if (MultiNode(config)) {
     for (const Node *node : *config->nodes()) {
       nodes.emplace_back(node);
     }