From f0b4525901aab281c3d2a8c3868574a580644e4f Mon Sep 17 00:00:00 2001 From: /dev/urandom Date: Mon, 29 Aug 2016 08:58:04 +0200 Subject: [PATCH] Properly wait for public key of minidump upload address. --- src/Components/Modules/BitMessage.cpp | 34 +++++++++++++++++++++-- src/Components/Modules/BitMessage.hpp | 2 ++ src/Components/Modules/MinidumpUpload.cpp | 4 ++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/BitMessage.cpp b/src/Components/Modules/BitMessage.cpp index 047d2851..0a7c9d5d 100644 --- a/src/Components/Modules/BitMessage.cpp +++ b/src/Components/Modules/BitMessage.cpp @@ -116,13 +116,13 @@ namespace Components else for (auto& addr : Singleton->BMClient->PubAddresses) { - Logger::Print("%s\n", addr.getAddress().c_str()); + Logger::Print("%s (waiting for public key: %s)\n", addr.getAddress().c_str(), addr.waitingPubKey() ? "yes" : "no"); } mlock.unlock(); }); Command::Add("bm_save", [](Command::Params) { - Singleton->BMClient->save(BITMESSAGE_OBJECT_STORAGE_FILENAME); + Singleton->Save(); }); Command::Add("bm_address_public", [](Command::Params params) { if (params.Length() < 2) return; @@ -187,6 +187,31 @@ namespace Components return true; } + bool BitMessage::RequestAndWaitForPublicKey(std::string targetAddress) + { + // Convert to ustring + ustring targetAddressU; + targetAddressU.fromString(targetAddress); + + // Convert to PubAddr + PubAddr pubAddr; + if (!pubAddr.loadAddr(targetAddressU)) + { + return false; + } + + // Request public key! + this->BMClient->getPubKey(pubAddr); + + // TODO: Wait for public key by using signalling in BitMRC, needs to be done directly in the fork. + do + { + sleep(1000); + } while (pubAddr.waitingPubKey()); + + return true; + } + bool BitMessage::Subscribe(std::string targetAddress) { // Convert to ustring @@ -256,6 +281,11 @@ namespace Components BMClient->addAddr(myAddress); return true; } + + void BitMessage::Save() + { + BMClient->save(); + } } #endif \ No newline at end of file diff --git a/src/Components/Modules/BitMessage.hpp b/src/Components/Modules/BitMessage.hpp index 5c52cd19..a77191b6 100644 --- a/src/Components/Modules/BitMessage.hpp +++ b/src/Components/Modules/BitMessage.hpp @@ -19,9 +19,11 @@ namespace Components void SetDefaultTTL(time_t ttl); bool RequestPublicKey(std::string targetAddress); + bool RequestAndWaitForPublicKey(std::string targetAddress); bool Subscribe(std::string targetAddress); bool SendMsg(std::string targetAddress, std::string message, time_t ttl = 0); bool SendBroadcast(std::string message, time_t ttl = 0); + void Save(); static BitMessage* Singleton; BitMRC* BMClient; diff --git a/src/Components/Modules/MinidumpUpload.cpp b/src/Components/Modules/MinidumpUpload.cpp index 976262a3..7cdc8400 100644 --- a/src/Components/Modules/MinidumpUpload.cpp +++ b/src/Components/Modules/MinidumpUpload.cpp @@ -216,10 +216,12 @@ namespace Components { #ifndef DISABLE_BITMESSAGE // Preload public key for our target that will receive minidumps - if (!BitMessage::Singleton->RequestPublicKey(MinidumpUpload::targetAddress)) + Logger::Print("Waiting for public key for minidump upload address.\n"); + if (!BitMessage::Singleton->RequestAndWaitForPublicKey(MinidumpUpload::targetAddress)) { Logger::Error("Failed to request public key for minidump collection address.\n"); } + BitMessage::Singleton->Save(); #endif // Check if folder exists