diff options
Diffstat (limited to 'network-handler')
| -rw-r--r-- | network-handler/CMakeLists.txt | 21 | ||||
| -rw-r--r-- | network-handler/main.cpp | 49 | ||||
| -rw-r--r-- | network-handler/networkhandler.cpp | 32 | ||||
| -rw-r--r-- | network-handler/networkhandler.hpp | 51 | ||||
| -rw-r--r-- | network-handler/nodemanager.cpp | 14 | ||||
| -rw-r--r-- | network-handler/nodemanager.hpp | 56 | ||||
| -rw-r--r-- | network-handler/userclient.cpp | 21 | ||||
| -rw-r--r-- | network-handler/userclient.hpp | 46 |
8 files changed, 0 insertions, 290 deletions
diff --git a/network-handler/CMakeLists.txt b/network-handler/CMakeLists.txt deleted file mode 100644 index 072172e..0000000 --- a/network-handler/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ - -find_package(Boost COMPONENTS system program_options REQUIRED) - -add_executable(network-handler - main.cpp - networkhandler.hpp networkhandler.cpp - userclient.hpp userclient.cpp - nodemanager.hpp nodemanager.cpp -) - -target_compile_options(network-handler - PRIVATE "-std=c++11" -) - -target_link_libraries(network-handler - PRIVATE Boost::boost - PRIVATE Boost::program_options - PRIVATE Boost::system - PRIVATE cmix - PRIVATE cmix-network -) diff --git a/network-handler/main.cpp b/network-handler/main.cpp deleted file mode 100644 index 84de894..0000000 --- a/network-handler/main.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -#include "networkhandler.hpp" -#include "nodemanager.hpp" - -#include <boost/program_options.hpp> - -#include <string> -#include <iostream> -#include <cstdint> - -NodeManager key_exchange_phase(); - -int main(int argc, char* argv[]) { - namespace po = boost::program_options; - - po::options_description desc("Allowed options"); - desc.add_options() - ("help,h", "produce help message.") - ("port,p", po::value<uint16_t>()->default_value(9200), "Set listening port.") - ("enable_v4", po::value<bool>()->default_value(true), "Enable/disable ipv4 accept support.") - ("interface4,4", po::value<std::string>()->default_value("0.0.0.0"), "Set the ipv4 address to listen on.") - ("enable_v6", po::value<bool>()->default_value(true), "Enable/disable ipv6 accept support.") - ("interface6,6", po::value<std::string>()->default_value("::"), "Set the ipv6 address to listen on.") - ("nodes,n", po::value<std::string>(), "Set the node addreses to use in the cmix network.") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - if (vm.count("help")) { - std::cout << desc << "\n"; - return 0; - } - - bool en4 = vm["enable_v4"].as<bool>(); - std::string if4 = vm["interface4"].as<std::string>(); - bool en6 = vm["enable_v6"].as<bool>(); - std::string if6 = vm["interface6"].as<std::string>(); - uint16_t port = vm["port"].as<uint16_t>(); - - NodeManager node_manager({}); - - ListenSettings lsettings{en4, if4, en6, if6, port}; - - NetworkHandler handler(lsettings); - handler.run(); -} - diff --git a/network-handler/networkhandler.cpp b/network-handler/networkhandler.cpp deleted file mode 100644 index 614d270..0000000 --- a/network-handler/networkhandler.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "networkhandler.hpp" - -#include <boost/bind.hpp> -#include <boost/asio/placeholders.hpp> - -#include <memory> -#include <iostream> - -NetworkHandler::NetworkHandler(const ListenSettings& listen_settings) -: io_service() -, server(io_service, listen_settings, [this](boost::asio::ip::tcp::socket&& socket){accept_handler(std::move(socket));}) -, clients() -{} - -void NetworkHandler::accept_handler(boost::asio::ip::tcp::socket&& socket) -{ - std::list<UserClient>::iterator it = clients.emplace(clients.end(), std::move(socket)); - clients.back().on_done( - [this, it]() { - clients.erase(it); - } - ); - - clients.back().receive(); -} - -void NetworkHandler::run() -{ - io_service.run(); -} - - diff --git a/network-handler/networkhandler.hpp b/network-handler/networkhandler.hpp deleted file mode 100644 index e9bb7fa..0000000 --- a/network-handler/networkhandler.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include "server.hpp" -#include "userclient.hpp" - -#include <boost/asio/io_service.hpp> - -#include <list> - -/*! - * \file - */ - -/*! - * \brief The NetworkHandler class - */ -class NetworkHandler -{ - /*! - * \brief io_service - */ - boost::asio::io_service io_service; - - /*! - * \brief server - */ - Server server; - - /*! - * \brief clients - */ - std::list<UserClient> clients; - - /*! - * \brief accept_handler - * \param socket - */ - void accept_handler(boost::asio::ip::tcp::socket&& socket); - -public: - /*! - * \brief NetworkHandler - * \param listen_settings - */ - NetworkHandler(ListenSettings const& listen_settings); - - /*! - * \brief run - */ - void run(); -}; diff --git a/network-handler/nodemanager.cpp b/network-handler/nodemanager.cpp deleted file mode 100644 index 165cb3b..0000000 --- a/network-handler/nodemanager.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "nodemanager.hpp" - -#include "connect.hpp" - -NodeManager::NodeManager(std::vector<ConnectionInfo> connections) -: io_service() -, api(get_curve25519_implementation()) -, key_pair(api.create_key_pair()) -, nodes() -{ - for(auto&& ci : connections) { - nodes.emplace_back(connect(ci.host, ci.port, io_service)); - } -} diff --git a/network-handler/nodemanager.hpp b/network-handler/nodemanager.hpp deleted file mode 100644 index 91d7160..0000000 --- a/network-handler/nodemanager.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include "nodeclient.hpp" -#include "api.h" -#include "curve25519.h" - -#include <list> - -/*! - * \file - */ - -/*! - * \brief The ConnectionInfo struct - */ -struct ConnectionInfo { - std::string host; ///< The host - std::string port; ///< The port -}; - -/*! - * \brief The NodeManager class - * - * This class will probably never be fleshed out. - */ -class NodeManager -{ - /*! - * \brief io_service - */ - boost::asio::io_service io_service; - - /*! - * \brief api - */ - Api api; - - /*! - * \brief key_pair - */ - KeyPair key_pair; - - /*! - * \brief nodes - */ - std::list<NodeClient> nodes; -public: - - /*! - * \brief NodeManager - * \param connections - */ - NodeManager(std::vector<ConnectionInfo> connections); - - -}; diff --git a/network-handler/userclient.cpp b/network-handler/userclient.cpp deleted file mode 100644 index bf4eaa4..0000000 --- a/network-handler/userclient.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "userclient.hpp" - -#include <iostream> - -void UserClient::handle_message(std::vector<uint8_t> message) -{ - std::cout << std::string(message.begin(), message.end()); -} - -UserClient::UserClient(boost::asio::ip::tcp::socket&& socket) -: client(std::move(socket)) -{} - -void UserClient::receive() -{ - client.receive(std::bind(&UserClient::handle_message, this, std::placeholders::_1)); -} - -void UserClient::on_done(Client::OnDoneFT done) { - client.on_done(done); -} diff --git a/network-handler/userclient.hpp b/network-handler/userclient.hpp deleted file mode 100644 index af810a7..0000000 --- a/network-handler/userclient.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include <boost/asio/ip/tcp.hpp> - -#include "client.hpp" - -/*! - * \file - */ - -/*! - * \brief The UserClient class - */ -class UserClient -{ - /*! - * \brief client - */ - Client client; - - /*! - * \brief handle_message - * \param message - */ - void handle_message(std::vector<uint8_t> message); - -public: - /*! - * \brief UserClient - * \param socket - */ - UserClient(boost::asio::ip::tcp::socket&& socket); - virtual ~UserClient() = default; - - /*! - * \brief receive - */ - void receive(); - - /*! - * \brief on_done - * \param done - */ - void on_done(Client::OnDoneFT done); - -}; |
