From 7bca48bc5b5e37a3a8b0b23e57b88d069fa50589 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Wed, 12 Oct 2016 14:26:12 +0200 Subject: Major network rewrite. One generic class has been introduced to handle all connection types. Typedefs provide Sender Receiver and SenderReceiver types, which limit the functionality of the types. As to not accidentally communicate with the wrong node about things. --- client/node.hpp | 72 --------------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 client/node.hpp (limited to 'client/node.hpp') diff --git a/client/node.hpp b/client/node.hpp deleted file mode 100644 index afcf56a..0000000 --- a/client/node.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include "client.hpp" - -#include "cmix.pb.h" - -#include - -/*! - * \file - */ - -/*! - * MESSAGE_SETTER is a boilerplate macro that generates a setter function for our CMix - * protobuf messages, This because there are seperate functions for each to type to use. - * And there seems no way to solve this using templates. - */ -#define MESSAGE_SETTER(TYPE, NAME) \ -inline void message_setter(cmix_proto::CMixMessage& m, cmix_proto::TYPE const& v) { \ - *m.mutable_##NAME() = v; \ -} \ - -MESSAGE_SETTER(ImAClient, imaclient) -MESSAGE_SETTER(Bye, bye) -MESSAGE_SETTER(KeyExchange, keyexchange) - -#undef MESSAGE_SETTER - -/*! - * \brief The Node class represents a node in the network. - */ -class Node -{ - Client client; -public: - /*! - * \brief Node - * \param socket an rvalue reference to the socket it takes ownership and uses to communicate with the next node in the network. - */ - Node(boost::asio::ip::tcp::socket&& socket); - - /*! - * \brief send - * \param v The CMixMessage type we try to send and first have to wrap in a CMixMessage. - */ - template - void send(T v) { - cmix_proto::CMixMessage m; - message_setter(m, v); - client.send(m.SerializeAsString()); - } - - /*! - * \brief receive - * \param receive_handler - */ - void receive(std::function const&)> receive_handler); - - /*! - * \brief async_connect - * \param next_host The host of the next node. - * \param next_port The port of the next node. - * \param on_connect The callback to call when the connect was succesfull. - */ - void async_connect(std::string next_host, std::string next_port, std::function on_connect); - - /*! - * \brief close This function closes the underlying socket connection. - */ - void close(); -}; - -- cgit v1.2.3-70-g09d2