aboutsummaryrefslogtreecommitdiff
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
parent67d933956f062bffef85f3158f7e5e19a13498ab (diff)
Use config file for boostrap nodes, currently set to localhost for debug
-rw-r--r--bootstrap_nodes1
m---------depends/dchat_core0
-rwxr-xr-xrun.sh2
-rw-r--r--src/GtkGif.cpp4
-rw-r--r--src/UserSettingsWindow.cpp2
-rw-r--r--src/Window.cpp51
6 files changed, 52 insertions, 8 deletions
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
-Subproject b0cdf80277d13af47e3abe3470dd8f77b7dd8bc
+Subproject 9506378c0423e4125c3ba208f5843e2c54a3071
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<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);