Add remote_boot_uuid to Context

This lets us track which boot a message came from and finally fix the
logger relying on ServerStatistics having all the required information
needed to build up the logfile header.

Change-Id: I17fc4c5718d5d69c7a1e154afdd83b1ccb388a8f
diff --git a/aos/network/message_bridge_client_lib.cc b/aos/network/message_bridge_client_lib.cc
index bde8480..a5113a0 100644
--- a/aos/network/message_bridge_client_lib.cc
+++ b/aos/network/message_bridge_client_lib.cc
@@ -250,7 +250,8 @@
                      chrono::nanoseconds(remote_data->monotonic_sent_time())),
                  realtime_clock::time_point(
                      chrono::nanoseconds(remote_data->realtime_sent_time())),
-                 remote_data->queue_index());
+                 remote_data->queue_index(),
+                 UUID::FromVector(remote_data->boot_uuid()));
 
     client_status_->SampleFilter(
         client_index_,
diff --git a/aos/network/message_bridge_server_lib.cc b/aos/network/message_bridge_server_lib.cc
index 7347607..18df3fa 100644
--- a/aos/network/message_bridge_server_lib.cc
+++ b/aos/network/message_bridge_server_lib.cc
@@ -39,6 +39,9 @@
       fbb.CreateVector(static_cast<const uint8_t *>(context.data),
                        context.size);
 
+  flatbuffers::Offset<flatbuffers::Vector<uint8_t>> boot_uuid_offset =
+      context.remote_boot_uuid.PackVector(&fbb);
+
   RemoteData::Builder remote_data_builder(fbb);
   remote_data_builder.add_channel_index(channel_index_);
   remote_data_builder.add_queue_index(context.queue_index);
@@ -47,6 +50,7 @@
   remote_data_builder.add_realtime_sent_time(
       context.realtime_event_time.time_since_epoch().count());
   remote_data_builder.add_data(data_offset);
+  remote_data_builder.add_boot_uuid(boot_uuid_offset);
 
   // TODO(austin): Use an iovec to build it up in 3 parts to avoid the copy?
   // Only useful when not logging.
diff --git a/aos/network/message_bridge_server_status.cc b/aos/network/message_bridge_server_status.cc
index 7788f4a..06f88ed 100644
--- a/aos/network/message_bridge_server_status.cc
+++ b/aos/network/message_bridge_server_status.cc
@@ -355,6 +355,7 @@
   context.realtime_event_time = timestamp_sender_.realtime_sent_time();
   context.queue_index = timestamp_sender_.sent_queue_index();
   context.size = timestamp_copy.span().size();
+  context.remote_boot_uuid = event_loop_->boot_uuid();
   context.data = timestamp_copy.span().data();
 
   // Since we are building up the timestamp to send here, we need to trigger the
diff --git a/aos/network/message_bridge_test.cc b/aos/network/message_bridge_test.cc
index e2dddc4..1b6f594 100644
--- a/aos/network/message_bridge_test.cc
+++ b/aos/network/message_bridge_test.cc
@@ -11,6 +11,8 @@
 #include "aos/util/file.h"
 #include "gtest/gtest.h"
 
+DECLARE_string(boot_uuid);
+
 namespace aos {
 void SetShmBase(const std::string_view base);
 
@@ -47,7 +49,9 @@
  public:
   MessageBridgeParameterizedTest()
       : config(aos::configuration::ReadConfig(
-            absl::StrCat("aos/network/", GetParam().config))) {
+            absl::StrCat("aos/network/", GetParam().config))),
+        pi1_boot_uuid_(UUID::Random()),
+        pi2_boot_uuid_(UUID::Random()) {
     util::UnlinkRecursive(ShmBase("pi1"));
     util::UnlinkRecursive(ShmBase("pi2"));
   }
@@ -57,11 +61,13 @@
   void OnPi1() {
     DoSetShmBase("pi1");
     FLAGS_override_hostname = "raspberrypi";
+    FLAGS_boot_uuid = pi1_boot_uuid_.ToString();
   }
 
   void OnPi2() {
     DoSetShmBase("pi2");
     FLAGS_override_hostname = "raspberrypi2";
+    FLAGS_boot_uuid = pi2_boot_uuid_.ToString();
   }
 
   void MakePi1Server() {
@@ -148,6 +154,12 @@
         "/pi1/aos", [](const Timestamp &timestamp) {
           VLOG(1) << "/pi1/aos Timestamp " << FlatbufferToJson(&timestamp);
         });
+    pi1_test_event_loop->MakeWatcher(
+        "/pi2/aos", [this](const Timestamp &timestamp) {
+          VLOG(1) << "/pi2/aos Timestamp " << FlatbufferToJson(&timestamp);
+          EXPECT_EQ(pi1_test_event_loop->context().remote_boot_uuid,
+                    pi2_boot_uuid_);
+        });
   }
 
   void StartPi1Test() {
@@ -258,6 +270,12 @@
         });
 
     pi2_test_event_loop->MakeWatcher(
+        "/pi1/aos", [this](const Timestamp &timestamp) {
+          VLOG(1) << "/pi1/aos Timestamp " << FlatbufferToJson(&timestamp);
+          EXPECT_EQ(pi2_test_event_loop->context().remote_boot_uuid,
+                    pi1_boot_uuid_);
+        });
+    pi2_test_event_loop->MakeWatcher(
         "/pi2/aos", [](const Timestamp &timestamp) {
           VLOG(1) << "/pi2/aos Timestamp " << FlatbufferToJson(&timestamp);
         });
@@ -276,6 +294,8 @@
   }
 
   aos::FlatbufferDetachedBuffer<aos::Configuration> config;
+  const UUID pi1_boot_uuid_;
+  const UUID pi2_boot_uuid_;
 
   std::unique_ptr<aos::ShmEventLoop> pi1_server_event_loop;
   std::unique_ptr<MessageBridgeServer> pi1_message_bridge_server;
@@ -380,11 +400,12 @@
 
   // Count the pongs.
   int pong_count = 0;
-  pong_event_loop.MakeWatcher(
-      "/test", [&pong_count](const examples::Ping &ping) {
-        ++pong_count;
-        VLOG(1) << "Got ping back " << FlatbufferToJson(&ping);
-      });
+  pong_event_loop.MakeWatcher("/test", [&pong_count, &pong_event_loop,
+                                        this](const examples::Ping &ping) {
+    EXPECT_EQ(pong_event_loop.context().remote_boot_uuid, pi1_boot_uuid_);
+    ++pong_count;
+    VLOG(1) << "Got ping back " << FlatbufferToJson(&ping);
+  });
 
   FLAGS_override_hostname = "";