Save remote timestamps in timestamp log file headers

We have the earliest time a message made it across the network in each
log file.  Previously, this was only done for the main data files, so
we'd only get timestamps when our message_bridge_client is connected to
the remote.  We see some logs where we never connect, so we never get
those timestamps.  There is still enough information in the log files to
sort if we fix that.

There are 3 parts to this.
  1) Clarify that we really mean source node for the timestamps, not
     logger node.
  2) Put the timestamps in the log file header
  3) Update the sorting code.

This exposes a bug in the log reader where it can't handle a node
without a start time.  A follow-up commit will fix that, but that can
happen while this is being reviewed.

Change-Id: Iff898dc30ec0fb54d670ea21412d8ad35ab80f4c
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/logging/log_namer.cc b/aos/events/logging/log_namer.cc
index 9a5d038..b41212c 100644
--- a/aos/events/logging/log_namer.cc
+++ b/aos/events/logging/log_namer.cc
@@ -46,11 +46,33 @@
   }
 }
 
-void NewDataWriter::Reboot() {
+void NewDataWriter::Reboot(const UUID &source_node_boot_uuid) {
   parts_uuid_ = UUID::Random();
   ++parts_index_;
   reopen_(this);
   header_written_ = false;
+  for (State &state : state_) {
+    state.boot_uuid = UUID::Zero();
+    state.oldest_remote_monotonic_timestamp = monotonic_clock::max_time;
+    state.oldest_local_monotonic_timestamp = monotonic_clock::max_time;
+    state.oldest_remote_unreliable_monotonic_timestamp =
+        monotonic_clock::max_time;
+    state.oldest_local_unreliable_monotonic_timestamp =
+        monotonic_clock::max_time;
+  }
+
+  state_[node_index_].boot_uuid = source_node_boot_uuid;
+
+  VLOG(1) << "Rebooted " << filename();
+}
+
+void NewDataWriter::UpdateBoot(const UUID &source_node_boot_uuid) {
+  if (state_[node_index_].boot_uuid != source_node_boot_uuid) {
+    state_[node_index_].boot_uuid = source_node_boot_uuid;
+    if (header_written_) {
+      Reboot(source_node_boot_uuid);
+    }
+  }
 }
 
 void NewDataWriter::UpdateRemote(
@@ -77,7 +99,6 @@
     rotate = true;
   }
 
-
   // Did the unreliable timestamps change?
   if (!reliable) {
     if (state.oldest_remote_unreliable_monotonic_timestamp >
@@ -113,18 +134,15 @@
                                  const UUID &source_node_boot_uuid,
                                  aos::monotonic_clock::time_point now) {
   // Trigger a reboot if we detect the boot UUID change.
-  if (state_[node_index_].boot_uuid != source_node_boot_uuid) {
-    state_[node_index_].boot_uuid = source_node_boot_uuid;
-    if (header_written_) {
-      Reboot();
-    }
+  UpdateBoot(source_node_boot_uuid);
 
+  if (!header_written_) {
     QueueHeader(MakeHeader());
   }
 
   // If the start time has changed for this node, trigger a rotation.
   if (log_namer_->monotonic_start_time(node_index_, source_node_boot_uuid) !=
-           monotonic_start_time_) {
+      monotonic_start_time_) {
     CHECK(header_written_);
     Rotate();
   }