From 3a5f81426395f1468e6d88e98da984a3fc2c2e78 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 30 Dec 2018 15:23:59 +0100 Subject: Use config file for boostrap nodes, currently set to localhost for debug --- bootstrap_nodes | 1 + depends/dchat_core | 2 +- run.sh | 2 +- src/GtkGif.cpp | 4 ++-- src/UserSettingsWindow.cpp | 2 +- src/Window.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 bootstrap_nodes diff --git a/bootstrap_nodes b/bootstrap_nodes new file mode 100644 index 0000000..e56ea71 --- /dev/null +++ b/bootstrap_nodes @@ -0,0 +1 @@ +127.0.0.1 \ No newline at end of file diff --git a/depends/dchat_core b/depends/dchat_core index b0cdf80..9506378 160000 --- a/depends/dchat_core +++ b/depends/dchat_core @@ -1 +1 @@ -Subproject commit b0cdf80277d13af47e3abe3470dd8f77b7dd8bcd +Subproject commit 9506378c0423e4125c3ba208f5843e2c54a30715 diff --git a/run.sh b/run.sh index b78f4e8..3fca183 100755 --- a/run.sh +++ b/run.sh @@ -14,4 +14,4 @@ if [ ! -f ~/.local/share/fonts/Lato-Bold.ttf ]; then fc-cache fi platform=`sibs platform` -env GTK_THEME="css/style.css" ./sibs-build/$platform/debug/dchat +env GTK_THEME=Adwaita:light ./sibs-build/$platform/debug/dchat diff --git a/src/GtkGif.cpp b/src/GtkGif.cpp index 76a6ebe..dc5cc53 100644 --- a/src/GtkGif.cpp +++ b/src/GtkGif.cpp @@ -18,7 +18,7 @@ namespace dchat { unsigned char *pixels = surface->get_data(); surface->flush(); - char *p = (char*)textureData; + unsigned char *p = (unsigned char*)textureData; // TODO: Optimize this for(int i = 0; i < surface->get_stride() * surface->get_height(); i += 4) { @@ -48,4 +48,4 @@ namespace dchat cairo->set_source(surface, 0.0, 0.0); cairo->mask(surface, 0.0, 0.0); } -} \ No newline at end of file +} diff --git a/src/UserSettingsWindow.cpp b/src/UserSettingsWindow.cpp index ac53f7a..8c945ff 100644 --- a/src/UserSettingsWindow.cpp +++ b/src/UserSettingsWindow.cpp @@ -82,7 +82,7 @@ namespace dchat avatarUrlEntry.set_hexpand(true); rightPanel->attach_next_to(avatarUrlEntry, *avatarUrlLabel, Gtk::POS_BOTTOM, 2, 1); - Gtk::Button *resetButton = Gtk::manage(new Gtk::Button("Rest")); + Gtk::Button *resetButton = Gtk::manage(new Gtk::Button("Reset")); resetButton->set_halign(Gtk::ALIGN_END); rightPanel->attach_next_to(*resetButton, avatarUrlEntry, Gtk::POS_BOTTOM, 1, 1); resetButton->signal_clicked().connect([this] 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 getBootstrapNodesFromFile() + { + std::vector result; + auto boostrapNodesConfigFile = Gio::File::create_for_path("bootstrap_nodes"); + auto bootstrapNodesFileContent = boostrapNodesConfigFile->read()->read_bytes(1024 * 10, Glib::RefPtr()); + 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, const char *errMsg) + roomCallbackFuncs.connectCallbackFunc = [this, bootstrapNode](std::shared_ptr 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 sizeDeviationRand(0, 5); -- cgit v1.2.3