p2p: Use p2p for updates

This is the main patch for enabling use of p2p for consuming and/or
sharing updates via p2p. Refer to the ddoc and other documentation for
how this works.

BUG=chromium:260426,chromium:273110
TEST=New unit tests + unit tests pass + manual testing
Change-Id: I6bc3bddae1e041ccc176969a651396e8e89cb3f0
Reviewed-on: https://chromium-review.googlesource.com/64829
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.h b/utils.h
index 79b6917..5518da6 100644
--- a/utils.h
+++ b/utils.h
@@ -35,6 +35,16 @@
 // boot mode. Returns false if the boot mode is developer.
 bool IsNormalBootMode();
 
+// Returns true if and only if P2P is allowed for interactive update
+// checks. This is implemented by checking the existence of a marker
+// file that can be created by the following command
+//
+// # touch /mnt/stateful_partition/p2p-allow-interactive
+//
+// This function returns false if the required marker file does not
+// exist or if an error occurred.
+bool IsP2PAllowedForInteractiveChecks();
+
 // Converts a struct timespec representing a number of seconds since
 // the Unix epoch to a base::Time. Sub-microsecond time is rounded
 // down.
@@ -49,6 +59,10 @@
 // Does no escaping, only use this for presentation in error messages.
 std::string StringVectorToString(const std::vector<std::string> &vector);
 
+// Calculates the p2p file id from payload hash and size
+std::string CalculateP2PFileId(const std::string& payload_hash,
+                               size_t payload_size);
+
 // Returns the HWID or an empty string on error.
 std::string GetHardwareClass();