aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------depends/odhtdb0
-rw-r--r--include/Channel.hpp4
-rw-r--r--src/Channel.cpp2
-rw-r--r--src/main.cpp23
4 files changed, 14 insertions, 15 deletions
diff --git a/depends/odhtdb b/depends/odhtdb
-Subproject acb17dec61717e2577cec9272ce22e2c8f7a285
+Subproject 22abf1aa83b2668f918556491a55947be798f89
diff --git a/include/Channel.hpp b/include/Channel.hpp
index 8c08244..443a722 100644
--- a/include/Channel.hpp
+++ b/include/Channel.hpp
@@ -35,7 +35,7 @@ namespace dchat
class Channel
{
public:
- Channel(const std::string &name, const odhtdb::DatabaseNode &databaseNodeInfo = odhtdb::DatabaseNode(), User *localUser = nullptr, odhtdb::Database *database = nullptr);
+ Channel(const std::string &name, const odhtdb::DatabaseNode &databaseNodeInfo = odhtdb::DatabaseNode(), User *localUser = nullptr, std::shared_ptr<odhtdb::Database> database = nullptr);
virtual ~Channel();
Channel(const Channel& other) = delete;
Channel& operator = (const Channel &other) = delete;
@@ -86,7 +86,7 @@ namespace dchat
private:
void sendPing(u32 pingTimestampSec);
protected:
- odhtdb::Database *database;
+ std::shared_ptr<odhtdb::Database> database;
odhtdb::DatabaseNode databaseNodeInfo;
std::string name;
MessageBoard messageBoard;
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<odhtdb::Database> _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<odhtdb::Database> database = nullptr;
odhtdb::DatabaseCallbackFuncs callbackFuncs;
using LocalUserMessageCallback = function<void(const odhtdb::DatabaseAddNodeRequest &request)>;
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<recursive_mutex> 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, &currentUsername, &currentPassword](const vector<string> &args)
+ Command::add("login", [&localNodeUsers, database, &channels, &loggedIn, &channelMessageMutex, &currentUsername, &currentPassword](const vector<string> &args)
{
lock_guard<recursive_mutex> 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, &currentUsername, &currentPassword](const vector<string> &args)
+ Command::add("register", [&localNodeUsers, database, &channels, &loggedIn, &channelMessageMutex, &currentUsername, &currentPassword](const vector<string> &args)
{
lock_guard<recursive_mutex> 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, &currentUsername, &currentPassword, &lastFocusedTimer, addSystemMessage](const vector<string> &args)
+ Command::add("cc", [database, &channels, &channelMessageMutex, &loggedIn, &localNodeUsers, &currentUsername, &currentPassword, &lastFocusedTimer, addSystemMessage](const vector<string> &args)
{
lock_guard<recursive_mutex> 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<string> &args)
+ Command::add("invite", [&channelMessageMutex, &offlineChannel, database, addSystemMessage](const vector<string> &args)
{
lock_guard<recursive_mutex> 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, &currentUsername, &currentPassword](const vector<string> &args)
+ Command::add("jc", [&loggedIn, database, &localNodeUsers, &channelMessageMutex, &waitingToJoin, &waitingToJoinChannels, &currentUsername, &currentPassword](const vector<string> &args)
{
lock_guard<recursive_mutex> 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, &currentUsername, &currentPassword, &localNodeUsers]
+ [database, nodeHash, encryptionKey, &waitingToJoinChannels, &channelMessageMutex, keyPair, &currentUsername, &currentPassword, &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<string> &args)
+ Command::add("clearcache", [database](const vector<string> &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;
}