p2p: Add P2PManager class

This class makes it simple to use p2p both as a client and a server.

For now, this feature is hidden behind a flag. The intent is that this
flag can be toggled with the crosh command - for now, only the reading
of the flag is implemented - see chromium:260441 for the remaining
work.

BUG=chromium:260426,chromium:260441
TEST=New unit tests + unit tests pass
Change-Id: If1879f4535c8e7e3af7c6d378e6df4054264b794
Reviewed-on: https://chromium-review.googlesource.com/64824
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
diff --git a/utils.cc b/utils.cc
index 248c665..8b4bffe 100644
--- a/utils.cc
+++ b/utils.cc
@@ -1026,6 +1026,36 @@
   return true;
 }
 
+Time TimeFromStructTimespec(struct timespec *ts) {
+  int64 us = static_cast<int64>(ts->tv_sec) * Time::kMicrosecondsPerSecond +
+      static_cast<int64>(ts->tv_nsec) / Time::kNanosecondsPerMicrosecond;
+  return Time::UnixEpoch() + TimeDelta::FromMicroseconds(us);
+}
+
+gchar** StringVectorToGStrv(const vector<string> &vector) {
+  GPtrArray *p = g_ptr_array_new();
+  for (std::vector<string>::const_iterator i = vector.begin();
+       i != vector.end(); ++i) {
+    g_ptr_array_add(p, g_strdup(i->c_str()));
+  }
+  g_ptr_array_add(p, NULL);
+  return reinterpret_cast<gchar**>(g_ptr_array_free(p, FALSE));
+}
+
+string StringVectorToString(const vector<string> &vector) {
+  string str = "[";
+  for (std::vector<string>::const_iterator i = vector.begin();
+       i != vector.end(); ++i) {
+    if (i != vector.begin())
+      str += ", ";
+    str += '"';
+    str += *i;
+    str += '"';
+  }
+  str += "]";
+  return str;
+}
+
 }  // namespace utils
 
 }  // namespace chromeos_update_engine