Browse Source

add pubkey cache

pull/130/head
DenioD 4 years ago
parent
commit
74de61d265
  1. 12
      src/chatmodel.cpp
  2. 1
      src/chatmodel.h
  3. 28
      src/controller.cpp
  4. 20
      src/mainwindow.cpp
  5. 5
      src/mainwindow.h

12
src/chatmodel.cpp

@ -260,6 +260,8 @@ void ChatModel::addHeader(QString tx, QString headerbytes)
this->headerMap[tx] = headerbytes;
}
void ChatModel::addrequestZaddr(QString tx, QString requestZaddr)
{
this->requestZaddrMap[tx] = requestZaddr;
@ -285,6 +287,9 @@ QString ChatModel::getCidByTx(QString tx)
return QString("0xdeadbeef");
}
QString ChatModel::getHeaderByTx(QString tx)
{
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 hashEncryptionKey = passphrase;
int length = hashEncryptionKey.length();
@ -474,8 +479,9 @@ Tx MainWindow::createTxFromChatPage() {
////Create the HM for this message
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
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();
qDebug()<<"Publickey created Request: "<<publicKey;
QString hmemo= createHeaderMemo(type,cid,myAddr,"", publicKey);

1
src/chatmodel.h

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

28
src/controller.cpp

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

20
src/mainwindow.cpp

@ -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() {
exportKeys("");
}

5
src/mainwindow.h

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

Loading…
Cancel
Save