Properly wait for public key of minidump upload address.

This commit is contained in:
/dev/urandom 2016-08-29 08:58:04 +02:00
parent e4a1390f2e
commit f0b4525901
No known key found for this signature in database
GPG Key ID: 41322B973E0F295E
3 changed files with 37 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -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