diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-16 21:39:18 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-16 21:39:36 +0200 |
| commit | ba6da37569dde1ed7616c14d591134575e6a6879 (patch) | |
| tree | 5562cad589f8c495bd02e61042cf633cd7f0e706 | |
| parent | c9082aa07394e15cd800bd5ad396c37a2334c98d (diff) | |
| download | cmix-ba6da37569dde1ed7616c14d591134575e6a6879.tar.gz cmix-ba6da37569dde1ed7616c14d591134575e6a6879.tar.bz2 cmix-ba6da37569dde1ed7616c14d591134575e6a6879.zip | |
Updates all the documentation.
Mainly covers the network rewrites.
| -rw-r--r-- | client/cmixclient.hpp | 23 | ||||
| -rw-r--r-- | libcmix-common/cmixprotofunctor.hpp | 35 | ||||
| -rw-r--r-- | libcmix-common/receiver.hpp | 11 | ||||
| -rw-r--r-- | libcmix-common/sender.hpp | 14 | ||||
| -rw-r--r-- | libcmix-common/senderreceiver.hpp | 18 | ||||
| -rw-r--r-- | libcmix-crypto/api.h | 7 | ||||
| -rw-r--r-- | libcmix-crypto/elgamal/elgamal.h | 29 | ||||
| -rw-r--r-- | libcmix-network/client.hpp | 7 | ||||
| -rw-r--r-- | libcmix-network/protobufclient.hpp | 24 | ||||
| -rw-r--r-- | liblog/logging.hpp | 1 |
10 files changed, 162 insertions, 7 deletions
diff --git a/client/cmixclient.hpp b/client/cmixclient.hpp index 1edb08e..d87c4b3 100644 --- a/client/cmixclient.hpp +++ b/client/cmixclient.hpp @@ -11,11 +11,21 @@ #include <string> #include <vector> +/*! + * \file + */ + +/*! + * \brief The NodeDetails struct + */ struct NodeDetails { - std::string host; - std::string port; + std::string host; ///< The host of the node. + std::string port; ///< The port of the node. }; +/*! + * \brief The CMixClient class + */ class CMixClient { struct NodeData { @@ -39,9 +49,16 @@ class CMixClient { void handle_message(int node_id, cmix_proto::CMixMessage message); -public: +public: + /*! + * \brief CMixClient + * \param details A vector of the connectiondetails for the cmix network + */ CMixClient(std::vector<NodeDetails> details); ~CMixClient(); + /*! + * \brief run Runs the underlying io_service. + */ void run(); };
\ No newline at end of file diff --git a/libcmix-common/cmixprotofunctor.hpp b/libcmix-common/cmixprotofunctor.hpp index c15f218..c3f6fe9 100644 --- a/libcmix-common/cmixprotofunctor.hpp +++ b/libcmix-common/cmixprotofunctor.hpp @@ -2,17 +2,52 @@ #include "cmix.pb.h" +/*! + * \file + */ + +/*! + * \brief The CMixProtoFunctor struct Is a functor that enables the ProtobufClient to serialize + * all the types you specify below. + */ + struct CMixProtoFunctor { + /*! + * \brief proto_type Typedef that exposes the cmix proto container message. + */ typedef cmix_proto::CMixMessage proto_type; + /*! + * \def MESSAGE_SETTER_DECL(TYPE) + * Generates a message setter declaration for the Protobuf type in TYPE. + */ #define MESSAGE_SETTER_DECL(TYPE) \ proto_type operator()(cmix_proto::TYPE const& v) + /*! + * #MESSAGE_SETTER_DECL(Initialization) + */ MESSAGE_SETTER_DECL(Initialization); + + /*! + * #MESSAGE_SETTER_DECL(ImANode) + */ MESSAGE_SETTER_DECL(ImANode); + + /*! + * #MESSAGE_SETTER_DECL(ImAClient) + */ MESSAGE_SETTER_DECL(ImAClient); + + /*! + * #MESSAGE_SETTER_DECL(Bye) + */ MESSAGE_SETTER_DECL(Bye); + + /*! + * #MESSAGE_SETTER_DECL(KeyExchange) + */ MESSAGE_SETTER_DECL(KeyExchange); #undef MESSAGE_SETTER diff --git a/libcmix-common/receiver.hpp b/libcmix-common/receiver.hpp index a70cde0..2b05790 100644 --- a/libcmix-common/receiver.hpp +++ b/libcmix-common/receiver.hpp @@ -4,10 +4,21 @@ #include "protobufclient.hpp" +/*! + * \file + */ + struct SenderReceiver; +/*! + * \brief The Receiver struct is a shim around ProtobufClient and only exposes things needed + * for receiving messages. + */ struct Receiver : private ProtobufClient<CMixProtoFunctor> { + /*! + * \brief friend decleration allowing Receivers to be upgraded to SenderReceivers. + */ friend SenderReceiver; using ProtobufClient::ProtobufClient; diff --git a/libcmix-common/sender.hpp b/libcmix-common/sender.hpp index 72f0b3d..ea16a81 100644 --- a/libcmix-common/sender.hpp +++ b/libcmix-common/sender.hpp @@ -4,10 +4,24 @@ #include "protobufclient.hpp" +/*! + * \file + */ + +/*! + * \brief forward declaration for SenderReceiver to allow for the friend declaration. + */ struct SenderReceiver; +/*! + * \brief The Sender struct is a shim around ProtobufClient and only exposes things needed + * for sending messages. + */ struct Sender : private ProtobufClient<CMixProtoFunctor> { + /*! + * The friend declaration that allows for the Sender to be upgraded to a SenderReceiver. + */ friend SenderReceiver; using ProtobufClient::ProtobufClient; diff --git a/libcmix-common/senderreceiver.hpp b/libcmix-common/senderreceiver.hpp index 9a07f78..c7fed3a 100644 --- a/libcmix-common/senderreceiver.hpp +++ b/libcmix-common/senderreceiver.hpp @@ -6,12 +6,28 @@ #include "protobufclient.hpp" +/*! + * \file + */ + +/*! + * \brief The SenderReciever struct is a shim around ProtobufClient and only exposes things needed + * for Sending and Receiving messages. + */ struct SenderReceiver : private ProtobufClient<CMixProtoFunctor> { + /*! + * \brief SenderReceiver Explicit conversion to SenderReceiver + * \param r The Receiver to upgrade + */ explicit SenderReceiver(Receiver&& r); + /*! + * \brief SenderReceiver Explicit conversion to SenderReceiver + * \param s The Sender to upgrade + */ explicit SenderReceiver(Sender&& s); - + using ProtobufClient::ProtobufClient; using ProtobufClient::async_receive; diff --git a/libcmix-crypto/api.h b/libcmix-crypto/api.h index 06afcd2..c6f904f 100644 --- a/libcmix-crypto/api.h +++ b/libcmix-crypto/api.h @@ -47,8 +47,15 @@ struct Api { SharedKeyDeleter free_shared_key; ///< Pointer to shared key deleter function }; +/*! + * A Pointer to function typedef to facilitate multiple implementations. + */ typedef struct Api(*ImplementationGetter)(); +/*! + * \brief get_implementation The pointer to member function variable to implement when + * defining a an implementation + */ extern ImplementationGetter get_implementation; #ifdef __cplusplus diff --git a/libcmix-crypto/elgamal/elgamal.h b/libcmix-crypto/elgamal/elgamal.h index feac7f5..826ea49 100644 --- a/libcmix-crypto/elgamal/elgamal.h +++ b/libcmix-crypto/elgamal/elgamal.h @@ -1,17 +1,46 @@ #pragma once +/*! + * \file + */ + #ifdef __cplusplus extern "C" { #endif #include "api.h" +/*! + * \brief elgamal_create_keypair + * \return The new keypair + */ extern struct KeyPair elgamal_create_keypair(); + +/*! + * \brief elgamal_keypair_deleter + * \param p the keypair to be freed + */ extern void elgamal_keypair_deleter(struct KeyPair p); +/*! + * \brief elgamal_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 elgamal_derive_shared_key(struct KeyPair pair, unsigned char const* pub_key, bool swap_pub_order); + +/*! + * \brief elgamal_shared_key_deleter + * \param s The shared key to be freed. + */ extern void elgamal_shared_key_deleter(struct SharedKey s); +/*! + * \brief get_elgamal_implementation + * \return + */ struct Api get_elgamal_implementation(); #ifdef __cplusplus diff --git a/libcmix-network/client.hpp b/libcmix-network/client.hpp index 4990667..bd66b98 100644 --- a/libcmix-network/client.hpp +++ b/libcmix-network/client.hpp @@ -75,11 +75,10 @@ public: */ void async_connect(std::string next_host, std::string next_port, std::function<void()> on_connect); - inline static void foo() {} - /*! * \brief send sends the string prefixed with it's length over the socket. * \param message The string to be sent. + * \param on_sent The callback to call when the message has been sent. */ template <typename F> void async_send(std::string message, F on_sent) { @@ -125,6 +124,10 @@ public: */ void on_done(OnDoneFT f); + /*! + * \brief is_open + * \return returns true if the underlying socket is opened. + */ bool is_open() const; diff --git a/libcmix-network/protobufclient.hpp b/libcmix-network/protobufclient.hpp index c28c347..247b71f 100644 --- a/libcmix-network/protobufclient.hpp +++ b/libcmix-network/protobufclient.hpp @@ -6,6 +6,15 @@ #include <type_traits> +/*! + * \file + */ + +/*! + * \brief A wrapper around Client that accepts a Functor that can turn specific protobuf messages. + * in to a desired wireformat to serialize and send or receive via the Client. + * \tparam T The Protobuf functor to use when transforming messages. + */ template <typename T> class ProtobufClient : private Client { @@ -14,18 +23,31 @@ public: using Client::operator=; using Client::async_connect; - + /*! + * \brief an async_send wrapper that transforms a specific message to the container message an sends it + * \param value The specific message to send. + * \param on_sent The function to call after succesfully sending the message. + */ template<typename V, typename F> void async_send(V value, F on_sent) { typename T::proto_type m = T()(value); Client::async_send(m.SerializeAsString(), on_sent); } + /*! + * \brief an async_send wrapper, like the above but without the on_sent callback. + * \param value The specific message to send. + */ template<typename V> void async_send(V value) { async_send(value, []{}); } + /*! + * \brief An async_receive wrapper that transforms the wireformat to the protobuf + * container message type. + * \param message_handler The callback to call after receiving a message. + */ template <typename F> void async_receive(F message_handler) { auto f = [message_handler](std::vector<uint8_t> const& buffer) { diff --git a/liblog/logging.hpp b/liblog/logging.hpp index b95ca64..f2aacef 100644 --- a/liblog/logging.hpp +++ b/liblog/logging.hpp @@ -9,6 +9,7 @@ /*! * \brief init_logging Initializes the logging system to log to file. * \param log_level minimum log level we are interested in. + * \param file_name The file name to log to, defaults to "log.log" */ void init_logging(boost::log::trivial::severity_level log_level, std::string file_name = "log"); |
