diff options
| -rw-r--r-- | node/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | node/nextnode.cpp | 7 | ||||
| -rw-r--r-- | node/nextnode.hpp | 12 | ||||
| -rw-r--r-- | node/node.cpp | 12 | ||||
| -rw-r--r-- | node/node.hpp | 21 |
5 files changed, 50 insertions, 3 deletions
diff --git a/node/CMakeLists.txt b/node/CMakeLists.txt index 1c3b771..a4e1f09 100644 --- a/node/CMakeLists.txt +++ b/node/CMakeLists.txt @@ -3,6 +3,7 @@ find_package(Boost COMPONENTS system program_options REQUIRED) add_executable(node main.cpp node.hpp node.cpp + nextnode.hpp nextnode.cpp ) target_compile_options(node diff --git a/node/nextnode.cpp b/node/nextnode.cpp new file mode 100644 index 0000000..3045462 --- /dev/null +++ b/node/nextnode.cpp @@ -0,0 +1,7 @@ +#include "nextnode.hpp" + +using namespace boost::asio::ip; + +NextNode::NextNode(tcp::socket&& socket) +: Client(std::move(socket)) +{} diff --git a/node/nextnode.hpp b/node/nextnode.hpp new file mode 100644 index 0000000..c1ce6a1 --- /dev/null +++ b/node/nextnode.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "client.hpp" + +#include <boost/asio/ip/tcp.hpp> + +class NextNode : public Client +{ +public: + NextNode(boost::asio::ip::tcp::socket&& socket); +}; + diff --git a/node/node.cpp b/node/node.cpp index 497a920..4b4bc2b 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -1,10 +1,18 @@ #include "node.hpp" +#include "connect.hpp" -Node::Node(ListenSettings const& listen_settings) +Node::Node(ListenSettings const& listen_settings, NodeNetworkSettings network_settings) : io_service() , server(io_service, listen_settings, [this](boost::asio::ip::tcp::socket&& socket){accept_handler(std::move(socket));}) , clients() -{} +, next_node(connect(network_settings.next_host, network_settings.next_port, io_service)) +, api(get_curve25519_implementation()) +, keypair(api.create_key_pair()) +{ + if(network_settings.is_first) { + start_initialisation(); + } +} void Node::accept_handler(boost::asio::ip::tcp::socket&& socket) { diff --git a/node/node.hpp b/node/node.hpp index 7d30188..9e321df 100644 --- a/node/node.hpp +++ b/node/node.hpp @@ -2,20 +2,39 @@ #include "server.hpp" #include "nodeclient.hpp" +#include "nextnode.hpp" + +#include "api.h" +#include "curve25519.h" #include <boost/asio/io_service.hpp> #include <list> +struct NodeNetworkSettings { + bool is_first; + std::string next_host; + std::string next_port; +}; + class Node { boost::asio::io_service io_service; Server server; std::list<NodeClient> clients; + NextNode next_node; + + Api api; + KeyPair keypair; + void accept_handler(boost::asio::ip::tcp::socket&& socket); + void start_initialisation() { + + } + public: - Node(ListenSettings const& listen_settings); + Node(ListenSettings const& listen_settings, NodeNetworkSettings network_settings); }; |
