From 6d00a0dd54d7ac563574a583929c2e99a17a6ae7 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 21 Oct 2018 14:40:36 +0200 Subject: Fix for odhtdb changes --- src/Channel.cpp | 2 +- src/main.cpp | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Channel.cpp b/src/Channel.cpp index 501e5bc..6107a22 100644 --- a/src/Channel.cpp +++ b/src/Channel.cpp @@ -10,7 +10,7 @@ namespace dchat { static Channel *currentChannel; - Channel::Channel(const string &_name, const odhtdb::DatabaseNode &_databaseNodeInfo, User *_localUser, odhtdb::Database *_database) : + Channel::Channel(const string &_name, const odhtdb::DatabaseNode &_databaseNodeInfo, User *_localUser, std::shared_ptr _database) : database(_database), databaseNodeInfo(_databaseNodeInfo), name(_name), diff --git a/src/main.cpp b/src/main.cpp index afdff99..e60f77c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -294,13 +294,13 @@ int main(int argc, char **argv) bool loggedIn = false; sf::Clock lastFocusedTimer; - odhtdb::Database *database = nullptr; + shared_ptr database = nullptr; odhtdb::DatabaseCallbackFuncs callbackFuncs; using LocalUserMessageCallback = function; LocalUserMessageCallback onMessageByLocalUser = nullptr; - callbackFuncs.createNodeCallbackFunc = [&waitingToJoinChannels, &database, &channels, &channelMessageMutex, &waitingToJoin, &localNodeUsers, &lastFocusedTimer](const odhtdb::DatabaseCreateNodeRequest &request) + callbackFuncs.createNodeCallbackFunc = [&waitingToJoinChannels, database, &channels, &channelMessageMutex, &waitingToJoin, &localNodeUsers, &lastFocusedTimer](const odhtdb::DatabaseCreateNodeRequest &request) { lock_guard lock(channelMessageMutex); printf("Create node callback func %s\n", request.nodeHash->toString().c_str()); @@ -398,7 +398,7 @@ int main(int argc, char **argv) } } }; - database = new odhtdb::Database("83.252.53.188", 27130, Cache::getDchatDir(), callbackFuncs); + database = odhtdb::Database::connect("83.252.53.188", 27130, Cache::getDchatDir(), callbackFuncs).get(); auto addSystemMessage = [&lastFocusedTimer](const std::string &msg, bool plainText = true) { @@ -407,7 +407,7 @@ int main(int argc, char **argv) }; // Login to account - Command::add("login", [&localNodeUsers, &database, &channels, &loggedIn, &channelMessageMutex, ¤tUsername, ¤tPassword](const vector &args) + Command::add("login", [&localNodeUsers, database, &channels, &loggedIn, &channelMessageMutex, ¤tUsername, ¤tPassword](const vector &args) { lock_guard lock(channelMessageMutex); if(args.size() != 2) @@ -445,7 +445,7 @@ int main(int argc, char **argv) }); // Register account - Command::add("register", [&localNodeUsers, &database, &channels, &loggedIn, &channelMessageMutex, ¤tUsername, ¤tPassword](const vector &args) + Command::add("register", [&localNodeUsers, database, &channels, &loggedIn, &channelMessageMutex, ¤tUsername, ¤tPassword](const vector &args) { lock_guard lock(channelMessageMutex); if(args.size() != 2) @@ -482,7 +482,7 @@ int main(int argc, char **argv) // TODO: Use database->addData to change channel name // Create channel - Command::add("cc", [&database, &channels, &channelMessageMutex, &loggedIn, &localNodeUsers, ¤tUsername, ¤tPassword, &lastFocusedTimer, addSystemMessage](const vector &args) + Command::add("cc", [database, &channels, &channelMessageMutex, &loggedIn, &localNodeUsers, ¤tUsername, ¤tPassword, &lastFocusedTimer, addSystemMessage](const vector &args) { lock_guard lock(channelMessageMutex); if(args.size() != 1) @@ -515,7 +515,7 @@ int main(int argc, char **argv) }); // Create invite key - Command::add("invite", [&channelMessageMutex, &offlineChannel, &database, addSystemMessage](const vector &args) + Command::add("invite", [&channelMessageMutex, &offlineChannel, database, addSystemMessage](const vector &args) { lock_guard lock(channelMessageMutex); if(args.size() != 0) @@ -552,7 +552,7 @@ int main(int argc, char **argv) keySerializer.add((const u8*)channelNodeHash->getData(), channelNodeHash->getSize()); keySerializer.add((const u8*)encryptionKey->data, odhtdb::ENCRYPTION_KEY_BYTE_SIZE); odhtdb::InfoHash key = odhtdb::Database::getInfoHash(keySerializer.getBuffer().data(), keySerializer.getBuffer().size()); - database->receiveCustomMessage(key, [&channelMessageMutex, encryptionKey, channelEncryptionKey, currentChannel, &database](const void *data, usize size) + database->receiveCustomMessage(key, [&channelMessageMutex, encryptionKey, channelEncryptionKey, currentChannel, database](const void *data, usize size) { // TODO: User can remove channel @currentChannel before we get here, meaning @currentChannel is deleted and would be invalid; causing the program to crash try @@ -599,7 +599,7 @@ int main(int argc, char **argv) }); // Join channel using invite key - Command::add("jc", [&loggedIn, &database, &localNodeUsers, &channelMessageMutex, &waitingToJoin, &waitingToJoinChannels, ¤tUsername, ¤tPassword](const vector &args) + Command::add("jc", [&loggedIn, database, &localNodeUsers, &channelMessageMutex, &waitingToJoin, &waitingToJoinChannels, ¤tUsername, ¤tPassword](const vector &args) { lock_guard lock(channelMessageMutex); if(args.size() != 1) @@ -651,7 +651,7 @@ int main(int argc, char **argv) keySerializer.add((const u8*)encryptionKeyBinRaw.data(), odhtdb::ENCRYPTION_KEY_BYTE_SIZE); odhtdb::InfoHash key = odhtdb::Database::getInfoHash(keySerializer.getBuffer().data(), keySerializer.getBuffer().size()); database->sendCustomMessage(key, serializer.getBuffer().data(), serializer.getBuffer().size(), - [&database, nodeHash, encryptionKey, &waitingToJoinChannels, &channelMessageMutex, keyPair, ¤tUsername, ¤tPassword, &localNodeUsers] + [database, nodeHash, encryptionKey, &waitingToJoinChannels, &channelMessageMutex, keyPair, ¤tUsername, ¤tPassword, &localNodeUsers] (bool gotResponse, const void *data, usize size) { if(!gotResponse) @@ -918,7 +918,7 @@ int main(int argc, char **argv) addSystemMessage(msg); }); - Command::add("clearcache", [&database](const vector &args) + Command::add("clearcache", [database](const vector &args) { printf("Cleared cache (%d bytes)\n", database->clearCache()); }); @@ -1296,7 +1296,6 @@ int main(int argc, char **argv) // We need to wait until our `ping` packet for disconnecting is sent to all channels printf("Shutting down...\n"); this_thread::sleep_for(chrono::seconds(3)); - delete database; return 0; } -- cgit v1.2.3