#pragma once #include "server.hpp" #include "receiver.hpp" #include "senderreceiver.hpp" #include "sender.hpp" #include "api.h" #include "cmix.pb.h" #include #include /*! * \file */ /*! * \brief The NodeNetworkSettings struct */ struct NodeNetworkSettings { bool is_first; ///< Are we the first node in the network. std::string next_host; ///< Next nodes host. std::string next_port; ///< Next nodes port. std::string certdir; ///< Directory containing trusted certificate authorities. }; /*! * \brief The Node class */ class Node { struct CMixClientData { SharedKey shared_value; }; boost::asio::io_service io_service; std::shared_ptr ctx; Server server; typedef std::list Purgatory; Purgatory purgatory; typedef std::map ClientConnections; ClientConnections clients; typedef std::map ClientData; ClientData data; NodeNetworkSettings network_settings; SSLReceiver prev_node; SSLSender next_node; Api api; KeyPair keypair; std::vector network_key; bool shutting_down; void accept_handler(std::unique_ptr>&& socket, std::shared_ptr ctx); void connect_to_next_node(); void start_precomputation(); void start_initialisation(); void handle_node_initialization(cmix_proto::Initialization const& init); void handle_node_secretkey(cmix_proto::SecretKey const& secret); void handle_node_message(cmix_proto::CMixMessage message); void handle_client_keyexchange(ClientConnections::key_type handle, cmix_proto::KeyExchange ke); void handle_client_bye(ClientConnections::key_type handle, cmix_proto::Bye); void handle_client_message(ClientConnections::key_type handle, cmix_proto::CMixMessage message); void handle_imanode(Purgatory::iterator handle); void handle_imaclient(Purgatory::iterator handle, cmix_proto::ImAClient c); void handle_message(Purgatory::iterator handle, cmix_proto::CMixMessage message); public: /*! * \brief Node * \param listen_settings The listen settings for the accepter. * \param network_settings The network settings containing if we are first and who is the next node. */ Node(ListenSettings const& listen_settings, NodeNetworkSettings network_settings); ~Node(); /*! * \brief run Starts the underlying io_service */ void run(); };