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..0dba6c3e2551a71788ffa2df4ac1094b5d2fedcf 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<EidDataWithTimestamp>& eids) { |
+ std::stringstream ss; |
+ ss << "["; |
+ for (const EidDataWithTimestamp& eid : eids) { |
+ ss << "\n " << eid.start_timestamp_ms << ": " << eid.DataInHex() << ","; |
Kyle Horimoto
2017/04/28 22:19:16
nit: Can you add parentheses around each EidDataWi
Tim Song
2017/04/29 01:07:50
Done.
|
+ } |
+ ss << "\n]"; |
Kyle Horimoto
2017/04/28 22:19:16
nit: Remove the final comma.
Tim Song
2017/04/29 01:07:50
Done.
|
+ 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<EidDataWithTimestamp> BackgroundEidGenerator::GenerateNearestEids( |
const std::vector<BeaconSeed>& beacon_seeds) const { |
int64_t now_timestamp_ms = clock_->Now().ToJavaTime(); |
- std::vector<std::string> eids; |
+ std::vector<EidDataWithTimestamp> 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<EidDataWithTimestamp> 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<EidDataWithTimestamp> 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<EidDataWithTimestamp>( |
+ eid, start_of_period_ms, start_of_period_ms + kEidPeriodMs); |
} |
} // cryptauth |