From d43289901f679639c537ff3ef70a874a01853e93 Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Fri, 4 Dec 2020 23:37:01 +0100 Subject: [PATCH] Working IPFS network test! --- .vscode/settings.json | 8 +++++++- src/CMakeLists.txt | 6 +++--- src/mainwindow.cc | 4 ++++ src/mainwindow.h | 2 ++ src/menu.h | 4 ++++ src/network.cc | 19 +++++++++++++++++++ src/network.h | 20 ++++++++++++++++++++ 7 files changed, 59 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index aeb60fb..b849ba8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -67,6 +67,12 @@ "bit": "cpp", "cstring": "cpp", "set": "cpp", - "valarray": "cpp" + "valarray": "cpp", + "bitset": "cpp", + "csignal": "cpp", + "forward_list": "cpp", + "unordered_set": "cpp", + "regex": "cpp", + "shared_mutex": "cpp" } } \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3146d80..50147d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,8 @@ set(SOURCES menu.h md-parser.cc md-parser.h + network.cc + network.h render-area.cc render-area.h ) @@ -63,13 +65,11 @@ get_property(CMAKE_BINARY_DIR GLOBAL PROPERTY COMMONMARKER_BINARY_DIR) get_property(CMAKE_EXTENSIONS_BINARY_DIR GLOBAL PROPERTY COMMONMARKER_EXTENSIONS_BINARY_DIR) target_include_directories(${PROJECT_TARGET} PRIVATE - ${PROJECT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR} ${CMAKE_EXTENSIONS_BINARY_DIR} ${GTKMM_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} - lib/commonmarker/src - lib/ipfs-http-client/include + ${PROJECT_SOURCE_DIR}/lib/ipfs-http-client/include ) target_link_directories(${PROJECT_TARGET} PRIVATE diff --git a/src/mainwindow.cc b/src/mainwindow.cc index c1105e9..536c750 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -28,6 +28,10 @@ MainWindow::MainWindow() : m_vbox(Gtk::ORIENTATION_VERTICAL, 0) add(m_vbox); show_all_children(); + // Just an IPFS test! Fetch a resource from the IPFS network + // Assuming you already running a IPFS deamon + network.FetchReadme(); + // Setup parser setupParser(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 280a1c1..47eb46c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -7,6 +7,7 @@ #include #include "render-area.h" #include "menu.h" +#include "network.h" class Parser; @@ -28,6 +29,7 @@ protected: RenderArea m_renderArea; private: Parser *parser; + Network network; void setupParser(); }; diff --git a/src/menu.h b/src/menu.h index 7e9e377..b048870 100644 --- a/src/menu.h +++ b/src/menu.h @@ -1,3 +1,6 @@ +#ifndef MENU_H +#define MENU_H + #include #include #include @@ -32,3 +35,4 @@ protected: private: Gtk::MenuItem* createMenuItem(const Glib::ustring& label_text); }; +#endif \ No newline at end of file diff --git a/src/network.cc b/src/network.cc index e69de29..b7b2a74 100644 --- a/src/network.cc +++ b/src/network.cc @@ -0,0 +1,19 @@ +#include "network.h" + +#include +#include + +Network::Network() +: client("localhost", 5001) +{ +} + +Network::~Network() { +} + +void Network::FetchReadme() { + // Demo ... + std::stringstream contents; + client.FilesGet("/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme", &contents); + std::cout << contents.str() << std::endl; +} \ No newline at end of file diff --git a/src/network.h b/src/network.h index e69de29..fe8d427 100644 --- a/src/network.h +++ b/src/network.h @@ -0,0 +1,20 @@ +#ifndef NETWORK_H +#define NETWORK_H + +#include + +/** + * \class Network + * \brief IPFS Network + */ +class Network +{ +public: + Network(); + virtual ~Network(); + + void FetchReadme(); +private: + ipfs::Client client; +}; +#endif \ No newline at end of file