Index: components/cryptauth/background_eid_generator.cc |
diff --git a/components/cryptauth/background_eid_generator.cc b/components/cryptauth/background_eid_generator.cc |
index 1103e8cba45c9c9676679b41c16b3cf6b76f2104..775741fb0b95952b0c8728698cb4c0c416dc8465 100644 |
--- a/components/cryptauth/background_eid_generator.cc |
+++ b/components/cryptauth/background_eid_generator.cc |
@@ -40,6 +40,18 @@ const BeaconSeed* GetBeaconSeedForTimestamp( |
return nullptr; |
} |
+// Given a list of |eids| and their respective |timestamps|, return a human |
+// readable string for debugging. |
+std::string EidsToDebugString(const std::vector<DataWithTimestamp>& eids) { |
Kyle Horimoto
2017/04/30 03:17:43
Can you make this a static function on DataWithTim
Tim Song
2017/05/01 22:23:38
Done.
|
+ std::stringstream ss; |
+ ss << "["; |
+ for (const DataWithTimestamp& eid : eids) { |
+ ss << "\n (" << eid.start_timestamp_ms << ": " << eid.DataInHex() << "),"; |
+ } |
+ ss << "\n]"; |
+ return ss.str(); |
+} |
+ |
} // namespace |
BackgroundEidGenerator::BackgroundEidGenerator() |
@@ -54,23 +66,24 @@ BackgroundEidGenerator::BackgroundEidGenerator( |
: raw_eid_generator_(std::move(raw_eid_generator)), |
clock_(std::move(clock)) {} |
-std::vector<std::string> BackgroundEidGenerator::GenerateNearestEids( |
+std::vector<DataWithTimestamp> BackgroundEidGenerator::GenerateNearestEids( |
const std::vector<BeaconSeed>& beacon_seeds) const { |
int64_t now_timestamp_ms = clock_->Now().ToJavaTime(); |
- std::vector<std::string> eids; |
+ std::vector<DataWithTimestamp> eids; |
- PA_LOG(INFO) << "Generating EIDs:"; |
for (int i = -kEidLookAhead; i <= kEidLookAhead; ++i) { |
int64_t timestamp_ms = now_timestamp_ms + i * kEidPeriodMs; |
- std::unique_ptr<std::string> eid = GenerateEid(timestamp_ms, beacon_seeds); |
+ std::unique_ptr<DataWithTimestamp> eid = |
+ GenerateEid(timestamp_ms, beacon_seeds); |
if (eid) |
eids.push_back(*eid); |
} |
+ PA_LOG(INFO) << "Generated EIDs: " << EidsToDebugString(eids); |
return eids; |
} |
-std::unique_ptr<std::string> BackgroundEidGenerator::GenerateEid( |
+std::unique_ptr<DataWithTimestamp> BackgroundEidGenerator::GenerateEid( |
int64_t timestamp_ms, |
const std::vector<BeaconSeed>& beacon_seeds) const { |
const BeaconSeed* beacon_seed = |
@@ -88,8 +101,8 @@ std::unique_ptr<std::string> BackgroundEidGenerator::GenerateEid( |
std::string eid = raw_eid_generator_->GenerateEid( |
beacon_seed->data(), start_of_period_ms, nullptr); |
- PA_LOG(INFO) << " " << start_of_period_ms << ": " << eid; |
- return base::MakeUnique<std::string>(eid); |
+ return base::MakeUnique<DataWithTimestamp>(eid, start_of_period_ms, |
+ start_of_period_ms + kEidPeriodMs); |
} |
} // cryptauth |