add pubkey cache

This commit is contained in:
DenioD
2020-06-01 22:21:17 +02:00
parent 21c727efb0
commit 74de61d265
5 changed files with 59 additions and 7 deletions

View File

@@ -260,6 +260,8 @@ void ChatModel::addHeader(QString tx, QString headerbytes)
this->headerMap[tx] = headerbytes; this->headerMap[tx] = headerbytes;
} }
void ChatModel::addrequestZaddr(QString tx, QString requestZaddr) void ChatModel::addrequestZaddr(QString tx, QString requestZaddr)
{ {
this->requestZaddrMap[tx] = requestZaddr; this->requestZaddrMap[tx] = requestZaddr;
@@ -285,6 +287,9 @@ QString ChatModel::getCidByTx(QString tx)
return QString("0xdeadbeef"); return QString("0xdeadbeef");
} }
QString ChatModel::getHeaderByTx(QString tx) QString ChatModel::getHeaderByTx(QString tx)
{ {
for(auto& pair : this->headerMap) for(auto& pair : this->headerMap)
@@ -415,7 +420,7 @@ Tx MainWindow::createTxFromChatPage() {
QString pubkey = "test"; QString pubkey = this->getPubkeyByAddress(addr);
QString passphrase = this->getPassword(); QString passphrase = this->getPassword();
QString hashEncryptionKey = passphrase; QString hashEncryptionKey = passphrase;
int length = hashEncryptionKey.length(); int length = hashEncryptionKey.length();
@@ -474,8 +479,9 @@ Tx MainWindow::createTxFromChatPage() {
////Create the HM for this message ////Create the HM for this message
QString headerbytes = QByteArray(reinterpret_cast<const char*>(header), crypto_secretstream_xchacha20poly1305_HEADERBYTES).toHex(); QString headerbytes = QByteArray(reinterpret_cast<const char*>(header), crypto_secretstream_xchacha20poly1305_HEADERBYTES).toHex();
QString publickeyAlice = QByteArray(reinterpret_cast<const char*>(pk), crypto_kx_PUBLICKEYBYTES).toHex();
QString hmemo= createHeaderMemo(type,cid,myAddr,"",headerbytes); QString hmemo= createHeaderMemo(type,cid,myAddr,publickeyAlice,headerbytes);
/////Ciphertext Memo /////Ciphertext Memo
QString memo = QByteArray(reinterpret_cast<const char*>(ciphertext), CIPHERTEXT_LEN).toHex(); QString memo = QByteArray(reinterpret_cast<const char*>(ciphertext), CIPHERTEXT_LEN).toHex();
@@ -751,6 +757,8 @@ Tx MainWindow::createTxForSafeContactRequest()
QString publicKey = QByteArray(reinterpret_cast<const char*>(pk), crypto_kx_PUBLICKEYBYTES).toHex(); QString publicKey = QByteArray(reinterpret_cast<const char*>(pk), crypto_kx_PUBLICKEYBYTES).toHex();
qDebug()<<"Publickey created Request: "<<publicKey;
QString hmemo= createHeaderMemo(type,cid,myAddr,"", publicKey); QString hmemo= createHeaderMemo(type,cid,myAddr,"", publicKey);

View File

@@ -37,6 +37,7 @@ class ChatModel
std::map<int, std::tuple<QString, QString, QString>> sendrequestMap; std::map<int, std::tuple<QString, QString, QString>> sendrequestMap;
std::map<QString, QString> headerMap; std::map<QString, QString> headerMap;
std::map<QString, QString> AddressbyLabelMap; std::map<QString, QString> AddressbyLabelMap;
public: public:
ChatModel() {}; ChatModel() {};

View File

@@ -910,7 +910,7 @@ void Controller::refreshTransactions() {
QString memo; QString memo;
QString cid; QString cid;
QString headerbytes; QString headerbytes;
QString pubkey; QString publickey;
if (!o["memo"].is_null()) { if (!o["memo"].is_null()) {
memo = QString::fromStdString(o["memo"].get<json::string_t>()); memo = QString::fromStdString(o["memo"].get<json::string_t>());
@@ -953,7 +953,15 @@ void Controller::refreshTransactions() {
headerbytes = ""; headerbytes = "";
} }
qDebug()<<"Headerbytes :"<<headerbytes; if (main->getPubkeyByAddress(address) != QString("0xdeadbeef")){
publickey = main->getPubkeyByAddress(address);
}else{
publickey = "";
}
qDebug()<<"Pubkey :"<<publickey;
int lengthcid = cid.length(); int lengthcid = cid.length();
@@ -1179,8 +1187,9 @@ void Controller::refreshTransactions() {
chatModel->addCid(txid, cid); chatModel->addCid(txid, cid);
chatModel->addrequestZaddr(txid, requestZaddr); chatModel->addrequestZaddr(txid, requestZaddr);
chatModel->addHeader(txid, headerbytes); chatModel->addHeader(txid, headerbytes);
main->addPubkey(requestZaddr, publickey);
} }
if (chatModel->getCidByTx(txid) != QString("0xdeadbeef")){ if (chatModel->getCidByTx(txid) != QString("0xdeadbeef")){
@@ -1207,6 +1216,14 @@ void Controller::refreshTransactions() {
headerbytes = ""; headerbytes = "";
} }
if (main->getPubkeyByAddress(requestZaddr) != QString("0xdeadbeef")){
publickey = main->getPubkeyByAddress(requestZaddr);
}else{
publickey = "";
}
//position = it["position"].get<json::number_integer_t>(); //position = it["position"].get<json::number_integer_t>();
bool isNotarized; bool isNotarized;
@@ -1226,7 +1243,7 @@ void Controller::refreshTransactions() {
cidchar = new char[lengthcid+1]; cidchar = new char[lengthcid+1];
strncpy(cidchar, cid.toLocal8Bit(), lengthcid +1); strncpy(cidchar, cid.toLocal8Bit(), lengthcid +1);
if ((memo.startsWith("{") == false) && (headerbytes > 0)) if ((memo.startsWith("{") == false) && (headerbytes > 0))
{ {
#define MESSAGEAS ((const unsigned char *) cidchar) #define MESSAGEAS ((const unsigned char *) cidchar)
@@ -1298,7 +1315,7 @@ void Controller::refreshTransactions() {
DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item);
}else{ }else{
@@ -1320,6 +1337,7 @@ void Controller::refreshTransactions() {
} }
} }
}
} }
} }
} }

View File

@@ -1062,6 +1062,26 @@ void MainWindow::exportSeed() {
}); });
} }
void MainWindow::addPubkey(QString requestZaddr, QString pubkey)
{
this->pubkeyMap[requestZaddr] = pubkey;
}
QString MainWindow::getPubkeyByAddress(QString requestZaddr)
{
for(auto& pair : this->pubkeyMap)
{
}
if(this->pubkeyMap.count(requestZaddr) > 0)
{
return this->pubkeyMap[requestZaddr];
}
return QString("0xdeadbeef");
}
void MainWindow::exportAllKeys() { void MainWindow::exportAllKeys() {
exportKeys(""); exportKeys("");
} }

View File

@@ -12,6 +12,7 @@ class Controller;
class Settings; class Settings;
class WSServer; class WSServer;
class WormholeClient; class WormholeClient;
class ChatModel;
using json = nlohmann::json; using json = nlohmann::json;
@@ -52,7 +53,11 @@ public:
QString doSendRequestTxValidations(Tx tx); QString doSendRequestTxValidations(Tx tx);
QString getCid(); QString getCid();
QString getPassword(); QString getPassword();
std::map<QString, QString> pubkeyMap;
QString getPubkeyByAddress(QString requestZaddr);
void setPassword(QString Password); void setPassword(QString Password);
void addPubkey(QString requestZaddr, QString pubkey);
void replaceWormholeClient(WormholeClient* newClient); void replaceWormholeClient(WormholeClient* newClient);
bool isWebsocketListening(); bool isWebsocketListening();