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; 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 // Convert to ustring
ustring targetAddressU; ustring targetAddressU;
targetAddressU.fromString(targetAddress); targetAddressU.fromString(targetAddress);
// Convert to PubAddr // Convert to PubAddr
PubAddr pubAddr; PubAddr address;
if (!pubAddr.loadAddr(targetAddressU)) if (!address.loadAddr(targetAddressU))
{ {
return false; return false;
} }
// Request public key! // Resolve our own copy to the registered PubAddr copy in BitMRC if possible
this->BMClient->getPubKey(pubAddr); 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. if (resolvedAddress == nullptr ||
do (!resolvedAddress->waitingPubKey() && resolvedAddress->getPubEncryptionKey().empty()))
{ {
sleep(1000); // Request public key
} while (pubAddr.waitingPubKey()); 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; return true;
} }

View File

@ -19,7 +19,7 @@ namespace Components
void SetDefaultTTL(time_t ttl); void SetDefaultTTL(time_t ttl);
bool RequestPublicKey(std::string targetAddress); bool RequestPublicKey(std::string targetAddress);
bool RequestAndWaitForPublicKey(std::string targetAddress); bool WaitForPublicKey(std::string targetAddress);
bool Subscribe(std::string targetAddress); bool Subscribe(std::string targetAddress);
bool SendMsg(std::string targetAddress, std::string message, time_t ttl = 0); bool SendMsg(std::string targetAddress, std::string message, time_t ttl = 0);
bool SendBroadcast(std::string message, time_t ttl = 0); bool SendBroadcast(std::string message, time_t ttl = 0);
@ -29,6 +29,7 @@ namespace Components
BitMRC* BMClient; BitMRC* BMClient;
private: private:
PubAddr* FindPublicKey(PubAddr addr);
bool InitAddr(); bool InitAddr();
}; };
} }

View File

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