diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-28 13:18:18 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-28 13:18:18 +0200 |
| commit | 3fe7a5b6a18b6841ae51f294dc58fe9c8df6d375 (patch) | |
| tree | 345583aaf457ce5076d0d5f7c158628dfd971360 | |
| parent | 85d25eebd38bb278ad598a291a007938854945a4 (diff) | |
| download | cmix-3fe7a5b6a18b6841ae51f294dc58fe9c8df6d375.tar.gz cmix-3fe7a5b6a18b6841ae51f294dc58fe9c8df6d375.tar.bz2 cmix-3fe7a5b6a18b6841ae51f294dc58fe9c8df6d375.zip | |
Finally made a initial doxygen documentation pass over all files.
| -rw-r--r-- | CMakeLists.txt | 5 | ||||
| -rw-r--r-- | Doxyfile.in | 15 | ||||
| -rw-r--r-- | libcmix-crypto/api.h | 34 | ||||
| -rw-r--r-- | libcmix-crypto/curve25519/curve25519.h | 29 | ||||
| -rw-r--r-- | libcmix-crypto/keypair.h | 18 | ||||
| -rw-r--r-- | libcmix-crypto/message.h | 36 | ||||
| -rw-r--r-- | libcmix-crypto/sharedkey.h | 13 | ||||
| -rw-r--r-- | libcmix-network/acceptor.hpp | 32 | ||||
| -rw-r--r-- | libcmix-network/client.hpp | 48 | ||||
| -rw-r--r-- | libcmix-network/connect.cpp | 4 | ||||
| -rw-r--r-- | libcmix-network/connect.hpp | 21 | ||||
| -rw-r--r-- | libcmix-network/nodeclient.hpp | 29 | ||||
| -rw-r--r-- | libcmix-network/server.hpp | 38 | ||||
| -rw-r--r-- | libcmix-network/uriparser.hpp | 39 | ||||
| -rw-r--r-- | libcmix/cmix.h | 10 | ||||
| -rw-r--r-- | liblog/logging.hpp | 8 | ||||
| -rw-r--r-- | network-handler/networkhandler.hpp | 31 | ||||
| -rw-r--r-- | network-handler/nodemanager.cpp | 2 | ||||
| -rw-r--r-- | network-handler/nodemanager.hpp | 35 | ||||
| -rw-r--r-- | network-handler/userclient.hpp | 26 | ||||
| -rw-r--r-- | node/nextnode.hpp | 26 | ||||
| -rw-r--r-- | node/node.cpp | 4 | ||||
| -rw-r--r-- | node/node.hpp | 28 |
23 files changed, 484 insertions, 47 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c1710c..a27da23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules) include(sanitizers) +set(VERSION_MAJOR 0 CACHE STRING "Project major version number.") +set(VERSION_MINOR 0 CACHE STRING "Project minor version number.") +set(VERSION_PATCH 1 CACHE STRING "Project patch version number.") +mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH) + find_package(Doxygen) if(DOXYGEN_FOUND) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) diff --git a/Doxyfile.in b/Doxyfile.in index 0b77583..38915c3 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -1 +1,14 @@ -INPUT = @CMAKE_CURRENT_SOURCE_DIR@/libcmix @CMAKE_CURRENT_SOURCE_DIR@/libcmix-crypto +PROJECT_NAME = "@CMAKE_PROJECT_NAME@" +PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ +STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ \ + @PROJECT_BINARY_DIR@ +INPUT = @doxy_main_page@ \ + @PROJECT_SOURCE_DIR@ +EXCLUDE_PATTERNS = @PROJECT_SOURCE_DIR@/build*/* +FILE_PATTERNS = *.h \ + *.c \ + *.hpp \ + *.cpp +RECURSIVE = YES +USE_MDFILE_AS_MAINPAGE = @doxy_main_page@ +ENABLE_PREPROCESSING = YES diff --git a/libcmix-crypto/api.h b/libcmix-crypto/api.h index a798876..09b474b 100644 --- a/libcmix-crypto/api.h +++ b/libcmix-crypto/api.h @@ -1,5 +1,9 @@ #pragma once +/*! + * \file + */ + #ifdef __cplusplus extern "C" { #endif @@ -9,16 +13,38 @@ extern "C" { #include "keypair.h" #include "sharedkey.h" +/*! + * \brief Defines how a KeyPair create function should look like. + * Used to store a pointer to function to a implementation. + */ typedef struct KeyPair (*KeyPairCreator)(); + +/*! + * \brief Defines how a KeyPair deleter function should look like. + * Used to store a pointer to function to a implementation. + */ typedef void (*KeyPairDeleter)(struct KeyPair); + +/*! + * \brief Defines how a Derived Shared Key function should look like. + * Used to store a pointer to function to a implementation. + */ typedef struct SharedKey (*SharedKeyDeriver)(struct KeyPair, unsigned char*, bool); + +/*! + * \brief Defines how a Derived Shared Key deleter function should look like. + * Used to store a pointer to function to a implementation. + */ typedef void (*SharedKeyDeleter)(struct SharedKey); +/*! + * \brief The Api struct stores pointers to functions of a specific implementation. Like a Curve25519 specific one. + */ struct Api { - KeyPairCreator create_key_pair; - KeyPairDeleter free_key_pair; - SharedKeyDeriver derive_shared_key; - SharedKeyDeleter free_shared_key; + KeyPairCreator create_key_pair; ///< Pointer to keypair creation function + KeyPairDeleter free_key_pair; ///< Pointer to keypair deletor function + SharedKeyDeriver derive_shared_key; ///< Pointer to shared key derivation function + SharedKeyDeleter free_shared_key; ///< Pointer to shared key deleter function }; #ifdef __cplusplus diff --git a/libcmix-crypto/curve25519/curve25519.h b/libcmix-crypto/curve25519/curve25519.h index 19c68e6..8e2ad4e 100644 --- a/libcmix-crypto/curve25519/curve25519.h +++ b/libcmix-crypto/curve25519/curve25519.h @@ -1,17 +1,44 @@ #pragma once +#include "api.h" + #ifdef __cplusplus extern "C" { #endif -#include "api.h" +/*! + * \file + */ +/*! + * \brief curve25519_create_keypair + * \return A curve25519 keypair. + */ extern struct KeyPair curve25519_create_keypair(); +/*! + * \brief curve25519_keypair_deleter + * \param p The keypair to free. + */ extern void curve25519_keypair_deleter(struct KeyPair p); +/*! + * \brief curve25519_derive_shared_key + * \param pair Our keypair. + * \param pub_key The public key of the other party. + * \param swap_pub_order Should we swap the order in which we feed the public keys to the hash function. + * \return A Shared key + */ extern struct SharedKey curve25519_derive_shared_key(struct KeyPair pair, unsigned char* pub_key, bool swap_pub_order); +/*! + * \brief curve25519_shared_key_deleter + * \param s the Shared key to free. + */ extern void curve25519_shared_key_deleter(struct SharedKey s); +/*! + * \brief get_curve25519_implementation + * \return An Api struct filled with a curve25519 implementation. + */ struct Api get_curve25519_implementation(); #ifdef __cplusplus diff --git a/libcmix-crypto/keypair.h b/libcmix-crypto/keypair.h index 9587db3..838291d 100644 --- a/libcmix-crypto/keypair.h +++ b/libcmix-crypto/keypair.h @@ -1,16 +1,26 @@ #pragma once +/*! + * \file + */ + #ifdef __cplusplus extern "C" { #endif #include <stdlib.h> +/*! + * \brief The KeyPair struct contains the private and public key, and the private and public key lengths. + * + * Is used as a generic storage container for multiple implementations. So the implementations are + * responsible for memory meanagement. See the Api struct for examples of this. + */ struct KeyPair { - unsigned char* sec; - unsigned char* pub; - unsigned int sec_len; - unsigned int pub_len; + unsigned char* sec; ///< Private key + unsigned char* pub; ///< Public key + unsigned int sec_len; ///< Private key length + unsigned int pub_len; ///< Public key length }; diff --git a/libcmix-crypto/message.h b/libcmix-crypto/message.h index 7222d00..b1c3b87 100644 --- a/libcmix-crypto/message.h +++ b/libcmix-crypto/message.h @@ -1,5 +1,9 @@ #pragma once +/** + * \file + */ + #ifdef __cplusplus extern "C" { #endif @@ -7,16 +11,33 @@ extern "C" { #include <stddef.h> #include <stdlib.h> +/*! + * Defines how a cMix Buffer allocater should look like. + */ typedef char*(*CmixBufferAllocator)(size_t); +/*! + * Defines how a cMix Buffer deallocater should look like. + */ typedef void(*CmixBufferDeallocator)(void*); +/*! + * Defines how the function looks like that returns the length of one message in this buffer implementation. + */ typedef size_t(*CmixBufferMessageLength)(); +/*! + * \brief The CmixBufferImpl struct + */ struct CmixBufferImpl { - CmixBufferAllocator allocate_cmix_buffer; - CmixBufferDeallocator deallocate_cmix_buffer; - CmixBufferMessageLength message_length; + CmixBufferAllocator allocate_cmix_buffer; ///< pointer to function to implementation specific allocater. + CmixBufferDeallocator deallocate_cmix_buffer; ///< pointer to function to implementation specific deallocater. + CmixBufferMessageLength message_length; ///< pointer to function to implementation specific function returning message length. }; +/*! + * \def DEFINE_CIPHER(NAME, MESSAGE_SIZE) + * Generates some cipher specific boilerplate for manipulating the message buffer. + */ + #define DEFINE_CIPHER(NAME, MESSAGE_SIZE)\ typedef char NAME ## Message[MESSAGE_SIZE];\ \ @@ -40,8 +61,15 @@ struct CmixBufferImpl get_cmix_ ## NAME ## _buffer_implementation() {\ };\ } +/*! + * #DEFINE_CIPHER(Null, 0) + */ DEFINE_CIPHER(Null, 0) -DEFINE_CIPHER(Curve25519, 20); + +/*! + * #DEFINE_CIPHER(Curve25519, 31) + */ +DEFINE_CIPHER(Curve25519, 31) #undef DEFINE_CIPHER diff --git a/libcmix-crypto/sharedkey.h b/libcmix-crypto/sharedkey.h index 9c959fe..c37ae41 100644 --- a/libcmix-crypto/sharedkey.h +++ b/libcmix-crypto/sharedkey.h @@ -1,12 +1,21 @@ #pragma once +/*! + * \file + */ + #ifdef __cplusplus extern "C" { #endif +/*! + * \brief The SharedKey struct. + * + * Stored the derived shared secret after for instance Diffie-Hellman. + */ struct SharedKey { - unsigned char* shared; - unsigned int shared_len; + unsigned char* shared; ///< The Shared key. + unsigned int shared_len; ///< The shared key length. }; #ifdef __cplusplus diff --git a/libcmix-network/acceptor.hpp b/libcmix-network/acceptor.hpp index 7d8e0a2..06b709d 100644 --- a/libcmix-network/acceptor.hpp +++ b/libcmix-network/acceptor.hpp @@ -4,15 +4,47 @@ #include <functional> +/*! + * \file + */ + +/*! + * \brief The Acceptor class + * + * Encapsulates an endpoint and an acceptor. + * Otherwise they would be side to side in the Server class. + */ class Acceptor{ boost::asio::ip::tcp::acceptor acceptor; boost::asio::ip::tcp::endpoint endpoint; public: + /*! + * \brief Acceptor + * \param io_service The io_service to associate with + * \param address The listen address + * \param port The listen port + */ Acceptor(boost::asio::io_service& io_service, boost::asio::ip::address address, uint16_t port); + /*! + * \brief get_address + * \return The listening address + */ boost::asio::ip::address get_address() { return endpoint.address(); } + /*! + * \brief bind_v6_and_v4_any + * \param accept_handler Function to call when accepting an incoming connection. + * + * If you want to accept on both ipv6 and ipv any you have to do some special setup. + * This function handles that and starts listening. + */ void bind_v6_and_v4_any(std::function<void(boost::asio::ip::tcp::socket&&)> accept_handler); + + /*! + * \brief setup_listen_socket + * \param accept_handler Function to call when accepting an incoming connection. + */ void setup_listen_socket(std::function<void(boost::asio::ip::tcp::socket&&)> accept_handler); }; diff --git a/libcmix-network/client.hpp b/libcmix-network/client.hpp index 46b989d..981283b 100644 --- a/libcmix-network/client.hpp +++ b/libcmix-network/client.hpp @@ -5,22 +5,66 @@ #include <array> +/*! + * \file + */ + +/*! + * \brief The Client class + */ class Client { public: + /*! + * \brief OnDoneFT Function type of the function being called when this instance is done operating. + */ typedef std::function<void(void)> OnDoneFT; + + /*! + * \brief MessageHandler Function type of the function handling incoming messages. + */ typedef std::function<void(std::vector<uint8_t>)> MessageHandler; protected: + /*! + * \brief socket The socket connection this instance handles. + */ boost::asio::ip::tcp::socket socket; private: + /*! + * \brief buffer Internal private buffer used to receive messages. + */ boost::asio::streambuf buffer; + + /*! + * \brief done The done function being called when this is done operating. + */ OnDoneFT done; + /*! + * \brief handle_receive + * \param message_handler The function to call when a message has been received. + * \param ec A possible error that occured during receiving. + * \param read_bytes The number of bytes read. + */ + void handle_receive(MessageHandler message_handler, boost::system::error_code const& ec, size_t read_bytes); + public: + /*! + * \brief Client + * \param socket An rvalue reference to a socket it will now own and receive from. + */ Client(boost::asio::ip::tcp::socket&& socket); - - void handle_receive(MessageHandler message_handler, boost::system::error_code const& ec, size_t read_bytes); + + /*! + * \brief receive + * \param message_handler The function to call when a message has been received. + */ void receive(MessageHandler message_handler); + + /*! + * \brief on_done sets the done callback. + * \param f The new done callback function. + */ void on_done(OnDoneFT f); }; diff --git a/libcmix-network/connect.cpp b/libcmix-network/connect.cpp index bf200d5..f25ae24 100644 --- a/libcmix-network/connect.cpp +++ b/libcmix-network/connect.cpp @@ -8,11 +8,11 @@ using namespace boost::asio::ip; using boost::asio::io_service; -boost::asio::ip::tcp::socket connect(std::string host, io_service& io_service) { +boost::asio::ip::tcp::socket connect(std::string host, std::string port, io_service& io_service) { boost::asio::ip::basic_resolver<tcp> resolver(io_service); - boost::asio::ip::basic_resolver_query<tcp> query(host, ""); + boost::asio::ip::basic_resolver_query<tcp> query(host, port); for(auto it = resolver.resolve(query); it != boost::asio::ip::tcp::resolver::iterator(); ++it) { diff --git a/libcmix-network/connect.hpp b/libcmix-network/connect.hpp index 071ed9b..0a58115 100644 --- a/libcmix-network/connect.hpp +++ b/libcmix-network/connect.hpp @@ -3,5 +3,24 @@ #include <boost/asio/ip/tcp.hpp> #include <boost/asio/io_service.hpp> -boost::asio::ip::tcp::socket connect(std::string host, boost::asio::io_service& io_service); +/*! + * \file + */ + +/*! + * \brief connect Connects to the supplied endpoint and returns the socket + * \param host The host + * \param port The port + * \param io_service The io_service used for the socket being returned. + * \return + */ +boost::asio::ip::tcp::socket connect(std::string host, std::string port, boost::asio::io_service& io_service); + +/*! + * \brief async_connect Asynchronously connects to the supplied endpoint. + * \param socket The socket on which to invoke the asynchronous connect. + * \param host The host + * \param next_port The port + * \param on_connect The function to call when the connect has succeeded. + */ void async_connect(boost::asio::ip::tcp::socket& socket, std::string host, std::string next_port, std::function<void()> on_connect); diff --git a/libcmix-network/nodeclient.hpp b/libcmix-network/nodeclient.hpp index 9a3799a..ca1ee67 100644 --- a/libcmix-network/nodeclient.hpp +++ b/libcmix-network/nodeclient.hpp @@ -6,15 +6,44 @@ #include <vector> +/*! + * \file + */ + +/*! + * \brief The NodeClient class + */ class NodeClient { + /*! + * \brief client + */ Client client; + + /*! + * \brief handle_message + * \param message + */ void handle_message(std::vector<uint8_t> message); public: + + /*! + * \brief NodeClient + * \param socket + */ NodeClient(boost::asio::ip::tcp::socket&& socket); + virtual ~NodeClient() = default; + /*! + * \brief receive + */ void receive(); + + /*! + * \brief on_done + * \param done + */ void on_done(Client::OnDoneFT done); }; diff --git a/libcmix-network/server.hpp b/libcmix-network/server.hpp index 942cb14..2e5b272 100644 --- a/libcmix-network/server.hpp +++ b/libcmix-network/server.hpp @@ -4,26 +4,54 @@ #include "acceptor.hpp" +/*! + * \file + */ + +/*! + * \brief The ListenSettings struct + */ struct ListenSettings { - bool enable_ipv4; - std::string ipv4_inaddr; - bool enable_ipv6; - std::string ipv6_inaddr; - uint16_t port; + bool enable_ipv4; ///< Should we listen on ipv4 + std::string ipv4_inaddr; ///< listen on this ipv4 address + bool enable_ipv6; ///< Should we listen on ipv6 + std::string ipv6_inaddr; ///< listen on this ipv6 address + uint16_t port; ///< listen on this port. }; +/*! + * \brief The Server class + */ class Server { public: + /*! + * \brief AcceptHandler + */ typedef std::function<void(boost::asio::ip::tcp::socket&& socket)> AcceptHandler; private: + /*! + * \brief listen_settings + */ ListenSettings const& listen_settings; + /*! + * \brief v4_acceptor + */ Acceptor v4_acceptor; + /*! + * \brief v6_acceptor + */ Acceptor v6_acceptor; public: + /*! + * \brief Server + * \param io_service The io_service this server will use for all its connections. + * \param listen_settings The parameters used for determining on what endpoints to listen. + * \param accept_handler The function to call when connections are established. + */ Server(boost::asio::io_service& io_service, ListenSettings const& listen_settings, AcceptHandler accept_handler); }; diff --git a/libcmix-network/uriparser.hpp b/libcmix-network/uriparser.hpp index c46b70a..dd439fb 100644 --- a/libcmix-network/uriparser.hpp +++ b/libcmix-network/uriparser.hpp @@ -4,16 +4,31 @@ #include <regex> #include <iostream> +/*! + * \file + */ + +/*! + * \brief The Uri struct + */ + struct Uri { - std::string scheme; - std::string username; - std::string password; - std::string host; - std::string port; - std::string query; - std::string hash; + std::string scheme; ///< The URI scheme + std::string username; ///< The URI username + std::string password; ///< The URI password + std::string host; ///< The URI host + std::string port; ///< The URI port + std::string query; ///< The URI query + std::string hash; ///< The URI hash }; +/*! + * \brief parse_uri + * \param str The string that contains a URI. + * It must be a valid URI, this function will to do no validation. + * There may be no leading or trailing whitespace + * \return The corresponding URI struct. + */ Uri parse_uri(std::string str) { std::string scheme = "(?:(.+?)://)?"; std::string uname_pass = "(?:(.*?)?(?::(.*?))@)?"; @@ -37,6 +52,11 @@ Uri parse_uri(std::string str) { }; } +/*! + * \brief debug_uri Debug function to see the contents of the URI struct. + * \param uri + * \return A Debug string representation of an URI + */ std::string debug_uri(Uri uri) { std::stringstream ss; ss << "scheme: " << uri.scheme << std::endl @@ -49,6 +69,11 @@ std::string debug_uri(Uri uri) { return ss.str(); } +/*! + * \brief uri_to_string + * \param uri + * \return returns the string representation of the URI stored in uri. + */ std::string uri_to_string(Uri uri) { return (!uri.scheme.empty() ? uri.scheme + "://" : "") + diff --git a/libcmix/cmix.h b/libcmix/cmix.h index 517f067..4a4441b 100644 --- a/libcmix/cmix.h +++ b/libcmix/cmix.h @@ -2,7 +2,7 @@ extern "C" { #endif -/** +/*! * \file */ @@ -17,7 +17,7 @@ struct CMixBuffer { unsigned int message_length; ///< The length of each message in the buffer }; -/** +/*! * \brief The cmix_error enum describes the output state of a each of the cmix functions */ enum cmix_error { @@ -25,14 +25,14 @@ enum cmix_error { index_out_of_range = 1000 }; -/** +/*! * \brief permutate mixes the messages before sending the messages. * \param[in,out] b A buffer of \p nr_messages messages, each message of length *message_len* * \return no_error */ enum cmix_error permute(struct CMixBuffer b); -/** +/*! * \brief get_message takes the \p index message of the buffer \p b copies it into \p message * \param[out] message is the output buffer that has to hold at least \p b.message_length bytes. * \param[in] b is the buffer from which to copy the message. @@ -41,7 +41,7 @@ enum cmix_error permute(struct CMixBuffer b); */ enum cmix_error get_message(char* message, struct CMixBuffer b, unsigned int index); -/** +/*! * \brief set_message set the \p index message of the buffer to a copy of \p message. * \param[in] message The message to set the part of the buffer to. * \param[in,out] b The buffer diff --git a/liblog/logging.hpp b/liblog/logging.hpp index 7a4e03e..b06d176 100644 --- a/liblog/logging.hpp +++ b/liblog/logging.hpp @@ -2,5 +2,13 @@ #include <boost/log/trivial.hpp> +/*! + * \file + */ + +/*! + * \brief init_logging Initializes the logging system to log to file. + * \param log_level minimum log level we are interested in. + */ void init_logging(boost::log::trivial::severity_level log_level); diff --git a/network-handler/networkhandler.hpp b/network-handler/networkhandler.hpp index dfa31f1..e9bb7fa 100644 --- a/network-handler/networkhandler.hpp +++ b/network-handler/networkhandler.hpp @@ -7,16 +7,45 @@ #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 index 179f239..165cb3b 100644 --- a/network-handler/nodemanager.cpp +++ b/network-handler/nodemanager.cpp @@ -9,6 +9,6 @@ NodeManager::NodeManager(std::vector<ConnectionInfo> connections) , nodes() { for(auto&& ci : connections) { - nodes.emplace_back(connect(ci.host, io_service)); + nodes.emplace_back(connect(ci.host, ci.port, io_service)); } } diff --git a/network-handler/nodemanager.hpp b/network-handler/nodemanager.hpp index 8f6e7af..91d7160 100644 --- a/network-handler/nodemanager.hpp +++ b/network-handler/nodemanager.hpp @@ -6,17 +6,50 @@ #include <list> +/*! + * \file + */ + +/*! + * \brief The ConnectionInfo struct + */ struct ConnectionInfo { - std::string host; + 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.hpp b/network-handler/userclient.hpp index 5734dd2..af810a7 100644 --- a/network-handler/userclient.hpp +++ b/network-handler/userclient.hpp @@ -4,17 +4,43 @@ #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); }; diff --git a/node/nextnode.hpp b/node/nextnode.hpp index 42206bb..24b93c4 100644 --- a/node/nextnode.hpp +++ b/node/nextnode.hpp @@ -4,13 +4,39 @@ #include <boost/asio/ip/tcp.hpp> +/*! + * \file + */ + +/*! + * \brief The NextNode class represents the next node in the network, will only be sent to. + */ class NextNode : public Client { public: + /*! + * \brief NextNode + * \param socket an rvalue reference to the socket it takes ownership and uses to communicate with the next node in the network. + */ NextNode(boost::asio::ip::tcp::socket&& socket); + /*! + * \brief send + * \param message is the string that is send to the next node. + */ void send(std::string message); + + /*! + * \brief 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 connect(std::string next_host, std::string next_port, std::function<void()> on_connect); + + /*! + * \brief close This function closes the underlying socket connection. + */ void close(); }; diff --git a/node/node.cpp b/node/node.cpp index b33f8a5..958990a 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -28,6 +28,10 @@ Node::~Node() { api.free_key_pair(keypair); } +void Node::run() { + io_service.run(); +} + void Node::accept_handler(boost::asio::ip::tcp::socket&& socket) { clients.emplace_back(std::move(socket)); diff --git a/node/node.hpp b/node/node.hpp index 5668dec..ef9e43c 100644 --- a/node/node.hpp +++ b/node/node.hpp @@ -13,12 +13,22 @@ #include <list> +/*! + * \file + */ + +/*! + * \brief The NodeNetworkSettings struct + */ struct NodeNetworkSettings { - bool is_first; - std::string next_host; - std::string next_port; + 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. }; +/*! + * \brief The Node class + */ class Node { boost::asio::io_service io_service; @@ -39,11 +49,17 @@ class Node void start_initialisation(); 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(); - void run() { - io_service.run(); - } + /*! + * \brief run Starts the underlying io_service + */ + void run(); }; |
