aboutsummaryrefslogtreecommitdiff
path: root/src/Window.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-12-30 15:23:59 +0100
committerdec05eba <dec05eba@protonmail.com>2018-12-30 15:24:04 +0100
commit3a5f81426395f1468e6d88e98da984a3fc2c2e78 (patch)
treea8025b09111d197384b72d6c9ea4d5ce7b862562 /src/Window.cpp
parent67d933956f062bffef85f3158f7e5e19a13498ab (diff)
Use config file for boostrap nodes, currently set to localhost for debug
Diffstat (limited to 'src/Window.cpp')
-rw-r--r--src/Window.cpp51
1 files changed, 47 insertions, 4 deletions
diff --git a/src/Window.cpp b/src/Window.cpp
index 4c4aab6..5e4930f 100644
--- a/src/Window.cpp
+++ b/src/Window.cpp
@@ -10,6 +10,37 @@ namespace dchat
const int nodesPerColumn = 10;
const int nodesPerRow = 10;
+ static std::vector<std::string> getBootstrapNodesFromFile()
+ {
+ std::vector<std::string> result;
+ auto boostrapNodesConfigFile = Gio::File::create_for_path("bootstrap_nodes");
+ auto bootstrapNodesFileContent = boostrapNodesConfigFile->read()->read_bytes(1024 * 10, Glib::RefPtr<Gio::Cancellable>());
+ if(!bootstrapNodesFileContent)
+ throw std::runtime_error("Failed to read bootstrap_nodes file");
+
+ gsize start = 0;
+
+ gsize size = bootstrapNodesFileContent->get_size();
+ const unsigned char *data = (const unsigned char*)bootstrapNodesFileContent->get_data(size);
+ for(gsize i = 0; i < size; ++i)
+ {
+ unsigned char c = data[i];
+ if(c == ' ' || c == '\n' || c == '\r' || c == '\t')
+ {
+ gsize length = i - start;
+ if(length > 0)
+ result.push_back(std::string(&data[start], &data[start + length]));
+ start = i + 1;
+ }
+ }
+
+ gsize length = size - start;
+ if(length > 0)
+ result.push_back(std::string(&data[start], &data[start + length]));
+
+ return result;
+ }
+
Window::Window() :
chatWindow(this)
{
@@ -91,15 +122,28 @@ namespace dchat
windowNotification->show("Passwords do not match");
});
+ auto bootstrapNodes = getBootstrapNodesFromFile();
+ if(bootstrapNodes.empty())
+ throw std::runtime_error("No boostrap nodes in boostrap_nodes file");
+
+ std::string msg = "Connecting to first boostrap node: ";
+ msg += bootstrapNodes[0];
+ msg += ":27130";
+ windowNotification->show(msg);
+ std::string *bootstrapNode = new std::string(bootstrapNodes[0]);
+
RoomCallbackFuncs roomCallbackFuncs;
- roomCallbackFuncs.connectCallbackFunc = [this](std::shared_ptr<Rooms> rooms, const char *errMsg)
+ roomCallbackFuncs.connectCallbackFunc = [this, bootstrapNode](std::shared_ptr<Rooms> rooms, const char *errMsg)
{
this->rooms = rooms;
if(rooms)
{
loginWindow.show();
stack.set_visible_child(loginWindow);
- windowNotification->show("Connected to 83.252.53.188:27130");
+ std::string msg = "Connected to ";
+ msg += *bootstrapNode;
+ msg += ":27130";
+ windowNotification->show(msg);
loginWindow.loginUsernameInput.grab_focus();
}
else
@@ -138,8 +182,7 @@ namespace dchat
chatWindow.addInviteRequest(request);
};
- windowNotification->show("Connecting to 83.252.53.188:27130");
- Rooms::connect("83.252.53.188", 27130, roomCallbackFuncs);
+ Rooms::connect(bootstrapNode->c_str(), 27130, roomCallbackFuncs);
backgroundRng.seed(std::random_device()());
std::uniform_int_distribution<std::mt19937::result_type> sizeDeviationRand(0, 5);