Fix waiting for public key when uploading minidumps.

This commit is contained in:
/dev/urandom 2016-08-29 10:10:37 +02:00
parent c4d1eb8940
commit 4d2d974ede
No known key found for this signature in database
GPG Key ID: 41322B973E0F295E
3 changed files with 53 additions and 13 deletions

View File

@ -188,27 +188,62 @@ namespace Components
return true;
}
bool BitMessage::RequestAndWaitForPublicKey(std::string targetAddress)
PubAddr* BitMessage::FindPublicKey(PubAddr address)
{
std::shared_lock<std::shared_timed_mutex> mlock(Singleton->BMClient->mutex_pub);
PubAddr* retval = nullptr;
for (auto& pubKey : BMClient->PubAddresses)
{
if (pubKey.getVersion() == address.getVersion()) //check same version
{
if ((address.getVersion() >= 4 && pubKey.getTag() == address.getTag()) // version 4+ equality check
|| (pubKey.getRipe() == address.getRipe())) // version 3- equality check
{
retval = &pubKey;
break;
}
}
}
mlock.unlock();
return retval;
}
bool BitMessage::WaitForPublicKey(std::string targetAddress)
{
// Convert to ustring
ustring targetAddressU;
targetAddressU.fromString(targetAddress);
// Convert to PubAddr
PubAddr pubAddr;
if (!pubAddr.loadAddr(targetAddressU))
PubAddr address;
if (!address.loadAddr(targetAddressU))
{
return false;
}
// Request public key!
this->BMClient->getPubKey(pubAddr);
// Resolve our own copy to the registered PubAddr copy in BitMRC if possible
auto resolvedAddress = FindPublicKey(address);
if (resolvedAddress != nullptr &&
!resolvedAddress->waitingPubKey() && !resolvedAddress->getPubEncryptionKey().empty())
return true;
// TODO: Wait for public key by using signalling in BitMRC, needs to be done directly in the fork.
do
if (resolvedAddress == nullptr ||
(!resolvedAddress->waitingPubKey() && resolvedAddress->getPubEncryptionKey().empty()))
{
sleep(1000);
} while (pubAddr.waitingPubKey());
// Request public key
this->BMClient->getPubKey(address);
resolvedAddress = FindPublicKey(address);
}
this->Save();
// TODO: Wait for public key by using signaling in BitMRC, needs to be done directly in the fork.
while (resolvedAddress->waitingPubKey())
{
sleep(1500);
}
this->Save();
return true;
}

View File

@ -19,7 +19,7 @@ namespace Components
void SetDefaultTTL(time_t ttl);
bool RequestPublicKey(std::string targetAddress);
bool RequestAndWaitForPublicKey(std::string targetAddress);
bool WaitForPublicKey(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);
@ -29,6 +29,7 @@ namespace Components
BitMRC* BMClient;
private:
PubAddr* FindPublicKey(PubAddr addr);
bool InitAddr();
};
}

View File

@ -216,12 +216,16 @@ namespace Components
{
#ifndef DISABLE_BITMESSAGE
// Preload public key for our target that will receive minidumps
Logger::Print("Waiting for public key for minidump upload address.\n");
if (!BitMessage::Singleton->RequestAndWaitForPublicKey(MinidumpUpload::targetAddress))
Logger::Print("About to send request for public key for minidump upload address.\n");
if (!BitMessage::Singleton->RequestPublicKey(MinidumpUpload::targetAddress))
{
Logger::Error("Failed to request public key for minidump collection address.\n");
}
BitMessage::Singleton->Save();
Logger::Print("Waiting for public key for minidump upload address.\n");
if (!BitMessage::Singleton->WaitForPublicKey(MinidumpUpload::targetAddress))
{
Logger::Error("Failed to fetch public key for minidump collection address.\n");
}
#endif
// Check if folder exists